blob: 6b85903f0dc7ce6206ed199be3e597dece1b0512 [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
2 * \file md_wrap.c
3 *
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 Bakkerfab5c822012-02-06 16:45:10 +00008 * Copyright (C) 2006-2012, 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 Bakker23986e52011-04-24 08:57:21 +000056int 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 Bakker343a8702011-06-09 14:27:58 +000062int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
63 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
80int aes_crypt_ctr_wrap( void *ctx, size_t length,
81 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 Bakker23986e52011-04-24 08:57:21 +0000100int 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 Bakker23986e52011-04-24 08:57:21 +0000105int 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 Bakker8123e9d2011-01-06 15:37:30 +0000225#endif
226
227#if defined(POLARSSL_CAMELLIA_C)
228
Paul Bakker23986e52011-04-24 08:57:21 +0000229int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000230 unsigned char *iv, const unsigned char *input, unsigned char *output )
231{
232 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
233}
234
Paul Bakker343a8702011-06-09 14:27:58 +0000235int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
236 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
237{
238#if defined(POLARSSL_CIPHER_MODE_CFB)
239 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
240#else
241 ((void) ctx);
242 ((void) operation);
243 ((void) length);
244 ((void) iv_off);
245 ((void) iv);
246 ((void) input);
247 ((void) output);
248
249 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
250#endif
251}
252
253int camellia_crypt_ctr_wrap( void *ctx, size_t length,
254 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
255 const unsigned char *input, unsigned char *output )
256{
257#if defined(POLARSSL_CIPHER_MODE_CTR)
258 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
259 stream_block, input, output );
260#else
261 ((void) ctx);
262 ((void) length);
263 ((void) nc_off);
264 ((void) nonce_counter);
265 ((void) stream_block);
266 ((void) input);
267 ((void) output);
268
269 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
270#endif
271}
272
Paul Bakker23986e52011-04-24 08:57:21 +0000273int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000274{
275 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
276}
277
Paul Bakker23986e52011-04-24 08:57:21 +0000278int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000279{
280 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
281}
282
283static void * camellia_ctx_alloc( void )
284{
285 return malloc( sizeof( camellia_context ) );
286}
287
288static void camellia_ctx_free( void *ctx )
289{
290 free( ctx );
291}
292
Paul Bakker343a8702011-06-09 14:27:58 +0000293const cipher_base_t camellia_info = {
294 POLARSSL_CIPHER_ID_CAMELLIA,
295 camellia_crypt_cbc_wrap,
296 camellia_crypt_cfb128_wrap,
297 camellia_crypt_ctr_wrap,
298 camellia_setkey_enc_wrap,
299 camellia_setkey_dec_wrap,
300 camellia_ctx_alloc,
301 camellia_ctx_free
302};
303
Paul Bakker8123e9d2011-01-06 15:37:30 +0000304const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000305 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000306 POLARSSL_MODE_CBC,
307 128,
308 "CAMELLIA-128-CBC",
309 16,
310 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000311 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000312};
313
314const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000315 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000316 POLARSSL_MODE_CBC,
317 192,
318 "CAMELLIA-192-CBC",
319 16,
320 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000321 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000322};
323
324const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000325 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000326 POLARSSL_MODE_CBC,
327 256,
328 "CAMELLIA-256-CBC",
329 16,
330 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000331 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000332};
Paul Bakker343a8702011-06-09 14:27:58 +0000333
334#if defined(POLARSSL_CIPHER_MODE_CFB)
335const cipher_info_t camellia_128_cfb128_info = {
336 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000337 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000338 128,
339 "CAMELLIA-128-CFB128",
340 16,
341 16,
342 &camellia_info
343};
344
345const cipher_info_t camellia_192_cfb128_info = {
346 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000347 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000348 192,
349 "CAMELLIA-192-CFB128",
350 16,
351 16,
352 &camellia_info
353};
354
355const cipher_info_t camellia_256_cfb128_info = {
356 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000357 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000358 256,
359 "CAMELLIA-256-CFB128",
360 16,
361 16,
362 &camellia_info
363};
364#endif /* POLARSSL_CIPHER_MODE_CFB */
365
366#if defined(POLARSSL_CIPHER_MODE_CTR)
367const cipher_info_t camellia_128_ctr_info = {
368 POLARSSL_CIPHER_CAMELLIA_128_CTR,
369 POLARSSL_MODE_CTR,
370 128,
371 "CAMELLIA-128-CTR",
372 16,
373 16,
374 &camellia_info
375};
376
377const cipher_info_t camellia_192_ctr_info = {
378 POLARSSL_CIPHER_CAMELLIA_192_CTR,
379 POLARSSL_MODE_CTR,
380 192,
381 "CAMELLIA-192-CTR",
382 16,
383 16,
384 &camellia_info
385};
386
387const cipher_info_t camellia_256_ctr_info = {
388 POLARSSL_CIPHER_CAMELLIA_256_CTR,
389 POLARSSL_MODE_CTR,
390 256,
391 "CAMELLIA-256-CTR",
392 16,
393 16,
394 &camellia_info
395};
396#endif /* POLARSSL_CIPHER_MODE_CTR */
397
Paul Bakker8123e9d2011-01-06 15:37:30 +0000398#endif
399
400#if defined(POLARSSL_DES_C)
401
Paul Bakker23986e52011-04-24 08:57:21 +0000402int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000403 unsigned char *iv, const unsigned char *input, unsigned char *output )
404{
405 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
406}
407
Paul Bakker23986e52011-04-24 08:57:21 +0000408int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000409 unsigned char *iv, const unsigned char *input, unsigned char *output )
410{
411 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
412}
413
Paul Bakker343a8702011-06-09 14:27:58 +0000414int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
415 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
416{
417 ((void) ctx);
418 ((void) operation);
419 ((void) length);
420 ((void) iv_off);
421 ((void) iv);
422 ((void) input);
423 ((void) output);
424
425 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
426}
427
428int des_crypt_ctr_wrap( void *ctx, size_t length,
429 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
430 const unsigned char *input, unsigned char *output )
431{
432 ((void) ctx);
433 ((void) length);
434 ((void) nc_off);
435 ((void) nonce_counter);
436 ((void) stream_block);
437 ((void) input);
438 ((void) output);
439
440 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
441}
442
443
Paul Bakker23986e52011-04-24 08:57:21 +0000444int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000445{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000446 ((void) key_length);
447
Paul Bakker8123e9d2011-01-06 15:37:30 +0000448 return des_setkey_dec( (des_context *) ctx, key );
449}
450
Paul Bakker23986e52011-04-24 08:57:21 +0000451int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000452{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000453 ((void) key_length);
454
Paul Bakker8123e9d2011-01-06 15:37:30 +0000455 return des_setkey_enc( (des_context *) ctx, key );
456}
457
Paul Bakker23986e52011-04-24 08:57:21 +0000458int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000459{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000460 ((void) key_length);
461
Paul Bakker8123e9d2011-01-06 15:37:30 +0000462 return des3_set2key_dec( (des3_context *) ctx, key );
463}
464
Paul Bakker23986e52011-04-24 08:57:21 +0000465int des3_set2key_enc_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 des3_set2key_enc( (des3_context *) ctx, key );
470}
471
Paul Bakker23986e52011-04-24 08:57:21 +0000472int des3_set3key_dec_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 des3_set3key_dec( (des3_context *) ctx, key );
477}
478
Paul Bakker23986e52011-04-24 08:57:21 +0000479int des3_set3key_enc_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_set3key_enc( (des3_context *) ctx, key );
484}
485
486static void * des_ctx_alloc( void )
487{
488 return malloc( sizeof( des_context ) );
489}
490
491static void * des3_ctx_alloc( void )
492{
493 return malloc( sizeof( des3_context ) );
494}
495
496static void des_ctx_free( void *ctx )
497{
498 free( ctx );
499}
500
Paul Bakker343a8702011-06-09 14:27:58 +0000501const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000502 POLARSSL_CIPHER_ID_DES,
Paul Bakker23986e52011-04-24 08:57:21 +0000503 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000504 des_crypt_cfb128_wrap,
505 des_crypt_ctr_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000506 des_setkey_enc_wrap,
507 des_setkey_dec_wrap,
508 des_ctx_alloc,
509 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000510};
511
Paul Bakker343a8702011-06-09 14:27:58 +0000512const cipher_info_t des_cbc_info = {
513 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000514 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000515 POLARSSL_KEY_LENGTH_DES,
516 "DES-CBC",
517 8,
518 8,
519 &des_info
520};
521
522const cipher_base_t des_ede_info = {
523 POLARSSL_CIPHER_ID_DES,
Paul Bakker23986e52011-04-24 08:57:21 +0000524 des3_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 des3_set2key_enc_wrap,
528 des3_set2key_dec_wrap,
529 des3_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_ede_cbc_info = {
534 POLARSSL_CIPHER_DES_EDE_CBC,
535 POLARSSL_MODE_CBC,
536 POLARSSL_KEY_LENGTH_DES_EDE,
537 "DES-EDE-CBC",
538 16,
539 16,
540 &des_ede_info
541};
542
543const cipher_base_t des_ede3_info = {
544 POLARSSL_CIPHER_ID_DES,
545 des3_crypt_cbc_wrap,
546 des_crypt_cfb128_wrap,
547 des_crypt_ctr_wrap,
548 des3_set3key_enc_wrap,
549 des3_set3key_dec_wrap,
550 des3_ctx_alloc,
551 des_ctx_free
552};
553
Paul Bakker8123e9d2011-01-06 15:37:30 +0000554const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000555 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000556 POLARSSL_MODE_CBC,
557 POLARSSL_KEY_LENGTH_DES_EDE3,
558 "DES-EDE3-CBC",
559 8,
560 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000561 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000562};
563#endif
564
Paul Bakker6132d0a2012-07-04 17:10:40 +0000565#if defined(POLARSSL_BLOWFISH_C)
566
567int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
568 unsigned char *iv, const unsigned char *input, unsigned char *output )
569{
570 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
571}
572
573int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
574 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
575{
576#if defined(POLARSSL_CIPHER_MODE_CFB)
577 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
578#else
579 ((void) ctx);
580 ((void) operation);
581 ((void) length);
582 ((void) iv_off);
583 ((void) iv);
584 ((void) input);
585 ((void) output);
586
587 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
588#endif
589}
590
591int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
592 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
593 const unsigned char *input, unsigned char *output )
594{
595#if defined(POLARSSL_CIPHER_MODE_CTR)
596 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
597 stream_block, input, output );
598#else
599 ((void) ctx);
600 ((void) length);
601 ((void) nc_off);
602 ((void) nonce_counter);
603 ((void) stream_block);
604 ((void) input);
605 ((void) output);
606
607 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
608#endif
609}
610
611int blowfish_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
612{
613 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
614}
615
616int blowfish_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
617{
618 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
619}
620
621static void * blowfish_ctx_alloc( void )
622{
623 return malloc( sizeof( blowfish_context ) );
624}
625
626static void blowfish_ctx_free( void *ctx )
627{
628 free( ctx );
629}
630
631const cipher_base_t blowfish_info = {
632 POLARSSL_CIPHER_ID_BLOWFISH,
633 blowfish_crypt_cbc_wrap,
634 blowfish_crypt_cfb64_wrap,
635 blowfish_crypt_ctr_wrap,
636 blowfish_setkey_enc_wrap,
637 blowfish_setkey_dec_wrap,
638 blowfish_ctx_alloc,
639 blowfish_ctx_free
640};
641
642const cipher_info_t blowfish_cbc_info = {
643 POLARSSL_CIPHER_BLOWFISH_CBC,
644 POLARSSL_MODE_CBC,
645 32,
646 "BLOWFISH-CBC",
647 8,
648 8,
649 &blowfish_info
650};
651
652#if defined(POLARSSL_CIPHER_MODE_CFB)
653const cipher_info_t blowfish_cfb64_info = {
654 POLARSSL_CIPHER_BLOWFISH_CFB64,
655 POLARSSL_MODE_CFB,
656 32,
657 "BLOWFISH-CFB64",
658 8,
659 8,
660 &blowfish_info
661};
662#endif /* POLARSSL_CIPHER_MODE_CFB */
663
664#if defined(POLARSSL_CIPHER_MODE_CTR)
665const cipher_info_t blowfish_ctr_info = {
666 POLARSSL_CIPHER_BLOWFISH_CTR,
667 POLARSSL_MODE_CTR,
668 32,
669 "BLOWFISH-CTR",
670 8,
671 8,
672 &blowfish_info
673};
674#endif /* POLARSSL_CIPHER_MODE_CTR */
675#endif /* POLARSSL_BLOWFISH_C */
676
Paul Bakkerfab5c822012-02-06 16:45:10 +0000677#if defined(POLARSSL_CIPHER_NULL_CIPHER)
678static void * null_ctx_alloc( void )
679{
680 return (void *) 1;
681}
682
683
684static void null_ctx_free( void *ctx )
685{
686 ((void) ctx);
687}
688
689const cipher_base_t null_base_info = {
690 POLARSSL_CIPHER_ID_NULL,
691 NULL,
692 NULL,
693 NULL,
694 NULL,
695 NULL,
696 null_ctx_alloc,
697 null_ctx_free
698};
699
700const cipher_info_t null_cipher_info = {
701 POLARSSL_CIPHER_NULL,
702 POLARSSL_MODE_NULL,
703 0,
704 "NULL",
705 1,
706 1,
707 &null_base_info
708};
709#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
710
Paul Bakker8123e9d2011-01-06 15:37:30 +0000711#endif