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