blob: 7466b959b3d09cebdabbd47fba0c1c6cec9c85ae [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker8123e9d2011-01-06 15:37:30 +00003 *
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 Bakker68884e32013-01-07 18:20:04 +01008 * Copyright (C) 2006-2013, 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
30#include "polarssl/config.h"
31
32#if defined(POLARSSL_CIPHER_C)
33
34#include "polarssl/cipher_wrap.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
36#if defined(POLARSSL_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000037#include "polarssl/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020040#if defined(POLARSSL_ARC4_C)
41#include "polarssl/arc4.h"
42#endif
43
Paul Bakkerf6543712012-03-05 14:01:29 +000044#if defined(POLARSSL_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000045#include "polarssl/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
48#if defined(POLARSSL_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000049#include "polarssl/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000050#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000051
Paul Bakker6132d0a2012-07-04 17:10:40 +000052#if defined(POLARSSL_BLOWFISH_C)
53#include "polarssl/blowfish.h"
54#endif
55
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020056#if defined(POLARSSL_GCM_C)
57#include "polarssl/gcm.h"
58#endif
59
Paul Bakker6e339b52013-07-03 13:37:05 +020060#if defined(POLARSSL_MEMORY_C)
61#include "polarssl/memory.h"
62#else
63#define polarssl_malloc malloc
64#define polarssl_free free
65#endif
66
Paul Bakker8123e9d2011-01-06 15:37:30 +000067#include <stdlib.h>
68
69#if defined(POLARSSL_AES_C)
70
Paul Bakker5e0efa72013-09-08 23:04:04 +020071static int aes_crypt_ecb_wrap( void *ctx, operation_t operation,
72 const unsigned char *input, unsigned char *output )
73{
74 return aes_crypt_ecb( (aes_context *) ctx, operation, input, output );
75}
76
Paul Bakkerfae35f02013-03-13 10:33:51 +010077static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +000078 unsigned char *iv, const unsigned char *input, unsigned char *output )
79{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +020080#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +000081 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +020082#else
83 ((void) ctx);
84 ((void) operation);
85 ((void) length);
86 ((void) iv);
87 ((void) input);
88 ((void) output);
89
90 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
91#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +000092}
93
Paul Bakkerfae35f02013-03-13 10:33:51 +010094static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +000095 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
96{
97#if defined(POLARSSL_CIPHER_MODE_CFB)
98 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output );
99#else
100 ((void) ctx);
101 ((void) operation);
102 ((void) length);
103 ((void) iv_off);
104 ((void) iv);
105 ((void) input);
106 ((void) output);
107
108 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
109#endif
110}
111
Paul Bakkerfae35f02013-03-13 10:33:51 +0100112static int aes_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000113 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
114 const unsigned char *input, unsigned char *output )
115{
116#if defined(POLARSSL_CIPHER_MODE_CTR)
117 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
118 stream_block, input, output );
119#else
120 ((void) ctx);
121 ((void) length);
122 ((void) nc_off);
123 ((void) nonce_counter);
124 ((void) stream_block);
125 ((void) input);
126 ((void) output);
127
128 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
129#endif
130}
131
Paul Bakkerfae35f02013-03-13 10:33:51 +0100132static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000133{
134 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
135}
136
Paul Bakkerfae35f02013-03-13 10:33:51 +0100137static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000138{
139 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
140}
141
142static void * aes_ctx_alloc( void )
143{
Paul Bakker6e339b52013-07-03 13:37:05 +0200144 return polarssl_malloc( sizeof( aes_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000145}
146
147static void aes_ctx_free( void *ctx )
148{
Paul Bakker6e339b52013-07-03 13:37:05 +0200149 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000150}
151
Paul Bakker343a8702011-06-09 14:27:58 +0000152const cipher_base_t aes_info = {
153 POLARSSL_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200154 aes_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000155 aes_crypt_cbc_wrap,
156 aes_crypt_cfb128_wrap,
157 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200158 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000159 aes_setkey_enc_wrap,
160 aes_setkey_dec_wrap,
161 aes_ctx_alloc,
162 aes_ctx_free
163};
164
Paul Bakker5e0efa72013-09-08 23:04:04 +0200165const cipher_info_t aes_128_ecb_info = {
166 POLARSSL_CIPHER_AES_128_ECB,
167 POLARSSL_MODE_ECB,
168 128,
169 "AES-128-ECB",
170 16,
171 0,
172 16,
173 &aes_info
174};
175
176const cipher_info_t aes_192_ecb_info = {
177 POLARSSL_CIPHER_AES_192_ECB,
178 POLARSSL_MODE_ECB,
179 192,
180 "AES-192-ECB",
181 16,
182 0,
183 16,
184 &aes_info
185};
186
187const cipher_info_t aes_256_ecb_info = {
188 POLARSSL_CIPHER_AES_256_ECB,
189 POLARSSL_MODE_ECB,
190 256,
191 "AES-256-ECB",
192 16,
193 0,
194 16,
195 &aes_info
196};
197
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200198#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000199const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000200 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000201 POLARSSL_MODE_CBC,
202 128,
203 "AES-128-CBC",
204 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200205 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000206 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000207 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000208};
209
210const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000211 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000212 POLARSSL_MODE_CBC,
213 192,
214 "AES-192-CBC",
215 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200216 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000217 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000218 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000219};
220
221const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000222 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000223 POLARSSL_MODE_CBC,
224 256,
225 "AES-256-CBC",
226 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200227 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000228 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000229 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000230};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200231#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000232
233#if defined(POLARSSL_CIPHER_MODE_CFB)
234const cipher_info_t aes_128_cfb128_info = {
235 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000236 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000237 128,
238 "AES-128-CFB128",
239 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200240 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000241 16,
242 &aes_info
243};
244
245const cipher_info_t aes_192_cfb128_info = {
246 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000247 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000248 192,
249 "AES-192-CFB128",
250 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200251 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000252 16,
253 &aes_info
254};
255
256const cipher_info_t aes_256_cfb128_info = {
257 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000258 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000259 256,
260 "AES-256-CFB128",
261 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200262 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000263 16,
264 &aes_info
265};
266#endif /* POLARSSL_CIPHER_MODE_CFB */
267
268#if defined(POLARSSL_CIPHER_MODE_CTR)
269const cipher_info_t aes_128_ctr_info = {
270 POLARSSL_CIPHER_AES_128_CTR,
271 POLARSSL_MODE_CTR,
272 128,
273 "AES-128-CTR",
274 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200275 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000276 16,
277 &aes_info
278};
279
280const cipher_info_t aes_192_ctr_info = {
281 POLARSSL_CIPHER_AES_192_CTR,
282 POLARSSL_MODE_CTR,
283 192,
284 "AES-192-CTR",
285 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200286 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000287 16,
288 &aes_info
289};
290
291const cipher_info_t aes_256_ctr_info = {
292 POLARSSL_CIPHER_AES_256_CTR,
293 POLARSSL_MODE_CTR,
294 256,
295 "AES-256-CTR",
296 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200297 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000298 16,
299 &aes_info
300};
301#endif /* POLARSSL_CIPHER_MODE_CTR */
302
Paul Bakker68884e32013-01-07 18:20:04 +0100303#if defined(POLARSSL_GCM_C)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200304static void *gcm_ctx_alloc( void )
305{
306 return polarssl_malloc( sizeof( gcm_context ) );
307}
308
309static void gcm_ctx_free( void *ctx )
310{
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200311 gcm_free( ctx );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200312 polarssl_free( ctx );
313}
314
Paul Bakker43aff2a2013-09-09 00:10:27 +0200315static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200316{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200317 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
318 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200319}
320
321const cipher_base_t gcm_aes_info = {
322 POLARSSL_CIPHER_ID_AES,
323 NULL,
324 NULL,
325 NULL,
326 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200327 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200328 gcm_aes_setkey_wrap,
329 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200330 gcm_ctx_alloc,
331 gcm_ctx_free,
332};
333
Paul Bakker68884e32013-01-07 18:20:04 +0100334const cipher_info_t aes_128_gcm_info = {
335 POLARSSL_CIPHER_AES_128_GCM,
336 POLARSSL_MODE_GCM,
337 128,
338 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200339 12,
340 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100341 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200342 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100343};
344
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200345const cipher_info_t aes_192_gcm_info = {
346 POLARSSL_CIPHER_AES_192_GCM,
347 POLARSSL_MODE_GCM,
348 192,
349 "AES-192-GCM",
350 12,
351 1,
352 16,
353 &gcm_aes_info
354};
355
Paul Bakker68884e32013-01-07 18:20:04 +0100356const cipher_info_t aes_256_gcm_info = {
357 POLARSSL_CIPHER_AES_256_GCM,
358 POLARSSL_MODE_GCM,
359 256,
360 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200361 12,
362 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100363 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200364 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100365};
366#endif /* POLARSSL_GCM_C */
367
Paul Bakker8123e9d2011-01-06 15:37:30 +0000368#endif
369
370#if defined(POLARSSL_CAMELLIA_C)
371
Paul Bakker5e0efa72013-09-08 23:04:04 +0200372static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
373 const unsigned char *input, unsigned char *output )
374{
375 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
376}
377
Paul Bakkerfae35f02013-03-13 10:33:51 +0100378static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000379 unsigned char *iv, const unsigned char *input, unsigned char *output )
380{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200381#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000382 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200383#else
384 ((void) ctx);
385 ((void) operation);
386 ((void) length);
387 ((void) iv);
388 ((void) input);
389 ((void) output);
390
391 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
392#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000393}
394
Paul Bakkerfae35f02013-03-13 10:33:51 +0100395static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000396 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
397{
398#if defined(POLARSSL_CIPHER_MODE_CFB)
399 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
400#else
401 ((void) ctx);
402 ((void) operation);
403 ((void) length);
404 ((void) iv_off);
405 ((void) iv);
406 ((void) input);
407 ((void) output);
408
409 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
410#endif
411}
412
Paul Bakkerfae35f02013-03-13 10:33:51 +0100413static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000414 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
415 const unsigned char *input, unsigned char *output )
416{
417#if defined(POLARSSL_CIPHER_MODE_CTR)
418 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
419 stream_block, input, output );
420#else
421 ((void) ctx);
422 ((void) length);
423 ((void) nc_off);
424 ((void) nonce_counter);
425 ((void) stream_block);
426 ((void) input);
427 ((void) output);
428
429 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
430#endif
431}
432
Paul Bakkerfae35f02013-03-13 10:33:51 +0100433static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000434{
435 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
436}
437
Paul Bakkerfae35f02013-03-13 10:33:51 +0100438static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000439{
440 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
441}
442
443static void * camellia_ctx_alloc( void )
444{
Paul Bakker6e339b52013-07-03 13:37:05 +0200445 return polarssl_malloc( sizeof( camellia_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000446}
447
448static void camellia_ctx_free( void *ctx )
449{
Paul Bakker6e339b52013-07-03 13:37:05 +0200450 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000451}
452
Paul Bakker343a8702011-06-09 14:27:58 +0000453const cipher_base_t camellia_info = {
454 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200455 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000456 camellia_crypt_cbc_wrap,
457 camellia_crypt_cfb128_wrap,
458 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200459 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000460 camellia_setkey_enc_wrap,
461 camellia_setkey_dec_wrap,
462 camellia_ctx_alloc,
463 camellia_ctx_free
464};
465
Paul Bakker5e0efa72013-09-08 23:04:04 +0200466const cipher_info_t camellia_128_ecb_info = {
467 POLARSSL_CIPHER_CAMELLIA_128_ECB,
468 POLARSSL_MODE_ECB,
469 128,
470 "CAMELLIA-128-ECB",
471 16,
472 0,
473 16,
474 &camellia_info
475};
476
477const cipher_info_t camellia_192_ecb_info = {
478 POLARSSL_CIPHER_CAMELLIA_192_ECB,
479 POLARSSL_MODE_ECB,
480 192,
481 "CAMELLIA-192-ECB",
482 16,
483 0,
484 16,
485 &camellia_info
486};
487
488const cipher_info_t camellia_256_ecb_info = {
489 POLARSSL_CIPHER_CAMELLIA_256_ECB,
490 POLARSSL_MODE_ECB,
491 256,
492 "CAMELLIA-256-ECB",
493 16,
494 0,
495 16,
496 &camellia_info
497};
498
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200499#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000500const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000501 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000502 POLARSSL_MODE_CBC,
503 128,
504 "CAMELLIA-128-CBC",
505 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200506 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000507 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000508 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000509};
510
511const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000512 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000513 POLARSSL_MODE_CBC,
514 192,
515 "CAMELLIA-192-CBC",
516 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200517 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000518 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000519 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000520};
521
522const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000523 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000524 POLARSSL_MODE_CBC,
525 256,
526 "CAMELLIA-256-CBC",
527 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200528 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000529 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000530 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000531};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200532#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000533
534#if defined(POLARSSL_CIPHER_MODE_CFB)
535const cipher_info_t camellia_128_cfb128_info = {
536 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000537 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000538 128,
539 "CAMELLIA-128-CFB128",
540 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200541 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000542 16,
543 &camellia_info
544};
545
546const cipher_info_t camellia_192_cfb128_info = {
547 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000548 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000549 192,
550 "CAMELLIA-192-CFB128",
551 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200552 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000553 16,
554 &camellia_info
555};
556
557const cipher_info_t camellia_256_cfb128_info = {
558 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000559 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000560 256,
561 "CAMELLIA-256-CFB128",
562 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200563 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000564 16,
565 &camellia_info
566};
567#endif /* POLARSSL_CIPHER_MODE_CFB */
568
569#if defined(POLARSSL_CIPHER_MODE_CTR)
570const cipher_info_t camellia_128_ctr_info = {
571 POLARSSL_CIPHER_CAMELLIA_128_CTR,
572 POLARSSL_MODE_CTR,
573 128,
574 "CAMELLIA-128-CTR",
575 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200576 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000577 16,
578 &camellia_info
579};
580
581const cipher_info_t camellia_192_ctr_info = {
582 POLARSSL_CIPHER_CAMELLIA_192_CTR,
583 POLARSSL_MODE_CTR,
584 192,
585 "CAMELLIA-192-CTR",
586 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200587 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000588 16,
589 &camellia_info
590};
591
592const cipher_info_t camellia_256_ctr_info = {
593 POLARSSL_CIPHER_CAMELLIA_256_CTR,
594 POLARSSL_MODE_CTR,
595 256,
596 "CAMELLIA-256-CTR",
597 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200598 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000599 16,
600 &camellia_info
601};
602#endif /* POLARSSL_CIPHER_MODE_CTR */
603
Paul Bakker8123e9d2011-01-06 15:37:30 +0000604#endif
605
606#if defined(POLARSSL_DES_C)
607
Paul Bakker5e0efa72013-09-08 23:04:04 +0200608static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
609 const unsigned char *input, unsigned char *output )
610{
611 ((void) operation);
612 return des_crypt_ecb( (des_context *) ctx, input, output );
613}
614
615static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
616 const unsigned char *input, unsigned char *output )
617{
618 ((void) operation);
619 return des3_crypt_ecb( (des3_context *) ctx, input, output );
620}
621
Paul Bakkerfae35f02013-03-13 10:33:51 +0100622static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000623 unsigned char *iv, const unsigned char *input, unsigned char *output )
624{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200625#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000626 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200627#else
628 ((void) ctx);
629 ((void) operation);
630 ((void) length);
631 ((void) iv);
632 ((void) input);
633 ((void) output);
634
635 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
636#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000637}
638
Paul Bakkerfae35f02013-03-13 10:33:51 +0100639static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000640 unsigned char *iv, const unsigned char *input, unsigned char *output )
641{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200642#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000643 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200644#else
645 ((void) ctx);
646 ((void) operation);
647 ((void) length);
648 ((void) iv);
649 ((void) input);
650 ((void) output);
651
652 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
653#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000654}
655
Paul Bakkerfae35f02013-03-13 10:33:51 +0100656static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000657 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
658{
659 ((void) ctx);
660 ((void) operation);
661 ((void) length);
662 ((void) iv_off);
663 ((void) iv);
664 ((void) input);
665 ((void) output);
666
667 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
668}
669
Paul Bakkerfae35f02013-03-13 10:33:51 +0100670static int des_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000671 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
672 const unsigned char *input, unsigned char *output )
673{
674 ((void) ctx);
675 ((void) length);
676 ((void) nc_off);
677 ((void) nonce_counter);
678 ((void) stream_block);
679 ((void) input);
680 ((void) output);
681
682 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
683}
684
Paul Bakkerfae35f02013-03-13 10:33:51 +0100685static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000686{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000687 ((void) key_length);
688
Paul Bakker8123e9d2011-01-06 15:37:30 +0000689 return des_setkey_dec( (des_context *) ctx, key );
690}
691
Paul Bakkerfae35f02013-03-13 10:33:51 +0100692static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000693{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000694 ((void) key_length);
695
Paul Bakker8123e9d2011-01-06 15:37:30 +0000696 return des_setkey_enc( (des_context *) ctx, key );
697}
698
Paul Bakkerfae35f02013-03-13 10:33:51 +0100699static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000700{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000701 ((void) key_length);
702
Paul Bakker8123e9d2011-01-06 15:37:30 +0000703 return des3_set2key_dec( (des3_context *) ctx, key );
704}
705
Paul Bakkerfae35f02013-03-13 10:33:51 +0100706static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000707{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000708 ((void) key_length);
709
Paul Bakker8123e9d2011-01-06 15:37:30 +0000710 return des3_set2key_enc( (des3_context *) ctx, key );
711}
712
Paul Bakkerfae35f02013-03-13 10:33:51 +0100713static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000714{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000715 ((void) key_length);
716
Paul Bakker8123e9d2011-01-06 15:37:30 +0000717 return des3_set3key_dec( (des3_context *) ctx, key );
718}
719
Paul Bakkerfae35f02013-03-13 10:33:51 +0100720static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000721{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000722 ((void) key_length);
723
Paul Bakker8123e9d2011-01-06 15:37:30 +0000724 return des3_set3key_enc( (des3_context *) ctx, key );
725}
726
727static void * des_ctx_alloc( void )
728{
Paul Bakker6e339b52013-07-03 13:37:05 +0200729 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000730}
731
732static void * des3_ctx_alloc( void )
733{
Paul Bakker6e339b52013-07-03 13:37:05 +0200734 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000735}
736
737static void des_ctx_free( void *ctx )
738{
Paul Bakker6e339b52013-07-03 13:37:05 +0200739 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000740}
741
Paul Bakker343a8702011-06-09 14:27:58 +0000742const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000743 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200744 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000745 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000746 des_crypt_cfb128_wrap,
747 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200748 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000749 des_setkey_enc_wrap,
750 des_setkey_dec_wrap,
751 des_ctx_alloc,
752 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000753};
754
Paul Bakker5e0efa72013-09-08 23:04:04 +0200755const cipher_info_t des_ecb_info = {
756 POLARSSL_CIPHER_DES_ECB,
757 POLARSSL_MODE_ECB,
758 POLARSSL_KEY_LENGTH_DES,
759 "DES-ECB",
760 8,
761 0,
762 8,
763 &des_info
764};
765
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200766#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000767const cipher_info_t des_cbc_info = {
768 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000769 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000770 POLARSSL_KEY_LENGTH_DES,
771 "DES-CBC",
772 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200773 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000774 8,
775 &des_info
776};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200777#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000778
779const cipher_base_t des_ede_info = {
780 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200781 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000782 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000783 des_crypt_cfb128_wrap,
784 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200785 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000786 des3_set2key_enc_wrap,
787 des3_set2key_dec_wrap,
788 des3_ctx_alloc,
789 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000790};
791
Paul Bakker5e0efa72013-09-08 23:04:04 +0200792const cipher_info_t des_ede_ecb_info = {
793 POLARSSL_CIPHER_DES_EDE_ECB,
794 POLARSSL_MODE_ECB,
795 POLARSSL_KEY_LENGTH_DES_EDE,
796 "DES-EDE-ECB",
797 8,
798 0,
799 8,
800 &des_ede_info
801};
802
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200803#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000804const cipher_info_t des_ede_cbc_info = {
805 POLARSSL_CIPHER_DES_EDE_CBC,
806 POLARSSL_MODE_CBC,
807 POLARSSL_KEY_LENGTH_DES_EDE,
808 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +0200809 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200810 0,
Paul Bakker0e342352013-06-24 19:33:02 +0200811 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000812 &des_ede_info
813};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200814#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000815
816const cipher_base_t des_ede3_info = {
817 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200818 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000819 des3_crypt_cbc_wrap,
820 des_crypt_cfb128_wrap,
821 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200822 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000823 des3_set3key_enc_wrap,
824 des3_set3key_dec_wrap,
825 des3_ctx_alloc,
826 des_ctx_free
827};
828
Paul Bakker5e0efa72013-09-08 23:04:04 +0200829const cipher_info_t des_ede3_ecb_info = {
830 POLARSSL_CIPHER_DES_EDE3_ECB,
831 POLARSSL_MODE_ECB,
832 POLARSSL_KEY_LENGTH_DES_EDE3,
833 "DES-EDE3-ECB",
834 8,
835 0,
836 8,
837 &des_ede3_info
838};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200839#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000840const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000841 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000842 POLARSSL_MODE_CBC,
843 POLARSSL_KEY_LENGTH_DES_EDE3,
844 "DES-EDE3-CBC",
845 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200846 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000847 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000848 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000849};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200850#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000851#endif
852
Paul Bakker6132d0a2012-07-04 17:10:40 +0000853#if defined(POLARSSL_BLOWFISH_C)
854
Paul Bakker5e0efa72013-09-08 23:04:04 +0200855static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
856 const unsigned char *input, unsigned char *output )
857{
858 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
859}
860
Paul Bakkerfae35f02013-03-13 10:33:51 +0100861static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000862 unsigned char *iv, const unsigned char *input, unsigned char *output )
863{
Manuel Pégourié-Gonnard92cb1d32013-09-13 16:24:20 +0200864#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +0000865 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, 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
874 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
875#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +0000876}
877
Paul Bakkerfae35f02013-03-13 10:33:51 +0100878static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000879 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
880{
881#if defined(POLARSSL_CIPHER_MODE_CFB)
882 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
883#else
884 ((void) ctx);
885 ((void) operation);
886 ((void) length);
887 ((void) iv_off);
888 ((void) iv);
889 ((void) input);
890 ((void) output);
891
892 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
893#endif
894}
895
Paul Bakkerfae35f02013-03-13 10:33:51 +0100896static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000897 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
898 const unsigned char *input, unsigned char *output )
899{
900#if defined(POLARSSL_CIPHER_MODE_CTR)
901 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
902 stream_block, input, output );
903#else
904 ((void) ctx);
905 ((void) length);
906 ((void) nc_off);
907 ((void) nonce_counter);
908 ((void) stream_block);
909 ((void) input);
910 ((void) output);
911
912 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
913#endif
914}
915
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200916static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000917{
918 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
919}
920
921static void * blowfish_ctx_alloc( void )
922{
Paul Bakker6e339b52013-07-03 13:37:05 +0200923 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000924}
925
926static void blowfish_ctx_free( void *ctx )
927{
Paul Bakker6e339b52013-07-03 13:37:05 +0200928 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000929}
930
931const cipher_base_t blowfish_info = {
932 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200933 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000934 blowfish_crypt_cbc_wrap,
935 blowfish_crypt_cfb64_wrap,
936 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200937 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200938 blowfish_setkey_wrap,
939 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000940 blowfish_ctx_alloc,
941 blowfish_ctx_free
942};
943
Paul Bakker5e0efa72013-09-08 23:04:04 +0200944const cipher_info_t blowfish_ecb_info = {
945 POLARSSL_CIPHER_BLOWFISH_ECB,
946 POLARSSL_MODE_ECB,
947 128,
948 "BLOWFISH-ECB",
949 8,
950 0,
951 8,
952 &blowfish_info
953};
954
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200955#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +0000956const cipher_info_t blowfish_cbc_info = {
957 POLARSSL_CIPHER_BLOWFISH_CBC,
958 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200959 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000960 "BLOWFISH-CBC",
961 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200962 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000963 8,
964 &blowfish_info
965};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200966#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +0000967
968#if defined(POLARSSL_CIPHER_MODE_CFB)
969const cipher_info_t blowfish_cfb64_info = {
970 POLARSSL_CIPHER_BLOWFISH_CFB64,
971 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200972 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000973 "BLOWFISH-CFB64",
974 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200975 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000976 8,
977 &blowfish_info
978};
979#endif /* POLARSSL_CIPHER_MODE_CFB */
980
981#if defined(POLARSSL_CIPHER_MODE_CTR)
982const cipher_info_t blowfish_ctr_info = {
983 POLARSSL_CIPHER_BLOWFISH_CTR,
984 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200985 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000986 "BLOWFISH-CTR",
987 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200988 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000989 8,
990 &blowfish_info
991};
992#endif /* POLARSSL_CIPHER_MODE_CTR */
993#endif /* POLARSSL_BLOWFISH_C */
994
Paul Bakker68884e32013-01-07 18:20:04 +0100995#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200996static int arc4_crypt_stream_wrap( void *ctx, size_t length,
997 const unsigned char *input,
998 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +0100999{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001000 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001001}
1002
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001003static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1004 unsigned int key_length )
1005{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001006 /* we get key_length in bits, arc4 expects it in bytes */
1007 if( key_length % 8 != 0)
1008 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
1009
1010 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001011 return( 0 );
1012}
1013
1014static void * arc4_ctx_alloc( void )
1015{
1016 return polarssl_malloc( sizeof( arc4_context ) );
1017}
Paul Bakker68884e32013-01-07 18:20:04 +01001018
1019static void arc4_ctx_free( void *ctx )
1020{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001021 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001022}
1023
1024const cipher_base_t arc4_base_info = {
1025 POLARSSL_CIPHER_ID_ARC4,
1026 NULL,
1027 NULL,
1028 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001029 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001030 arc4_crypt_stream_wrap,
1031 arc4_setkey_wrap,
1032 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001033 arc4_ctx_alloc,
1034 arc4_ctx_free
1035};
1036
1037const cipher_info_t arc4_128_info = {
1038 POLARSSL_CIPHER_ARC4_128,
1039 POLARSSL_MODE_STREAM,
1040 128,
1041 "ARC4-128",
1042 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001043 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001044 1,
1045 &arc4_base_info
1046};
1047#endif /* POLARSSL_ARC4_C */
1048
Paul Bakkerfab5c822012-02-06 16:45:10 +00001049#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001050static int null_crypt_stream( void *ctx, size_t length,
1051 const unsigned char *input,
1052 unsigned char *output )
1053{
1054 ((void) ctx);
1055 memmove( output, input, length );
1056 return( 0 );
1057}
1058
1059static int null_setkey( void *ctx, const unsigned char *key,
1060 unsigned int key_length )
1061{
1062 ((void) ctx);
1063 ((void) key);
1064 ((void) key_length);
1065
1066 return( 0 );
1067}
1068
Paul Bakkerfab5c822012-02-06 16:45:10 +00001069static void * null_ctx_alloc( void )
1070{
1071 return (void *) 1;
1072}
1073
Paul Bakkerfab5c822012-02-06 16:45:10 +00001074static void null_ctx_free( void *ctx )
1075{
1076 ((void) ctx);
1077}
1078
1079const cipher_base_t null_base_info = {
1080 POLARSSL_CIPHER_ID_NULL,
1081 NULL,
1082 NULL,
1083 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001084 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001085 null_crypt_stream,
1086 null_setkey,
1087 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001088 null_ctx_alloc,
1089 null_ctx_free
1090};
1091
1092const cipher_info_t null_cipher_info = {
1093 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001094 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001095 0,
1096 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001097 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001098 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001099 1,
1100 &null_base_info
1101};
1102#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1103
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001104const cipher_definition_t cipher_definitions[] =
1105{
1106#if defined(POLARSSL_AES_C)
1107 { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1108 { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1109 { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1110#if defined(POLARSSL_CIPHER_MODE_CBC)
1111 { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1112 { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1113 { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info },
1114#endif
1115#if defined(POLARSSL_CIPHER_MODE_CFB)
1116 { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1117 { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1118 { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
1119#endif
1120#if defined(POLARSSL_CIPHER_MODE_CTR)
1121 { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1122 { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1123 { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info },
1124#endif
1125#if defined(POLARSSL_GCM_C)
1126 { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1127 { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1128 { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
1129#endif
1130#endif /* POLARSSL_AES_C */
1131
1132#if defined(POLARSSL_ARC4_C)
1133 { POLARSSL_CIPHER_ARC4_128, &arc4_128_info },
1134#endif
1135
1136#if defined(POLARSSL_BLOWFISH_C)
1137 { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1138#if defined(POLARSSL_CIPHER_MODE_CBC)
1139 { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
1140#endif
1141#if defined(POLARSSL_CIPHER_MODE_CFB)
1142 { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
1143#endif
1144#if defined(POLARSSL_CIPHER_MODE_CTR)
1145 { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
1146#endif
1147#endif /* POLARSSL_BLOWFISH_C */
1148
1149#if defined(POLARSSL_CAMELLIA_C)
1150 { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1151 { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1152#if defined(POLARSSL_CIPHER_MODE_CBC)
1153 { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1154 { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1155 { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
1156#endif
1157#if defined(POLARSSL_CIPHER_MODE_CFB)
1158 { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1159 { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1160 { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
1161#endif
1162#if defined(POLARSSL_CIPHER_MODE_CTR)
1163 { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1164 { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1165 { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
1166#endif
1167#endif /* POLARSSL_CAMELLIA_C */
1168
1169#if defined(POLARSSL_DES_C)
1170 { POLARSSL_CIPHER_DES_ECB, &des_ecb_info },
1171 { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1172 { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1173#if defined(POLARSSL_CIPHER_MODE_CBC)
1174 { POLARSSL_CIPHER_DES_CBC, &des_cbc_info },
1175 { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1176 { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
1177#endif
1178#endif /* POLARSSL_DES_C */
1179
1180#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard057e0cf2013-10-14 14:19:31 +02001181 { POLARSSL_CIPHER_NULL, &null_cipher_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001182#endif /* POLARSSL_CIPHER_NULL_CIPHER */
1183
1184 { 0, NULL }
1185};
1186
1187#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
1188int supported_ciphers[NUM_CIPHERS];
1189
Paul Bakker8123e9d2011-01-06 15:37:30 +00001190#endif