blob: ddfb006256fdb53ad8b70f805f3a69df000e53fc [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 *
Paul Bakker20281562011-11-11 10:34:04 +00004 * \brief Generic cipher wrapper for PolarSSL
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Paul Bakker7dc4c442014-02-01 22:50:26 +01008 * Copyright (C) 2006-2014, Brainspark B.V.
Paul Bakker8123e9d2011-01-06 15:37:30 +00009 *
10 * This file is part of PolarSSL (http://www.polarssl.org)
11 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
12 *
13 * All rights reserved.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 */
29
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker8123e9d2011-01-06 15:37:30 +000031#include "polarssl/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020032#else
33#include POLARSSL_CONFIG_FILE
34#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000035
36#if defined(POLARSSL_CIPHER_C)
37
38#include "polarssl/cipher_wrap.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000039
40#if defined(POLARSSL_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000041#include "polarssl/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020044#if defined(POLARSSL_ARC4_C)
45#include "polarssl/arc4.h"
46#endif
47
Paul Bakkerf6543712012-03-05 14:01:29 +000048#if defined(POLARSSL_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000049#include "polarssl/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000050#endif
51
52#if defined(POLARSSL_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000053#include "polarssl/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000054#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000055
Paul Bakker6132d0a2012-07-04 17:10:40 +000056#if defined(POLARSSL_BLOWFISH_C)
57#include "polarssl/blowfish.h"
58#endif
59
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020060#if defined(POLARSSL_GCM_C)
61#include "polarssl/gcm.h"
62#endif
63
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020064#if defined(POLARSSL_CCM_C)
65#include "polarssl/ccm.h"
66#endif
67
Paul Bakker7dc4c442014-02-01 22:50:26 +010068#if defined(POLARSSL_PLATFORM_C)
69#include "polarssl/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020070#else
71#define polarssl_malloc malloc
72#define polarssl_free free
73#endif
74
Paul Bakker8123e9d2011-01-06 15:37:30 +000075#include <stdlib.h>
76
Paul Bakker34617722014-06-13 17:20:13 +020077/* Implementation that should never be optimized out by the compiler */
78static void polarssl_zeroize( void *v, size_t n ) {
79 volatile unsigned char *p = v; while( n-- ) *p++ = 0;
80}
81
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020082#if defined(POLARSSL_GCM_C)
83/* shared by all GCM ciphers */
84static void *gcm_ctx_alloc( void )
85{
86 return polarssl_malloc( sizeof( gcm_context ) );
87}
88
89static void gcm_ctx_free( void *ctx )
90{
91 gcm_free( ctx );
92 polarssl_free( ctx );
93}
Paul Bakker9af723c2014-05-01 13:03:14 +020094#endif /* POLARSSL_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020095
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020096#if defined(POLARSSL_CCM_C)
97/* shared by all CCM ciphers */
98static void *ccm_ctx_alloc( void )
99{
100 return polarssl_malloc( sizeof( ccm_context ) );
101}
102
103static void ccm_ctx_free( void *ctx )
104{
105 ccm_free( ctx );
106 polarssl_free( ctx );
107}
108#endif /* POLARSSL_CCM_C */
109
Paul Bakker8123e9d2011-01-06 15:37:30 +0000110#if defined(POLARSSL_AES_C)
111
Paul Bakker5e0efa72013-09-08 23:04:04 +0200112static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
113 const unsigned char *input, unsigned char *output )
114{
115 return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
116}
117
Paul Bakkerfae35f02013-03-13 10:33:51 +0100118static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000119 unsigned char *iv, const unsigned char *input, unsigned char *output )
120{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200121#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200122 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
123 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200124#else
125 ((void) ctx);
126 ((void) operation);
127 ((void) length);
128 ((void) iv);
129 ((void) input);
130 ((void) output);
131
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200132 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200133#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000134}
135
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200136static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
137 size_t length, size_t *iv_off, unsigned char *iv,
138 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000139{
140#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200141 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
142 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000143#else
144 ((void) ctx);
145 ((void) operation);
146 ((void) length);
147 ((void) iv_off);
148 ((void) iv);
149 ((void) input);
150 ((void) output);
151
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200152 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200153#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000154}
155
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200156static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
157 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000158 const unsigned char *input, unsigned char *output )
159{
160#if defined(POLARSSL_CIPHER_MODE_CTR)
161 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
162 stream_block, input, output );
163#else
164 ((void) ctx);
165 ((void) length);
166 ((void) nc_off);
167 ((void) nonce_counter);
168 ((void) stream_block);
169 ((void) input);
170 ((void) output);
171
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200172 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200173#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000174}
175
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200176static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
177 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000178{
179 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
180}
181
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200182static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
183 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000184{
185 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
186}
187
188static void * aes_ctx_alloc( void )
189{
Paul Bakker6e339b52013-07-03 13:37:05 +0200190 return polarssl_malloc( sizeof( aes_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000191}
192
193static void aes_ctx_free( void *ctx )
194{
Paul Bakker34617722014-06-13 17:20:13 +0200195 polarssl_zeroize( ctx, sizeof( aes_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200196 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000197}
198
Paul Bakker343a8702011-06-09 14:27:58 +0000199const cipher_base_t aes_info = {
200 POLARSSL_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200201 aes_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000202 aes_crypt_cbc_wrap,
203 aes_crypt_cfb128_wrap,
204 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200205 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000206 aes_setkey_enc_wrap,
207 aes_setkey_dec_wrap,
208 aes_ctx_alloc,
209 aes_ctx_free
210};
211
Paul Bakker5e0efa72013-09-08 23:04:04 +0200212const cipher_info_t aes_128_ecb_info = {
213 POLARSSL_CIPHER_AES_128_ECB,
214 POLARSSL_MODE_ECB,
215 128,
216 "AES-128-ECB",
217 16,
218 0,
219 16,
220 &aes_info
221};
222
223const cipher_info_t aes_192_ecb_info = {
224 POLARSSL_CIPHER_AES_192_ECB,
225 POLARSSL_MODE_ECB,
226 192,
227 "AES-192-ECB",
228 16,
229 0,
230 16,
231 &aes_info
232};
233
234const cipher_info_t aes_256_ecb_info = {
235 POLARSSL_CIPHER_AES_256_ECB,
236 POLARSSL_MODE_ECB,
237 256,
238 "AES-256-ECB",
239 16,
240 0,
241 16,
242 &aes_info
243};
244
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200245#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000246const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000247 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000248 POLARSSL_MODE_CBC,
249 128,
250 "AES-128-CBC",
251 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200252 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000253 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000254 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000255};
256
257const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000258 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000259 POLARSSL_MODE_CBC,
260 192,
261 "AES-192-CBC",
262 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200263 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000264 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000265 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000266};
267
268const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000269 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000270 POLARSSL_MODE_CBC,
271 256,
272 "AES-256-CBC",
273 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200274 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000275 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000276 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000277};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200278#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000279
280#if defined(POLARSSL_CIPHER_MODE_CFB)
281const cipher_info_t aes_128_cfb128_info = {
282 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000283 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000284 128,
285 "AES-128-CFB128",
286 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200287 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000288 16,
289 &aes_info
290};
291
292const cipher_info_t aes_192_cfb128_info = {
293 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000294 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000295 192,
296 "AES-192-CFB128",
297 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200298 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000299 16,
300 &aes_info
301};
302
303const cipher_info_t aes_256_cfb128_info = {
304 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000305 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000306 256,
307 "AES-256-CFB128",
308 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200309 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000310 16,
311 &aes_info
312};
313#endif /* POLARSSL_CIPHER_MODE_CFB */
314
315#if defined(POLARSSL_CIPHER_MODE_CTR)
316const cipher_info_t aes_128_ctr_info = {
317 POLARSSL_CIPHER_AES_128_CTR,
318 POLARSSL_MODE_CTR,
319 128,
320 "AES-128-CTR",
321 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200322 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000323 16,
324 &aes_info
325};
326
327const cipher_info_t aes_192_ctr_info = {
328 POLARSSL_CIPHER_AES_192_CTR,
329 POLARSSL_MODE_CTR,
330 192,
331 "AES-192-CTR",
332 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200333 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000334 16,
335 &aes_info
336};
337
338const cipher_info_t aes_256_ctr_info = {
339 POLARSSL_CIPHER_AES_256_CTR,
340 POLARSSL_MODE_CTR,
341 256,
342 "AES-256-CTR",
343 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200344 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000345 16,
346 &aes_info
347};
348#endif /* POLARSSL_CIPHER_MODE_CTR */
349
Paul Bakker68884e32013-01-07 18:20:04 +0100350#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200351static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
352 unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200353{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200354 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
355 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200356}
357
358const cipher_base_t gcm_aes_info = {
359 POLARSSL_CIPHER_ID_AES,
360 NULL,
361 NULL,
362 NULL,
363 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200364 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200365 gcm_aes_setkey_wrap,
366 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200367 gcm_ctx_alloc,
368 gcm_ctx_free,
369};
370
Paul Bakker68884e32013-01-07 18:20:04 +0100371const cipher_info_t aes_128_gcm_info = {
372 POLARSSL_CIPHER_AES_128_GCM,
373 POLARSSL_MODE_GCM,
374 128,
375 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200376 12,
377 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100378 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200379 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100380};
381
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200382const cipher_info_t aes_192_gcm_info = {
383 POLARSSL_CIPHER_AES_192_GCM,
384 POLARSSL_MODE_GCM,
385 192,
386 "AES-192-GCM",
387 12,
388 1,
389 16,
390 &gcm_aes_info
391};
392
Paul Bakker68884e32013-01-07 18:20:04 +0100393const cipher_info_t aes_256_gcm_info = {
394 POLARSSL_CIPHER_AES_256_GCM,
395 POLARSSL_MODE_GCM,
396 256,
397 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200398 12,
399 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100400 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200401 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100402};
403#endif /* POLARSSL_GCM_C */
404
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200405#if defined(POLARSSL_CCM_C)
406static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
407 unsigned int key_length )
408{
409 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_AES,
410 key, key_length );
411}
412
413const cipher_base_t ccm_aes_info = {
414 POLARSSL_CIPHER_ID_AES,
415 NULL,
416 NULL,
417 NULL,
418 NULL,
419 NULL,
420 ccm_aes_setkey_wrap,
421 ccm_aes_setkey_wrap,
422 ccm_ctx_alloc,
423 ccm_ctx_free,
424};
425
426const cipher_info_t aes_128_ccm_info = {
427 POLARSSL_CIPHER_AES_128_CCM,
428 POLARSSL_MODE_CCM,
429 128,
430 "AES-128-CCM",
431 12,
432 1,
433 16,
434 &ccm_aes_info
435};
436
437const cipher_info_t aes_192_ccm_info = {
438 POLARSSL_CIPHER_AES_192_CCM,
439 POLARSSL_MODE_CCM,
440 192,
441 "AES-192-CCM",
442 12,
443 1,
444 16,
445 &ccm_aes_info
446};
447
448const cipher_info_t aes_256_ccm_info = {
449 POLARSSL_CIPHER_AES_256_CCM,
450 POLARSSL_MODE_CCM,
451 256,
452 "AES-256-CCM",
453 12,
454 1,
455 16,
456 &ccm_aes_info
457};
458#endif /* POLARSSL_CCM_C */
459
Paul Bakker9af723c2014-05-01 13:03:14 +0200460#endif /* POLARSSL_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000461
462#if defined(POLARSSL_CAMELLIA_C)
463
Paul Bakker5e0efa72013-09-08 23:04:04 +0200464static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
465 const unsigned char *input, unsigned char *output )
466{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200467 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input,
468 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200469}
470
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200471static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
472 size_t length, unsigned char *iv,
473 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000474{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200475#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200476 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
477 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200478#else
479 ((void) ctx);
480 ((void) operation);
481 ((void) length);
482 ((void) iv);
483 ((void) input);
484 ((void) output);
485
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200486 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200487#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000488}
489
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200490static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
491 size_t length, size_t *iv_off, unsigned char *iv,
492 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000493{
494#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200495 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
496 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000497#else
498 ((void) ctx);
499 ((void) operation);
500 ((void) length);
501 ((void) iv_off);
502 ((void) iv);
503 ((void) input);
504 ((void) output);
505
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200506 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200507#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000508}
509
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200510static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
511 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000512 const unsigned char *input, unsigned char *output )
513{
514#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200515 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
516 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000517#else
518 ((void) ctx);
519 ((void) length);
520 ((void) nc_off);
521 ((void) nonce_counter);
522 ((void) stream_block);
523 ((void) input);
524 ((void) output);
525
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200526 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200527#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000528}
529
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200530static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
531 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000532{
533 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
534}
535
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200536static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
537 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000538{
539 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
540}
541
542static void * camellia_ctx_alloc( void )
543{
Paul Bakker6e339b52013-07-03 13:37:05 +0200544 return polarssl_malloc( sizeof( camellia_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000545}
546
547static void camellia_ctx_free( void *ctx )
548{
Paul Bakker34617722014-06-13 17:20:13 +0200549 polarssl_zeroize( ctx, sizeof( camellia_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200550 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000551}
552
Paul Bakker343a8702011-06-09 14:27:58 +0000553const cipher_base_t camellia_info = {
554 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200555 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000556 camellia_crypt_cbc_wrap,
557 camellia_crypt_cfb128_wrap,
558 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200559 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000560 camellia_setkey_enc_wrap,
561 camellia_setkey_dec_wrap,
562 camellia_ctx_alloc,
563 camellia_ctx_free
564};
565
Paul Bakker5e0efa72013-09-08 23:04:04 +0200566const cipher_info_t camellia_128_ecb_info = {
567 POLARSSL_CIPHER_CAMELLIA_128_ECB,
568 POLARSSL_MODE_ECB,
569 128,
570 "CAMELLIA-128-ECB",
571 16,
572 0,
573 16,
574 &camellia_info
575};
576
577const cipher_info_t camellia_192_ecb_info = {
578 POLARSSL_CIPHER_CAMELLIA_192_ECB,
579 POLARSSL_MODE_ECB,
580 192,
581 "CAMELLIA-192-ECB",
582 16,
583 0,
584 16,
585 &camellia_info
586};
587
588const cipher_info_t camellia_256_ecb_info = {
589 POLARSSL_CIPHER_CAMELLIA_256_ECB,
590 POLARSSL_MODE_ECB,
591 256,
592 "CAMELLIA-256-ECB",
593 16,
594 0,
595 16,
596 &camellia_info
597};
598
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200599#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000600const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000601 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000602 POLARSSL_MODE_CBC,
603 128,
604 "CAMELLIA-128-CBC",
605 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200606 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000607 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000608 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000609};
610
611const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000612 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000613 POLARSSL_MODE_CBC,
614 192,
615 "CAMELLIA-192-CBC",
616 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200617 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000618 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000619 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000620};
621
622const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000623 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000624 POLARSSL_MODE_CBC,
625 256,
626 "CAMELLIA-256-CBC",
627 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200628 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000629 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000630 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000631};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200632#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000633
634#if defined(POLARSSL_CIPHER_MODE_CFB)
635const cipher_info_t camellia_128_cfb128_info = {
636 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000637 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000638 128,
639 "CAMELLIA-128-CFB128",
640 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200641 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000642 16,
643 &camellia_info
644};
645
646const cipher_info_t camellia_192_cfb128_info = {
647 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000648 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000649 192,
650 "CAMELLIA-192-CFB128",
651 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200652 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000653 16,
654 &camellia_info
655};
656
657const cipher_info_t camellia_256_cfb128_info = {
658 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000659 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000660 256,
661 "CAMELLIA-256-CFB128",
662 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200663 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000664 16,
665 &camellia_info
666};
667#endif /* POLARSSL_CIPHER_MODE_CFB */
668
669#if defined(POLARSSL_CIPHER_MODE_CTR)
670const cipher_info_t camellia_128_ctr_info = {
671 POLARSSL_CIPHER_CAMELLIA_128_CTR,
672 POLARSSL_MODE_CTR,
673 128,
674 "CAMELLIA-128-CTR",
675 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200676 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000677 16,
678 &camellia_info
679};
680
681const cipher_info_t camellia_192_ctr_info = {
682 POLARSSL_CIPHER_CAMELLIA_192_CTR,
683 POLARSSL_MODE_CTR,
684 192,
685 "CAMELLIA-192-CTR",
686 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200687 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000688 16,
689 &camellia_info
690};
691
692const cipher_info_t camellia_256_ctr_info = {
693 POLARSSL_CIPHER_CAMELLIA_256_CTR,
694 POLARSSL_MODE_CTR,
695 256,
696 "CAMELLIA-256-CTR",
697 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200698 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000699 16,
700 &camellia_info
701};
702#endif /* POLARSSL_CIPHER_MODE_CTR */
703
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200704#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200705static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
706 unsigned int key_length )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200707{
708 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
709 key, key_length );
710}
711
712const cipher_base_t gcm_camellia_info = {
713 POLARSSL_CIPHER_ID_CAMELLIA,
714 NULL,
715 NULL,
716 NULL,
717 NULL,
718 NULL,
719 gcm_camellia_setkey_wrap,
720 gcm_camellia_setkey_wrap,
721 gcm_ctx_alloc,
722 gcm_ctx_free,
723};
724
725const cipher_info_t camellia_128_gcm_info = {
726 POLARSSL_CIPHER_CAMELLIA_128_GCM,
727 POLARSSL_MODE_GCM,
728 128,
729 "CAMELLIA-128-GCM",
730 12,
731 1,
732 16,
733 &gcm_camellia_info
734};
735
736const cipher_info_t camellia_192_gcm_info = {
737 POLARSSL_CIPHER_CAMELLIA_192_GCM,
738 POLARSSL_MODE_GCM,
739 192,
740 "CAMELLIA-192-GCM",
741 12,
742 1,
743 16,
744 &gcm_camellia_info
745};
746
747const cipher_info_t camellia_256_gcm_info = {
748 POLARSSL_CIPHER_CAMELLIA_256_GCM,
749 POLARSSL_MODE_GCM,
750 256,
751 "CAMELLIA-256-GCM",
752 12,
753 1,
754 16,
755 &gcm_camellia_info
756};
757#endif /* POLARSSL_GCM_C */
758
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200759#if defined(POLARSSL_CCM_C)
760static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
761 unsigned int key_length )
762{
763 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
764 key, key_length );
765}
766
767const cipher_base_t ccm_camellia_info = {
768 POLARSSL_CIPHER_ID_CAMELLIA,
769 NULL,
770 NULL,
771 NULL,
772 NULL,
773 NULL,
774 ccm_camellia_setkey_wrap,
775 ccm_camellia_setkey_wrap,
776 ccm_ctx_alloc,
777 ccm_ctx_free,
778};
779
780const cipher_info_t camellia_128_ccm_info = {
781 POLARSSL_CIPHER_CAMELLIA_128_CCM,
782 POLARSSL_MODE_CCM,
783 128,
784 "CAMELLIA-128-CCM",
785 12,
786 1,
787 16,
788 &ccm_camellia_info
789};
790
791const cipher_info_t camellia_192_ccm_info = {
792 POLARSSL_CIPHER_CAMELLIA_192_CCM,
793 POLARSSL_MODE_CCM,
794 192,
795 "CAMELLIA-192-CCM",
796 12,
797 1,
798 16,
799 &ccm_camellia_info
800};
801
802const cipher_info_t camellia_256_ccm_info = {
803 POLARSSL_CIPHER_CAMELLIA_256_CCM,
804 POLARSSL_MODE_CCM,
805 256,
806 "CAMELLIA-256-CCM",
807 12,
808 1,
809 16,
810 &ccm_camellia_info
811};
812#endif /* POLARSSL_CCM_C */
813
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200814#endif /* POLARSSL_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000815
816#if defined(POLARSSL_DES_C)
817
Paul Bakker5e0efa72013-09-08 23:04:04 +0200818static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
819 const unsigned char *input, unsigned char *output )
820{
821 ((void) operation);
822 return des_crypt_ecb( (des_context *) ctx, input, output );
823}
824
825static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
826 const unsigned char *input, unsigned char *output )
827{
828 ((void) operation);
829 return des3_crypt_ecb( (des3_context *) ctx, input, output );
830}
831
Paul Bakkerfae35f02013-03-13 10:33:51 +0100832static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000833 unsigned char *iv, const unsigned char *input, unsigned char *output )
834{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200835#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200836 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
837 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200838#else
839 ((void) ctx);
840 ((void) operation);
841 ((void) length);
842 ((void) iv);
843 ((void) input);
844 ((void) output);
845
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200846 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200847#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000848}
849
Paul Bakkerfae35f02013-03-13 10:33:51 +0100850static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000851 unsigned char *iv, const unsigned char *input, unsigned char *output )
852{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200853#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200854 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
855 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200856#else
857 ((void) ctx);
858 ((void) operation);
859 ((void) length);
860 ((void) iv);
861 ((void) input);
862 ((void) output);
863
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200864 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200865#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000866}
867
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200868static int des_crypt_cfb128_wrap( void *ctx, operation_t operation,
869 size_t length, size_t *iv_off, unsigned char *iv,
870 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000871{
872 ((void) ctx);
873 ((void) operation);
874 ((void) length);
875 ((void) iv_off);
876 ((void) iv);
877 ((void) input);
878 ((void) output);
879
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200880 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker343a8702011-06-09 14:27:58 +0000881}
882
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200883static int des_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
884 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000885 const unsigned char *input, unsigned char *output )
886{
887 ((void) ctx);
888 ((void) length);
889 ((void) nc_off);
890 ((void) nonce_counter);
891 ((void) stream_block);
892 ((void) input);
893 ((void) output);
894
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200895 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker343a8702011-06-09 14:27:58 +0000896}
897
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200898static int des_setkey_dec_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 des_setkey_dec( (des_context *) ctx, key );
904}
905
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200906static int des_setkey_enc_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 des_setkey_enc( (des_context *) ctx, key );
912}
913
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200914static int des3_set2key_dec_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_set2key_dec( (des3_context *) ctx, key );
920}
921
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200922static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
923 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000924{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000925 ((void) key_length);
926
Paul Bakker8123e9d2011-01-06 15:37:30 +0000927 return des3_set2key_enc( (des3_context *) ctx, key );
928}
929
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200930static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
931 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000932{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000933 ((void) key_length);
934
Paul Bakker8123e9d2011-01-06 15:37:30 +0000935 return des3_set3key_dec( (des3_context *) ctx, key );
936}
937
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200938static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
939 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000940{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000941 ((void) key_length);
942
Paul Bakker8123e9d2011-01-06 15:37:30 +0000943 return des3_set3key_enc( (des3_context *) ctx, key );
944}
945
946static void * des_ctx_alloc( void )
947{
Paul Bakker6e339b52013-07-03 13:37:05 +0200948 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000949}
950
951static void * des3_ctx_alloc( void )
952{
Paul Bakker6e339b52013-07-03 13:37:05 +0200953 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000954}
955
956static void des_ctx_free( void *ctx )
957{
Paul Bakker34617722014-06-13 17:20:13 +0200958 polarssl_zeroize( ctx, sizeof( des_context ) );
959 polarssl_free( ctx );
960}
961
962static void des3_ctx_free( void *ctx )
963{
964 polarssl_zeroize( ctx, sizeof( des3_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200965 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000966}
967
Paul Bakker343a8702011-06-09 14:27:58 +0000968const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000969 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200970 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000971 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000972 des_crypt_cfb128_wrap,
973 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200974 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000975 des_setkey_enc_wrap,
976 des_setkey_dec_wrap,
977 des_ctx_alloc,
978 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000979};
980
Paul Bakker5e0efa72013-09-08 23:04:04 +0200981const cipher_info_t des_ecb_info = {
982 POLARSSL_CIPHER_DES_ECB,
983 POLARSSL_MODE_ECB,
984 POLARSSL_KEY_LENGTH_DES,
985 "DES-ECB",
986 8,
987 0,
988 8,
989 &des_info
990};
991
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200992#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000993const cipher_info_t des_cbc_info = {
994 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000995 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000996 POLARSSL_KEY_LENGTH_DES,
997 "DES-CBC",
998 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200999 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001000 8,
1001 &des_info
1002};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001003#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001004
1005const cipher_base_t des_ede_info = {
1006 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001007 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +00001008 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +00001009 des_crypt_cfb128_wrap,
1010 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001011 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +00001012 des3_set2key_enc_wrap,
1013 des3_set2key_dec_wrap,
1014 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001015 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001016};
1017
Paul Bakker5e0efa72013-09-08 23:04:04 +02001018const cipher_info_t des_ede_ecb_info = {
1019 POLARSSL_CIPHER_DES_EDE_ECB,
1020 POLARSSL_MODE_ECB,
1021 POLARSSL_KEY_LENGTH_DES_EDE,
1022 "DES-EDE-ECB",
1023 8,
1024 0,
1025 8,
1026 &des_ede_info
1027};
1028
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001029#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001030const cipher_info_t des_ede_cbc_info = {
1031 POLARSSL_CIPHER_DES_EDE_CBC,
1032 POLARSSL_MODE_CBC,
1033 POLARSSL_KEY_LENGTH_DES_EDE,
1034 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001035 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001036 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001037 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001038 &des_ede_info
1039};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001040#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001041
1042const cipher_base_t des_ede3_info = {
1043 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001044 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +00001045 des3_crypt_cbc_wrap,
1046 des_crypt_cfb128_wrap,
1047 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001048 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +00001049 des3_set3key_enc_wrap,
1050 des3_set3key_dec_wrap,
1051 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001052 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001053};
1054
Paul Bakker5e0efa72013-09-08 23:04:04 +02001055const cipher_info_t des_ede3_ecb_info = {
1056 POLARSSL_CIPHER_DES_EDE3_ECB,
1057 POLARSSL_MODE_ECB,
1058 POLARSSL_KEY_LENGTH_DES_EDE3,
1059 "DES-EDE3-ECB",
1060 8,
1061 0,
1062 8,
1063 &des_ede3_info
1064};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001065#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001066const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +00001067 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +00001068 POLARSSL_MODE_CBC,
1069 POLARSSL_KEY_LENGTH_DES_EDE3,
1070 "DES-EDE3-CBC",
1071 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001072 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001073 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001074 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001075};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001076#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker9af723c2014-05-01 13:03:14 +02001077#endif /* POLARSSL_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001078
Paul Bakker6132d0a2012-07-04 17:10:40 +00001079#if defined(POLARSSL_BLOWFISH_C)
1080
Paul Bakker5e0efa72013-09-08 23:04:04 +02001081static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
1082 const unsigned char *input, unsigned char *output )
1083{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001084 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
1085 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001086}
1087
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001088static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
1089 size_t length, unsigned char *iv, const unsigned char *input,
1090 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001091{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001092#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001093 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
1094 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001095#else
1096 ((void) ctx);
1097 ((void) operation);
1098 ((void) length);
1099 ((void) iv);
1100 ((void) input);
1101 ((void) output);
1102
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001103 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001104#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001105}
1106
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001107static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
1108 size_t length, size_t *iv_off, unsigned char *iv,
1109 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001110{
1111#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001112 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
1113 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001114#else
1115 ((void) ctx);
1116 ((void) operation);
1117 ((void) length);
1118 ((void) iv_off);
1119 ((void) iv);
1120 ((void) input);
1121 ((void) output);
1122
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001123 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001124#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001125}
1126
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001127static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1128 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001129 const unsigned char *input, unsigned char *output )
1130{
1131#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001132 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
1133 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001134#else
1135 ((void) ctx);
1136 ((void) length);
1137 ((void) nc_off);
1138 ((void) nonce_counter);
1139 ((void) stream_block);
1140 ((void) input);
1141 ((void) output);
1142
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001143 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001144#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001145}
1146
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001147static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1148 unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001149{
1150 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
1151}
1152
1153static void * blowfish_ctx_alloc( void )
1154{
Paul Bakker6e339b52013-07-03 13:37:05 +02001155 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001156}
1157
1158static void blowfish_ctx_free( void *ctx )
1159{
Paul Bakker34617722014-06-13 17:20:13 +02001160 polarssl_zeroize( ctx, sizeof( blowfish_context ) );
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,
1183 0,
1184 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é-Gonnarda235b5b2013-09-03 13:25:52 +02001195 0,
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é-Gonnarda235b5b2013-09-03 13:25:52 +02001208 0,
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é-Gonnarda235b5b2013-09-03 13:25:52 +02001221 0,
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 */
1240 if( key_length % 8 != 0)
1241 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{
1249 return polarssl_malloc( sizeof( arc4_context ) );
1250}
Paul Bakker68884e32013-01-07 18:20:04 +01001251
1252static void arc4_ctx_free( void *ctx )
1253{
Paul Bakker34617722014-06-13 17:20:13 +02001254 polarssl_zeroize( ctx, sizeof( arc4_context ) );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001255 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001256}
1257
1258const cipher_base_t arc4_base_info = {
1259 POLARSSL_CIPHER_ID_ARC4,
1260 NULL,
1261 NULL,
1262 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001263 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001264 arc4_crypt_stream_wrap,
1265 arc4_setkey_wrap,
1266 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001267 arc4_ctx_alloc,
1268 arc4_ctx_free
1269};
1270
1271const cipher_info_t arc4_128_info = {
1272 POLARSSL_CIPHER_ARC4_128,
1273 POLARSSL_MODE_STREAM,
1274 128,
1275 "ARC4-128",
1276 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001277 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001278 1,
1279 &arc4_base_info
1280};
1281#endif /* POLARSSL_ARC4_C */
1282
Paul Bakkerfab5c822012-02-06 16:45:10 +00001283#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001284static int null_crypt_stream( void *ctx, size_t length,
1285 const unsigned char *input,
1286 unsigned char *output )
1287{
1288 ((void) ctx);
1289 memmove( output, input, length );
1290 return( 0 );
1291}
1292
1293static int null_setkey( void *ctx, const unsigned char *key,
1294 unsigned int key_length )
1295{
1296 ((void) ctx);
1297 ((void) key);
1298 ((void) key_length);
1299
1300 return( 0 );
1301}
1302
Paul Bakkerfab5c822012-02-06 16:45:10 +00001303static void * null_ctx_alloc( void )
1304{
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001305 return( (void *) 1 )
Paul Bakkerfab5c822012-02-06 16:45:10 +00001306}
1307
Paul Bakkerfab5c822012-02-06 16:45:10 +00001308static void null_ctx_free( void *ctx )
1309{
1310 ((void) ctx);
1311}
1312
1313const cipher_base_t null_base_info = {
1314 POLARSSL_CIPHER_ID_NULL,
1315 NULL,
1316 NULL,
1317 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001318 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001319 null_crypt_stream,
1320 null_setkey,
1321 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001322 null_ctx_alloc,
1323 null_ctx_free
1324};
1325
1326const cipher_info_t null_cipher_info = {
1327 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001328 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001329 0,
1330 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001331 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001332 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001333 1,
1334 &null_base_info
1335};
1336#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1337
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001338const cipher_definition_t cipher_definitions[] =
1339{
1340#if defined(POLARSSL_AES_C)
1341 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1342 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1343 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1344#if defined(POLARSSL_CIPHER_MODE_CBC)
1345 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1346 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1347 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1348#endif
1349#if defined(POLARSSL_CIPHER_MODE_CFB)
1350 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1351 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1352 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1353#endif
1354#if defined(POLARSSL_CIPHER_MODE_CTR)
1355 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1356 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1357 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1358#endif
1359#if defined(POLARSSL_GCM_C)
1360 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1361 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1362 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1363#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001364#if defined(POLARSSL_CCM_C)
1365 { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1366 { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1367 { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
1368#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001369#endif /* POLARSSL_AES_C */
1370
1371#if defined(POLARSSL_ARC4_C)
1372 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1373#endif
1374
1375#if defined(POLARSSL_BLOWFISH_C)
1376 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1377#if defined(POLARSSL_CIPHER_MODE_CBC)
1378 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1379#endif
1380#if defined(POLARSSL_CIPHER_MODE_CFB)
1381 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1382#endif
1383#if defined(POLARSSL_CIPHER_MODE_CTR)
1384 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1385#endif
1386#endif /* POLARSSL_BLOWFISH_C */
1387
1388#if defined(POLARSSL_CAMELLIA_C)
1389 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1390 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
Manuel Pégourié-Gonnard13e0d442013-10-24 12:59:00 +02001391 { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001392#if defined(POLARSSL_CIPHER_MODE_CBC)
1393 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1394 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1395 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1396#endif
1397#if defined(POLARSSL_CIPHER_MODE_CFB)
1398 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1399 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1400 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1401#endif
1402#if defined(POLARSSL_CIPHER_MODE_CTR)
1403 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1404 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1405 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1406#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001407#if defined(POLARSSL_GCM_C)
1408 { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1409 { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1410 { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
1411#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001412#if defined(POLARSSL_CCM_C)
1413 { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1414 { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1415 { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
1416#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001417#endif /* POLARSSL_CAMELLIA_C */
1418
1419#if defined(POLARSSL_DES_C)
1420 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1421 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1422 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1423#if defined(POLARSSL_CIPHER_MODE_CBC)
1424 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1425 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1426 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1427#endif
1428#endif /* POLARSSL_DES_C */
1429
1430#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard057e0cf2013-10-14 14:19:31 +02001431 { POLARSSL_CIPHER_NULL, &null_cipher_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001432#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1433
1434 { 0, NULL }
1435};
1436
1437#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1438int supported_ciphers[NUM_CIPHERS];
1439
Paul Bakker9af723c2014-05-01 13:03:14 +02001440#endif /* POLARSSL_CIPHER_C */