blob: 7ee217885e373eb404bde43bc9bdc7825eddaaf9 [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
40#if defined(POLARSSL_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000041#include "polarssl/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
44#if defined(POLARSSL_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000045#include "polarssl/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000046#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000047
Paul Bakker6132d0a2012-07-04 17:10:40 +000048#if defined(POLARSSL_BLOWFISH_C)
49#include "polarssl/blowfish.h"
50#endif
51
Paul Bakker8123e9d2011-01-06 15:37:30 +000052#include <stdlib.h>
53
54#if defined(POLARSSL_AES_C)
55
Paul Bakkerfae35f02013-03-13 10:33:51 +010056static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +000057 unsigned char *iv, const unsigned char *input, unsigned char *output )
58{
59 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output );
60}
61
Paul Bakkerfae35f02013-03-13 10:33:51 +010062static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +000063 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
64{
65#if defined(POLARSSL_CIPHER_MODE_CFB)
66 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output );
67#else
68 ((void) ctx);
69 ((void) operation);
70 ((void) length);
71 ((void) iv_off);
72 ((void) iv);
73 ((void) input);
74 ((void) output);
75
76 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
77#endif
78}
79
Paul Bakkerfae35f02013-03-13 10:33:51 +010080static int aes_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +000081 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
82 const unsigned char *input, unsigned char *output )
83{
84#if defined(POLARSSL_CIPHER_MODE_CTR)
85 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
86 stream_block, input, output );
87#else
88 ((void) ctx);
89 ((void) length);
90 ((void) nc_off);
91 ((void) nonce_counter);
92 ((void) stream_block);
93 ((void) input);
94 ((void) output);
95
96 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
97#endif
98}
99
Paul Bakkerfae35f02013-03-13 10:33:51 +0100100static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000101{
102 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
103}
104
Paul Bakkerfae35f02013-03-13 10:33:51 +0100105static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000106{
107 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
108}
109
110static void * aes_ctx_alloc( void )
111{
112 return malloc( sizeof( aes_context ) );
113}
114
115static void aes_ctx_free( void *ctx )
116{
117 free( ctx );
118}
119
Paul Bakker343a8702011-06-09 14:27:58 +0000120const cipher_base_t aes_info = {
121 POLARSSL_CIPHER_ID_AES,
122 aes_crypt_cbc_wrap,
123 aes_crypt_cfb128_wrap,
124 aes_crypt_ctr_wrap,
125 aes_setkey_enc_wrap,
126 aes_setkey_dec_wrap,
127 aes_ctx_alloc,
128 aes_ctx_free
129};
130
Paul Bakker8123e9d2011-01-06 15:37:30 +0000131const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000132 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000133 POLARSSL_MODE_CBC,
134 128,
135 "AES-128-CBC",
136 16,
137 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000138 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000139};
140
141const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000142 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000143 POLARSSL_MODE_CBC,
144 192,
145 "AES-192-CBC",
146 16,
147 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000148 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000149};
150
151const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000152 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000153 POLARSSL_MODE_CBC,
154 256,
155 "AES-256-CBC",
156 16,
157 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000158 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000159};
Paul Bakker343a8702011-06-09 14:27:58 +0000160
161#if defined(POLARSSL_CIPHER_MODE_CFB)
162const cipher_info_t aes_128_cfb128_info = {
163 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000164 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000165 128,
166 "AES-128-CFB128",
167 16,
168 16,
169 &aes_info
170};
171
172const cipher_info_t aes_192_cfb128_info = {
173 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000174 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000175 192,
176 "AES-192-CFB128",
177 16,
178 16,
179 &aes_info
180};
181
182const cipher_info_t aes_256_cfb128_info = {
183 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000184 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000185 256,
186 "AES-256-CFB128",
187 16,
188 16,
189 &aes_info
190};
191#endif /* POLARSSL_CIPHER_MODE_CFB */
192
193#if defined(POLARSSL_CIPHER_MODE_CTR)
194const cipher_info_t aes_128_ctr_info = {
195 POLARSSL_CIPHER_AES_128_CTR,
196 POLARSSL_MODE_CTR,
197 128,
198 "AES-128-CTR",
199 16,
200 16,
201 &aes_info
202};
203
204const cipher_info_t aes_192_ctr_info = {
205 POLARSSL_CIPHER_AES_192_CTR,
206 POLARSSL_MODE_CTR,
207 192,
208 "AES-192-CTR",
209 16,
210 16,
211 &aes_info
212};
213
214const cipher_info_t aes_256_ctr_info = {
215 POLARSSL_CIPHER_AES_256_CTR,
216 POLARSSL_MODE_CTR,
217 256,
218 "AES-256-CTR",
219 16,
220 16,
221 &aes_info
222};
223#endif /* POLARSSL_CIPHER_MODE_CTR */
224
Paul Bakker68884e32013-01-07 18:20:04 +0100225#if defined(POLARSSL_GCM_C)
226const cipher_info_t aes_128_gcm_info = {
227 POLARSSL_CIPHER_AES_128_GCM,
228 POLARSSL_MODE_GCM,
229 128,
230 "AES-128-GCM",
231 16,
232 16,
233 &aes_info
234};
235
236const cipher_info_t aes_256_gcm_info = {
237 POLARSSL_CIPHER_AES_256_GCM,
238 POLARSSL_MODE_GCM,
239 256,
240 "AES-256-GCM",
241 16,
242 16,
243 &aes_info
244};
245#endif /* POLARSSL_GCM_C */
246
Paul Bakker8123e9d2011-01-06 15:37:30 +0000247#endif
248
249#if defined(POLARSSL_CAMELLIA_C)
250
Paul Bakkerfae35f02013-03-13 10:33:51 +0100251static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000252 unsigned char *iv, const unsigned char *input, unsigned char *output )
253{
254 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
255}
256
Paul Bakkerfae35f02013-03-13 10:33:51 +0100257static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000258 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
259{
260#if defined(POLARSSL_CIPHER_MODE_CFB)
261 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
262#else
263 ((void) ctx);
264 ((void) operation);
265 ((void) length);
266 ((void) iv_off);
267 ((void) iv);
268 ((void) input);
269 ((void) output);
270
271 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
272#endif
273}
274
Paul Bakkerfae35f02013-03-13 10:33:51 +0100275static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000276 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
277 const unsigned char *input, unsigned char *output )
278{
279#if defined(POLARSSL_CIPHER_MODE_CTR)
280 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
281 stream_block, input, output );
282#else
283 ((void) ctx);
284 ((void) length);
285 ((void) nc_off);
286 ((void) nonce_counter);
287 ((void) stream_block);
288 ((void) input);
289 ((void) output);
290
291 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
292#endif
293}
294
Paul Bakkerfae35f02013-03-13 10:33:51 +0100295static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000296{
297 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
298}
299
Paul Bakkerfae35f02013-03-13 10:33:51 +0100300static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000301{
302 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
303}
304
305static void * camellia_ctx_alloc( void )
306{
307 return malloc( sizeof( camellia_context ) );
308}
309
310static void camellia_ctx_free( void *ctx )
311{
312 free( ctx );
313}
314
Paul Bakker343a8702011-06-09 14:27:58 +0000315const cipher_base_t camellia_info = {
316 POLARSSL_CIPHER_ID_CAMELLIA,
317 camellia_crypt_cbc_wrap,
318 camellia_crypt_cfb128_wrap,
319 camellia_crypt_ctr_wrap,
320 camellia_setkey_enc_wrap,
321 camellia_setkey_dec_wrap,
322 camellia_ctx_alloc,
323 camellia_ctx_free
324};
325
Paul Bakker8123e9d2011-01-06 15:37:30 +0000326const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000327 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000328 POLARSSL_MODE_CBC,
329 128,
330 "CAMELLIA-128-CBC",
331 16,
332 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000333 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000334};
335
336const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000337 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000338 POLARSSL_MODE_CBC,
339 192,
340 "CAMELLIA-192-CBC",
341 16,
342 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000344};
345
346const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000347 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000348 POLARSSL_MODE_CBC,
349 256,
350 "CAMELLIA-256-CBC",
351 16,
352 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000353 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000354};
Paul Bakker343a8702011-06-09 14:27:58 +0000355
356#if defined(POLARSSL_CIPHER_MODE_CFB)
357const cipher_info_t camellia_128_cfb128_info = {
358 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000359 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000360 128,
361 "CAMELLIA-128-CFB128",
362 16,
363 16,
364 &camellia_info
365};
366
367const cipher_info_t camellia_192_cfb128_info = {
368 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000369 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000370 192,
371 "CAMELLIA-192-CFB128",
372 16,
373 16,
374 &camellia_info
375};
376
377const cipher_info_t camellia_256_cfb128_info = {
378 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000379 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000380 256,
381 "CAMELLIA-256-CFB128",
382 16,
383 16,
384 &camellia_info
385};
386#endif /* POLARSSL_CIPHER_MODE_CFB */
387
388#if defined(POLARSSL_CIPHER_MODE_CTR)
389const cipher_info_t camellia_128_ctr_info = {
390 POLARSSL_CIPHER_CAMELLIA_128_CTR,
391 POLARSSL_MODE_CTR,
392 128,
393 "CAMELLIA-128-CTR",
394 16,
395 16,
396 &camellia_info
397};
398
399const cipher_info_t camellia_192_ctr_info = {
400 POLARSSL_CIPHER_CAMELLIA_192_CTR,
401 POLARSSL_MODE_CTR,
402 192,
403 "CAMELLIA-192-CTR",
404 16,
405 16,
406 &camellia_info
407};
408
409const cipher_info_t camellia_256_ctr_info = {
410 POLARSSL_CIPHER_CAMELLIA_256_CTR,
411 POLARSSL_MODE_CTR,
412 256,
413 "CAMELLIA-256-CTR",
414 16,
415 16,
416 &camellia_info
417};
418#endif /* POLARSSL_CIPHER_MODE_CTR */
419
Paul Bakker8123e9d2011-01-06 15:37:30 +0000420#endif
421
422#if defined(POLARSSL_DES_C)
423
Paul Bakkerfae35f02013-03-13 10:33:51 +0100424static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000425 unsigned char *iv, const unsigned char *input, unsigned char *output )
426{
427 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
428}
429
Paul Bakkerfae35f02013-03-13 10:33:51 +0100430static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000431 unsigned char *iv, const unsigned char *input, unsigned char *output )
432{
433 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
434}
435
Paul Bakkerfae35f02013-03-13 10:33:51 +0100436static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000437 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
438{
439 ((void) ctx);
440 ((void) operation);
441 ((void) length);
442 ((void) iv_off);
443 ((void) iv);
444 ((void) input);
445 ((void) output);
446
447 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
448}
449
Paul Bakkerfae35f02013-03-13 10:33:51 +0100450static int des_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000451 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
452 const unsigned char *input, unsigned char *output )
453{
454 ((void) ctx);
455 ((void) length);
456 ((void) nc_off);
457 ((void) nonce_counter);
458 ((void) stream_block);
459 ((void) input);
460 ((void) output);
461
462 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
463}
464
Paul Bakkerfae35f02013-03-13 10:33:51 +0100465static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000466{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000467 ((void) key_length);
468
Paul Bakker8123e9d2011-01-06 15:37:30 +0000469 return des_setkey_dec( (des_context *) ctx, key );
470}
471
Paul Bakkerfae35f02013-03-13 10:33:51 +0100472static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000473{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000474 ((void) key_length);
475
Paul Bakker8123e9d2011-01-06 15:37:30 +0000476 return des_setkey_enc( (des_context *) ctx, key );
477}
478
Paul Bakkerfae35f02013-03-13 10:33:51 +0100479static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000480{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000481 ((void) key_length);
482
Paul Bakker8123e9d2011-01-06 15:37:30 +0000483 return des3_set2key_dec( (des3_context *) ctx, key );
484}
485
Paul Bakkerfae35f02013-03-13 10:33:51 +0100486static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000487{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000488 ((void) key_length);
489
Paul Bakker8123e9d2011-01-06 15:37:30 +0000490 return des3_set2key_enc( (des3_context *) ctx, key );
491}
492
Paul Bakkerfae35f02013-03-13 10:33:51 +0100493static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000494{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000495 ((void) key_length);
496
Paul Bakker8123e9d2011-01-06 15:37:30 +0000497 return des3_set3key_dec( (des3_context *) ctx, key );
498}
499
Paul Bakkerfae35f02013-03-13 10:33:51 +0100500static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000501{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000502 ((void) key_length);
503
Paul Bakker8123e9d2011-01-06 15:37:30 +0000504 return des3_set3key_enc( (des3_context *) ctx, key );
505}
506
507static void * des_ctx_alloc( void )
508{
509 return malloc( sizeof( des_context ) );
510}
511
512static void * des3_ctx_alloc( void )
513{
514 return malloc( sizeof( des3_context ) );
515}
516
517static void des_ctx_free( void *ctx )
518{
519 free( ctx );
520}
521
Paul Bakker343a8702011-06-09 14:27:58 +0000522const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000523 POLARSSL_CIPHER_ID_DES,
Paul Bakker23986e52011-04-24 08:57:21 +0000524 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000525 des_crypt_cfb128_wrap,
526 des_crypt_ctr_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000527 des_setkey_enc_wrap,
528 des_setkey_dec_wrap,
529 des_ctx_alloc,
530 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000531};
532
Paul Bakker343a8702011-06-09 14:27:58 +0000533const cipher_info_t des_cbc_info = {
534 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000535 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000536 POLARSSL_KEY_LENGTH_DES,
537 "DES-CBC",
538 8,
539 8,
540 &des_info
541};
542
543const cipher_base_t des_ede_info = {
544 POLARSSL_CIPHER_ID_DES,
Paul Bakker23986e52011-04-24 08:57:21 +0000545 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000546 des_crypt_cfb128_wrap,
547 des_crypt_ctr_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000548 des3_set2key_enc_wrap,
549 des3_set2key_dec_wrap,
550 des3_ctx_alloc,
551 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000552};
553
Paul Bakker343a8702011-06-09 14:27:58 +0000554const cipher_info_t des_ede_cbc_info = {
555 POLARSSL_CIPHER_DES_EDE_CBC,
556 POLARSSL_MODE_CBC,
557 POLARSSL_KEY_LENGTH_DES_EDE,
558 "DES-EDE-CBC",
559 16,
560 16,
561 &des_ede_info
562};
563
564const cipher_base_t des_ede3_info = {
565 POLARSSL_CIPHER_ID_DES,
566 des3_crypt_cbc_wrap,
567 des_crypt_cfb128_wrap,
568 des_crypt_ctr_wrap,
569 des3_set3key_enc_wrap,
570 des3_set3key_dec_wrap,
571 des3_ctx_alloc,
572 des_ctx_free
573};
574
Paul Bakker8123e9d2011-01-06 15:37:30 +0000575const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000576 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000577 POLARSSL_MODE_CBC,
578 POLARSSL_KEY_LENGTH_DES_EDE3,
579 "DES-EDE3-CBC",
580 8,
581 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000582 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000583};
584#endif
585
Paul Bakker6132d0a2012-07-04 17:10:40 +0000586#if defined(POLARSSL_BLOWFISH_C)
587
Paul Bakkerfae35f02013-03-13 10:33:51 +0100588static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000589 unsigned char *iv, const unsigned char *input, unsigned char *output )
590{
591 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
592}
593
Paul Bakkerfae35f02013-03-13 10:33:51 +0100594static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000595 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
596{
597#if defined(POLARSSL_CIPHER_MODE_CFB)
598 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
599#else
600 ((void) ctx);
601 ((void) operation);
602 ((void) length);
603 ((void) iv_off);
604 ((void) iv);
605 ((void) input);
606 ((void) output);
607
608 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
609#endif
610}
611
Paul Bakkerfae35f02013-03-13 10:33:51 +0100612static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000613 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
614 const unsigned char *input, unsigned char *output )
615{
616#if defined(POLARSSL_CIPHER_MODE_CTR)
617 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
618 stream_block, input, output );
619#else
620 ((void) ctx);
621 ((void) length);
622 ((void) nc_off);
623 ((void) nonce_counter);
624 ((void) stream_block);
625 ((void) input);
626 ((void) output);
627
628 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
629#endif
630}
631
Paul Bakkerfae35f02013-03-13 10:33:51 +0100632static int blowfish_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000633{
634 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
635}
636
Paul Bakkerfae35f02013-03-13 10:33:51 +0100637static int blowfish_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000638{
639 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
640}
641
642static void * blowfish_ctx_alloc( void )
643{
644 return malloc( sizeof( blowfish_context ) );
645}
646
647static void blowfish_ctx_free( void *ctx )
648{
649 free( ctx );
650}
651
652const cipher_base_t blowfish_info = {
653 POLARSSL_CIPHER_ID_BLOWFISH,
654 blowfish_crypt_cbc_wrap,
655 blowfish_crypt_cfb64_wrap,
656 blowfish_crypt_ctr_wrap,
657 blowfish_setkey_enc_wrap,
658 blowfish_setkey_dec_wrap,
659 blowfish_ctx_alloc,
660 blowfish_ctx_free
661};
662
663const cipher_info_t blowfish_cbc_info = {
664 POLARSSL_CIPHER_BLOWFISH_CBC,
665 POLARSSL_MODE_CBC,
666 32,
667 "BLOWFISH-CBC",
668 8,
669 8,
670 &blowfish_info
671};
672
673#if defined(POLARSSL_CIPHER_MODE_CFB)
674const cipher_info_t blowfish_cfb64_info = {
675 POLARSSL_CIPHER_BLOWFISH_CFB64,
676 POLARSSL_MODE_CFB,
677 32,
678 "BLOWFISH-CFB64",
679 8,
680 8,
681 &blowfish_info
682};
683#endif /* POLARSSL_CIPHER_MODE_CFB */
684
685#if defined(POLARSSL_CIPHER_MODE_CTR)
686const cipher_info_t blowfish_ctr_info = {
687 POLARSSL_CIPHER_BLOWFISH_CTR,
688 POLARSSL_MODE_CTR,
689 32,
690 "BLOWFISH-CTR",
691 8,
692 8,
693 &blowfish_info
694};
695#endif /* POLARSSL_CIPHER_MODE_CTR */
696#endif /* POLARSSL_BLOWFISH_C */
697
Paul Bakker68884e32013-01-07 18:20:04 +0100698#if defined(POLARSSL_ARC4_C)
699static void * arc4_ctx_alloc( void )
700{
701 return (void *) 1;
702}
703
704
705static void arc4_ctx_free( void *ctx )
706{
707 ((void) ctx);
708}
709
710const cipher_base_t arc4_base_info = {
711 POLARSSL_CIPHER_ID_ARC4,
712 NULL,
713 NULL,
714 NULL,
715 NULL,
716 NULL,
717 arc4_ctx_alloc,
718 arc4_ctx_free
719};
720
721const cipher_info_t arc4_128_info = {
722 POLARSSL_CIPHER_ARC4_128,
723 POLARSSL_MODE_STREAM,
724 128,
725 "ARC4-128",
726 0,
727 1,
728 &arc4_base_info
729};
730#endif /* POLARSSL_ARC4_C */
731
Paul Bakkerfab5c822012-02-06 16:45:10 +0000732#if defined(POLARSSL_CIPHER_NULL_CIPHER)
733static void * null_ctx_alloc( void )
734{
735 return (void *) 1;
736}
737
738
739static void null_ctx_free( void *ctx )
740{
741 ((void) ctx);
742}
743
744const cipher_base_t null_base_info = {
745 POLARSSL_CIPHER_ID_NULL,
746 NULL,
747 NULL,
748 NULL,
749 NULL,
750 NULL,
751 null_ctx_alloc,
752 null_ctx_free
753};
754
755const cipher_info_t null_cipher_info = {
756 POLARSSL_CIPHER_NULL,
757 POLARSSL_MODE_NULL,
758 0,
759 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +0100760 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +0000761 1,
762 &null_base_info
763};
764#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
765
Paul Bakker8123e9d2011-01-06 15:37:30 +0000766#endif