blob: ab2f9bc6ee9aa5f52c34b526ef3198d9d59c9c70 [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
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020077#if defined(POLARSSL_GCM_C)
78/* shared by all GCM ciphers */
79static void *gcm_ctx_alloc( void )
80{
81 return polarssl_malloc( sizeof( gcm_context ) );
82}
83
84static void gcm_ctx_free( void *ctx )
85{
86 gcm_free( ctx );
87 polarssl_free( ctx );
88}
Paul Bakker9af723c2014-05-01 13:03:14 +020089#endif /* POLARSSL_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020090
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020091#if defined(POLARSSL_CCM_C)
92/* shared by all CCM ciphers */
93static void *ccm_ctx_alloc( void )
94{
95 return polarssl_malloc( sizeof( ccm_context ) );
96}
97
98static void ccm_ctx_free( void *ctx )
99{
100 ccm_free( ctx );
101 polarssl_free( ctx );
102}
103#endif /* POLARSSL_CCM_C */
104
Paul Bakker8123e9d2011-01-06 15:37:30 +0000105#if defined(POLARSSL_AES_C)
106
Paul Bakker5e0efa72013-09-08 23:04:04 +0200107static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
108 const unsigned char *input, unsigned char *output )
109{
110 return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
111}
112
Paul Bakkerfae35f02013-03-13 10:33:51 +0100113static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000114 unsigned char *iv, const unsigned char *input, unsigned char *output )
115{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200116#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200117 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
118 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200119#else
120 ((void) ctx);
121 ((void) operation);
122 ((void) length);
123 ((void) iv);
124 ((void) input);
125 ((void) output);
126
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200127 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200128#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000129}
130
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200131static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
132 size_t length, size_t *iv_off, unsigned char *iv,
133 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000134{
135#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200136 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
137 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000138#else
139 ((void) ctx);
140 ((void) operation);
141 ((void) length);
142 ((void) iv_off);
143 ((void) iv);
144 ((void) input);
145 ((void) output);
146
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200147 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200148#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000149}
150
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200151static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
152 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000153 const unsigned char *input, unsigned char *output )
154{
155#if defined(POLARSSL_CIPHER_MODE_CTR)
156 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
157 stream_block, input, output );
158#else
159 ((void) ctx);
160 ((void) length);
161 ((void) nc_off);
162 ((void) nonce_counter);
163 ((void) stream_block);
164 ((void) input);
165 ((void) output);
166
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200167 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200168#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000169}
170
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200171static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
172 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000173{
174 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
175}
176
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200177static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
178 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000179{
180 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
181}
182
183static void * aes_ctx_alloc( void )
184{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200185 aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
186
187 if( aes == NULL )
188 return( NULL );
189
190 aes_init( aes );
191
192 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000193}
194
195static void aes_ctx_free( void *ctx )
196{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200197 aes_free( (aes_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200198 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000199}
200
Paul Bakker343a8702011-06-09 14:27:58 +0000201const cipher_base_t aes_info = {
202 POLARSSL_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200203 aes_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000204 aes_crypt_cbc_wrap,
205 aes_crypt_cfb128_wrap,
206 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200207 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000208 aes_setkey_enc_wrap,
209 aes_setkey_dec_wrap,
210 aes_ctx_alloc,
211 aes_ctx_free
212};
213
Paul Bakker5e0efa72013-09-08 23:04:04 +0200214const cipher_info_t aes_128_ecb_info = {
215 POLARSSL_CIPHER_AES_128_ECB,
216 POLARSSL_MODE_ECB,
217 128,
218 "AES-128-ECB",
219 16,
220 0,
221 16,
222 &aes_info
223};
224
225const cipher_info_t aes_192_ecb_info = {
226 POLARSSL_CIPHER_AES_192_ECB,
227 POLARSSL_MODE_ECB,
228 192,
229 "AES-192-ECB",
230 16,
231 0,
232 16,
233 &aes_info
234};
235
236const cipher_info_t aes_256_ecb_info = {
237 POLARSSL_CIPHER_AES_256_ECB,
238 POLARSSL_MODE_ECB,
239 256,
240 "AES-256-ECB",
241 16,
242 0,
243 16,
244 &aes_info
245};
246
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200247#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000248const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000249 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000250 POLARSSL_MODE_CBC,
251 128,
252 "AES-128-CBC",
253 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200254 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000255 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000256 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000257};
258
259const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000260 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000261 POLARSSL_MODE_CBC,
262 192,
263 "AES-192-CBC",
264 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200265 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000266 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000267 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000268};
269
270const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000271 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000272 POLARSSL_MODE_CBC,
273 256,
274 "AES-256-CBC",
275 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200276 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000277 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000278 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000279};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200280#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000281
282#if defined(POLARSSL_CIPHER_MODE_CFB)
283const cipher_info_t aes_128_cfb128_info = {
284 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000285 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000286 128,
287 "AES-128-CFB128",
288 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200289 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000290 16,
291 &aes_info
292};
293
294const cipher_info_t aes_192_cfb128_info = {
295 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000296 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000297 192,
298 "AES-192-CFB128",
299 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200300 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000301 16,
302 &aes_info
303};
304
305const cipher_info_t aes_256_cfb128_info = {
306 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000307 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000308 256,
309 "AES-256-CFB128",
310 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200311 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000312 16,
313 &aes_info
314};
315#endif /* POLARSSL_CIPHER_MODE_CFB */
316
317#if defined(POLARSSL_CIPHER_MODE_CTR)
318const cipher_info_t aes_128_ctr_info = {
319 POLARSSL_CIPHER_AES_128_CTR,
320 POLARSSL_MODE_CTR,
321 128,
322 "AES-128-CTR",
323 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200324 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000325 16,
326 &aes_info
327};
328
329const cipher_info_t aes_192_ctr_info = {
330 POLARSSL_CIPHER_AES_192_CTR,
331 POLARSSL_MODE_CTR,
332 192,
333 "AES-192-CTR",
334 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200335 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000336 16,
337 &aes_info
338};
339
340const cipher_info_t aes_256_ctr_info = {
341 POLARSSL_CIPHER_AES_256_CTR,
342 POLARSSL_MODE_CTR,
343 256,
344 "AES-256-CTR",
345 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200346 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000347 16,
348 &aes_info
349};
350#endif /* POLARSSL_CIPHER_MODE_CTR */
351
Paul Bakker68884e32013-01-07 18:20:04 +0100352#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200353static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
354 unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200355{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200356 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
357 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200358}
359
360const cipher_base_t gcm_aes_info = {
361 POLARSSL_CIPHER_ID_AES,
362 NULL,
363 NULL,
364 NULL,
365 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200366 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200367 gcm_aes_setkey_wrap,
368 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200369 gcm_ctx_alloc,
370 gcm_ctx_free,
371};
372
Paul Bakker68884e32013-01-07 18:20:04 +0100373const cipher_info_t aes_128_gcm_info = {
374 POLARSSL_CIPHER_AES_128_GCM,
375 POLARSSL_MODE_GCM,
376 128,
377 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200378 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200379 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100380 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200381 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100382};
383
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200384const cipher_info_t aes_192_gcm_info = {
385 POLARSSL_CIPHER_AES_192_GCM,
386 POLARSSL_MODE_GCM,
387 192,
388 "AES-192-GCM",
389 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200390 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200391 16,
392 &gcm_aes_info
393};
394
Paul Bakker68884e32013-01-07 18:20:04 +0100395const cipher_info_t aes_256_gcm_info = {
396 POLARSSL_CIPHER_AES_256_GCM,
397 POLARSSL_MODE_GCM,
398 256,
399 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200400 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200401 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100402 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200403 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100404};
405#endif /* POLARSSL_GCM_C */
406
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200407#if defined(POLARSSL_CCM_C)
408static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
409 unsigned int key_length )
410{
411 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_AES,
412 key, key_length );
413}
414
415const cipher_base_t ccm_aes_info = {
416 POLARSSL_CIPHER_ID_AES,
417 NULL,
418 NULL,
419 NULL,
420 NULL,
421 NULL,
422 ccm_aes_setkey_wrap,
423 ccm_aes_setkey_wrap,
424 ccm_ctx_alloc,
425 ccm_ctx_free,
426};
427
428const cipher_info_t aes_128_ccm_info = {
429 POLARSSL_CIPHER_AES_128_CCM,
430 POLARSSL_MODE_CCM,
431 128,
432 "AES-128-CCM",
433 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200434 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200435 16,
436 &ccm_aes_info
437};
438
439const cipher_info_t aes_192_ccm_info = {
440 POLARSSL_CIPHER_AES_192_CCM,
441 POLARSSL_MODE_CCM,
442 192,
443 "AES-192-CCM",
444 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200445 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200446 16,
447 &ccm_aes_info
448};
449
450const cipher_info_t aes_256_ccm_info = {
451 POLARSSL_CIPHER_AES_256_CCM,
452 POLARSSL_MODE_CCM,
453 256,
454 "AES-256-CCM",
455 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200456 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200457 16,
458 &ccm_aes_info
459};
460#endif /* POLARSSL_CCM_C */
461
Paul Bakker9af723c2014-05-01 13:03:14 +0200462#endif /* POLARSSL_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000463
464#if defined(POLARSSL_CAMELLIA_C)
465
Paul Bakker5e0efa72013-09-08 23:04:04 +0200466static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
467 const unsigned char *input, unsigned char *output )
468{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200469 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input,
470 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200471}
472
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200473static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
474 size_t length, unsigned char *iv,
475 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000476{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200477#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200478 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
479 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200480#else
481 ((void) ctx);
482 ((void) operation);
483 ((void) length);
484 ((void) iv);
485 ((void) input);
486 ((void) output);
487
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200488 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200489#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000490}
491
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200492static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
493 size_t length, size_t *iv_off, unsigned char *iv,
494 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000495{
496#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200497 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
498 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000499#else
500 ((void) ctx);
501 ((void) operation);
502 ((void) length);
503 ((void) iv_off);
504 ((void) iv);
505 ((void) input);
506 ((void) output);
507
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200508 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200509#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000510}
511
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200512static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
513 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000514 const unsigned char *input, unsigned char *output )
515{
516#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200517 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
518 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000519#else
520 ((void) ctx);
521 ((void) length);
522 ((void) nc_off);
523 ((void) nonce_counter);
524 ((void) stream_block);
525 ((void) input);
526 ((void) output);
527
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200528 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +0200529#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000530}
531
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200532static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
533 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000534{
535 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
536}
537
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200538static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
539 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000540{
541 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
542}
543
544static void * camellia_ctx_alloc( void )
545{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200546 camellia_context *ctx;
547 ctx = (camellia_context *) polarssl_malloc( sizeof( camellia_context ) );
548
549 if( ctx == NULL )
550 return( NULL );
551
552 camellia_init( ctx );
553
554 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000555}
556
557static void camellia_ctx_free( void *ctx )
558{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200559 camellia_free( (camellia_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200560 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000561}
562
Paul Bakker343a8702011-06-09 14:27:58 +0000563const cipher_base_t camellia_info = {
564 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200565 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000566 camellia_crypt_cbc_wrap,
567 camellia_crypt_cfb128_wrap,
568 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200569 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000570 camellia_setkey_enc_wrap,
571 camellia_setkey_dec_wrap,
572 camellia_ctx_alloc,
573 camellia_ctx_free
574};
575
Paul Bakker5e0efa72013-09-08 23:04:04 +0200576const cipher_info_t camellia_128_ecb_info = {
577 POLARSSL_CIPHER_CAMELLIA_128_ECB,
578 POLARSSL_MODE_ECB,
579 128,
580 "CAMELLIA-128-ECB",
581 16,
582 0,
583 16,
584 &camellia_info
585};
586
587const cipher_info_t camellia_192_ecb_info = {
588 POLARSSL_CIPHER_CAMELLIA_192_ECB,
589 POLARSSL_MODE_ECB,
590 192,
591 "CAMELLIA-192-ECB",
592 16,
593 0,
594 16,
595 &camellia_info
596};
597
598const cipher_info_t camellia_256_ecb_info = {
599 POLARSSL_CIPHER_CAMELLIA_256_ECB,
600 POLARSSL_MODE_ECB,
601 256,
602 "CAMELLIA-256-ECB",
603 16,
604 0,
605 16,
606 &camellia_info
607};
608
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200609#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000610const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000611 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000612 POLARSSL_MODE_CBC,
613 128,
614 "CAMELLIA-128-CBC",
615 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200616 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000617 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000618 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000619};
620
621const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000622 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000623 POLARSSL_MODE_CBC,
624 192,
625 "CAMELLIA-192-CBC",
626 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200627 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000628 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000629 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000630};
631
632const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000633 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000634 POLARSSL_MODE_CBC,
635 256,
636 "CAMELLIA-256-CBC",
637 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200638 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000639 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000640 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000641};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200642#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000643
644#if defined(POLARSSL_CIPHER_MODE_CFB)
645const cipher_info_t camellia_128_cfb128_info = {
646 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000647 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000648 128,
649 "CAMELLIA-128-CFB128",
650 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200651 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000652 16,
653 &camellia_info
654};
655
656const cipher_info_t camellia_192_cfb128_info = {
657 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000658 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000659 192,
660 "CAMELLIA-192-CFB128",
661 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200662 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000663 16,
664 &camellia_info
665};
666
667const cipher_info_t camellia_256_cfb128_info = {
668 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000669 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000670 256,
671 "CAMELLIA-256-CFB128",
672 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200673 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000674 16,
675 &camellia_info
676};
677#endif /* POLARSSL_CIPHER_MODE_CFB */
678
679#if defined(POLARSSL_CIPHER_MODE_CTR)
680const cipher_info_t camellia_128_ctr_info = {
681 POLARSSL_CIPHER_CAMELLIA_128_CTR,
682 POLARSSL_MODE_CTR,
683 128,
684 "CAMELLIA-128-CTR",
685 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200686 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000687 16,
688 &camellia_info
689};
690
691const cipher_info_t camellia_192_ctr_info = {
692 POLARSSL_CIPHER_CAMELLIA_192_CTR,
693 POLARSSL_MODE_CTR,
694 192,
695 "CAMELLIA-192-CTR",
696 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200697 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000698 16,
699 &camellia_info
700};
701
702const cipher_info_t camellia_256_ctr_info = {
703 POLARSSL_CIPHER_CAMELLIA_256_CTR,
704 POLARSSL_MODE_CTR,
705 256,
706 "CAMELLIA-256-CTR",
707 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200708 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000709 16,
710 &camellia_info
711};
712#endif /* POLARSSL_CIPHER_MODE_CTR */
713
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200714#if defined(POLARSSL_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200715static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
716 unsigned int key_length )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200717{
718 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
719 key, key_length );
720}
721
722const cipher_base_t gcm_camellia_info = {
723 POLARSSL_CIPHER_ID_CAMELLIA,
724 NULL,
725 NULL,
726 NULL,
727 NULL,
728 NULL,
729 gcm_camellia_setkey_wrap,
730 gcm_camellia_setkey_wrap,
731 gcm_ctx_alloc,
732 gcm_ctx_free,
733};
734
735const cipher_info_t camellia_128_gcm_info = {
736 POLARSSL_CIPHER_CAMELLIA_128_GCM,
737 POLARSSL_MODE_GCM,
738 128,
739 "CAMELLIA-128-GCM",
740 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200741 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200742 16,
743 &gcm_camellia_info
744};
745
746const cipher_info_t camellia_192_gcm_info = {
747 POLARSSL_CIPHER_CAMELLIA_192_GCM,
748 POLARSSL_MODE_GCM,
749 192,
750 "CAMELLIA-192-GCM",
751 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200752 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200753 16,
754 &gcm_camellia_info
755};
756
757const cipher_info_t camellia_256_gcm_info = {
758 POLARSSL_CIPHER_CAMELLIA_256_GCM,
759 POLARSSL_MODE_GCM,
760 256,
761 "CAMELLIA-256-GCM",
762 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200763 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200764 16,
765 &gcm_camellia_info
766};
767#endif /* POLARSSL_GCM_C */
768
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200769#if defined(POLARSSL_CCM_C)
770static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
771 unsigned int key_length )
772{
773 return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
774 key, key_length );
775}
776
777const cipher_base_t ccm_camellia_info = {
778 POLARSSL_CIPHER_ID_CAMELLIA,
779 NULL,
780 NULL,
781 NULL,
782 NULL,
783 NULL,
784 ccm_camellia_setkey_wrap,
785 ccm_camellia_setkey_wrap,
786 ccm_ctx_alloc,
787 ccm_ctx_free,
788};
789
790const cipher_info_t camellia_128_ccm_info = {
791 POLARSSL_CIPHER_CAMELLIA_128_CCM,
792 POLARSSL_MODE_CCM,
793 128,
794 "CAMELLIA-128-CCM",
795 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200796 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200797 16,
798 &ccm_camellia_info
799};
800
801const cipher_info_t camellia_192_ccm_info = {
802 POLARSSL_CIPHER_CAMELLIA_192_CCM,
803 POLARSSL_MODE_CCM,
804 192,
805 "CAMELLIA-192-CCM",
806 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200807 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200808 16,
809 &ccm_camellia_info
810};
811
812const cipher_info_t camellia_256_ccm_info = {
813 POLARSSL_CIPHER_CAMELLIA_256_CCM,
814 POLARSSL_MODE_CCM,
815 256,
816 "CAMELLIA-256-CCM",
817 12,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200818 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200819 16,
820 &ccm_camellia_info
821};
822#endif /* POLARSSL_CCM_C */
823
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200824#endif /* POLARSSL_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000825
826#if defined(POLARSSL_DES_C)
827
Paul Bakker5e0efa72013-09-08 23:04:04 +0200828static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
829 const unsigned char *input, unsigned char *output )
830{
831 ((void) operation);
832 return des_crypt_ecb( (des_context *) ctx, input, output );
833}
834
835static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
836 const unsigned char *input, unsigned char *output )
837{
838 ((void) operation);
839 return des3_crypt_ecb( (des3_context *) ctx, input, output );
840}
841
Paul Bakkerfae35f02013-03-13 10:33:51 +0100842static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000843 unsigned char *iv, const unsigned char *input, unsigned char *output )
844{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200845#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200846 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
847 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200848#else
849 ((void) ctx);
850 ((void) operation);
851 ((void) length);
852 ((void) iv);
853 ((void) input);
854 ((void) output);
855
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200856 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200857#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000858}
859
Paul Bakkerfae35f02013-03-13 10:33:51 +0100860static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000861 unsigned char *iv, const unsigned char *input, unsigned char *output )
862{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200863#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200864 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
865 output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200866#else
867 ((void) ctx);
868 ((void) operation);
869 ((void) length);
870 ((void) iv);
871 ((void) input);
872 ((void) output);
873
Paul Bakkerd8bb8262014-06-17 14:06:49 +0200874 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200875#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000876}
877
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200878static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
879 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000880{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000881 ((void) key_length);
882
Paul Bakker8123e9d2011-01-06 15:37:30 +0000883 return des_setkey_dec( (des_context *) ctx, key );
884}
885
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200886static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
887 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000888{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000889 ((void) key_length);
890
Paul Bakker8123e9d2011-01-06 15:37:30 +0000891 return des_setkey_enc( (des_context *) ctx, key );
892}
893
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200894static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
895 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000896{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000897 ((void) key_length);
898
Paul Bakker8123e9d2011-01-06 15:37:30 +0000899 return des3_set2key_dec( (des3_context *) ctx, key );
900}
901
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200902static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
903 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000904{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000905 ((void) key_length);
906
Paul Bakker8123e9d2011-01-06 15:37:30 +0000907 return des3_set2key_enc( (des3_context *) ctx, key );
908}
909
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200910static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
911 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000912{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000913 ((void) key_length);
914
Paul Bakker8123e9d2011-01-06 15:37:30 +0000915 return des3_set3key_dec( (des3_context *) ctx, key );
916}
917
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200918static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
919 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000920{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000921 ((void) key_length);
922
Paul Bakker8123e9d2011-01-06 15:37:30 +0000923 return des3_set3key_enc( (des3_context *) ctx, key );
924}
925
926static void * des_ctx_alloc( void )
927{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200928 des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000929
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200930 if( des == NULL )
931 return( NULL );
932
933 des_init( des );
934
935 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000936}
937
938static void des_ctx_free( void *ctx )
939{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200940 des_free( (des_context *) ctx );
Paul Bakker34617722014-06-13 17:20:13 +0200941 polarssl_free( ctx );
942}
943
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200944static void * des3_ctx_alloc( void )
945{
946 des3_context *des3;
947 des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
948
949 if( des3 == NULL )
950 return( NULL );
951
952 des3_init( des3 );
953
954 return( des3 );
955}
956
Paul Bakker34617722014-06-13 17:20:13 +0200957static void des3_ctx_free( void *ctx )
958{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200959 des3_free( (des3_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +0200960 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000961}
962
Paul Bakker343a8702011-06-09 14:27:58 +0000963const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000964 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200965 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000966 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200967 NULL,
968 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200969 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000970 des_setkey_enc_wrap,
971 des_setkey_dec_wrap,
972 des_ctx_alloc,
973 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000974};
975
Paul Bakker5e0efa72013-09-08 23:04:04 +0200976const cipher_info_t des_ecb_info = {
977 POLARSSL_CIPHER_DES_ECB,
978 POLARSSL_MODE_ECB,
979 POLARSSL_KEY_LENGTH_DES,
980 "DES-ECB",
981 8,
982 0,
983 8,
984 &des_info
985};
986
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200987#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000988const cipher_info_t des_cbc_info = {
989 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000990 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000991 POLARSSL_KEY_LENGTH_DES,
992 "DES-CBC",
993 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200994 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000995 8,
996 &des_info
997};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200998#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000999
1000const cipher_base_t des_ede_info = {
1001 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001002 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +00001003 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001004 NULL,
1005 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001006 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +00001007 des3_set2key_enc_wrap,
1008 des3_set2key_dec_wrap,
1009 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001010 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001011};
1012
Paul Bakker5e0efa72013-09-08 23:04:04 +02001013const cipher_info_t des_ede_ecb_info = {
1014 POLARSSL_CIPHER_DES_EDE_ECB,
1015 POLARSSL_MODE_ECB,
1016 POLARSSL_KEY_LENGTH_DES_EDE,
1017 "DES-EDE-ECB",
1018 8,
1019 0,
1020 8,
1021 &des_ede_info
1022};
1023
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001024#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001025const cipher_info_t des_ede_cbc_info = {
1026 POLARSSL_CIPHER_DES_EDE_CBC,
1027 POLARSSL_MODE_CBC,
1028 POLARSSL_KEY_LENGTH_DES_EDE,
1029 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001030 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001031 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001032 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001033 &des_ede_info
1034};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001035#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001036
1037const cipher_base_t des_ede3_info = {
1038 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001039 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +00001040 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001041 NULL,
1042 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001043 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +00001044 des3_set3key_enc_wrap,
1045 des3_set3key_dec_wrap,
1046 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001047 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001048};
1049
Paul Bakker5e0efa72013-09-08 23:04:04 +02001050const cipher_info_t des_ede3_ecb_info = {
1051 POLARSSL_CIPHER_DES_EDE3_ECB,
1052 POLARSSL_MODE_ECB,
1053 POLARSSL_KEY_LENGTH_DES_EDE3,
1054 "DES-EDE3-ECB",
1055 8,
1056 0,
1057 8,
1058 &des_ede3_info
1059};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001060#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001061const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +00001062 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +00001063 POLARSSL_MODE_CBC,
1064 POLARSSL_KEY_LENGTH_DES_EDE3,
1065 "DES-EDE3-CBC",
1066 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001067 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001068 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001069 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001070};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001071#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker9af723c2014-05-01 13:03:14 +02001072#endif /* POLARSSL_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001073
Paul Bakker6132d0a2012-07-04 17:10:40 +00001074#if defined(POLARSSL_BLOWFISH_C)
1075
Paul Bakker5e0efa72013-09-08 23:04:04 +02001076static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
1077 const unsigned char *input, unsigned char *output )
1078{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001079 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
1080 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001081}
1082
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001083static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
1084 size_t length, unsigned char *iv, const unsigned char *input,
1085 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001086{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001087#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001088 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
1089 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001090#else
1091 ((void) ctx);
1092 ((void) operation);
1093 ((void) length);
1094 ((void) iv);
1095 ((void) input);
1096 ((void) output);
1097
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001098 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001099#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001100}
1101
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001102static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
1103 size_t length, size_t *iv_off, unsigned char *iv,
1104 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001105{
1106#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001107 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
1108 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001109#else
1110 ((void) ctx);
1111 ((void) operation);
1112 ((void) length);
1113 ((void) iv_off);
1114 ((void) iv);
1115 ((void) input);
1116 ((void) output);
1117
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001118 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001119#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001120}
1121
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001122static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1123 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001124 const unsigned char *input, unsigned char *output )
1125{
1126#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001127 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
1128 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001129#else
1130 ((void) ctx);
1131 ((void) length);
1132 ((void) nc_off);
1133 ((void) nonce_counter);
1134 ((void) stream_block);
1135 ((void) input);
1136 ((void) output);
1137
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001138 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001139#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001140}
1141
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001142static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1143 unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001144{
1145 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
1146}
1147
1148static void * blowfish_ctx_alloc( void )
1149{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001150 blowfish_context *ctx;
1151 ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
1152
1153 if( ctx == NULL )
1154 return( NULL );
1155
1156 blowfish_init( ctx );
1157
1158 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001159}
1160
1161static void blowfish_ctx_free( void *ctx )
1162{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001163 blowfish_free( (blowfish_context *) ctx );
Paul Bakker6e339b52013-07-03 13:37:05 +02001164 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001165}
1166
1167const cipher_base_t blowfish_info = {
1168 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001169 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001170 blowfish_crypt_cbc_wrap,
1171 blowfish_crypt_cfb64_wrap,
1172 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001173 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001174 blowfish_setkey_wrap,
1175 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001176 blowfish_ctx_alloc,
1177 blowfish_ctx_free
1178};
1179
Paul Bakker5e0efa72013-09-08 23:04:04 +02001180const cipher_info_t blowfish_ecb_info = {
1181 POLARSSL_CIPHER_BLOWFISH_ECB,
1182 POLARSSL_MODE_ECB,
1183 128,
1184 "BLOWFISH-ECB",
1185 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001186 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001187 8,
1188 &blowfish_info
1189};
1190
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001191#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001192const cipher_info_t blowfish_cbc_info = {
1193 POLARSSL_CIPHER_BLOWFISH_CBC,
1194 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001195 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001196 "BLOWFISH-CBC",
1197 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001198 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001199 8,
1200 &blowfish_info
1201};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001202#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001203
1204#if defined(POLARSSL_CIPHER_MODE_CFB)
1205const cipher_info_t blowfish_cfb64_info = {
1206 POLARSSL_CIPHER_BLOWFISH_CFB64,
1207 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001208 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001209 "BLOWFISH-CFB64",
1210 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001211 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001212 8,
1213 &blowfish_info
1214};
1215#endif /* POLARSSL_CIPHER_MODE_CFB */
1216
1217#if defined(POLARSSL_CIPHER_MODE_CTR)
1218const cipher_info_t blowfish_ctr_info = {
1219 POLARSSL_CIPHER_BLOWFISH_CTR,
1220 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001221 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001222 "BLOWFISH-CTR",
1223 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001224 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001225 8,
1226 &blowfish_info
1227};
1228#endif /* POLARSSL_CIPHER_MODE_CTR */
1229#endif /* POLARSSL_BLOWFISH_C */
1230
Paul Bakker68884e32013-01-07 18:20:04 +01001231#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001232static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1233 const unsigned char *input,
1234 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001235{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001236 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001237}
1238
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001239static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1240 unsigned int key_length )
1241{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001242 /* we get key_length in bits, arc4 expects it in bytes */
Paul Bakker66d5d072014-06-17 16:39:18 +02001243 if( key_length % 8 != 0 )
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001244 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
1245
1246 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001247 return( 0 );
1248}
1249
1250static void * arc4_ctx_alloc( void )
1251{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001252 arc4_context *ctx;
1253 ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
1254
1255 if( ctx == NULL )
1256 return( NULL );
1257
1258 arc4_init( ctx );
1259
1260 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001261}
Paul Bakker68884e32013-01-07 18:20:04 +01001262
1263static void arc4_ctx_free( void *ctx )
1264{
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001265 arc4_free( (arc4_context *) ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001266 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001267}
1268
1269const cipher_base_t arc4_base_info = {
1270 POLARSSL_CIPHER_ID_ARC4,
1271 NULL,
1272 NULL,
1273 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001274 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001275 arc4_crypt_stream_wrap,
1276 arc4_setkey_wrap,
1277 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001278 arc4_ctx_alloc,
1279 arc4_ctx_free
1280};
1281
1282const cipher_info_t arc4_128_info = {
1283 POLARSSL_CIPHER_ARC4_128,
1284 POLARSSL_MODE_STREAM,
1285 128,
1286 "ARC4-128",
1287 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001288 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001289 1,
1290 &arc4_base_info
1291};
1292#endif /* POLARSSL_ARC4_C */
1293
Paul Bakkerfab5c822012-02-06 16:45:10 +00001294#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001295static int null_crypt_stream( void *ctx, size_t length,
1296 const unsigned char *input,
1297 unsigned char *output )
1298{
1299 ((void) ctx);
1300 memmove( output, input, length );
1301 return( 0 );
1302}
1303
1304static int null_setkey( void *ctx, const unsigned char *key,
1305 unsigned int key_length )
1306{
1307 ((void) ctx);
1308 ((void) key);
1309 ((void) key_length);
1310
1311 return( 0 );
1312}
1313
Paul Bakkerfab5c822012-02-06 16:45:10 +00001314static void * null_ctx_alloc( void )
1315{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001316 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001317}
1318
Paul Bakkerfab5c822012-02-06 16:45:10 +00001319static void null_ctx_free( void *ctx )
1320{
1321 ((void) ctx);
1322}
1323
1324const cipher_base_t null_base_info = {
1325 POLARSSL_CIPHER_ID_NULL,
1326 NULL,
1327 NULL,
1328 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001329 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001330 null_crypt_stream,
1331 null_setkey,
1332 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001333 null_ctx_alloc,
1334 null_ctx_free
1335};
1336
1337const cipher_info_t null_cipher_info = {
1338 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001339 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001340 0,
1341 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001342 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001343 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001344 1,
1345 &null_base_info
1346};
1347#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1348
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001349const cipher_definition_t cipher_definitions[] =
1350{
1351#if defined(POLARSSL_AES_C)
1352 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1353 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1354 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1355#if defined(POLARSSL_CIPHER_MODE_CBC)
1356 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1357 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1358 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1359#endif
1360#if defined(POLARSSL_CIPHER_MODE_CFB)
1361 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1362 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1363 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1364#endif
1365#if defined(POLARSSL_CIPHER_MODE_CTR)
1366 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1367 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1368 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1369#endif
1370#if defined(POLARSSL_GCM_C)
1371 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1372 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1373 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1374#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001375#if defined(POLARSSL_CCM_C)
1376 { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1377 { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1378 { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
1379#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001380#endif /* POLARSSL_AES_C */
1381
1382#if defined(POLARSSL_ARC4_C)
1383 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1384#endif
1385
1386#if defined(POLARSSL_BLOWFISH_C)
1387 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1388#if defined(POLARSSL_CIPHER_MODE_CBC)
1389 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1390#endif
1391#if defined(POLARSSL_CIPHER_MODE_CFB)
1392 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1393#endif
1394#if defined(POLARSSL_CIPHER_MODE_CTR)
1395 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1396#endif
1397#endif /* POLARSSL_BLOWFISH_C */
1398
1399#if defined(POLARSSL_CAMELLIA_C)
1400 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1401 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
Manuel Pégourié-Gonnard13e0d442013-10-24 12:59:00 +02001402 { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001403#if defined(POLARSSL_CIPHER_MODE_CBC)
1404 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1405 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1406 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1407#endif
1408#if defined(POLARSSL_CIPHER_MODE_CFB)
1409 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1410 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1411 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1412#endif
1413#if defined(POLARSSL_CIPHER_MODE_CTR)
1414 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1415 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1416 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1417#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001418#if defined(POLARSSL_GCM_C)
1419 { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1420 { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1421 { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
1422#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001423#if defined(POLARSSL_CCM_C)
1424 { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1425 { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1426 { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
1427#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001428#endif /* POLARSSL_CAMELLIA_C */
1429
1430#if defined(POLARSSL_DES_C)
1431 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1432 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1433 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1434#if defined(POLARSSL_CIPHER_MODE_CBC)
1435 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1436 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1437 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1438#endif
1439#endif /* POLARSSL_DES_C */
1440
1441#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard057e0cf2013-10-14 14:19:31 +02001442 { POLARSSL_CIPHER_NULL, &null_cipher_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001443#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1444
1445 { 0, NULL }
1446};
1447
1448#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1449int supported_ciphers[NUM_CIPHERS];
1450
Paul Bakker9af723c2014-05-01 13:03:14 +02001451#endif /* POLARSSL_CIPHER_C */