blob: cebd677e712e5bfbac0ef4e847c05cc709b7edc6 [file] [log] [blame]
Paul Bakker38119b12009-01-10 23:31:23 +00001/**
2 * \file camellia.h
3 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief Camellia block cipher
5 *
Paul Bakker84f12b72010-07-18 10:13:04 +00006 * Copyright (C) 2006-2010, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00009 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +000010 *
Paul Bakker77b385e2009-07-28 17:23:11 +000011 * All rights reserved.
Paul Bakker38119b12009-01-10 23:31:23 +000012 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_CAMELLIA_H
28#define POLARSSL_CAMELLIA_H
Paul Bakker477fd322009-10-04 13:22:13 +000029
30#ifdef _MSC_VER
31#include <basetsd.h>
32typedef UINT32 uint32_t;
Paul Bakker80ab9f52009-05-24 14:42:46 +000033#else
Paul Bakker477fd322009-10-04 13:22:13 +000034#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000035#endif
Paul Bakkerc81f6c32009-05-03 13:09:15 +000036
Paul Bakker38119b12009-01-10 23:31:23 +000037#define CAMELLIA_ENCRYPT 1
38#define CAMELLIA_DECRYPT 0
39
Paul Bakker3391b122009-07-28 20:11:54 +000040#define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0a00
Paul Bakkerf3ccc682010-03-18 21:21:02 +000041#define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0a10
Paul Bakker2b222c82009-07-27 21:03:45 +000042
Paul Bakker38119b12009-01-10 23:31:23 +000043/**
44 * \brief CAMELLIA context structure
45 */
46typedef struct
47{
48 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000049 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000050}
51camellia_context;
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/**
58 * \brief CAMELLIA key schedule (encryption)
59 *
60 * \param ctx CAMELLIA context to be initialized
61 * \param key encryption key
62 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000063 *
64 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000065 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000066int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000067
68/**
69 * \brief CAMELLIA key schedule (decryption)
70 *
71 * \param ctx CAMELLIA context to be initialized
72 * \param key decryption key
73 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000074 *
75 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000076 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000077int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000078
79/**
80 * \brief CAMELLIA-ECB block encryption/decryption
81 *
82 * \param ctx CAMELLIA context
83 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
84 * \param input 16-byte input block
85 * \param output 16-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000086 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000087 * \return 0 if successful
Paul Bakker38119b12009-01-10 23:31:23 +000088 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000089int camellia_crypt_ecb( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +000090 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000091 const unsigned char input[16],
Paul Bakker38119b12009-01-10 23:31:23 +000092 unsigned char output[16] );
93
94/**
95 * \brief CAMELLIA-CBC buffer encryption/decryption
Paul Bakker4c067eb2009-05-17 10:25:19 +000096 * Length should be a multiple of the block
97 * size (16 bytes)
Paul Bakker38119b12009-01-10 23:31:23 +000098 *
99 * \param ctx CAMELLIA context
100 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
101 * \param length length of the input data
102 * \param iv initialization vector (updated after use)
103 * \param input buffer holding the input data
104 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000105 *
106 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +0000107 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000108int camellia_crypt_cbc( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000109 int mode,
110 int length,
111 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000112 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000113 unsigned char *output );
114
115/**
116 * \brief CAMELLIA-CFB128 buffer encryption/decryption
117 *
118 * \param ctx CAMELLIA context
119 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
120 * \param length length of the input data
121 * \param iv_off offset in IV (updated after use)
122 * \param iv initialization vector (updated after use)
123 * \param input buffer holding the input data
124 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000125 *
126 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +0000127 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000128int camellia_crypt_cfb128( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000129 int mode,
130 int length,
131 int *iv_off,
132 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000133 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000134 unsigned char *output );
135
136/**
137 * \brief Checkup routine
138 *
139 * \return 0 if successful, or 1 if the test failed
140 */
141int camellia_self_test( int verbose );
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* camellia.h */