blob: 862328f69934af7dcc913a125af1800651eb41ea [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
Paul Bakker8123e9d2011-01-06 15:37:30 +0000187const cipher_info_t aes_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000188 POLARSSL_CIPHER_AES_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000189 POLARSSL_MODE_CBC,
190 128,
191 "AES-128-CBC",
192 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200193 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000194 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000195 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000196};
197
198const cipher_info_t aes_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000199 POLARSSL_CIPHER_AES_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000200 POLARSSL_MODE_CBC,
201 192,
202 "AES-192-CBC",
203 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200204 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000205 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000206 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000207};
208
209const cipher_info_t aes_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000210 POLARSSL_CIPHER_AES_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000211 POLARSSL_MODE_CBC,
212 256,
213 "AES-256-CBC",
214 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200215 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000216 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000217 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000218};
Paul Bakker343a8702011-06-09 14:27:58 +0000219
220#if defined(POLARSSL_CIPHER_MODE_CFB)
221const cipher_info_t aes_128_cfb128_info = {
222 POLARSSL_CIPHER_AES_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000223 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000224 128,
225 "AES-128-CFB128",
226 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200227 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000228 16,
229 &aes_info
230};
231
232const cipher_info_t aes_192_cfb128_info = {
233 POLARSSL_CIPHER_AES_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000234 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000235 192,
236 "AES-192-CFB128",
237 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200238 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000239 16,
240 &aes_info
241};
242
243const cipher_info_t aes_256_cfb128_info = {
244 POLARSSL_CIPHER_AES_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000245 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000246 256,
247 "AES-256-CFB128",
248 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200249 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000250 16,
251 &aes_info
252};
253#endif /* POLARSSL_CIPHER_MODE_CFB */
254
255#if defined(POLARSSL_CIPHER_MODE_CTR)
256const cipher_info_t aes_128_ctr_info = {
257 POLARSSL_CIPHER_AES_128_CTR,
258 POLARSSL_MODE_CTR,
259 128,
260 "AES-128-CTR",
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
267const cipher_info_t aes_192_ctr_info = {
268 POLARSSL_CIPHER_AES_192_CTR,
269 POLARSSL_MODE_CTR,
270 192,
271 "AES-192-CTR",
272 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200273 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000274 16,
275 &aes_info
276};
277
278const cipher_info_t aes_256_ctr_info = {
279 POLARSSL_CIPHER_AES_256_CTR,
280 POLARSSL_MODE_CTR,
281 256,
282 "AES-256-CTR",
283 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200284 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000285 16,
286 &aes_info
287};
288#endif /* POLARSSL_CIPHER_MODE_CTR */
289
Paul Bakker68884e32013-01-07 18:20:04 +0100290#if defined(POLARSSL_GCM_C)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200291static void *gcm_ctx_alloc( void )
292{
293 return polarssl_malloc( sizeof( gcm_context ) );
294}
295
296static void gcm_ctx_free( void *ctx )
297{
298 polarssl_free( ctx );
299}
300
Paul Bakker43aff2a2013-09-09 00:10:27 +0200301static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200302{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200303 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
304 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200305}
306
307const cipher_base_t gcm_aes_info = {
308 POLARSSL_CIPHER_ID_AES,
309 NULL,
310 NULL,
311 NULL,
312 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200313 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200314 gcm_aes_setkey_wrap,
315 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200316 gcm_ctx_alloc,
317 gcm_ctx_free,
318};
319
Paul Bakker68884e32013-01-07 18:20:04 +0100320const cipher_info_t aes_128_gcm_info = {
321 POLARSSL_CIPHER_AES_128_GCM,
322 POLARSSL_MODE_GCM,
323 128,
324 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200325 12,
326 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100327 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200328 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100329};
330
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200331const cipher_info_t aes_192_gcm_info = {
332 POLARSSL_CIPHER_AES_192_GCM,
333 POLARSSL_MODE_GCM,
334 192,
335 "AES-192-GCM",
336 12,
337 1,
338 16,
339 &gcm_aes_info
340};
341
Paul Bakker68884e32013-01-07 18:20:04 +0100342const cipher_info_t aes_256_gcm_info = {
343 POLARSSL_CIPHER_AES_256_GCM,
344 POLARSSL_MODE_GCM,
345 256,
346 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200347 12,
348 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100349 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200350 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100351};
352#endif /* POLARSSL_GCM_C */
353
Paul Bakker8123e9d2011-01-06 15:37:30 +0000354#endif
355
356#if defined(POLARSSL_CAMELLIA_C)
357
Paul Bakker5e0efa72013-09-08 23:04:04 +0200358static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
359 const unsigned char *input, unsigned char *output )
360{
361 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
362}
363
Paul Bakkerfae35f02013-03-13 10:33:51 +0100364static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000365 unsigned char *iv, const unsigned char *input, unsigned char *output )
366{
367 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
368}
369
Paul Bakkerfae35f02013-03-13 10:33:51 +0100370static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000371 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
372{
373#if defined(POLARSSL_CIPHER_MODE_CFB)
374 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
375#else
376 ((void) ctx);
377 ((void) operation);
378 ((void) length);
379 ((void) iv_off);
380 ((void) iv);
381 ((void) input);
382 ((void) output);
383
384 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
385#endif
386}
387
Paul Bakkerfae35f02013-03-13 10:33:51 +0100388static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000389 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
390 const unsigned char *input, unsigned char *output )
391{
392#if defined(POLARSSL_CIPHER_MODE_CTR)
393 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
394 stream_block, input, output );
395#else
396 ((void) ctx);
397 ((void) length);
398 ((void) nc_off);
399 ((void) nonce_counter);
400 ((void) stream_block);
401 ((void) input);
402 ((void) output);
403
404 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
405#endif
406}
407
Paul Bakkerfae35f02013-03-13 10:33:51 +0100408static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000409{
410 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
411}
412
Paul Bakkerfae35f02013-03-13 10:33:51 +0100413static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000414{
415 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
416}
417
418static void * camellia_ctx_alloc( void )
419{
Paul Bakker6e339b52013-07-03 13:37:05 +0200420 return polarssl_malloc( sizeof( camellia_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000421}
422
423static void camellia_ctx_free( void *ctx )
424{
Paul Bakker6e339b52013-07-03 13:37:05 +0200425 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000426}
427
Paul Bakker343a8702011-06-09 14:27:58 +0000428const cipher_base_t camellia_info = {
429 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200430 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000431 camellia_crypt_cbc_wrap,
432 camellia_crypt_cfb128_wrap,
433 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200434 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000435 camellia_setkey_enc_wrap,
436 camellia_setkey_dec_wrap,
437 camellia_ctx_alloc,
438 camellia_ctx_free
439};
440
Paul Bakker5e0efa72013-09-08 23:04:04 +0200441const cipher_info_t camellia_128_ecb_info = {
442 POLARSSL_CIPHER_CAMELLIA_128_ECB,
443 POLARSSL_MODE_ECB,
444 128,
445 "CAMELLIA-128-ECB",
446 16,
447 0,
448 16,
449 &camellia_info
450};
451
452const cipher_info_t camellia_192_ecb_info = {
453 POLARSSL_CIPHER_CAMELLIA_192_ECB,
454 POLARSSL_MODE_ECB,
455 192,
456 "CAMELLIA-192-ECB",
457 16,
458 0,
459 16,
460 &camellia_info
461};
462
463const cipher_info_t camellia_256_ecb_info = {
464 POLARSSL_CIPHER_CAMELLIA_256_ECB,
465 POLARSSL_MODE_ECB,
466 256,
467 "CAMELLIA-256-ECB",
468 16,
469 0,
470 16,
471 &camellia_info
472};
473
Paul Bakker8123e9d2011-01-06 15:37:30 +0000474const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000475 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000476 POLARSSL_MODE_CBC,
477 128,
478 "CAMELLIA-128-CBC",
479 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200480 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000481 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000482 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000483};
484
485const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000486 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000487 POLARSSL_MODE_CBC,
488 192,
489 "CAMELLIA-192-CBC",
490 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200491 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000492 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000493 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000494};
495
496const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000497 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000498 POLARSSL_MODE_CBC,
499 256,
500 "CAMELLIA-256-CBC",
501 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200502 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000503 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000504 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000505};
Paul Bakker343a8702011-06-09 14:27:58 +0000506
507#if defined(POLARSSL_CIPHER_MODE_CFB)
508const cipher_info_t camellia_128_cfb128_info = {
509 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000510 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000511 128,
512 "CAMELLIA-128-CFB128",
513 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200514 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000515 16,
516 &camellia_info
517};
518
519const cipher_info_t camellia_192_cfb128_info = {
520 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000521 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000522 192,
523 "CAMELLIA-192-CFB128",
524 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200525 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000526 16,
527 &camellia_info
528};
529
530const cipher_info_t camellia_256_cfb128_info = {
531 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000532 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000533 256,
534 "CAMELLIA-256-CFB128",
535 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200536 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000537 16,
538 &camellia_info
539};
540#endif /* POLARSSL_CIPHER_MODE_CFB */
541
542#if defined(POLARSSL_CIPHER_MODE_CTR)
543const cipher_info_t camellia_128_ctr_info = {
544 POLARSSL_CIPHER_CAMELLIA_128_CTR,
545 POLARSSL_MODE_CTR,
546 128,
547 "CAMELLIA-128-CTR",
548 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200549 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000550 16,
551 &camellia_info
552};
553
554const cipher_info_t camellia_192_ctr_info = {
555 POLARSSL_CIPHER_CAMELLIA_192_CTR,
556 POLARSSL_MODE_CTR,
557 192,
558 "CAMELLIA-192-CTR",
559 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200560 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000561 16,
562 &camellia_info
563};
564
565const cipher_info_t camellia_256_ctr_info = {
566 POLARSSL_CIPHER_CAMELLIA_256_CTR,
567 POLARSSL_MODE_CTR,
568 256,
569 "CAMELLIA-256-CTR",
570 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200571 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000572 16,
573 &camellia_info
574};
575#endif /* POLARSSL_CIPHER_MODE_CTR */
576
Paul Bakker8123e9d2011-01-06 15:37:30 +0000577#endif
578
579#if defined(POLARSSL_DES_C)
580
Paul Bakker5e0efa72013-09-08 23:04:04 +0200581static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
582 const unsigned char *input, unsigned char *output )
583{
584 ((void) operation);
585 return des_crypt_ecb( (des_context *) ctx, input, output );
586}
587
588static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
589 const unsigned char *input, unsigned char *output )
590{
591 ((void) operation);
592 return des3_crypt_ecb( (des3_context *) ctx, input, output );
593}
594
Paul Bakkerfae35f02013-03-13 10:33:51 +0100595static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000596 unsigned char *iv, const unsigned char *input, unsigned char *output )
597{
598 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
599}
600
Paul Bakkerfae35f02013-03-13 10:33:51 +0100601static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000602 unsigned char *iv, const unsigned char *input, unsigned char *output )
603{
604 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
605}
606
Paul Bakkerfae35f02013-03-13 10:33:51 +0100607static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000608 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
609{
610 ((void) ctx);
611 ((void) operation);
612 ((void) length);
613 ((void) iv_off);
614 ((void) iv);
615 ((void) input);
616 ((void) output);
617
618 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
619}
620
Paul Bakkerfae35f02013-03-13 10:33:51 +0100621static int des_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000622 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
623 const unsigned char *input, unsigned char *output )
624{
625 ((void) ctx);
626 ((void) length);
627 ((void) nc_off);
628 ((void) nonce_counter);
629 ((void) stream_block);
630 ((void) input);
631 ((void) output);
632
633 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
634}
635
Paul Bakkerfae35f02013-03-13 10:33:51 +0100636static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000637{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000638 ((void) key_length);
639
Paul Bakker8123e9d2011-01-06 15:37:30 +0000640 return des_setkey_dec( (des_context *) ctx, key );
641}
642
Paul Bakkerfae35f02013-03-13 10:33:51 +0100643static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000644{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000645 ((void) key_length);
646
Paul Bakker8123e9d2011-01-06 15:37:30 +0000647 return des_setkey_enc( (des_context *) ctx, key );
648}
649
Paul Bakkerfae35f02013-03-13 10:33:51 +0100650static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000651{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000652 ((void) key_length);
653
Paul Bakker8123e9d2011-01-06 15:37:30 +0000654 return des3_set2key_dec( (des3_context *) ctx, key );
655}
656
Paul Bakkerfae35f02013-03-13 10:33:51 +0100657static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000658{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000659 ((void) key_length);
660
Paul Bakker8123e9d2011-01-06 15:37:30 +0000661 return des3_set2key_enc( (des3_context *) ctx, key );
662}
663
Paul Bakkerfae35f02013-03-13 10:33:51 +0100664static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000665{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000666 ((void) key_length);
667
Paul Bakker8123e9d2011-01-06 15:37:30 +0000668 return des3_set3key_dec( (des3_context *) ctx, key );
669}
670
Paul Bakkerfae35f02013-03-13 10:33:51 +0100671static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000672{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000673 ((void) key_length);
674
Paul Bakker8123e9d2011-01-06 15:37:30 +0000675 return des3_set3key_enc( (des3_context *) ctx, key );
676}
677
678static void * des_ctx_alloc( void )
679{
Paul Bakker6e339b52013-07-03 13:37:05 +0200680 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000681}
682
683static void * des3_ctx_alloc( void )
684{
Paul Bakker6e339b52013-07-03 13:37:05 +0200685 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000686}
687
688static void des_ctx_free( void *ctx )
689{
Paul Bakker6e339b52013-07-03 13:37:05 +0200690 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000691}
692
Paul Bakker343a8702011-06-09 14:27:58 +0000693const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000694 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200695 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000696 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000697 des_crypt_cfb128_wrap,
698 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200699 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000700 des_setkey_enc_wrap,
701 des_setkey_dec_wrap,
702 des_ctx_alloc,
703 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000704};
705
Paul Bakker5e0efa72013-09-08 23:04:04 +0200706const cipher_info_t des_ecb_info = {
707 POLARSSL_CIPHER_DES_ECB,
708 POLARSSL_MODE_ECB,
709 POLARSSL_KEY_LENGTH_DES,
710 "DES-ECB",
711 8,
712 0,
713 8,
714 &des_info
715};
716
Paul Bakker343a8702011-06-09 14:27:58 +0000717const cipher_info_t des_cbc_info = {
718 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000719 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000720 POLARSSL_KEY_LENGTH_DES,
721 "DES-CBC",
722 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200723 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000724 8,
725 &des_info
726};
727
728const cipher_base_t des_ede_info = {
729 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200730 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000731 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000732 des_crypt_cfb128_wrap,
733 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200734 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000735 des3_set2key_enc_wrap,
736 des3_set2key_dec_wrap,
737 des3_ctx_alloc,
738 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000739};
740
Paul Bakker5e0efa72013-09-08 23:04:04 +0200741const cipher_info_t des_ede_ecb_info = {
742 POLARSSL_CIPHER_DES_EDE_ECB,
743 POLARSSL_MODE_ECB,
744 POLARSSL_KEY_LENGTH_DES_EDE,
745 "DES-EDE-ECB",
746 8,
747 0,
748 8,
749 &des_ede_info
750};
751
Paul Bakker343a8702011-06-09 14:27:58 +0000752const cipher_info_t des_ede_cbc_info = {
753 POLARSSL_CIPHER_DES_EDE_CBC,
754 POLARSSL_MODE_CBC,
755 POLARSSL_KEY_LENGTH_DES_EDE,
756 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +0200757 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200758 0,
Paul Bakker0e342352013-06-24 19:33:02 +0200759 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000760 &des_ede_info
761};
762
763const cipher_base_t des_ede3_info = {
764 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200765 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000766 des3_crypt_cbc_wrap,
767 des_crypt_cfb128_wrap,
768 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200769 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000770 des3_set3key_enc_wrap,
771 des3_set3key_dec_wrap,
772 des3_ctx_alloc,
773 des_ctx_free
774};
775
Paul Bakker5e0efa72013-09-08 23:04:04 +0200776const cipher_info_t des_ede3_ecb_info = {
777 POLARSSL_CIPHER_DES_EDE3_ECB,
778 POLARSSL_MODE_ECB,
779 POLARSSL_KEY_LENGTH_DES_EDE3,
780 "DES-EDE3-ECB",
781 8,
782 0,
783 8,
784 &des_ede3_info
785};
Paul Bakker8123e9d2011-01-06 15:37:30 +0000786const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000787 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000788 POLARSSL_MODE_CBC,
789 POLARSSL_KEY_LENGTH_DES_EDE3,
790 "DES-EDE3-CBC",
791 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200792 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000793 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000794 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000795};
796#endif
797
Paul Bakker6132d0a2012-07-04 17:10:40 +0000798#if defined(POLARSSL_BLOWFISH_C)
799
Paul Bakker5e0efa72013-09-08 23:04:04 +0200800static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
801 const unsigned char *input, unsigned char *output )
802{
803 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
804}
805
Paul Bakkerfae35f02013-03-13 10:33:51 +0100806static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000807 unsigned char *iv, const unsigned char *input, unsigned char *output )
808{
809 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
810}
811
Paul Bakkerfae35f02013-03-13 10:33:51 +0100812static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000813 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
814{
815#if defined(POLARSSL_CIPHER_MODE_CFB)
816 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
817#else
818 ((void) ctx);
819 ((void) operation);
820 ((void) length);
821 ((void) iv_off);
822 ((void) iv);
823 ((void) input);
824 ((void) output);
825
826 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
827#endif
828}
829
Paul Bakkerfae35f02013-03-13 10:33:51 +0100830static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000831 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
832 const unsigned char *input, unsigned char *output )
833{
834#if defined(POLARSSL_CIPHER_MODE_CTR)
835 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
836 stream_block, input, output );
837#else
838 ((void) ctx);
839 ((void) length);
840 ((void) nc_off);
841 ((void) nonce_counter);
842 ((void) stream_block);
843 ((void) input);
844 ((void) output);
845
846 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
847#endif
848}
849
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200850static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000851{
852 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
853}
854
855static void * blowfish_ctx_alloc( void )
856{
Paul Bakker6e339b52013-07-03 13:37:05 +0200857 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000858}
859
860static void blowfish_ctx_free( void *ctx )
861{
Paul Bakker6e339b52013-07-03 13:37:05 +0200862 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000863}
864
865const cipher_base_t blowfish_info = {
866 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200867 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000868 blowfish_crypt_cbc_wrap,
869 blowfish_crypt_cfb64_wrap,
870 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200871 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200872 blowfish_setkey_wrap,
873 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000874 blowfish_ctx_alloc,
875 blowfish_ctx_free
876};
877
Paul Bakker5e0efa72013-09-08 23:04:04 +0200878const cipher_info_t blowfish_ecb_info = {
879 POLARSSL_CIPHER_BLOWFISH_ECB,
880 POLARSSL_MODE_ECB,
881 128,
882 "BLOWFISH-ECB",
883 8,
884 0,
885 8,
886 &blowfish_info
887};
888
Paul Bakker6132d0a2012-07-04 17:10:40 +0000889const cipher_info_t blowfish_cbc_info = {
890 POLARSSL_CIPHER_BLOWFISH_CBC,
891 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200892 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000893 "BLOWFISH-CBC",
894 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200895 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000896 8,
897 &blowfish_info
898};
899
900#if defined(POLARSSL_CIPHER_MODE_CFB)
901const cipher_info_t blowfish_cfb64_info = {
902 POLARSSL_CIPHER_BLOWFISH_CFB64,
903 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200904 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000905 "BLOWFISH-CFB64",
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};
911#endif /* POLARSSL_CIPHER_MODE_CFB */
912
913#if defined(POLARSSL_CIPHER_MODE_CTR)
914const cipher_info_t blowfish_ctr_info = {
915 POLARSSL_CIPHER_BLOWFISH_CTR,
916 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200917 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000918 "BLOWFISH-CTR",
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_CTR */
925#endif /* POLARSSL_BLOWFISH_C */
926
Paul Bakker68884e32013-01-07 18:20:04 +0100927#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200928static int arc4_crypt_stream_wrap( void *ctx, size_t length,
929 const unsigned char *input,
930 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +0100931{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200932 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +0100933}
934
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200935static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
936 unsigned int key_length )
937{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +0200938 /* we get key_length in bits, arc4 expects it in bytes */
939 if( key_length % 8 != 0)
940 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
941
942 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200943 return( 0 );
944}
945
946static void * arc4_ctx_alloc( void )
947{
948 return polarssl_malloc( sizeof( arc4_context ) );
949}
Paul Bakker68884e32013-01-07 18:20:04 +0100950
951static void arc4_ctx_free( void *ctx )
952{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200953 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +0100954}
955
956const cipher_base_t arc4_base_info = {
957 POLARSSL_CIPHER_ID_ARC4,
958 NULL,
959 NULL,
960 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200961 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200962 arc4_crypt_stream_wrap,
963 arc4_setkey_wrap,
964 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +0100965 arc4_ctx_alloc,
966 arc4_ctx_free
967};
968
969const cipher_info_t arc4_128_info = {
970 POLARSSL_CIPHER_ARC4_128,
971 POLARSSL_MODE_STREAM,
972 128,
973 "ARC4-128",
974 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200975 0,
Paul Bakker68884e32013-01-07 18:20:04 +0100976 1,
977 &arc4_base_info
978};
979#endif /* POLARSSL_ARC4_C */
980
Paul Bakkerfab5c822012-02-06 16:45:10 +0000981#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200982static int null_crypt_stream( void *ctx, size_t length,
983 const unsigned char *input,
984 unsigned char *output )
985{
986 ((void) ctx);
987 memmove( output, input, length );
988 return( 0 );
989}
990
991static int null_setkey( void *ctx, const unsigned char *key,
992 unsigned int key_length )
993{
994 ((void) ctx);
995 ((void) key);
996 ((void) key_length);
997
998 return( 0 );
999}
1000
Paul Bakkerfab5c822012-02-06 16:45:10 +00001001static void * null_ctx_alloc( void )
1002{
1003 return (void *) 1;
1004}
1005
Paul Bakkerfab5c822012-02-06 16:45:10 +00001006static void null_ctx_free( void *ctx )
1007{
1008 ((void) ctx);
1009}
1010
1011const cipher_base_t null_base_info = {
1012 POLARSSL_CIPHER_ID_NULL,
1013 NULL,
1014 NULL,
1015 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001016 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001017 null_crypt_stream,
1018 null_setkey,
1019 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001020 null_ctx_alloc,
1021 null_ctx_free
1022};
1023
1024const cipher_info_t null_cipher_info = {
1025 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001026 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001027 0,
1028 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001029 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001030 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001031 1,
1032 &null_base_info
1033};
1034#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1035
Paul Bakker8123e9d2011-01-06 15:37:30 +00001036#endif