initial commit; it works
[psslcertgen.git] / src / libpolarssl / camellia.h
blob050c6cdb8bb2a308685296cc0f3a1d5b3124f899
1 /**
2 * \file camellia.h
4 * \brief Camellia block cipher
6 * Copyright (C) 2006-2013, Brainspark B.V.
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
11 * All rights reserved.
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.
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.
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.
27 #ifndef POLARSSL_CAMELLIA_H
28 #define POLARSSL_CAMELLIA_H
30 #include "config.h"
32 #include <string.h>
34 #ifdef _MSC_VER
35 #include <basetsd.h>
36 typedef UINT32 uint32_t;
37 #else
38 #include <inttypes.h>
39 #endif
41 #define CAMELLIA_ENCRYPT 1
42 #define CAMELLIA_DECRYPT 0
44 #define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH -0x0024 /**< Invalid key length. */
45 #define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH -0x0026 /**< Invalid data input length. */
47 #if !defined(POLARSSL_CAMELLIA_ALT)
48 // Regular implementation
51 /**
52 * \brief CAMELLIA context structure
54 typedef struct
56 int nr; /*!< number of rounds */
57 uint32_t rk[68]; /*!< CAMELLIA round keys */
59 camellia_context;
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
65 /**
66 * \brief CAMELLIA key schedule (encryption)
68 * \param ctx CAMELLIA context to be initialized
69 * \param key encryption key
70 * \param keysize must be 128, 192 or 256
72 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
74 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize );
76 /**
77 * \brief CAMELLIA key schedule (decryption)
79 * \param ctx CAMELLIA context to be initialized
80 * \param key decryption key
81 * \param keysize must be 128, 192 or 256
83 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH
85 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize );
87 /**
88 * \brief CAMELLIA-ECB block encryption/decryption
90 * \param ctx CAMELLIA context
91 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
92 * \param input 16-byte input block
93 * \param output 16-byte output block
95 * \return 0 if successful
97 int camellia_crypt_ecb( camellia_context *ctx,
98 int mode,
99 const unsigned char input[16],
100 unsigned char output[16] );
103 * \brief CAMELLIA-CBC buffer encryption/decryption
104 * Length should be a multiple of the block
105 * size (16 bytes)
107 * \param ctx CAMELLIA context
108 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
109 * \param length length of the input data
110 * \param iv initialization vector (updated after use)
111 * \param input buffer holding the input data
112 * \param output buffer holding the output data
114 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
116 int camellia_crypt_cbc( camellia_context *ctx,
117 int mode,
118 size_t length,
119 unsigned char iv[16],
120 const unsigned char *input,
121 unsigned char *output );
124 * \brief CAMELLIA-CFB128 buffer encryption/decryption
126 * Note: Due to the nature of CFB you should use the same key schedule for
127 * both encryption and decryption. So a context initialized with
128 * camellia_setkey_enc() for both CAMELLIA_ENCRYPT and CAMELLIE_DECRYPT.
130 * \param ctx CAMELLIA context
131 * \param mode CAMELLIA_ENCRYPT or CAMELLIA_DECRYPT
132 * \param length length of the input data
133 * \param iv_off offset in IV (updated after use)
134 * \param iv initialization vector (updated after use)
135 * \param input buffer holding the input data
136 * \param output buffer holding the output data
138 * \return 0 if successful, or POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH
140 int camellia_crypt_cfb128( camellia_context *ctx,
141 int mode,
142 size_t length,
143 size_t *iv_off,
144 unsigned char iv[16],
145 const unsigned char *input,
146 unsigned char *output );
149 * \brief CAMELLIA-CTR buffer encryption/decryption
151 * Warning: You have to keep the maximum use of your counter in mind!
153 * Note: Due to the nature of CTR you should use the same key schedule for
154 * both encryption and decryption. So a context initialized with
155 * camellia_setkey_enc() for both CAMELLIA_ENCRYPT and CAMELLIA_DECRYPT.
157 * \param length The length of the data
158 * \param nc_off The offset in the current stream_block (for resuming
159 * within current cipher stream). The offset pointer to
160 * should be 0 at the start of a stream.
161 * \param nonce_counter The 128-bit nonce and counter.
162 * \param stream_block The saved stream-block for resuming. Is overwritten
163 * by the function.
164 * \param input The input data stream
165 * \param output The output data stream
167 * \return 0 if successful
169 int camellia_crypt_ctr( camellia_context *ctx,
170 size_t length,
171 size_t *nc_off,
172 unsigned char nonce_counter[16],
173 unsigned char stream_block[16],
174 const unsigned char *input,
175 unsigned char *output );
177 #ifdef __cplusplus
179 #endif
181 #else /* POLARSSL_CAMELLIA_ALT */
182 #include "camellia_alt.h"
183 #endif /* POLARSSL_CAMELLIA_ALT */
185 #ifdef __cplusplus
186 extern "C" {
187 #endif
190 * \brief Checkup routine
192 * \return 0 if successful, or 1 if the test failed
194 int camellia_self_test( int verbose );
196 #ifdef __cplusplus
198 #endif
200 #endif /* camellia.h */