blob: ede299bf633145b12c8689c971bf14f06b7e0ce6 [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{
80 return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output );
81}
82
Paul Bakkerfae35f02013-03-13 10:33:51 +010083static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +000084 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
85{
86#if defined(POLARSSL_CIPHER_MODE_CFB)
87 return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output );
88#else
89 ((void) ctx);
90 ((void) operation);
91 ((void) length);
92 ((void) iv_off);
93 ((void) iv);
94 ((void) input);
95 ((void) output);
96
97 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
98#endif
99}
100
Paul Bakkerfae35f02013-03-13 10:33:51 +0100101static int aes_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000102 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
103 const unsigned char *input, unsigned char *output )
104{
105#if defined(POLARSSL_CIPHER_MODE_CTR)
106 return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter,
107 stream_block, input, output );
108#else
109 ((void) ctx);
110 ((void) length);
111 ((void) nc_off);
112 ((void) nonce_counter);
113 ((void) stream_block);
114 ((void) input);
115 ((void) output);
116
117 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
118#endif
119}
120
Paul Bakkerfae35f02013-03-13 10:33:51 +0100121static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000122{
123 return aes_setkey_dec( (aes_context *) ctx, key, key_length );
124}
125
Paul Bakkerfae35f02013-03-13 10:33:51 +0100126static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000127{
128 return aes_setkey_enc( (aes_context *) ctx, key, key_length );
129}
130
131static void * aes_ctx_alloc( void )
132{
Paul Bakker6e339b52013-07-03 13:37:05 +0200133 return polarssl_malloc( sizeof( aes_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000134}
135
136static void aes_ctx_free( void *ctx )
137{
Paul Bakker6e339b52013-07-03 13:37:05 +0200138 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000139}
140
Paul Bakker343a8702011-06-09 14:27:58 +0000141const cipher_base_t aes_info = {
142 POLARSSL_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200143 aes_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000144 aes_crypt_cbc_wrap,
145 aes_crypt_cfb128_wrap,
146 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200147 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000148 aes_setkey_enc_wrap,
149 aes_setkey_dec_wrap,
150 aes_ctx_alloc,
151 aes_ctx_free
152};
153
Paul Bakker5e0efa72013-09-08 23:04:04 +0200154const cipher_info_t aes_128_ecb_info = {
155 POLARSSL_CIPHER_AES_128_ECB,
156 POLARSSL_MODE_ECB,
157 128,
158 "AES-128-ECB",
159 16,
160 0,
161 16,
162 &aes_info
163};
164
165const cipher_info_t aes_192_ecb_info = {
166 POLARSSL_CIPHER_AES_192_ECB,
167 POLARSSL_MODE_ECB,
168 192,
169 "AES-192-ECB",
170 16,
171 0,
172 16,
173 &aes_info
174};
175
176const cipher_info_t aes_256_ecb_info = {
177 POLARSSL_CIPHER_AES_256_ECB,
178 POLARSSL_MODE_ECB,
179 256,
180 "AES-256-ECB",
181 16,
182 0,
183 16,
184 &aes_info
185};
186
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200187#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000188const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000189 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000190 POLARSSL_MODE_CBC,
191 128,
192 "AES-128-CBC",
193 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200194 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000195 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000196 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000197};
198
199const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000200 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000201 POLARSSL_MODE_CBC,
202 192,
203 "AES-192-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_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000211 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000212 POLARSSL_MODE_CBC,
213 256,
214 "AES-256-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};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200220#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000221
222#if defined(POLARSSL_CIPHER_MODE_CFB)
223const cipher_info_t aes_128_cfb128_info = {
224 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000225 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000226 128,
227 "AES-128-CFB128",
228 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200229 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000230 16,
231 &aes_info
232};
233
234const cipher_info_t aes_192_cfb128_info = {
235 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000236 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000237 192,
238 "AES-192-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_256_cfb128_info = {
246 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000247 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000248 256,
249 "AES-256-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#endif /* POLARSSL_CIPHER_MODE_CFB */
256
257#if defined(POLARSSL_CIPHER_MODE_CTR)
258const cipher_info_t aes_128_ctr_info = {
259 POLARSSL_CIPHER_AES_128_CTR,
260 POLARSSL_MODE_CTR,
261 128,
262 "AES-128-CTR",
263 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200264 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000265 16,
266 &aes_info
267};
268
269const cipher_info_t aes_192_ctr_info = {
270 POLARSSL_CIPHER_AES_192_CTR,
271 POLARSSL_MODE_CTR,
272 192,
273 "AES-192-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_256_ctr_info = {
281 POLARSSL_CIPHER_AES_256_CTR,
282 POLARSSL_MODE_CTR,
283 256,
284 "AES-256-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#endif /* POLARSSL_CIPHER_MODE_CTR */
291
Paul Bakker68884e32013-01-07 18:20:04 +0100292#if defined(POLARSSL_GCM_C)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200293static void *gcm_ctx_alloc( void )
294{
295 return polarssl_malloc( sizeof( gcm_context ) );
296}
297
298static void gcm_ctx_free( void *ctx )
299{
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200300 gcm_free( ctx );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200301 polarssl_free( ctx );
302}
303
Paul Bakker43aff2a2013-09-09 00:10:27 +0200304static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200305{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200306 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
307 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200308}
309
310const cipher_base_t gcm_aes_info = {
311 POLARSSL_CIPHER_ID_AES,
312 NULL,
313 NULL,
314 NULL,
315 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200316 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200317 gcm_aes_setkey_wrap,
318 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200319 gcm_ctx_alloc,
320 gcm_ctx_free,
321};
322
Paul Bakker68884e32013-01-07 18:20:04 +0100323const cipher_info_t aes_128_gcm_info = {
324 POLARSSL_CIPHER_AES_128_GCM,
325 POLARSSL_MODE_GCM,
326 128,
327 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200328 12,
329 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100330 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200331 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100332};
333
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200334const cipher_info_t aes_192_gcm_info = {
335 POLARSSL_CIPHER_AES_192_GCM,
336 POLARSSL_MODE_GCM,
337 192,
338 "AES-192-GCM",
339 12,
340 1,
341 16,
342 &gcm_aes_info
343};
344
Paul Bakker68884e32013-01-07 18:20:04 +0100345const cipher_info_t aes_256_gcm_info = {
346 POLARSSL_CIPHER_AES_256_GCM,
347 POLARSSL_MODE_GCM,
348 256,
349 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200350 12,
351 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100352 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200353 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100354};
355#endif /* POLARSSL_GCM_C */
356
Paul Bakker8123e9d2011-01-06 15:37:30 +0000357#endif
358
359#if defined(POLARSSL_CAMELLIA_C)
360
Paul Bakker5e0efa72013-09-08 23:04:04 +0200361static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
362 const unsigned char *input, unsigned char *output )
363{
364 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
365}
366
Paul Bakkerfae35f02013-03-13 10:33:51 +0100367static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000368 unsigned char *iv, const unsigned char *input, unsigned char *output )
369{
370 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
371}
372
Paul Bakkerfae35f02013-03-13 10:33:51 +0100373static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000374 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
375{
376#if defined(POLARSSL_CIPHER_MODE_CFB)
377 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
378#else
379 ((void) ctx);
380 ((void) operation);
381 ((void) length);
382 ((void) iv_off);
383 ((void) iv);
384 ((void) input);
385 ((void) output);
386
387 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
388#endif
389}
390
Paul Bakkerfae35f02013-03-13 10:33:51 +0100391static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000392 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
393 const unsigned char *input, unsigned char *output )
394{
395#if defined(POLARSSL_CIPHER_MODE_CTR)
396 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
397 stream_block, input, output );
398#else
399 ((void) ctx);
400 ((void) length);
401 ((void) nc_off);
402 ((void) nonce_counter);
403 ((void) stream_block);
404 ((void) input);
405 ((void) output);
406
407 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
408#endif
409}
410
Paul Bakkerfae35f02013-03-13 10:33:51 +0100411static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000412{
413 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
414}
415
Paul Bakkerfae35f02013-03-13 10:33:51 +0100416static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000417{
418 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
419}
420
421static void * camellia_ctx_alloc( void )
422{
Paul Bakker6e339b52013-07-03 13:37:05 +0200423 return polarssl_malloc( sizeof( camellia_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000424}
425
426static void camellia_ctx_free( void *ctx )
427{
Paul Bakker6e339b52013-07-03 13:37:05 +0200428 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000429}
430
Paul Bakker343a8702011-06-09 14:27:58 +0000431const cipher_base_t camellia_info = {
432 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200433 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000434 camellia_crypt_cbc_wrap,
435 camellia_crypt_cfb128_wrap,
436 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200437 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000438 camellia_setkey_enc_wrap,
439 camellia_setkey_dec_wrap,
440 camellia_ctx_alloc,
441 camellia_ctx_free
442};
443
Paul Bakker5e0efa72013-09-08 23:04:04 +0200444const cipher_info_t camellia_128_ecb_info = {
445 POLARSSL_CIPHER_CAMELLIA_128_ECB,
446 POLARSSL_MODE_ECB,
447 128,
448 "CAMELLIA-128-ECB",
449 16,
450 0,
451 16,
452 &camellia_info
453};
454
455const cipher_info_t camellia_192_ecb_info = {
456 POLARSSL_CIPHER_CAMELLIA_192_ECB,
457 POLARSSL_MODE_ECB,
458 192,
459 "CAMELLIA-192-ECB",
460 16,
461 0,
462 16,
463 &camellia_info
464};
465
466const cipher_info_t camellia_256_ecb_info = {
467 POLARSSL_CIPHER_CAMELLIA_256_ECB,
468 POLARSSL_MODE_ECB,
469 256,
470 "CAMELLIA-256-ECB",
471 16,
472 0,
473 16,
474 &camellia_info
475};
476
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200477#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000478const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000479 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000480 POLARSSL_MODE_CBC,
481 128,
482 "CAMELLIA-128-CBC",
483 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200484 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000485 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000486 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000487};
488
489const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000490 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000491 POLARSSL_MODE_CBC,
492 192,
493 "CAMELLIA-192-CBC",
494 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200495 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000496 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000497 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000498};
499
500const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000501 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000502 POLARSSL_MODE_CBC,
503 256,
504 "CAMELLIA-256-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};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200510#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000511
512#if defined(POLARSSL_CIPHER_MODE_CFB)
513const cipher_info_t camellia_128_cfb128_info = {
514 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000515 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000516 128,
517 "CAMELLIA-128-CFB128",
518 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200519 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000520 16,
521 &camellia_info
522};
523
524const cipher_info_t camellia_192_cfb128_info = {
525 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000526 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000527 192,
528 "CAMELLIA-192-CFB128",
529 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200530 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000531 16,
532 &camellia_info
533};
534
535const cipher_info_t camellia_256_cfb128_info = {
536 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000537 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000538 256,
539 "CAMELLIA-256-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#endif /* POLARSSL_CIPHER_MODE_CFB */
546
547#if defined(POLARSSL_CIPHER_MODE_CTR)
548const cipher_info_t camellia_128_ctr_info = {
549 POLARSSL_CIPHER_CAMELLIA_128_CTR,
550 POLARSSL_MODE_CTR,
551 128,
552 "CAMELLIA-128-CTR",
553 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200554 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000555 16,
556 &camellia_info
557};
558
559const cipher_info_t camellia_192_ctr_info = {
560 POLARSSL_CIPHER_CAMELLIA_192_CTR,
561 POLARSSL_MODE_CTR,
562 192,
563 "CAMELLIA-192-CTR",
564 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200565 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000566 16,
567 &camellia_info
568};
569
570const cipher_info_t camellia_256_ctr_info = {
571 POLARSSL_CIPHER_CAMELLIA_256_CTR,
572 POLARSSL_MODE_CTR,
573 256,
574 "CAMELLIA-256-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#endif /* POLARSSL_CIPHER_MODE_CTR */
581
Paul Bakker8123e9d2011-01-06 15:37:30 +0000582#endif
583
584#if defined(POLARSSL_DES_C)
585
Paul Bakker5e0efa72013-09-08 23:04:04 +0200586static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
587 const unsigned char *input, unsigned char *output )
588{
589 ((void) operation);
590 return des_crypt_ecb( (des_context *) ctx, input, output );
591}
592
593static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
594 const unsigned char *input, unsigned char *output )
595{
596 ((void) operation);
597 return des3_crypt_ecb( (des3_context *) ctx, input, output );
598}
599
Paul Bakkerfae35f02013-03-13 10:33:51 +0100600static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000601 unsigned char *iv, const unsigned char *input, unsigned char *output )
602{
603 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
604}
605
Paul Bakkerfae35f02013-03-13 10:33:51 +0100606static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000607 unsigned char *iv, const unsigned char *input, unsigned char *output )
608{
609 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
610}
611
Paul Bakkerfae35f02013-03-13 10:33:51 +0100612static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000613 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
614{
615 ((void) ctx);
616 ((void) operation);
617 ((void) length);
618 ((void) iv_off);
619 ((void) iv);
620 ((void) input);
621 ((void) output);
622
623 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
624}
625
Paul Bakkerfae35f02013-03-13 10:33:51 +0100626static int des_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000627 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
628 const unsigned char *input, unsigned char *output )
629{
630 ((void) ctx);
631 ((void) length);
632 ((void) nc_off);
633 ((void) nonce_counter);
634 ((void) stream_block);
635 ((void) input);
636 ((void) output);
637
638 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
639}
640
Paul Bakkerfae35f02013-03-13 10:33:51 +0100641static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000642{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000643 ((void) key_length);
644
Paul Bakker8123e9d2011-01-06 15:37:30 +0000645 return des_setkey_dec( (des_context *) ctx, key );
646}
647
Paul Bakkerfae35f02013-03-13 10:33:51 +0100648static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000649{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000650 ((void) key_length);
651
Paul Bakker8123e9d2011-01-06 15:37:30 +0000652 return des_setkey_enc( (des_context *) ctx, key );
653}
654
Paul Bakkerfae35f02013-03-13 10:33:51 +0100655static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000656{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000657 ((void) key_length);
658
Paul Bakker8123e9d2011-01-06 15:37:30 +0000659 return des3_set2key_dec( (des3_context *) ctx, key );
660}
661
Paul Bakkerfae35f02013-03-13 10:33:51 +0100662static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000663{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000664 ((void) key_length);
665
Paul Bakker8123e9d2011-01-06 15:37:30 +0000666 return des3_set2key_enc( (des3_context *) ctx, key );
667}
668
Paul Bakkerfae35f02013-03-13 10:33:51 +0100669static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000670{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000671 ((void) key_length);
672
Paul Bakker8123e9d2011-01-06 15:37:30 +0000673 return des3_set3key_dec( (des3_context *) ctx, key );
674}
675
Paul Bakkerfae35f02013-03-13 10:33:51 +0100676static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000677{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000678 ((void) key_length);
679
Paul Bakker8123e9d2011-01-06 15:37:30 +0000680 return des3_set3key_enc( (des3_context *) ctx, key );
681}
682
683static void * des_ctx_alloc( void )
684{
Paul Bakker6e339b52013-07-03 13:37:05 +0200685 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000686}
687
688static void * des3_ctx_alloc( void )
689{
Paul Bakker6e339b52013-07-03 13:37:05 +0200690 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000691}
692
693static void des_ctx_free( void *ctx )
694{
Paul Bakker6e339b52013-07-03 13:37:05 +0200695 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000696}
697
Paul Bakker343a8702011-06-09 14:27:58 +0000698const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000699 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200700 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000701 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000702 des_crypt_cfb128_wrap,
703 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200704 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000705 des_setkey_enc_wrap,
706 des_setkey_dec_wrap,
707 des_ctx_alloc,
708 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000709};
710
Paul Bakker5e0efa72013-09-08 23:04:04 +0200711const cipher_info_t des_ecb_info = {
712 POLARSSL_CIPHER_DES_ECB,
713 POLARSSL_MODE_ECB,
714 POLARSSL_KEY_LENGTH_DES,
715 "DES-ECB",
716 8,
717 0,
718 8,
719 &des_info
720};
721
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200722#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000723const cipher_info_t des_cbc_info = {
724 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000725 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000726 POLARSSL_KEY_LENGTH_DES,
727 "DES-CBC",
728 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200729 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000730 8,
731 &des_info
732};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200733#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000734
735const cipher_base_t des_ede_info = {
736 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200737 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000738 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000739 des_crypt_cfb128_wrap,
740 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200741 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000742 des3_set2key_enc_wrap,
743 des3_set2key_dec_wrap,
744 des3_ctx_alloc,
745 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000746};
747
Paul Bakker5e0efa72013-09-08 23:04:04 +0200748const cipher_info_t des_ede_ecb_info = {
749 POLARSSL_CIPHER_DES_EDE_ECB,
750 POLARSSL_MODE_ECB,
751 POLARSSL_KEY_LENGTH_DES_EDE,
752 "DES-EDE-ECB",
753 8,
754 0,
755 8,
756 &des_ede_info
757};
758
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200759#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000760const cipher_info_t des_ede_cbc_info = {
761 POLARSSL_CIPHER_DES_EDE_CBC,
762 POLARSSL_MODE_CBC,
763 POLARSSL_KEY_LENGTH_DES_EDE,
764 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +0200765 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200766 0,
Paul Bakker0e342352013-06-24 19:33:02 +0200767 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000768 &des_ede_info
769};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200770#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000771
772const cipher_base_t des_ede3_info = {
773 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200774 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000775 des3_crypt_cbc_wrap,
776 des_crypt_cfb128_wrap,
777 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200778 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000779 des3_set3key_enc_wrap,
780 des3_set3key_dec_wrap,
781 des3_ctx_alloc,
782 des_ctx_free
783};
784
Paul Bakker5e0efa72013-09-08 23:04:04 +0200785const cipher_info_t des_ede3_ecb_info = {
786 POLARSSL_CIPHER_DES_EDE3_ECB,
787 POLARSSL_MODE_ECB,
788 POLARSSL_KEY_LENGTH_DES_EDE3,
789 "DES-EDE3-ECB",
790 8,
791 0,
792 8,
793 &des_ede3_info
794};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200795#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000796const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000797 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000798 POLARSSL_MODE_CBC,
799 POLARSSL_KEY_LENGTH_DES_EDE3,
800 "DES-EDE3-CBC",
801 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200802 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000803 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000804 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000805};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200806#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000807#endif
808
Paul Bakker6132d0a2012-07-04 17:10:40 +0000809#if defined(POLARSSL_BLOWFISH_C)
810
Paul Bakker5e0efa72013-09-08 23:04:04 +0200811static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
812 const unsigned char *input, unsigned char *output )
813{
814 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
815}
816
Paul Bakkerfae35f02013-03-13 10:33:51 +0100817static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000818 unsigned char *iv, const unsigned char *input, unsigned char *output )
819{
820 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
821}
822
Paul Bakkerfae35f02013-03-13 10:33:51 +0100823static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000824 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
825{
826#if defined(POLARSSL_CIPHER_MODE_CFB)
827 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
828#else
829 ((void) ctx);
830 ((void) operation);
831 ((void) length);
832 ((void) iv_off);
833 ((void) iv);
834 ((void) input);
835 ((void) output);
836
837 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
838#endif
839}
840
Paul Bakkerfae35f02013-03-13 10:33:51 +0100841static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000842 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
843 const unsigned char *input, unsigned char *output )
844{
845#if defined(POLARSSL_CIPHER_MODE_CTR)
846 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
847 stream_block, input, output );
848#else
849 ((void) ctx);
850 ((void) length);
851 ((void) nc_off);
852 ((void) nonce_counter);
853 ((void) stream_block);
854 ((void) input);
855 ((void) output);
856
857 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
858#endif
859}
860
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200861static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000862{
863 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
864}
865
866static void * blowfish_ctx_alloc( void )
867{
Paul Bakker6e339b52013-07-03 13:37:05 +0200868 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000869}
870
871static void blowfish_ctx_free( void *ctx )
872{
Paul Bakker6e339b52013-07-03 13:37:05 +0200873 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000874}
875
876const cipher_base_t blowfish_info = {
877 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200878 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000879 blowfish_crypt_cbc_wrap,
880 blowfish_crypt_cfb64_wrap,
881 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200882 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200883 blowfish_setkey_wrap,
884 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000885 blowfish_ctx_alloc,
886 blowfish_ctx_free
887};
888
Paul Bakker5e0efa72013-09-08 23:04:04 +0200889const cipher_info_t blowfish_ecb_info = {
890 POLARSSL_CIPHER_BLOWFISH_ECB,
891 POLARSSL_MODE_ECB,
892 128,
893 "BLOWFISH-ECB",
894 8,
895 0,
896 8,
897 &blowfish_info
898};
899
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200900#if defined(POLARSSL_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +0000901const cipher_info_t blowfish_cbc_info = {
902 POLARSSL_CIPHER_BLOWFISH_CBC,
903 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200904 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000905 "BLOWFISH-CBC",
906 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200907 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000908 8,
909 &blowfish_info
910};
Manuel Pégourié-Gonnard989ed382013-09-13 14:41:45 +0200911#endif /* POLARSSL_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +0000912
913#if defined(POLARSSL_CIPHER_MODE_CFB)
914const cipher_info_t blowfish_cfb64_info = {
915 POLARSSL_CIPHER_BLOWFISH_CFB64,
916 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200917 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000918 "BLOWFISH-CFB64",
919 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200920 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000921 8,
922 &blowfish_info
923};
924#endif /* POLARSSL_CIPHER_MODE_CFB */
925
926#if defined(POLARSSL_CIPHER_MODE_CTR)
927const cipher_info_t blowfish_ctr_info = {
928 POLARSSL_CIPHER_BLOWFISH_CTR,
929 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200930 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000931 "BLOWFISH-CTR",
932 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200933 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000934 8,
935 &blowfish_info
936};
937#endif /* POLARSSL_CIPHER_MODE_CTR */
938#endif /* POLARSSL_BLOWFISH_C */
939
Paul Bakker68884e32013-01-07 18:20:04 +0100940#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200941static int arc4_crypt_stream_wrap( void *ctx, size_t length,
942 const unsigned char *input,
943 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +0100944{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200945 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +0100946}
947
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200948static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
949 unsigned int key_length )
950{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +0200951 /* we get key_length in bits, arc4 expects it in bytes */
952 if( key_length % 8 != 0)
953 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
954
955 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200956 return( 0 );
957}
958
959static void * arc4_ctx_alloc( void )
960{
961 return polarssl_malloc( sizeof( arc4_context ) );
962}
Paul Bakker68884e32013-01-07 18:20:04 +0100963
964static void arc4_ctx_free( void *ctx )
965{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200966 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +0100967}
968
969const cipher_base_t arc4_base_info = {
970 POLARSSL_CIPHER_ID_ARC4,
971 NULL,
972 NULL,
973 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200974 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200975 arc4_crypt_stream_wrap,
976 arc4_setkey_wrap,
977 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +0100978 arc4_ctx_alloc,
979 arc4_ctx_free
980};
981
982const cipher_info_t arc4_128_info = {
983 POLARSSL_CIPHER_ARC4_128,
984 POLARSSL_MODE_STREAM,
985 128,
986 "ARC4-128",
987 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200988 0,
Paul Bakker68884e32013-01-07 18:20:04 +0100989 1,
990 &arc4_base_info
991};
992#endif /* POLARSSL_ARC4_C */
993
Paul Bakkerfab5c822012-02-06 16:45:10 +0000994#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200995static int null_crypt_stream( void *ctx, size_t length,
996 const unsigned char *input,
997 unsigned char *output )
998{
999 ((void) ctx);
1000 memmove( output, input, length );
1001 return( 0 );
1002}
1003
1004static int null_setkey( void *ctx, const unsigned char *key,
1005 unsigned int key_length )
1006{
1007 ((void) ctx);
1008 ((void) key);
1009 ((void) key_length);
1010
1011 return( 0 );
1012}
1013
Paul Bakkerfab5c822012-02-06 16:45:10 +00001014static void * null_ctx_alloc( void )
1015{
1016 return (void *) 1;
1017}
1018
Paul Bakkerfab5c822012-02-06 16:45:10 +00001019static void null_ctx_free( void *ctx )
1020{
1021 ((void) ctx);
1022}
1023
1024const cipher_base_t null_base_info = {
1025 POLARSSL_CIPHER_ID_NULL,
1026 NULL,
1027 NULL,
1028 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001029 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001030 null_crypt_stream,
1031 null_setkey,
1032 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001033 null_ctx_alloc,
1034 null_ctx_free
1035};
1036
1037const cipher_info_t null_cipher_info = {
1038 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001039 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001040 0,
1041 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001042 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001043 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001044 1,
1045 &null_base_info
1046};
1047#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1048
Paul Bakker8123e9d2011-01-06 15:37:30 +00001049#endif