blob: b623b3c59dd13f6a91516c5c1911c55dedd0e4ad [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
Rich Evans00ab4702015-02-06 13:43:58 +000068#include <stdlib.h>
Paul Bakker6e339b52013-07-03 13:37:05 +020069#define polarssl_malloc malloc
70#define polarssl_free free
71#endif
72
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020073#if defined(POLARSSL_GCM_C)
74/* shared by all GCM ciphers */
75static void *gcm_ctx_alloc( void )
76{
77 return polarssl_malloc( sizeof( gcm_context ) );
78}
79
80static void gcm_ctx_free( void *ctx )
81{
82 gcm_free( ctx );
83 polarssl_free( ctx );
84}
Paul Bakker9af723c2014-05-01 13:03:14 +020085#endif /* POLARSSL_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020086
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020087#if defined(POLARSSL_CCM_C)
88/* shared by all CCM ciphers */
89static void *ccm_ctx_alloc( void )
90{
91 return polarssl_malloc( sizeof( ccm_context ) );
92}
93
94static void ccm_ctx_free( void *ctx )
95{
96 ccm_free( ctx );
97 polarssl_free( ctx );
98}
99#endif /* POLARSSL_CCM_C */
100
Paul Bakker8123e9d2011-01-06 15:37:30 +0000101#if defined(POLARSSL_AES_C)
102
Paul Bakker5e0efa72013-09-08 23:04:04 +0200103static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
104 const unsigned char *input, unsigned char *output )
105{
106 return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
107}
108
Paul Bakkerfae35f02013-03-13 10:33:51 +0100109static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000110 unsigned char *iv, const unsigned char *input, unsigned char *output )
111{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200112#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200113 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
114 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200115#else
116 ((void) ctx);
117 ((void) operation);
118 ((void) length);
119 ((void) iv);
120 ((void) input);
121 ((void) output);
122
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200123 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200124#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000125}
126
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200127static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
128 size_t length, size_t *iv_off, unsigned char *iv,
129 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000130{
131#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200132 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
133 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000134#else
135 ((void) ctx);
136 ((void) operation);
137 ((void) length);
138 ((void) iv_off);
139 ((void) iv);
140 ((void) input);
141 ((void) output);
142
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200143 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200144#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000145}
146
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200147static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
148 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000149 const unsigned char *input, unsigned char *output )
150{
151#if defined(POLARSSL_CIPHER_MODE_CTR)
152 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
153 stream_block, input, output );
154#else
155 ((void) ctx);
156 ((void) length);
157 ((void) nc_off);
158 ((void) nonce_counter);
159 ((void) stream_block);
160 ((void) input);
161 ((void) output);
162
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200163 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200164#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000165}
166
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200167static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
168 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000169{
170 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
171}
172
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200173static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
174 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000175{
176 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
177}
178
179static void * aes_ctx_alloc( void )
180{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200181 aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
182
183 if( aes == NULL )
184 return( NULL );
185
186 aes_init( aes );
187
188 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000189}
190
191static void aes_ctx_free( void *ctx )
192{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200193 aes_free( (aes_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200194 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000195}
196
Paul Bakker343a8702011-06-09 14:27:58 +0000197const cipher_base_t aes_info = {
198 POLARSSL_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200199 aes_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000200 aes_crypt_cbc_wrap,
201 aes_crypt_cfb128_wrap,
202 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200203 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000204 aes_setkey_enc_wrap,
205 aes_setkey_dec_wrap,
206 aes_ctx_alloc,
207 aes_ctx_free
208};
209
Paul Bakker5e0efa72013-09-08 23:04:04 +0200210const cipher_info_t aes_128_ecb_info = {
211 POLARSSL_CIPHER_AES_128_ECB,
212 POLARSSL_MODE_ECB,
213 128,
214 "AES-128-ECB",
215 16,
216 0,
217 16,
218 &aes_info
219};
220
221const cipher_info_t aes_192_ecb_info = {
222 POLARSSL_CIPHER_AES_192_ECB,
223 POLARSSL_MODE_ECB,
224 192,
225 "AES-192-ECB",
226 16,
227 0,
228 16,
229 &aes_info
230};
231
232const cipher_info_t aes_256_ecb_info = {
233 POLARSSL_CIPHER_AES_256_ECB,
234 POLARSSL_MODE_ECB,
235 256,
236 "AES-256-ECB",
237 16,
238 0,
239 16,
240 &aes_info
241};
242
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200243#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000244const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000245 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000246 POLARSSL_MODE_CBC,
247 128,
248 "AES-128-CBC",
249 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200250 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000251 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000252 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000253};
254
255const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000256 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000257 POLARSSL_MODE_CBC,
258 192,
259 "AES-192-CBC",
260 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200261 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000262 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000263 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000264};
265
266const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000267 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000268 POLARSSL_MODE_CBC,
269 256,
270 "AES-256-CBC",
271 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200272 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000273 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000274 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000275};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200276#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000277
278#if defined(POLARSSL_CIPHER_MODE_CFB)
279const cipher_info_t aes_128_cfb128_info = {
280 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000281 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000282 128,
283 "AES-128-CFB128",
284 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200285 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000286 16,
287 &aes_info
288};
289
290const cipher_info_t aes_192_cfb128_info = {
291 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000292 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000293 192,
294 "AES-192-CFB128",
295 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200296 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000297 16,
298 &aes_info
299};
300
301const cipher_info_t aes_256_cfb128_info = {
302 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000303 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000304 256,
305 "AES-256-CFB128",
306 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200307 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000308 16,
309 &aes_info
310};
311#endif /* POLARSSL_CIPHER_MODE_CFB */
312
313#if defined(POLARSSL_CIPHER_MODE_CTR)
314const cipher_info_t aes_128_ctr_info = {
315 POLARSSL_CIPHER_AES_128_CTR,
316 POLARSSL_MODE_CTR,
317 128,
318 "AES-128-CTR",
319 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200320 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000321 16,
322 &aes_info
323};
324
325const cipher_info_t aes_192_ctr_info = {
326 POLARSSL_CIPHER_AES_192_CTR,
327 POLARSSL_MODE_CTR,
328 192,
329 "AES-192-CTR",
330 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200331 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000332 16,
333 &aes_info
334};
335
336const cipher_info_t aes_256_ctr_info = {
337 POLARSSL_CIPHER_AES_256_CTR,
338 POLARSSL_MODE_CTR,
339 256,
340 "AES-256-CTR",
341 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200342 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 16,
344 &aes_info
345};
346#endif /* POLARSSL_CIPHER_MODE_CTR */
347
Paul Bakker68884e32013-01-07 18:20:04 +0100348#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200349static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
350 unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200351{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200352 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
353 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200354}
355
356const cipher_base_t gcm_aes_info = {
357 POLARSSL_CIPHER_ID_AES,
358 NULL,
359 NULL,
360 NULL,
361 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200362 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200363 gcm_aes_setkey_wrap,
364 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200365 gcm_ctx_alloc,
366 gcm_ctx_free,
367};
368
Paul Bakker68884e32013-01-07 18:20:04 +0100369const cipher_info_t aes_128_gcm_info = {
370 POLARSSL_CIPHER_AES_128_GCM,
371 POLARSSL_MODE_GCM,
372 128,
373 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200374 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200375 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100376 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200377 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100378};
379
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200380const cipher_info_t aes_192_gcm_info = {
381 POLARSSL_CIPHER_AES_192_GCM,
382 POLARSSL_MODE_GCM,
383 192,
384 "AES-192-GCM",
385 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200386 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200387 16,
388 &gcm_aes_info
389};
390
Paul Bakker68884e32013-01-07 18:20:04 +0100391const cipher_info_t aes_256_gcm_info = {
392 POLARSSL_CIPHER_AES_256_GCM,
393 POLARSSL_MODE_GCM,
394 256,
395 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200396 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200397 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100398 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200399 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100400};
401#endif /* POLARSSL_GCM_C */
402
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200403#if defined(POLARSSL_CCM_C)
404static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
405 unsigned int key_length )
406{
407 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_AES,
408 key, key_length );
409}
410
411const cipher_base_t ccm_aes_info = {
412 POLARSSL_CIPHER_ID_AES,
413 NULL,
414 NULL,
415 NULL,
416 NULL,
417 NULL,
418 ccm_aes_setkey_wrap,
419 ccm_aes_setkey_wrap,
420 ccm_ctx_alloc,
421 ccm_ctx_free,
422};
423
424const cipher_info_t aes_128_ccm_info = {
425 POLARSSL_CIPHER_AES_128_CCM,
426 POLARSSL_MODE_CCM,
427 128,
428 "AES-128-CCM",
429 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200430 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200431 16,
432 &ccm_aes_info
433};
434
435const cipher_info_t aes_192_ccm_info = {
436 POLARSSL_CIPHER_AES_192_CCM,
437 POLARSSL_MODE_CCM,
438 192,
439 "AES-192-CCM",
440 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200441 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200442 16,
443 &ccm_aes_info
444};
445
446const cipher_info_t aes_256_ccm_info = {
447 POLARSSL_CIPHER_AES_256_CCM,
448 POLARSSL_MODE_CCM,
449 256,
450 "AES-256-CCM",
451 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200452 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200453 16,
454 &ccm_aes_info
455};
456#endif /* POLARSSL_CCM_C */
457
Paul Bakker9af723c2014-05-01 13:03:14 +0200458#endif /* POLARSSL_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000459
460#if defined(POLARSSL_CAMELLIA_C)
461
Paul Bakker5e0efa72013-09-08 23:04:04 +0200462static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
463 const unsigned char *input, unsigned char *output )
464{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200465 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input,
466 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200467}
468
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200469static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
470 size_t length, unsigned char *iv,
471 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000472{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200473#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200474 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
475 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200476#else
477 ((void) ctx);
478 ((void) operation);
479 ((void) length);
480 ((void) iv);
481 ((void) input);
482 ((void) output);
483
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200484 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200485#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000486}
487
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200488static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
489 size_t length, size_t *iv_off, unsigned char *iv,
490 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000491{
492#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200493 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
494 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000495#else
496 ((void) ctx);
497 ((void) operation);
498 ((void) length);
499 ((void) iv_off);
500 ((void) iv);
501 ((void) input);
502 ((void) output);
503
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200504 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200505#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000506}
507
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200508static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
509 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000510 const unsigned char *input, unsigned char *output )
511{
512#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200513 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
514 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000515#else
516 ((void) ctx);
517 ((void) length);
518 ((void) nc_off);
519 ((void) nonce_counter);
520 ((void) stream_block);
521 ((void) input);
522 ((void) output);
523
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200524 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200525#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000526}
527
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200528static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
529 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000530{
531 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
532}
533
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200534static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
535 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000536{
537 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
538}
539
540static void * camellia_ctx_alloc( void )
541{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200542 camellia_context *ctx;
543 ctx = (camellia_context *) polarssl_malloc( sizeof( camellia_context ) );
544
545 if( ctx == NULL )
546 return( NULL );
547
548 camellia_init( ctx );
549
550 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000551}
552
553static void camellia_ctx_free( void *ctx )
554{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200555 camellia_free( (camellia_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200556 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000557}
558
Paul Bakker343a8702011-06-09 14:27:58 +0000559const cipher_base_t camellia_info = {
560 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200561 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000562 camellia_crypt_cbc_wrap,
563 camellia_crypt_cfb128_wrap,
564 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200565 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000566 camellia_setkey_enc_wrap,
567 camellia_setkey_dec_wrap,
568 camellia_ctx_alloc,
569 camellia_ctx_free
570};
571
Paul Bakker5e0efa72013-09-08 23:04:04 +0200572const cipher_info_t camellia_128_ecb_info = {
573 POLARSSL_CIPHER_CAMELLIA_128_ECB,
574 POLARSSL_MODE_ECB,
575 128,
576 "CAMELLIA-128-ECB",
577 16,
578 0,
579 16,
580 &camellia_info
581};
582
583const cipher_info_t camellia_192_ecb_info = {
584 POLARSSL_CIPHER_CAMELLIA_192_ECB,
585 POLARSSL_MODE_ECB,
586 192,
587 "CAMELLIA-192-ECB",
588 16,
589 0,
590 16,
591 &camellia_info
592};
593
594const cipher_info_t camellia_256_ecb_info = {
595 POLARSSL_CIPHER_CAMELLIA_256_ECB,
596 POLARSSL_MODE_ECB,
597 256,
598 "CAMELLIA-256-ECB",
599 16,
600 0,
601 16,
602 &camellia_info
603};
604
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200605#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000606const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000607 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000608 POLARSSL_MODE_CBC,
609 128,
610 "CAMELLIA-128-CBC",
611 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200612 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000613 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000614 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000615};
616
617const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000618 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000619 POLARSSL_MODE_CBC,
620 192,
621 "CAMELLIA-192-CBC",
622 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200623 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000624 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000625 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000626};
627
628const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000629 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000630 POLARSSL_MODE_CBC,
631 256,
632 "CAMELLIA-256-CBC",
633 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200634 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000635 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000636 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000637};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200638#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000639
640#if defined(POLARSSL_CIPHER_MODE_CFB)
641const cipher_info_t camellia_128_cfb128_info = {
642 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000643 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000644 128,
645 "CAMELLIA-128-CFB128",
646 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200647 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000648 16,
649 &camellia_info
650};
651
652const cipher_info_t camellia_192_cfb128_info = {
653 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000654 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000655 192,
656 "CAMELLIA-192-CFB128",
657 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200658 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000659 16,
660 &camellia_info
661};
662
663const cipher_info_t camellia_256_cfb128_info = {
664 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000665 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000666 256,
667 "CAMELLIA-256-CFB128",
668 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200669 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000670 16,
671 &camellia_info
672};
673#endif /* POLARSSL_CIPHER_MODE_CFB */
674
675#if defined(POLARSSL_CIPHER_MODE_CTR)
676const cipher_info_t camellia_128_ctr_info = {
677 POLARSSL_CIPHER_CAMELLIA_128_CTR,
678 POLARSSL_MODE_CTR,
679 128,
680 "CAMELLIA-128-CTR",
681 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200682 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000683 16,
684 &camellia_info
685};
686
687const cipher_info_t camellia_192_ctr_info = {
688 POLARSSL_CIPHER_CAMELLIA_192_CTR,
689 POLARSSL_MODE_CTR,
690 192,
691 "CAMELLIA-192-CTR",
692 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200693 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000694 16,
695 &camellia_info
696};
697
698const cipher_info_t camellia_256_ctr_info = {
699 POLARSSL_CIPHER_CAMELLIA_256_CTR,
700 POLARSSL_MODE_CTR,
701 256,
702 "CAMELLIA-256-CTR",
703 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200704 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000705 16,
706 &camellia_info
707};
708#endif /* POLARSSL_CIPHER_MODE_CTR */
709
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200710#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200711static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
712 unsigned int key_length )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200713{
714 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
715 key, key_length );
716}
717
718const cipher_base_t gcm_camellia_info = {
719 POLARSSL_CIPHER_ID_CAMELLIA,
720 NULL,
721 NULL,
722 NULL,
723 NULL,
724 NULL,
725 gcm_camellia_setkey_wrap,
726 gcm_camellia_setkey_wrap,
727 gcm_ctx_alloc,
728 gcm_ctx_free,
729};
730
731const cipher_info_t camellia_128_gcm_info = {
732 POLARSSL_CIPHER_CAMELLIA_128_GCM,
733 POLARSSL_MODE_GCM,
734 128,
735 "CAMELLIA-128-GCM",
736 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200737 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200738 16,
739 &gcm_camellia_info
740};
741
742const cipher_info_t camellia_192_gcm_info = {
743 POLARSSL_CIPHER_CAMELLIA_192_GCM,
744 POLARSSL_MODE_GCM,
745 192,
746 "CAMELLIA-192-GCM",
747 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200748 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200749 16,
750 &gcm_camellia_info
751};
752
753const cipher_info_t camellia_256_gcm_info = {
754 POLARSSL_CIPHER_CAMELLIA_256_GCM,
755 POLARSSL_MODE_GCM,
756 256,
757 "CAMELLIA-256-GCM",
758 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200759 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200760 16,
761 &gcm_camellia_info
762};
763#endif /* POLARSSL_GCM_C */
764
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200765#if defined(POLARSSL_CCM_C)
766static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
767 unsigned int key_length )
768{
769 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
770 key, key_length );
771}
772
773const cipher_base_t ccm_camellia_info = {
774 POLARSSL_CIPHER_ID_CAMELLIA,
775 NULL,
776 NULL,
777 NULL,
778 NULL,
779 NULL,
780 ccm_camellia_setkey_wrap,
781 ccm_camellia_setkey_wrap,
782 ccm_ctx_alloc,
783 ccm_ctx_free,
784};
785
786const cipher_info_t camellia_128_ccm_info = {
787 POLARSSL_CIPHER_CAMELLIA_128_CCM,
788 POLARSSL_MODE_CCM,
789 128,
790 "CAMELLIA-128-CCM",
791 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200792 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200793 16,
794 &ccm_camellia_info
795};
796
797const cipher_info_t camellia_192_ccm_info = {
798 POLARSSL_CIPHER_CAMELLIA_192_CCM,
799 POLARSSL_MODE_CCM,
800 192,
801 "CAMELLIA-192-CCM",
802 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200803 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200804 16,
805 &ccm_camellia_info
806};
807
808const cipher_info_t camellia_256_ccm_info = {
809 POLARSSL_CIPHER_CAMELLIA_256_CCM,
810 POLARSSL_MODE_CCM,
811 256,
812 "CAMELLIA-256-CCM",
813 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200814 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200815 16,
816 &ccm_camellia_info
817};
818#endif /* POLARSSL_CCM_C */
819
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200820#endif /* POLARSSL_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000821
822#if defined(POLARSSL_DES_C)
823
Paul Bakker5e0efa72013-09-08 23:04:04 +0200824static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
825 const unsigned char *input, unsigned char *output )
826{
827 ((void) operation);
828 return des_crypt_ecb( (des_context *) ctx, input, output );
829}
830
831static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
832 const unsigned char *input, unsigned char *output )
833{
834 ((void) operation);
835 return des3_crypt_ecb( (des3_context *) ctx, input, output );
836}
837
Paul Bakkerfae35f02013-03-13 10:33:51 +0100838static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000839 unsigned char *iv, const unsigned char *input, unsigned char *output )
840{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200841#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200842 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
843 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200844#else
845 ((void) ctx);
846 ((void) operation);
847 ((void) length);
848 ((void) iv);
849 ((void) input);
850 ((void) output);
851
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200852 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200853#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000854}
855
Paul Bakkerfae35f02013-03-13 10:33:51 +0100856static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000857 unsigned char *iv, const unsigned char *input, unsigned char *output )
858{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200859#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200860 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
861 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200862#else
863 ((void) ctx);
864 ((void) operation);
865 ((void) length);
866 ((void) iv);
867 ((void) input);
868 ((void) output);
869
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200870 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200871#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000872}
873
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200874static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
875 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000876{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000877 ((void) key_length);
878
Paul Bakker8123e9d2011-01-06 15:37:30 +0000879 return des_setkey_dec( (des_context *) ctx, key );
880}
881
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200882static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
883 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000884{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000885 ((void) key_length);
886
Paul Bakker8123e9d2011-01-06 15:37:30 +0000887 return des_setkey_enc( (des_context *) ctx, key );
888}
889
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200890static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
891 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000892{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000893 ((void) key_length);
894
Paul Bakker8123e9d2011-01-06 15:37:30 +0000895 return des3_set2key_dec( (des3_context *) ctx, key );
896}
897
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200898static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
899 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000900{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000901 ((void) key_length);
902
Paul Bakker8123e9d2011-01-06 15:37:30 +0000903 return des3_set2key_enc( (des3_context *) ctx, key );
904}
905
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200906static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
907 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000908{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000909 ((void) key_length);
910
Paul Bakker8123e9d2011-01-06 15:37:30 +0000911 return des3_set3key_dec( (des3_context *) ctx, key );
912}
913
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200914static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
915 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000916{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000917 ((void) key_length);
918
Paul Bakker8123e9d2011-01-06 15:37:30 +0000919 return des3_set3key_enc( (des3_context *) ctx, key );
920}
921
922static void * des_ctx_alloc( void )
923{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200924 des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000925
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200926 if( des == NULL )
927 return( NULL );
928
929 des_init( des );
930
931 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000932}
933
934static void des_ctx_free( void *ctx )
935{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200936 des_free( (des_context *) ctx );
Paul Bakker34617722014-06-13 17:20:13 +0200937 polarssl_free( ctx );
938}
939
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200940static void * des3_ctx_alloc( void )
941{
942 des3_context *des3;
943 des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
944
945 if( des3 == NULL )
946 return( NULL );
947
948 des3_init( des3 );
949
950 return( des3 );
951}
952
Paul Bakker34617722014-06-13 17:20:13 +0200953static void des3_ctx_free( void *ctx )
954{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200955 des3_free( (des3_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200956 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000957}
958
Paul Bakker343a8702011-06-09 14:27:58 +0000959const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000960 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200961 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000962 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200963 NULL,
964 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200965 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000966 des_setkey_enc_wrap,
967 des_setkey_dec_wrap,
968 des_ctx_alloc,
969 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000970};
971
Paul Bakker5e0efa72013-09-08 23:04:04 +0200972const cipher_info_t des_ecb_info = {
973 POLARSSL_CIPHER_DES_ECB,
974 POLARSSL_MODE_ECB,
975 POLARSSL_KEY_LENGTH_DES,
976 "DES-ECB",
977 8,
978 0,
979 8,
980 &des_info
981};
982
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200983#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000984const cipher_info_t des_cbc_info = {
985 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000986 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000987 POLARSSL_KEY_LENGTH_DES,
988 "DES-CBC",
989 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200990 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000991 8,
992 &des_info
993};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200994#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000995
996const cipher_base_t des_ede_info = {
997 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200998 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000999 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001000 NULL,
1001 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001002 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +00001003 des3_set2key_enc_wrap,
1004 des3_set2key_dec_wrap,
1005 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001006 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001007};
1008
Paul Bakker5e0efa72013-09-08 23:04:04 +02001009const cipher_info_t des_ede_ecb_info = {
1010 POLARSSL_CIPHER_DES_EDE_ECB,
1011 POLARSSL_MODE_ECB,
1012 POLARSSL_KEY_LENGTH_DES_EDE,
1013 "DES-EDE-ECB",
1014 8,
1015 0,
1016 8,
1017 &des_ede_info
1018};
1019
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001020#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001021const cipher_info_t des_ede_cbc_info = {
1022 POLARSSL_CIPHER_DES_EDE_CBC,
1023 POLARSSL_MODE_CBC,
1024 POLARSSL_KEY_LENGTH_DES_EDE,
1025 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001026 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001027 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001028 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001029 &des_ede_info
1030};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001031#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001032
1033const cipher_base_t des_ede3_info = {
1034 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001035 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +00001036 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001037 NULL,
1038 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001039 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +00001040 des3_set3key_enc_wrap,
1041 des3_set3key_dec_wrap,
1042 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001043 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001044};
1045
Paul Bakker5e0efa72013-09-08 23:04:04 +02001046const cipher_info_t des_ede3_ecb_info = {
1047 POLARSSL_CIPHER_DES_EDE3_ECB,
1048 POLARSSL_MODE_ECB,
1049 POLARSSL_KEY_LENGTH_DES_EDE3,
1050 "DES-EDE3-ECB",
1051 8,
1052 0,
1053 8,
1054 &des_ede3_info
1055};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001056#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001057const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +00001058 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +00001059 POLARSSL_MODE_CBC,
1060 POLARSSL_KEY_LENGTH_DES_EDE3,
1061 "DES-EDE3-CBC",
1062 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001063 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001064 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001065 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001066};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001067#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker9af723c2014-05-01 13:03:14 +02001068#endif /* POLARSSL_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001069
Paul Bakker6132d0a2012-07-04 17:10:40 +00001070#if defined(POLARSSL_BLOWFISH_C)
1071
Paul Bakker5e0efa72013-09-08 23:04:04 +02001072static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
1073 const unsigned char *input, unsigned char *output )
1074{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001075 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
1076 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001077}
1078
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001079static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
1080 size_t length, unsigned char *iv, const unsigned char *input,
1081 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001082{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001083#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001084 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
1085 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001086#else
1087 ((void) ctx);
1088 ((void) operation);
1089 ((void) length);
1090 ((void) iv);
1091 ((void) input);
1092 ((void) output);
1093
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001094 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001095#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001096}
1097
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001098static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
1099 size_t length, size_t *iv_off, unsigned char *iv,
1100 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001101{
1102#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001103 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
1104 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001105#else
1106 ((void) ctx);
1107 ((void) operation);
1108 ((void) length);
1109 ((void) iv_off);
1110 ((void) iv);
1111 ((void) input);
1112 ((void) output);
1113
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001114 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001115#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001116}
1117
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001118static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1119 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001120 const unsigned char *input, unsigned char *output )
1121{
1122#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001123 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
1124 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001125#else
1126 ((void) ctx);
1127 ((void) length);
1128 ((void) nc_off);
1129 ((void) nonce_counter);
1130 ((void) stream_block);
1131 ((void) input);
1132 ((void) output);
1133
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001134 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001135#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001136}
1137
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001138static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1139 unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001140{
1141 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
1142}
1143
1144static void * blowfish_ctx_alloc( void )
1145{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001146 blowfish_context *ctx;
1147 ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
1148
1149 if( ctx == NULL )
1150 return( NULL );
1151
1152 blowfish_init( ctx );
1153
1154 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001155}
1156
1157static void blowfish_ctx_free( void *ctx )
1158{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001159 blowfish_free( (blowfish_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +02001160 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001161}
1162
1163const cipher_base_t blowfish_info = {
1164 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001165 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001166 blowfish_crypt_cbc_wrap,
1167 blowfish_crypt_cfb64_wrap,
1168 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001169 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001170 blowfish_setkey_wrap,
1171 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001172 blowfish_ctx_alloc,
1173 blowfish_ctx_free
1174};
1175
Paul Bakker5e0efa72013-09-08 23:04:04 +02001176const cipher_info_t blowfish_ecb_info = {
1177 POLARSSL_CIPHER_BLOWFISH_ECB,
1178 POLARSSL_MODE_ECB,
1179 128,
1180 "BLOWFISH-ECB",
1181 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001182 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001183 8,
1184 &blowfish_info
1185};
1186
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001187#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001188const cipher_info_t blowfish_cbc_info = {
1189 POLARSSL_CIPHER_BLOWFISH_CBC,
1190 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001191 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001192 "BLOWFISH-CBC",
1193 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001194 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001195 8,
1196 &blowfish_info
1197};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001198#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001199
1200#if defined(POLARSSL_CIPHER_MODE_CFB)
1201const cipher_info_t blowfish_cfb64_info = {
1202 POLARSSL_CIPHER_BLOWFISH_CFB64,
1203 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001204 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001205 "BLOWFISH-CFB64",
1206 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001207 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001208 8,
1209 &blowfish_info
1210};
1211#endif /* POLARSSL_CIPHER_MODE_CFB */
1212
1213#if defined(POLARSSL_CIPHER_MODE_CTR)
1214const cipher_info_t blowfish_ctr_info = {
1215 POLARSSL_CIPHER_BLOWFISH_CTR,
1216 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001217 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001218 "BLOWFISH-CTR",
1219 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001220 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001221 8,
1222 &blowfish_info
1223};
1224#endif /* POLARSSL_CIPHER_MODE_CTR */
1225#endif /* POLARSSL_BLOWFISH_C */
1226
Paul Bakker68884e32013-01-07 18:20:04 +01001227#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001228static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1229 const unsigned char *input,
1230 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001231{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001232 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001233}
1234
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001235static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1236 unsigned int key_length )
1237{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001238 /* we get key_length in bits, arc4 expects it in bytes */
Paul Bakker66d5d072014-06-17 16:39:18 +02001239 if( key_length % 8 != 0 )
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001240 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
1241
1242 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001243 return( 0 );
1244}
1245
1246static void * arc4_ctx_alloc( void )
1247{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001248 arc4_context *ctx;
1249 ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
1250
1251 if( ctx == NULL )
1252 return( NULL );
1253
1254 arc4_init( ctx );
1255
1256 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001257}
Paul Bakker68884e32013-01-07 18:20:04 +01001258
1259static void arc4_ctx_free( void *ctx )
1260{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001261 arc4_free( (arc4_context *) ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001262 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001263}
1264
1265const cipher_base_t arc4_base_info = {
1266 POLARSSL_CIPHER_ID_ARC4,
1267 NULL,
1268 NULL,
1269 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001270 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001271 arc4_crypt_stream_wrap,
1272 arc4_setkey_wrap,
1273 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001274 arc4_ctx_alloc,
1275 arc4_ctx_free
1276};
1277
1278const cipher_info_t arc4_128_info = {
1279 POLARSSL_CIPHER_ARC4_128,
1280 POLARSSL_MODE_STREAM,
1281 128,
1282 "ARC4-128",
1283 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001284 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001285 1,
1286 &arc4_base_info
1287};
1288#endif /* POLARSSL_ARC4_C */
1289
Paul Bakkerfab5c822012-02-06 16:45:10 +00001290#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001291static int null_crypt_stream( void *ctx, size_t length,
1292 const unsigned char *input,
1293 unsigned char *output )
1294{
1295 ((void) ctx);
1296 memmove( output, input, length );
1297 return( 0 );
1298}
1299
1300static int null_setkey( void *ctx, const unsigned char *key,
1301 unsigned int key_length )
1302{
1303 ((void) ctx);
1304 ((void) key);
1305 ((void) key_length);
1306
1307 return( 0 );
1308}
1309
Paul Bakkerfab5c822012-02-06 16:45:10 +00001310static void * null_ctx_alloc( void )
1311{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001312 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001313}
1314
Paul Bakkerfab5c822012-02-06 16:45:10 +00001315static void null_ctx_free( void *ctx )
1316{
1317 ((void) ctx);
1318}
1319
1320const cipher_base_t null_base_info = {
1321 POLARSSL_CIPHER_ID_NULL,
1322 NULL,
1323 NULL,
1324 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001325 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001326 null_crypt_stream,
1327 null_setkey,
1328 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001329 null_ctx_alloc,
1330 null_ctx_free
1331};
1332
1333const cipher_info_t null_cipher_info = {
1334 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001335 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001336 0,
1337 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001338 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001339 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001340 1,
1341 &null_base_info
1342};
1343#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1344
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001345const cipher_definition_t cipher_definitions[] =
1346{
1347#if defined(POLARSSL_AES_C)
1348 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1349 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1350 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1351#if defined(POLARSSL_CIPHER_MODE_CBC)
1352 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1353 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1354 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1355#endif
1356#if defined(POLARSSL_CIPHER_MODE_CFB)
1357 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1358 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1359 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1360#endif
1361#if defined(POLARSSL_CIPHER_MODE_CTR)
1362 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1363 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1364 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1365#endif
1366#if defined(POLARSSL_GCM_C)
1367 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1368 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1369 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1370#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001371#if defined(POLARSSL_CCM_C)
1372 { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1373 { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1374 { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
1375#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001376#endif /* POLARSSL_AES_C */
1377
1378#if defined(POLARSSL_ARC4_C)
1379 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1380#endif
1381
1382#if defined(POLARSSL_BLOWFISH_C)
1383 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1384#if defined(POLARSSL_CIPHER_MODE_CBC)
1385 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1386#endif
1387#if defined(POLARSSL_CIPHER_MODE_CFB)
1388 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1389#endif
1390#if defined(POLARSSL_CIPHER_MODE_CTR)
1391 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1392#endif
1393#endif /* POLARSSL_BLOWFISH_C */
1394
1395#if defined(POLARSSL_CAMELLIA_C)
1396 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1397 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
Manuel Pégourié-Gonnard13e0d442013-10-24 12:59:00 +02001398 { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001399#if defined(POLARSSL_CIPHER_MODE_CBC)
1400 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1401 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1402 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1403#endif
1404#if defined(POLARSSL_CIPHER_MODE_CFB)
1405 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1406 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1407 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1408#endif
1409#if defined(POLARSSL_CIPHER_MODE_CTR)
1410 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1411 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1412 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1413#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001414#if defined(POLARSSL_GCM_C)
1415 { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1416 { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1417 { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
1418#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001419#if defined(POLARSSL_CCM_C)
1420 { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1421 { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1422 { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
1423#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001424#endif /* POLARSSL_CAMELLIA_C */
1425
1426#if defined(POLARSSL_DES_C)
1427 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1428 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1429 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1430#if defined(POLARSSL_CIPHER_MODE_CBC)
1431 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1432 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1433 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1434#endif
1435#endif /* POLARSSL_DES_C */
1436
1437#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard057e0cf2013-10-14 14:19:31 +02001438 { POLARSSL_CIPHER_NULL, &null_cipher_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001439#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1440
1441 { 0, NULL }
1442};
1443
1444#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1445int supported_ciphers[NUM_CIPHERS];
1446
Paul Bakker9af723c2014-05-01 13:03:14 +02001447#endif /* POLARSSL_CIPHER_C */