blob: e289aa2e937c18e1d500d5971f6fc95854b5fda7 [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief Generic cipher wrapper for mbed TLS
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00008 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakker8123e9d2011-01-06 15:37:30 +00009 *
Manuel Pégourié-Gonnard860b5162015-01-28 17:12:07 +000010 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000011 *
Paul Bakker8123e9d2011-01-06 15:37:30 +000012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker8123e9d2011-01-06 15:37:30 +000028#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000032
33#if defined(POLARSSL_CIPHER_C)
34
35#include "polarssl/cipher_wrap.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000036
37#if defined(POLARSSL_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000038#include "polarssl/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000039#endif
40
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020041#if defined(POLARSSL_ARC4_C)
42#include "polarssl/arc4.h"
43#endif
44
Paul Bakkerf6543712012-03-05 14:01:29 +000045#if defined(POLARSSL_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000046#include "polarssl/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000047#endif
48
49#if defined(POLARSSL_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000050#include "polarssl/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000051#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000052
Paul Bakker6132d0a2012-07-04 17:10:40 +000053#if defined(POLARSSL_BLOWFISH_C)
54#include "polarssl/blowfish.h"
55#endif
56
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020057#if defined(POLARSSL_GCM_C)
58#include "polarssl/gcm.h"
59#endif
60
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020061#if defined(POLARSSL_CCM_C)
62#include "polarssl/ccm.h"
63#endif
64
Paul Bakker7dc4c442014-02-01 22:50:26 +010065#if defined(POLARSSL_PLATFORM_C)
66#include "polarssl/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020067#else
68#define polarssl_malloc malloc
69#define polarssl_free free
70#endif
71
Paul Bakker8123e9d2011-01-06 15:37:30 +000072#include <stdlib.h>
73
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020074#if defined(POLARSSL_GCM_C)
75/* shared by all GCM ciphers */
76static void *gcm_ctx_alloc( void )
77{
78 return polarssl_malloc( sizeof( gcm_context ) );
79}
80
81static void gcm_ctx_free( void *ctx )
82{
83 gcm_free( ctx );
84 polarssl_free( ctx );
85}
Paul Bakker9af723c2014-05-01 13:03:14 +020086#endif /* POLARSSL_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020087
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020088#if defined(POLARSSL_CCM_C)
89/* shared by all CCM ciphers */
90static void *ccm_ctx_alloc( void )
91{
92 return polarssl_malloc( sizeof( ccm_context ) );
93}
94
95static void ccm_ctx_free( void *ctx )
96{
97 ccm_free( ctx );
98 polarssl_free( ctx );
99}
100#endif /* POLARSSL_CCM_C */
101
Paul Bakker8123e9d2011-01-06 15:37:30 +0000102#if defined(POLARSSL_AES_C)
103
Paul Bakker5e0efa72013-09-08 23:04:04 +0200104static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
105 const unsigned char *input, unsigned char *output )
106{
107 return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
108}
109
Paul Bakkerfae35f02013-03-13 10:33:51 +0100110static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000111 unsigned char *iv, const unsigned char *input, unsigned char *output )
112{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200113#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200114 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
115 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200116#else
117 ((void) ctx);
118 ((void) operation);
119 ((void) length);
120 ((void) iv);
121 ((void) input);
122 ((void) output);
123
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200124 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200125#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000126}
127
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200128static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
129 size_t length, size_t *iv_off, unsigned char *iv,
130 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000131{
132#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200133 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
134 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000135#else
136 ((void) ctx);
137 ((void) operation);
138 ((void) length);
139 ((void) iv_off);
140 ((void) iv);
141 ((void) input);
142 ((void) output);
143
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200144 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200145#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000146}
147
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200148static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
149 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000150 const unsigned char *input, unsigned char *output )
151{
152#if defined(POLARSSL_CIPHER_MODE_CTR)
153 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
154 stream_block, input, output );
155#else
156 ((void) ctx);
157 ((void) length);
158 ((void) nc_off);
159 ((void) nonce_counter);
160 ((void) stream_block);
161 ((void) input);
162 ((void) output);
163
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200164 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200165#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000166}
167
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200168static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
169 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000170{
171 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
172}
173
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200174static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
175 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000176{
177 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
178}
179
180static void * aes_ctx_alloc( void )
181{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200182 aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
183
184 if( aes == NULL )
185 return( NULL );
186
187 aes_init( aes );
188
189 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000190}
191
192static void aes_ctx_free( void *ctx )
193{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200194 aes_free( (aes_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200195 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000196}
197
Paul Bakker343a8702011-06-09 14:27:58 +0000198const cipher_base_t aes_info = {
199 POLARSSL_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200200 aes_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000201 aes_crypt_cbc_wrap,
202 aes_crypt_cfb128_wrap,
203 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200204 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000205 aes_setkey_enc_wrap,
206 aes_setkey_dec_wrap,
207 aes_ctx_alloc,
208 aes_ctx_free
209};
210
Paul Bakker5e0efa72013-09-08 23:04:04 +0200211const cipher_info_t aes_128_ecb_info = {
212 POLARSSL_CIPHER_AES_128_ECB,
213 POLARSSL_MODE_ECB,
214 128,
215 "AES-128-ECB",
216 16,
217 0,
218 16,
219 &aes_info
220};
221
222const cipher_info_t aes_192_ecb_info = {
223 POLARSSL_CIPHER_AES_192_ECB,
224 POLARSSL_MODE_ECB,
225 192,
226 "AES-192-ECB",
227 16,
228 0,
229 16,
230 &aes_info
231};
232
233const cipher_info_t aes_256_ecb_info = {
234 POLARSSL_CIPHER_AES_256_ECB,
235 POLARSSL_MODE_ECB,
236 256,
237 "AES-256-ECB",
238 16,
239 0,
240 16,
241 &aes_info
242};
243
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200244#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000245const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000246 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000247 POLARSSL_MODE_CBC,
248 128,
249 "AES-128-CBC",
250 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200251 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000252 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000253 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000254};
255
256const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000257 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000258 POLARSSL_MODE_CBC,
259 192,
260 "AES-192-CBC",
261 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200262 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000263 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000264 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000265};
266
267const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000268 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000269 POLARSSL_MODE_CBC,
270 256,
271 "AES-256-CBC",
272 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200273 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000274 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000275 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000276};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200277#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000278
279#if defined(POLARSSL_CIPHER_MODE_CFB)
280const cipher_info_t aes_128_cfb128_info = {
281 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000282 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000283 128,
284 "AES-128-CFB128",
285 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200286 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000287 16,
288 &aes_info
289};
290
291const cipher_info_t aes_192_cfb128_info = {
292 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000293 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000294 192,
295 "AES-192-CFB128",
296 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200297 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000298 16,
299 &aes_info
300};
301
302const cipher_info_t aes_256_cfb128_info = {
303 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000304 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000305 256,
306 "AES-256-CFB128",
307 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200308 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000309 16,
310 &aes_info
311};
312#endif /* POLARSSL_CIPHER_MODE_CFB */
313
314#if defined(POLARSSL_CIPHER_MODE_CTR)
315const cipher_info_t aes_128_ctr_info = {
316 POLARSSL_CIPHER_AES_128_CTR,
317 POLARSSL_MODE_CTR,
318 128,
319 "AES-128-CTR",
320 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200321 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000322 16,
323 &aes_info
324};
325
326const cipher_info_t aes_192_ctr_info = {
327 POLARSSL_CIPHER_AES_192_CTR,
328 POLARSSL_MODE_CTR,
329 192,
330 "AES-192-CTR",
331 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200332 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000333 16,
334 &aes_info
335};
336
337const cipher_info_t aes_256_ctr_info = {
338 POLARSSL_CIPHER_AES_256_CTR,
339 POLARSSL_MODE_CTR,
340 256,
341 "AES-256-CTR",
342 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200343 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000344 16,
345 &aes_info
346};
347#endif /* POLARSSL_CIPHER_MODE_CTR */
348
Paul Bakker68884e32013-01-07 18:20:04 +0100349#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200350static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
351 unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200352{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200353 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
354 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200355}
356
357const cipher_base_t gcm_aes_info = {
358 POLARSSL_CIPHER_ID_AES,
359 NULL,
360 NULL,
361 NULL,
362 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200363 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200364 gcm_aes_setkey_wrap,
365 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200366 gcm_ctx_alloc,
367 gcm_ctx_free,
368};
369
Paul Bakker68884e32013-01-07 18:20:04 +0100370const cipher_info_t aes_128_gcm_info = {
371 POLARSSL_CIPHER_AES_128_GCM,
372 POLARSSL_MODE_GCM,
373 128,
374 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200375 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200376 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100377 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200378 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100379};
380
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200381const cipher_info_t aes_192_gcm_info = {
382 POLARSSL_CIPHER_AES_192_GCM,
383 POLARSSL_MODE_GCM,
384 192,
385 "AES-192-GCM",
386 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200387 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200388 16,
389 &gcm_aes_info
390};
391
Paul Bakker68884e32013-01-07 18:20:04 +0100392const cipher_info_t aes_256_gcm_info = {
393 POLARSSL_CIPHER_AES_256_GCM,
394 POLARSSL_MODE_GCM,
395 256,
396 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200397 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200398 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100399 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200400 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100401};
402#endif /* POLARSSL_GCM_C */
403
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200404#if defined(POLARSSL_CCM_C)
405static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
406 unsigned int key_length )
407{
408 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_AES,
409 key, key_length );
410}
411
412const cipher_base_t ccm_aes_info = {
413 POLARSSL_CIPHER_ID_AES,
414 NULL,
415 NULL,
416 NULL,
417 NULL,
418 NULL,
419 ccm_aes_setkey_wrap,
420 ccm_aes_setkey_wrap,
421 ccm_ctx_alloc,
422 ccm_ctx_free,
423};
424
425const cipher_info_t aes_128_ccm_info = {
426 POLARSSL_CIPHER_AES_128_CCM,
427 POLARSSL_MODE_CCM,
428 128,
429 "AES-128-CCM",
430 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200431 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200432 16,
433 &ccm_aes_info
434};
435
436const cipher_info_t aes_192_ccm_info = {
437 POLARSSL_CIPHER_AES_192_CCM,
438 POLARSSL_MODE_CCM,
439 192,
440 "AES-192-CCM",
441 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200442 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200443 16,
444 &ccm_aes_info
445};
446
447const cipher_info_t aes_256_ccm_info = {
448 POLARSSL_CIPHER_AES_256_CCM,
449 POLARSSL_MODE_CCM,
450 256,
451 "AES-256-CCM",
452 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200453 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200454 16,
455 &ccm_aes_info
456};
457#endif /* POLARSSL_CCM_C */
458
Paul Bakker9af723c2014-05-01 13:03:14 +0200459#endif /* POLARSSL_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000460
461#if defined(POLARSSL_CAMELLIA_C)
462
Paul Bakker5e0efa72013-09-08 23:04:04 +0200463static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
464 const unsigned char *input, unsigned char *output )
465{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200466 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input,
467 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200468}
469
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200470static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
471 size_t length, unsigned char *iv,
472 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000473{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200474#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200475 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
476 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200477#else
478 ((void) ctx);
479 ((void) operation);
480 ((void) length);
481 ((void) iv);
482 ((void) input);
483 ((void) output);
484
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200485 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200486#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000487}
488
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200489static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
490 size_t length, size_t *iv_off, unsigned char *iv,
491 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000492{
493#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200494 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
495 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000496#else
497 ((void) ctx);
498 ((void) operation);
499 ((void) length);
500 ((void) iv_off);
501 ((void) iv);
502 ((void) input);
503 ((void) output);
504
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200505 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200506#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000507}
508
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200509static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
510 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000511 const unsigned char *input, unsigned char *output )
512{
513#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200514 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
515 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000516#else
517 ((void) ctx);
518 ((void) length);
519 ((void) nc_off);
520 ((void) nonce_counter);
521 ((void) stream_block);
522 ((void) input);
523 ((void) output);
524
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200525 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200526#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000527}
528
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200529static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
530 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000531{
532 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
533}
534
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200535static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
536 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000537{
538 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
539}
540
541static void * camellia_ctx_alloc( void )
542{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200543 camellia_context *ctx;
544 ctx = (camellia_context *) polarssl_malloc( sizeof( camellia_context ) );
545
546 if( ctx == NULL )
547 return( NULL );
548
549 camellia_init( ctx );
550
551 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000552}
553
554static void camellia_ctx_free( void *ctx )
555{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200556 camellia_free( (camellia_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200557 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000558}
559
Paul Bakker343a8702011-06-09 14:27:58 +0000560const cipher_base_t camellia_info = {
561 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200562 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000563 camellia_crypt_cbc_wrap,
564 camellia_crypt_cfb128_wrap,
565 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200566 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000567 camellia_setkey_enc_wrap,
568 camellia_setkey_dec_wrap,
569 camellia_ctx_alloc,
570 camellia_ctx_free
571};
572
Paul Bakker5e0efa72013-09-08 23:04:04 +0200573const cipher_info_t camellia_128_ecb_info = {
574 POLARSSL_CIPHER_CAMELLIA_128_ECB,
575 POLARSSL_MODE_ECB,
576 128,
577 "CAMELLIA-128-ECB",
578 16,
579 0,
580 16,
581 &camellia_info
582};
583
584const cipher_info_t camellia_192_ecb_info = {
585 POLARSSL_CIPHER_CAMELLIA_192_ECB,
586 POLARSSL_MODE_ECB,
587 192,
588 "CAMELLIA-192-ECB",
589 16,
590 0,
591 16,
592 &camellia_info
593};
594
595const cipher_info_t camellia_256_ecb_info = {
596 POLARSSL_CIPHER_CAMELLIA_256_ECB,
597 POLARSSL_MODE_ECB,
598 256,
599 "CAMELLIA-256-ECB",
600 16,
601 0,
602 16,
603 &camellia_info
604};
605
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200606#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000607const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000608 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000609 POLARSSL_MODE_CBC,
610 128,
611 "CAMELLIA-128-CBC",
612 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200613 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000614 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000615 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000616};
617
618const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000619 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000620 POLARSSL_MODE_CBC,
621 192,
622 "CAMELLIA-192-CBC",
623 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200624 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000625 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000626 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000627};
628
629const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000630 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000631 POLARSSL_MODE_CBC,
632 256,
633 "CAMELLIA-256-CBC",
634 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200635 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000636 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000637 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000638};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200639#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000640
641#if defined(POLARSSL_CIPHER_MODE_CFB)
642const cipher_info_t camellia_128_cfb128_info = {
643 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000644 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000645 128,
646 "CAMELLIA-128-CFB128",
647 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200648 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000649 16,
650 &camellia_info
651};
652
653const cipher_info_t camellia_192_cfb128_info = {
654 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000655 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000656 192,
657 "CAMELLIA-192-CFB128",
658 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200659 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000660 16,
661 &camellia_info
662};
663
664const cipher_info_t camellia_256_cfb128_info = {
665 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000666 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000667 256,
668 "CAMELLIA-256-CFB128",
669 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200670 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000671 16,
672 &camellia_info
673};
674#endif /* POLARSSL_CIPHER_MODE_CFB */
675
676#if defined(POLARSSL_CIPHER_MODE_CTR)
677const cipher_info_t camellia_128_ctr_info = {
678 POLARSSL_CIPHER_CAMELLIA_128_CTR,
679 POLARSSL_MODE_CTR,
680 128,
681 "CAMELLIA-128-CTR",
682 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200683 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000684 16,
685 &camellia_info
686};
687
688const cipher_info_t camellia_192_ctr_info = {
689 POLARSSL_CIPHER_CAMELLIA_192_CTR,
690 POLARSSL_MODE_CTR,
691 192,
692 "CAMELLIA-192-CTR",
693 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200694 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000695 16,
696 &camellia_info
697};
698
699const cipher_info_t camellia_256_ctr_info = {
700 POLARSSL_CIPHER_CAMELLIA_256_CTR,
701 POLARSSL_MODE_CTR,
702 256,
703 "CAMELLIA-256-CTR",
704 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200705 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000706 16,
707 &camellia_info
708};
709#endif /* POLARSSL_CIPHER_MODE_CTR */
710
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200711#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200712static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
713 unsigned int key_length )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200714{
715 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
716 key, key_length );
717}
718
719const cipher_base_t gcm_camellia_info = {
720 POLARSSL_CIPHER_ID_CAMELLIA,
721 NULL,
722 NULL,
723 NULL,
724 NULL,
725 NULL,
726 gcm_camellia_setkey_wrap,
727 gcm_camellia_setkey_wrap,
728 gcm_ctx_alloc,
729 gcm_ctx_free,
730};
731
732const cipher_info_t camellia_128_gcm_info = {
733 POLARSSL_CIPHER_CAMELLIA_128_GCM,
734 POLARSSL_MODE_GCM,
735 128,
736 "CAMELLIA-128-GCM",
737 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200738 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200739 16,
740 &gcm_camellia_info
741};
742
743const cipher_info_t camellia_192_gcm_info = {
744 POLARSSL_CIPHER_CAMELLIA_192_GCM,
745 POLARSSL_MODE_GCM,
746 192,
747 "CAMELLIA-192-GCM",
748 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200749 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200750 16,
751 &gcm_camellia_info
752};
753
754const cipher_info_t camellia_256_gcm_info = {
755 POLARSSL_CIPHER_CAMELLIA_256_GCM,
756 POLARSSL_MODE_GCM,
757 256,
758 "CAMELLIA-256-GCM",
759 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200760 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200761 16,
762 &gcm_camellia_info
763};
764#endif /* POLARSSL_GCM_C */
765
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200766#if defined(POLARSSL_CCM_C)
767static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
768 unsigned int key_length )
769{
770 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
771 key, key_length );
772}
773
774const cipher_base_t ccm_camellia_info = {
775 POLARSSL_CIPHER_ID_CAMELLIA,
776 NULL,
777 NULL,
778 NULL,
779 NULL,
780 NULL,
781 ccm_camellia_setkey_wrap,
782 ccm_camellia_setkey_wrap,
783 ccm_ctx_alloc,
784 ccm_ctx_free,
785};
786
787const cipher_info_t camellia_128_ccm_info = {
788 POLARSSL_CIPHER_CAMELLIA_128_CCM,
789 POLARSSL_MODE_CCM,
790 128,
791 "CAMELLIA-128-CCM",
792 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200793 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200794 16,
795 &ccm_camellia_info
796};
797
798const cipher_info_t camellia_192_ccm_info = {
799 POLARSSL_CIPHER_CAMELLIA_192_CCM,
800 POLARSSL_MODE_CCM,
801 192,
802 "CAMELLIA-192-CCM",
803 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200804 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200805 16,
806 &ccm_camellia_info
807};
808
809const cipher_info_t camellia_256_ccm_info = {
810 POLARSSL_CIPHER_CAMELLIA_256_CCM,
811 POLARSSL_MODE_CCM,
812 256,
813 "CAMELLIA-256-CCM",
814 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200815 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200816 16,
817 &ccm_camellia_info
818};
819#endif /* POLARSSL_CCM_C */
820
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200821#endif /* POLARSSL_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000822
823#if defined(POLARSSL_DES_C)
824
Paul Bakker5e0efa72013-09-08 23:04:04 +0200825static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
826 const unsigned char *input, unsigned char *output )
827{
828 ((void) operation);
829 return des_crypt_ecb( (des_context *) ctx, input, output );
830}
831
832static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
833 const unsigned char *input, unsigned char *output )
834{
835 ((void) operation);
836 return des3_crypt_ecb( (des3_context *) ctx, input, output );
837}
838
Paul Bakkerfae35f02013-03-13 10:33:51 +0100839static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000840 unsigned char *iv, const unsigned char *input, unsigned char *output )
841{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200842#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200843 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
844 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200845#else
846 ((void) ctx);
847 ((void) operation);
848 ((void) length);
849 ((void) iv);
850 ((void) input);
851 ((void) output);
852
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200853 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200854#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000855}
856
Paul Bakkerfae35f02013-03-13 10:33:51 +0100857static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000858 unsigned char *iv, const unsigned char *input, unsigned char *output )
859{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200860#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200861 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
862 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200863#else
864 ((void) ctx);
865 ((void) operation);
866 ((void) length);
867 ((void) iv);
868 ((void) input);
869 ((void) output);
870
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200871 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200872#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000873}
874
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200875static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
876 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000877{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000878 ((void) key_length);
879
Paul Bakker8123e9d2011-01-06 15:37:30 +0000880 return des_setkey_dec( (des_context *) ctx, key );
881}
882
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200883static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
884 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000885{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000886 ((void) key_length);
887
Paul Bakker8123e9d2011-01-06 15:37:30 +0000888 return des_setkey_enc( (des_context *) ctx, key );
889}
890
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200891static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
892 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000893{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000894 ((void) key_length);
895
Paul Bakker8123e9d2011-01-06 15:37:30 +0000896 return des3_set2key_dec( (des3_context *) ctx, key );
897}
898
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200899static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
900 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000901{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000902 ((void) key_length);
903
Paul Bakker8123e9d2011-01-06 15:37:30 +0000904 return des3_set2key_enc( (des3_context *) ctx, key );
905}
906
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200907static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
908 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000909{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000910 ((void) key_length);
911
Paul Bakker8123e9d2011-01-06 15:37:30 +0000912 return des3_set3key_dec( (des3_context *) ctx, key );
913}
914
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200915static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
916 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000917{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000918 ((void) key_length);
919
Paul Bakker8123e9d2011-01-06 15:37:30 +0000920 return des3_set3key_enc( (des3_context *) ctx, key );
921}
922
923static void * des_ctx_alloc( void )
924{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200925 des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000926
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200927 if( des == NULL )
928 return( NULL );
929
930 des_init( des );
931
932 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000933}
934
935static void des_ctx_free( void *ctx )
936{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200937 des_free( (des_context *) ctx );
Paul Bakker34617722014-06-13 17:20:13 +0200938 polarssl_free( ctx );
939}
940
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200941static void * des3_ctx_alloc( void )
942{
943 des3_context *des3;
944 des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
945
946 if( des3 == NULL )
947 return( NULL );
948
949 des3_init( des3 );
950
951 return( des3 );
952}
953
Paul Bakker34617722014-06-13 17:20:13 +0200954static void des3_ctx_free( void *ctx )
955{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200956 des3_free( (des3_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200957 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000958}
959
Paul Bakker343a8702011-06-09 14:27:58 +0000960const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000961 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200962 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000963 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200964 NULL,
965 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200966 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000967 des_setkey_enc_wrap,
968 des_setkey_dec_wrap,
969 des_ctx_alloc,
970 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000971};
972
Paul Bakker5e0efa72013-09-08 23:04:04 +0200973const cipher_info_t des_ecb_info = {
974 POLARSSL_CIPHER_DES_ECB,
975 POLARSSL_MODE_ECB,
976 POLARSSL_KEY_LENGTH_DES,
977 "DES-ECB",
978 8,
979 0,
980 8,
981 &des_info
982};
983
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200984#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000985const cipher_info_t des_cbc_info = {
986 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000987 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000988 POLARSSL_KEY_LENGTH_DES,
989 "DES-CBC",
990 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200991 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000992 8,
993 &des_info
994};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200995#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000996
997const cipher_base_t des_ede_info = {
998 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200999 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +00001000 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001001 NULL,
1002 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001003 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +00001004 des3_set2key_enc_wrap,
1005 des3_set2key_dec_wrap,
1006 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001007 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001008};
1009
Paul Bakker5e0efa72013-09-08 23:04:04 +02001010const cipher_info_t des_ede_ecb_info = {
1011 POLARSSL_CIPHER_DES_EDE_ECB,
1012 POLARSSL_MODE_ECB,
1013 POLARSSL_KEY_LENGTH_DES_EDE,
1014 "DES-EDE-ECB",
1015 8,
1016 0,
1017 8,
1018 &des_ede_info
1019};
1020
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001021#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001022const cipher_info_t des_ede_cbc_info = {
1023 POLARSSL_CIPHER_DES_EDE_CBC,
1024 POLARSSL_MODE_CBC,
1025 POLARSSL_KEY_LENGTH_DES_EDE,
1026 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001027 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001028 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001029 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001030 &des_ede_info
1031};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001032#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001033
1034const cipher_base_t des_ede3_info = {
1035 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001036 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +00001037 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001038 NULL,
1039 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001040 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +00001041 des3_set3key_enc_wrap,
1042 des3_set3key_dec_wrap,
1043 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001044 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001045};
1046
Paul Bakker5e0efa72013-09-08 23:04:04 +02001047const cipher_info_t des_ede3_ecb_info = {
1048 POLARSSL_CIPHER_DES_EDE3_ECB,
1049 POLARSSL_MODE_ECB,
1050 POLARSSL_KEY_LENGTH_DES_EDE3,
1051 "DES-EDE3-ECB",
1052 8,
1053 0,
1054 8,
1055 &des_ede3_info
1056};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001057#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001058const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +00001059 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +00001060 POLARSSL_MODE_CBC,
1061 POLARSSL_KEY_LENGTH_DES_EDE3,
1062 "DES-EDE3-CBC",
1063 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001064 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001065 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001066 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001067};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001068#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker9af723c2014-05-01 13:03:14 +02001069#endif /* POLARSSL_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001070
Paul Bakker6132d0a2012-07-04 17:10:40 +00001071#if defined(POLARSSL_BLOWFISH_C)
1072
Paul Bakker5e0efa72013-09-08 23:04:04 +02001073static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
1074 const unsigned char *input, unsigned char *output )
1075{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001076 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
1077 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001078}
1079
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001080static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
1081 size_t length, unsigned char *iv, const unsigned char *input,
1082 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001083{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001084#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001085 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
1086 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001087#else
1088 ((void) ctx);
1089 ((void) operation);
1090 ((void) length);
1091 ((void) iv);
1092 ((void) input);
1093 ((void) output);
1094
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001095 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001096#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001097}
1098
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001099static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
1100 size_t length, size_t *iv_off, unsigned char *iv,
1101 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001102{
1103#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001104 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
1105 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001106#else
1107 ((void) ctx);
1108 ((void) operation);
1109 ((void) length);
1110 ((void) iv_off);
1111 ((void) iv);
1112 ((void) input);
1113 ((void) output);
1114
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001115 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001116#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001117}
1118
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001119static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1120 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001121 const unsigned char *input, unsigned char *output )
1122{
1123#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001124 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
1125 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001126#else
1127 ((void) ctx);
1128 ((void) length);
1129 ((void) nc_off);
1130 ((void) nonce_counter);
1131 ((void) stream_block);
1132 ((void) input);
1133 ((void) output);
1134
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001135 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001136#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001137}
1138
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001139static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1140 unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001141{
1142 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
1143}
1144
1145static void * blowfish_ctx_alloc( void )
1146{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001147 blowfish_context *ctx;
1148 ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
1149
1150 if( ctx == NULL )
1151 return( NULL );
1152
1153 blowfish_init( ctx );
1154
1155 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001156}
1157
1158static void blowfish_ctx_free( void *ctx )
1159{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001160 blowfish_free( (blowfish_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +02001161 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001162}
1163
1164const cipher_base_t blowfish_info = {
1165 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001166 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001167 blowfish_crypt_cbc_wrap,
1168 blowfish_crypt_cfb64_wrap,
1169 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001170 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001171 blowfish_setkey_wrap,
1172 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001173 blowfish_ctx_alloc,
1174 blowfish_ctx_free
1175};
1176
Paul Bakker5e0efa72013-09-08 23:04:04 +02001177const cipher_info_t blowfish_ecb_info = {
1178 POLARSSL_CIPHER_BLOWFISH_ECB,
1179 POLARSSL_MODE_ECB,
1180 128,
1181 "BLOWFISH-ECB",
1182 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001183 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001184 8,
1185 &blowfish_info
1186};
1187
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001188#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001189const cipher_info_t blowfish_cbc_info = {
1190 POLARSSL_CIPHER_BLOWFISH_CBC,
1191 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001192 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001193 "BLOWFISH-CBC",
1194 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001195 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001196 8,
1197 &blowfish_info
1198};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001199#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001200
1201#if defined(POLARSSL_CIPHER_MODE_CFB)
1202const cipher_info_t blowfish_cfb64_info = {
1203 POLARSSL_CIPHER_BLOWFISH_CFB64,
1204 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001205 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001206 "BLOWFISH-CFB64",
1207 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001208 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001209 8,
1210 &blowfish_info
1211};
1212#endif /* POLARSSL_CIPHER_MODE_CFB */
1213
1214#if defined(POLARSSL_CIPHER_MODE_CTR)
1215const cipher_info_t blowfish_ctr_info = {
1216 POLARSSL_CIPHER_BLOWFISH_CTR,
1217 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001218 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001219 "BLOWFISH-CTR",
1220 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001221 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001222 8,
1223 &blowfish_info
1224};
1225#endif /* POLARSSL_CIPHER_MODE_CTR */
1226#endif /* POLARSSL_BLOWFISH_C */
1227
Paul Bakker68884e32013-01-07 18:20:04 +01001228#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001229static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1230 const unsigned char *input,
1231 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001232{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001233 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001234}
1235
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001236static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1237 unsigned int key_length )
1238{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001239 /* we get key_length in bits, arc4 expects it in bytes */
Paul Bakker66d5d072014-06-17 16:39:18 +02001240 if( key_length % 8 != 0 )
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001241 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
1242
1243 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001244 return( 0 );
1245}
1246
1247static void * arc4_ctx_alloc( void )
1248{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001249 arc4_context *ctx;
1250 ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
1251
1252 if( ctx == NULL )
1253 return( NULL );
1254
1255 arc4_init( ctx );
1256
1257 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001258}
Paul Bakker68884e32013-01-07 18:20:04 +01001259
1260static void arc4_ctx_free( void *ctx )
1261{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001262 arc4_free( (arc4_context *) ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001263 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001264}
1265
1266const cipher_base_t arc4_base_info = {
1267 POLARSSL_CIPHER_ID_ARC4,
1268 NULL,
1269 NULL,
1270 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001271 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001272 arc4_crypt_stream_wrap,
1273 arc4_setkey_wrap,
1274 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001275 arc4_ctx_alloc,
1276 arc4_ctx_free
1277};
1278
1279const cipher_info_t arc4_128_info = {
1280 POLARSSL_CIPHER_ARC4_128,
1281 POLARSSL_MODE_STREAM,
1282 128,
1283 "ARC4-128",
1284 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001285 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001286 1,
1287 &arc4_base_info
1288};
1289#endif /* POLARSSL_ARC4_C */
1290
Paul Bakkerfab5c822012-02-06 16:45:10 +00001291#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001292static int null_crypt_stream( void *ctx, size_t length,
1293 const unsigned char *input,
1294 unsigned char *output )
1295{
1296 ((void) ctx);
1297 memmove( output, input, length );
1298 return( 0 );
1299}
1300
1301static int null_setkey( void *ctx, const unsigned char *key,
1302 unsigned int key_length )
1303{
1304 ((void) ctx);
1305 ((void) key);
1306 ((void) key_length);
1307
1308 return( 0 );
1309}
1310
Paul Bakkerfab5c822012-02-06 16:45:10 +00001311static void * null_ctx_alloc( void )
1312{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001313 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001314}
1315
Paul Bakkerfab5c822012-02-06 16:45:10 +00001316static void null_ctx_free( void *ctx )
1317{
1318 ((void) ctx);
1319}
1320
1321const cipher_base_t null_base_info = {
1322 POLARSSL_CIPHER_ID_NULL,
1323 NULL,
1324 NULL,
1325 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001326 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001327 null_crypt_stream,
1328 null_setkey,
1329 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001330 null_ctx_alloc,
1331 null_ctx_free
1332};
1333
1334const cipher_info_t null_cipher_info = {
1335 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001336 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001337 0,
1338 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001339 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001340 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001341 1,
1342 &null_base_info
1343};
1344#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1345
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001346const cipher_definition_t cipher_definitions[] =
1347{
1348#if defined(POLARSSL_AES_C)
1349 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1350 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1351 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1352#if defined(POLARSSL_CIPHER_MODE_CBC)
1353 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1354 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1355 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1356#endif
1357#if defined(POLARSSL_CIPHER_MODE_CFB)
1358 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1359 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1360 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1361#endif
1362#if defined(POLARSSL_CIPHER_MODE_CTR)
1363 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1364 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1365 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1366#endif
1367#if defined(POLARSSL_GCM_C)
1368 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1369 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1370 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1371#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001372#if defined(POLARSSL_CCM_C)
1373 { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1374 { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1375 { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
1376#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001377#endif /* POLARSSL_AES_C */
1378
1379#if defined(POLARSSL_ARC4_C)
1380 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1381#endif
1382
1383#if defined(POLARSSL_BLOWFISH_C)
1384 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1385#if defined(POLARSSL_CIPHER_MODE_CBC)
1386 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1387#endif
1388#if defined(POLARSSL_CIPHER_MODE_CFB)
1389 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1390#endif
1391#if defined(POLARSSL_CIPHER_MODE_CTR)
1392 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1393#endif
1394#endif /* POLARSSL_BLOWFISH_C */
1395
1396#if defined(POLARSSL_CAMELLIA_C)
1397 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1398 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
Manuel Pégourié-Gonnard13e0d442013-10-24 12:59:00 +02001399 { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001400#if defined(POLARSSL_CIPHER_MODE_CBC)
1401 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1402 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1403 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1404#endif
1405#if defined(POLARSSL_CIPHER_MODE_CFB)
1406 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1407 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1408 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1409#endif
1410#if defined(POLARSSL_CIPHER_MODE_CTR)
1411 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1412 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1413 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1414#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001415#if defined(POLARSSL_GCM_C)
1416 { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1417 { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1418 { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
1419#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001420#if defined(POLARSSL_CCM_C)
1421 { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1422 { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1423 { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
1424#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001425#endif /* POLARSSL_CAMELLIA_C */
1426
1427#if defined(POLARSSL_DES_C)
1428 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1429 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1430 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1431#if defined(POLARSSL_CIPHER_MODE_CBC)
1432 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1433 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1434 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1435#endif
1436#endif /* POLARSSL_DES_C */
1437
1438#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard057e0cf2013-10-14 14:19:31 +02001439 { POLARSSL_CIPHER_NULL, &null_cipher_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001440#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1441
1442 { 0, NULL }
1443};
1444
1445#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1446int supported_ciphers[NUM_CIPHERS];
1447
Paul Bakker9af723c2014-05-01 13:03:14 +02001448#endif /* POLARSSL_CIPHER_C */