blob: 13c8f42c94b31bc28a4190f2bdf2f26c345659a6 [file] [log] [blame]
Paul Bakker38119b12009-01-10 23:31:23 +00001/**
2 * \file camellia.h
3 *
Paul Bakker84f12b72010-07-18 10:13:04 +00004 * Copyright (C) 2006-2010, Brainspark B.V.
5 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakker77b385e2009-07-28 17:23:11 +00006 * All rights reserved.
Paul Bakker38119b12009-01-10 23:31:23 +00007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22#ifndef POLARSSL_CAMELLIA_H
23#define POLARSSL_CAMELLIA_H
Paul Bakker477fd322009-10-04 13:22:13 +000024
25#ifdef _MSC_VER
26#include <basetsd.h>
27typedef UINT32 uint32_t;
Paul Bakker80ab9f52009-05-24 14:42:46 +000028#else
Paul Bakker477fd322009-10-04 13:22:13 +000029#include <inttypes.h>
Paul Bakker80ab9f52009-05-24 14:42:46 +000030#endif
Paul Bakkerc81f6c32009-05-03 13:09:15 +000031
Paul Bakker38119b12009-01-10 23:31:23 +000032#define CAMELLIA_ENCRYPT 1
33#define CAMELLIA_DECRYPT 0
34
Paul Bakker3391b122009-07-28 20:11:54 +000035#define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0a00
Paul Bakkerf3ccc682010-03-18 21:21:02 +000036#define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0a10
Paul Bakker2b222c82009-07-27 21:03:45 +000037
Paul Bakker38119b12009-01-10 23:31:23 +000038/**
39 * \brief CAMELLIA context structure
40 */
41typedef struct
42{
43 int nr; /*!< number of rounds */
Paul Bakkerc81f6c32009-05-03 13:09:15 +000044 uint32_t rk[68]; /*!< CAMELLIA round keys */
Paul Bakker38119b12009-01-10 23:31:23 +000045}
46camellia_context;
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/**
53 * \brief CAMELLIA key schedule (encryption)
54 *
55 * \param ctx CAMELLIA context to be initialized
56 * \param key encryption key
57 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000058 *
59 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000060 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000061int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000062
63/**
64 * \brief CAMELLIA key schedule (decryption)
65 *
66 * \param ctx CAMELLIA context to be initialized
67 * \param key decryption key
68 * \param keysize must be 128, 192 or 256
Paul Bakker2b222c82009-07-27 21:03:45 +000069 *
70 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +000071 */
Paul Bakkerff60ee62010-03-16 21:09:09 +000072int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, int keysize );
Paul Bakker38119b12009-01-10 23:31:23 +000073
74/**
75 * \brief CAMELLIA-ECB block encryption/decryption
76 *
77 * \param ctx CAMELLIA context
78 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
79 * \param input 16-byte input block
80 * \param output 16-byte output block
Paul Bakkerf3ccc682010-03-18 21:21:02 +000081 *
Paul Bakker27caa8a2010-03-21 15:43:59 +000082 * \return 0 if successful
Paul Bakker38119b12009-01-10 23:31:23 +000083 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +000084int camellia_crypt_ecb( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +000085 int mode,
Paul Bakkerff60ee62010-03-16 21:09:09 +000086 const unsigned char input[16],
Paul Bakker38119b12009-01-10 23:31:23 +000087 unsigned char output[16] );
88
89/**
90 * \brief CAMELLIA-CBC buffer encryption/decryption
Paul Bakker4c067eb2009-05-17 10:25:19 +000091 * Length should be a multiple of the block
92 * size (16 bytes)
Paul Bakker38119b12009-01-10 23:31:23 +000093 *
94 * \param ctx CAMELLIA context
95 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
96 * \param length length of the input data
97 * \param iv initialization vector (updated after use)
98 * \param input buffer holding the input data
99 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000100 *
101 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +0000102 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000103int camellia_crypt_cbc( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000104 int mode,
105 int length,
106 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000107 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000108 unsigned char *output );
109
110/**
111 * \brief CAMELLIA-CFB128 buffer encryption/decryption
112 *
113 * \param ctx CAMELLIA context
114 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
115 * \param length length of the input data
116 * \param iv_off offset in IV (updated after use)
117 * \param iv initialization vector (updated after use)
118 * \param input buffer holding the input data
119 * \param output buffer holding the output data
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000120 *
121 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
Paul Bakker38119b12009-01-10 23:31:23 +0000122 */
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000123int camellia_crypt_cfb128( camellia_context *ctx,
Paul Bakker38119b12009-01-10 23:31:23 +0000124 int mode,
125 int length,
126 int *iv_off,
127 unsigned char iv[16],
Paul Bakkerff60ee62010-03-16 21:09:09 +0000128 const unsigned char *input,
Paul Bakker38119b12009-01-10 23:31:23 +0000129 unsigned char *output );
130
131/**
132 * \brief Checkup routine
133 *
134 * \return 0 if successful, or 1 if the test failed
135 */
136int camellia_self_test( int verbose );
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif /* camellia.h */