blob: 070963a36c20c928602d96e1dae5984fd2943f15 [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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200377 POLARSSL_CIPHER_VARIABLE_IV_LEN,
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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200388 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200389 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200399 POLARSSL_CIPHER_VARIABLE_IV_LEN,
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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200432 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200433 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200443 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200444 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200454 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200455 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200731 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200732 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200742 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200743 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200753 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200754 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200786 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200787 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200797 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200798 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,
Manuel Pégourié-Gonnard81754a02014-06-23 11:33:18 +0200808 POLARSSL_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200809 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_setkey_dec_wrap( void *ctx, const unsigned char *key,
869 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000870{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000871 ((void) key_length);
872
Paul Bakker8123e9d2011-01-06 15:37:30 +0000873 return des_setkey_dec( (des_context *) ctx, key );
874}
875
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200876static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
877 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000878{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000879 ((void) key_length);
880
Paul Bakker8123e9d2011-01-06 15:37:30 +0000881 return des_setkey_enc( (des_context *) ctx, key );
882}
883
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200884static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
885 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000886{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000887 ((void) key_length);
888
Paul Bakker8123e9d2011-01-06 15:37:30 +0000889 return des3_set2key_dec( (des3_context *) ctx, key );
890}
891
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200892static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
893 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000894{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000895 ((void) key_length);
896
Paul Bakker8123e9d2011-01-06 15:37:30 +0000897 return des3_set2key_enc( (des3_context *) ctx, key );
898}
899
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200900static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
901 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000902{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000903 ((void) key_length);
904
Paul Bakker8123e9d2011-01-06 15:37:30 +0000905 return des3_set3key_dec( (des3_context *) ctx, key );
906}
907
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200908static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
909 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000910{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000911 ((void) key_length);
912
Paul Bakker8123e9d2011-01-06 15:37:30 +0000913 return des3_set3key_enc( (des3_context *) ctx, key );
914}
915
916static void * des_ctx_alloc( void )
917{
Paul Bakker6e339b52013-07-03 13:37:05 +0200918 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000919}
920
921static void * des3_ctx_alloc( void )
922{
Paul Bakker6e339b52013-07-03 13:37:05 +0200923 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000924}
925
926static void des_ctx_free( void *ctx )
927{
Paul Bakker34617722014-06-13 17:20:13 +0200928 polarssl_zeroize( ctx, sizeof( des_context ) );
929 polarssl_free( ctx );
930}
931
932static void des3_ctx_free( void *ctx )
933{
934 polarssl_zeroize( ctx, sizeof( des3_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +0200935 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000936}
937
Paul Bakker343a8702011-06-09 14:27:58 +0000938const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000939 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200940 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000941 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200942 NULL,
943 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200944 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000945 des_setkey_enc_wrap,
946 des_setkey_dec_wrap,
947 des_ctx_alloc,
948 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000949};
950
Paul Bakker5e0efa72013-09-08 23:04:04 +0200951const cipher_info_t des_ecb_info = {
952 POLARSSL_CIPHER_DES_ECB,
953 POLARSSL_MODE_ECB,
954 POLARSSL_KEY_LENGTH_DES,
955 "DES-ECB",
956 8,
957 0,
958 8,
959 &des_info
960};
961
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200962#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000963const cipher_info_t des_cbc_info = {
964 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000965 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000966 POLARSSL_KEY_LENGTH_DES,
967 "DES-CBC",
968 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200969 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000970 8,
971 &des_info
972};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200973#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000974
975const cipher_base_t des_ede_info = {
976 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200977 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000978 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200979 NULL,
980 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200981 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000982 des3_set2key_enc_wrap,
983 des3_set2key_dec_wrap,
984 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +0200985 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000986};
987
Paul Bakker5e0efa72013-09-08 23:04:04 +0200988const cipher_info_t des_ede_ecb_info = {
989 POLARSSL_CIPHER_DES_EDE_ECB,
990 POLARSSL_MODE_ECB,
991 POLARSSL_KEY_LENGTH_DES_EDE,
992 "DES-EDE-ECB",
993 8,
994 0,
995 8,
996 &des_ede_info
997};
998
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200999#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001000const cipher_info_t des_ede_cbc_info = {
1001 POLARSSL_CIPHER_DES_EDE_CBC,
1002 POLARSSL_MODE_CBC,
1003 POLARSSL_KEY_LENGTH_DES_EDE,
1004 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001005 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001006 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001007 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001008 &des_ede_info
1009};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001010#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001011
1012const cipher_base_t des_ede3_info = {
1013 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001014 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +00001015 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001016 NULL,
1017 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001018 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +00001019 des3_set3key_enc_wrap,
1020 des3_set3key_dec_wrap,
1021 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001022 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001023};
1024
Paul Bakker5e0efa72013-09-08 23:04:04 +02001025const cipher_info_t des_ede3_ecb_info = {
1026 POLARSSL_CIPHER_DES_EDE3_ECB,
1027 POLARSSL_MODE_ECB,
1028 POLARSSL_KEY_LENGTH_DES_EDE3,
1029 "DES-EDE3-ECB",
1030 8,
1031 0,
1032 8,
1033 &des_ede3_info
1034};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001035#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001036const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +00001037 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +00001038 POLARSSL_MODE_CBC,
1039 POLARSSL_KEY_LENGTH_DES_EDE3,
1040 "DES-EDE3-CBC",
1041 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001042 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001043 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001044 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001045};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001046#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker9af723c2014-05-01 13:03:14 +02001047#endif /* POLARSSL_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001048
Paul Bakker6132d0a2012-07-04 17:10:40 +00001049#if defined(POLARSSL_BLOWFISH_C)
1050
Paul Bakker5e0efa72013-09-08 23:04:04 +02001051static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
1052 const unsigned char *input, unsigned char *output )
1053{
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001054 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
1055 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001056}
1057
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001058static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
1059 size_t length, unsigned char *iv, const unsigned char *input,
1060 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001061{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001062#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001063 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
1064 input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001065#else
1066 ((void) ctx);
1067 ((void) operation);
1068 ((void) length);
1069 ((void) iv);
1070 ((void) input);
1071 ((void) output);
1072
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001073 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +02001074#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001075}
1076
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001077static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
1078 size_t length, size_t *iv_off, unsigned char *iv,
1079 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001080{
1081#if defined(POLARSSL_CIPHER_MODE_CFB)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001082 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
1083 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001084#else
1085 ((void) ctx);
1086 ((void) operation);
1087 ((void) length);
1088 ((void) iv_off);
1089 ((void) iv);
1090 ((void) input);
1091 ((void) output);
1092
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001093 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001094#endif /* POLARSSL_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001095}
1096
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001097static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1098 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001099 const unsigned char *input, unsigned char *output )
1100{
1101#if defined(POLARSSL_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001102 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
1103 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001104#else
1105 ((void) ctx);
1106 ((void) length);
1107 ((void) nc_off);
1108 ((void) nonce_counter);
1109 ((void) stream_block);
1110 ((void) input);
1111 ((void) output);
1112
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001113 return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
Paul Bakker9af723c2014-05-01 13:03:14 +02001114#endif /* POLARSSL_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001115}
1116
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001117static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1118 unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001119{
1120 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
1121}
1122
1123static void * blowfish_ctx_alloc( void )
1124{
Paul Bakker6e339b52013-07-03 13:37:05 +02001125 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001126}
1127
1128static void blowfish_ctx_free( void *ctx )
1129{
Paul Bakker34617722014-06-13 17:20:13 +02001130 polarssl_zeroize( ctx, sizeof( blowfish_context ) );
Paul Bakker6e339b52013-07-03 13:37:05 +02001131 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001132}
1133
1134const cipher_base_t blowfish_info = {
1135 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001136 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001137 blowfish_crypt_cbc_wrap,
1138 blowfish_crypt_cfb64_wrap,
1139 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001140 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001141 blowfish_setkey_wrap,
1142 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001143 blowfish_ctx_alloc,
1144 blowfish_ctx_free
1145};
1146
Paul Bakker5e0efa72013-09-08 23:04:04 +02001147const cipher_info_t blowfish_ecb_info = {
1148 POLARSSL_CIPHER_BLOWFISH_ECB,
1149 POLARSSL_MODE_ECB,
1150 128,
1151 "BLOWFISH-ECB",
1152 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001153 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001154 8,
1155 &blowfish_info
1156};
1157
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001158#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001159const cipher_info_t blowfish_cbc_info = {
1160 POLARSSL_CIPHER_BLOWFISH_CBC,
1161 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001162 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001163 "BLOWFISH-CBC",
1164 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001165 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001166 8,
1167 &blowfish_info
1168};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +02001169#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001170
1171#if defined(POLARSSL_CIPHER_MODE_CFB)
1172const cipher_info_t blowfish_cfb64_info = {
1173 POLARSSL_CIPHER_BLOWFISH_CFB64,
1174 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001175 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001176 "BLOWFISH-CFB64",
1177 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001178 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001179 8,
1180 &blowfish_info
1181};
1182#endif /* POLARSSL_CIPHER_MODE_CFB */
1183
1184#if defined(POLARSSL_CIPHER_MODE_CTR)
1185const cipher_info_t blowfish_ctr_info = {
1186 POLARSSL_CIPHER_BLOWFISH_CTR,
1187 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001188 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001189 "BLOWFISH-CTR",
1190 8,
Manuel Pégourié-Gonnard398c57b2014-06-23 12:10:59 +02001191 POLARSSL_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001192 8,
1193 &blowfish_info
1194};
1195#endif /* POLARSSL_CIPHER_MODE_CTR */
1196#endif /* POLARSSL_BLOWFISH_C */
1197
Paul Bakker68884e32013-01-07 18:20:04 +01001198#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001199static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1200 const unsigned char *input,
1201 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001202{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001203 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001204}
1205
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001206static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1207 unsigned int key_length )
1208{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001209 /* we get key_length in bits, arc4 expects it in bytes */
Paul Bakker66d5d072014-06-17 16:39:18 +02001210 if( key_length % 8 != 0 )
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001211 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
1212
1213 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001214 return( 0 );
1215}
1216
1217static void * arc4_ctx_alloc( void )
1218{
1219 return polarssl_malloc( sizeof( arc4_context ) );
1220}
Paul Bakker68884e32013-01-07 18:20:04 +01001221
1222static void arc4_ctx_free( void *ctx )
1223{
Paul Bakker34617722014-06-13 17:20:13 +02001224 polarssl_zeroize( ctx, sizeof( arc4_context ) );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001225 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001226}
1227
1228const cipher_base_t arc4_base_info = {
1229 POLARSSL_CIPHER_ID_ARC4,
1230 NULL,
1231 NULL,
1232 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001233 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001234 arc4_crypt_stream_wrap,
1235 arc4_setkey_wrap,
1236 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001237 arc4_ctx_alloc,
1238 arc4_ctx_free
1239};
1240
1241const cipher_info_t arc4_128_info = {
1242 POLARSSL_CIPHER_ARC4_128,
1243 POLARSSL_MODE_STREAM,
1244 128,
1245 "ARC4-128",
1246 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001247 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001248 1,
1249 &arc4_base_info
1250};
1251#endif /* POLARSSL_ARC4_C */
1252
Paul Bakkerfab5c822012-02-06 16:45:10 +00001253#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001254static int null_crypt_stream( void *ctx, size_t length,
1255 const unsigned char *input,
1256 unsigned char *output )
1257{
1258 ((void) ctx);
1259 memmove( output, input, length );
1260 return( 0 );
1261}
1262
1263static int null_setkey( void *ctx, const unsigned char *key,
1264 unsigned int key_length )
1265{
1266 ((void) ctx);
1267 ((void) key);
1268 ((void) key_length);
1269
1270 return( 0 );
1271}
1272
Paul Bakkerfab5c822012-02-06 16:45:10 +00001273static void * null_ctx_alloc( void )
1274{
Paul Bakkerd8bb8262014-06-17 14:06:49 +02001275 return( (void *) 1 )
Paul Bakkerfab5c822012-02-06 16:45:10 +00001276}
1277
Paul Bakkerfab5c822012-02-06 16:45:10 +00001278static void null_ctx_free( void *ctx )
1279{
1280 ((void) ctx);
1281}
1282
1283const cipher_base_t null_base_info = {
1284 POLARSSL_CIPHER_ID_NULL,
1285 NULL,
1286 NULL,
1287 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001288 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001289 null_crypt_stream,
1290 null_setkey,
1291 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001292 null_ctx_alloc,
1293 null_ctx_free
1294};
1295
1296const cipher_info_t null_cipher_info = {
1297 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001298 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001299 0,
1300 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001301 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001302 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001303 1,
1304 &null_base_info
1305};
1306#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1307
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001308const cipher_definition_t cipher_definitions[] =
1309{
1310#if defined(POLARSSL_AES_C)
1311 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1312 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1313 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1314#if defined(POLARSSL_CIPHER_MODE_CBC)
1315 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1316 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1317 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1318#endif
1319#if defined(POLARSSL_CIPHER_MODE_CFB)
1320 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1321 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1322 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1323#endif
1324#if defined(POLARSSL_CIPHER_MODE_CTR)
1325 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1326 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1327 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1328#endif
1329#if defined(POLARSSL_GCM_C)
1330 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1331 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1332 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1333#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001334#if defined(POLARSSL_CCM_C)
1335 { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1336 { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1337 { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
1338#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001339#endif /* POLARSSL_AES_C */
1340
1341#if defined(POLARSSL_ARC4_C)
1342 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1343#endif
1344
1345#if defined(POLARSSL_BLOWFISH_C)
1346 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1347#if defined(POLARSSL_CIPHER_MODE_CBC)
1348 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1349#endif
1350#if defined(POLARSSL_CIPHER_MODE_CFB)
1351 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1352#endif
1353#if defined(POLARSSL_CIPHER_MODE_CTR)
1354 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1355#endif
1356#endif /* POLARSSL_BLOWFISH_C */
1357
1358#if defined(POLARSSL_CAMELLIA_C)
1359 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1360 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
Manuel Pégourié-Gonnard13e0d442013-10-24 12:59:00 +02001361 { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001362#if defined(POLARSSL_CIPHER_MODE_CBC)
1363 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1364 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1365 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1366#endif
1367#if defined(POLARSSL_CIPHER_MODE_CFB)
1368 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1369 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1370 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1371#endif
1372#if defined(POLARSSL_CIPHER_MODE_CTR)
1373 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1374 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1375 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1376#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001377#if defined(POLARSSL_GCM_C)
1378 { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1379 { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1380 { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
1381#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001382#if defined(POLARSSL_CCM_C)
1383 { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1384 { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1385 { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
1386#endif
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001387#endif /* POLARSSL_CAMELLIA_C */
1388
1389#if defined(POLARSSL_DES_C)
1390 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1391 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1392 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1393#if defined(POLARSSL_CIPHER_MODE_CBC)
1394 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1395 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1396 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1397#endif
1398#endif /* POLARSSL_DES_C */
1399
1400#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard057e0cf2013-10-14 14:19:31 +02001401 { POLARSSL_CIPHER_NULL, &null_cipher_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001402#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1403
1404 { 0, NULL }
1405};
1406
1407#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1408int supported_ciphers[NUM_CIPHERS];
1409
Paul Bakker9af723c2014-05-01 13:03:14 +02001410#endif /* POLARSSL_CIPHER_C */