blob: 253fcdce18a320eeef2070c61c51a4e3ec859c38 [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
301static int gcm_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
302{
303 return gcm_init( (gcm_context *) ctx, key, key_length );
304}
305
306const cipher_base_t gcm_aes_info = {
307 POLARSSL_CIPHER_ID_AES,
308 NULL,
309 NULL,
310 NULL,
311 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200312 NULL,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200313 gcm_setkey_wrap,
314 gcm_setkey_wrap,
315 gcm_ctx_alloc,
316 gcm_ctx_free,
317};
318
Paul Bakker68884e32013-01-07 18:20:04 +0100319const cipher_info_t aes_128_gcm_info = {
320 POLARSSL_CIPHER_AES_128_GCM,
321 POLARSSL_MODE_GCM,
322 128,
323 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200324 12,
325 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100326 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200327 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100328};
329
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200330const cipher_info_t aes_192_gcm_info = {
331 POLARSSL_CIPHER_AES_192_GCM,
332 POLARSSL_MODE_GCM,
333 192,
334 "AES-192-GCM",
335 12,
336 1,
337 16,
338 &gcm_aes_info
339};
340
Paul Bakker68884e32013-01-07 18:20:04 +0100341const cipher_info_t aes_256_gcm_info = {
342 POLARSSL_CIPHER_AES_256_GCM,
343 POLARSSL_MODE_GCM,
344 256,
345 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200346 12,
347 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100348 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200349 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100350};
351#endif /* POLARSSL_GCM_C */
352
Paul Bakker8123e9d2011-01-06 15:37:30 +0000353#endif
354
355#if defined(POLARSSL_CAMELLIA_C)
356
Paul Bakker5e0efa72013-09-08 23:04:04 +0200357static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
358 const unsigned char *input, unsigned char *output )
359{
360 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
361}
362
Paul Bakkerfae35f02013-03-13 10:33:51 +0100363static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000364 unsigned char *iv, const unsigned char *input, unsigned char *output )
365{
366 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
367}
368
Paul Bakkerfae35f02013-03-13 10:33:51 +0100369static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000370 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
371{
372#if defined(POLARSSL_CIPHER_MODE_CFB)
373 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
374#else
375 ((void) ctx);
376 ((void) operation);
377 ((void) length);
378 ((void) iv_off);
379 ((void) iv);
380 ((void) input);
381 ((void) output);
382
383 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
384#endif
385}
386
Paul Bakkerfae35f02013-03-13 10:33:51 +0100387static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000388 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
389 const unsigned char *input, unsigned char *output )
390{
391#if defined(POLARSSL_CIPHER_MODE_CTR)
392 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
393 stream_block, input, output );
394#else
395 ((void) ctx);
396 ((void) length);
397 ((void) nc_off);
398 ((void) nonce_counter);
399 ((void) stream_block);
400 ((void) input);
401 ((void) output);
402
403 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
404#endif
405}
406
Paul Bakkerfae35f02013-03-13 10:33:51 +0100407static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000408{
409 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
410}
411
Paul Bakkerfae35f02013-03-13 10:33:51 +0100412static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000413{
414 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
415}
416
417static void * camellia_ctx_alloc( void )
418{
Paul Bakker6e339b52013-07-03 13:37:05 +0200419 return polarssl_malloc( sizeof( camellia_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000420}
421
422static void camellia_ctx_free( void *ctx )
423{
Paul Bakker6e339b52013-07-03 13:37:05 +0200424 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000425}
426
Paul Bakker343a8702011-06-09 14:27:58 +0000427const cipher_base_t camellia_info = {
428 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200429 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000430 camellia_crypt_cbc_wrap,
431 camellia_crypt_cfb128_wrap,
432 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200433 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000434 camellia_setkey_enc_wrap,
435 camellia_setkey_dec_wrap,
436 camellia_ctx_alloc,
437 camellia_ctx_free
438};
439
Paul Bakker5e0efa72013-09-08 23:04:04 +0200440const cipher_info_t camellia_128_ecb_info = {
441 POLARSSL_CIPHER_CAMELLIA_128_ECB,
442 POLARSSL_MODE_ECB,
443 128,
444 "CAMELLIA-128-ECB",
445 16,
446 0,
447 16,
448 &camellia_info
449};
450
451const cipher_info_t camellia_192_ecb_info = {
452 POLARSSL_CIPHER_CAMELLIA_192_ECB,
453 POLARSSL_MODE_ECB,
454 192,
455 "CAMELLIA-192-ECB",
456 16,
457 0,
458 16,
459 &camellia_info
460};
461
462const cipher_info_t camellia_256_ecb_info = {
463 POLARSSL_CIPHER_CAMELLIA_256_ECB,
464 POLARSSL_MODE_ECB,
465 256,
466 "CAMELLIA-256-ECB",
467 16,
468 0,
469 16,
470 &camellia_info
471};
472
Paul Bakker8123e9d2011-01-06 15:37:30 +0000473const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000474 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000475 POLARSSL_MODE_CBC,
476 128,
477 "CAMELLIA-128-CBC",
478 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200479 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000480 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000481 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000482};
483
484const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000485 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000486 POLARSSL_MODE_CBC,
487 192,
488 "CAMELLIA-192-CBC",
489 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200490 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000491 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000492 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000493};
494
495const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000496 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000497 POLARSSL_MODE_CBC,
498 256,
499 "CAMELLIA-256-CBC",
500 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200501 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000502 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000503 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000504};
Paul Bakker343a8702011-06-09 14:27:58 +0000505
506#if defined(POLARSSL_CIPHER_MODE_CFB)
507const cipher_info_t camellia_128_cfb128_info = {
508 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000509 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000510 128,
511 "CAMELLIA-128-CFB128",
512 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200513 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000514 16,
515 &camellia_info
516};
517
518const cipher_info_t camellia_192_cfb128_info = {
519 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000520 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000521 192,
522 "CAMELLIA-192-CFB128",
523 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200524 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000525 16,
526 &camellia_info
527};
528
529const cipher_info_t camellia_256_cfb128_info = {
530 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000531 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000532 256,
533 "CAMELLIA-256-CFB128",
534 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200535 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000536 16,
537 &camellia_info
538};
539#endif /* POLARSSL_CIPHER_MODE_CFB */
540
541#if defined(POLARSSL_CIPHER_MODE_CTR)
542const cipher_info_t camellia_128_ctr_info = {
543 POLARSSL_CIPHER_CAMELLIA_128_CTR,
544 POLARSSL_MODE_CTR,
545 128,
546 "CAMELLIA-128-CTR",
547 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200548 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000549 16,
550 &camellia_info
551};
552
553const cipher_info_t camellia_192_ctr_info = {
554 POLARSSL_CIPHER_CAMELLIA_192_CTR,
555 POLARSSL_MODE_CTR,
556 192,
557 "CAMELLIA-192-CTR",
558 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200559 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000560 16,
561 &camellia_info
562};
563
564const cipher_info_t camellia_256_ctr_info = {
565 POLARSSL_CIPHER_CAMELLIA_256_CTR,
566 POLARSSL_MODE_CTR,
567 256,
568 "CAMELLIA-256-CTR",
569 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200570 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000571 16,
572 &camellia_info
573};
574#endif /* POLARSSL_CIPHER_MODE_CTR */
575
Paul Bakker8123e9d2011-01-06 15:37:30 +0000576#endif
577
578#if defined(POLARSSL_DES_C)
579
Paul Bakker5e0efa72013-09-08 23:04:04 +0200580static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
581 const unsigned char *input, unsigned char *output )
582{
583 ((void) operation);
584 return des_crypt_ecb( (des_context *) ctx, input, output );
585}
586
587static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
588 const unsigned char *input, unsigned char *output )
589{
590 ((void) operation);
591 return des3_crypt_ecb( (des3_context *) ctx, input, output );
592}
593
Paul Bakkerfae35f02013-03-13 10:33:51 +0100594static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000595 unsigned char *iv, const unsigned char *input, unsigned char *output )
596{
597 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
598}
599
Paul Bakkerfae35f02013-03-13 10:33:51 +0100600static int des3_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 des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
604}
605
Paul Bakkerfae35f02013-03-13 10:33:51 +0100606static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000607 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
608{
609 ((void) ctx);
610 ((void) operation);
611 ((void) length);
612 ((void) iv_off);
613 ((void) iv);
614 ((void) input);
615 ((void) output);
616
617 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
618}
619
Paul Bakkerfae35f02013-03-13 10:33:51 +0100620static int des_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000621 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
622 const unsigned char *input, unsigned char *output )
623{
624 ((void) ctx);
625 ((void) length);
626 ((void) nc_off);
627 ((void) nonce_counter);
628 ((void) stream_block);
629 ((void) input);
630 ((void) output);
631
632 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
633}
634
Paul Bakkerfae35f02013-03-13 10:33:51 +0100635static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000636{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000637 ((void) key_length);
638
Paul Bakker8123e9d2011-01-06 15:37:30 +0000639 return des_setkey_dec( (des_context *) ctx, key );
640}
641
Paul Bakkerfae35f02013-03-13 10:33:51 +0100642static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000643{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000644 ((void) key_length);
645
Paul Bakker8123e9d2011-01-06 15:37:30 +0000646 return des_setkey_enc( (des_context *) ctx, key );
647}
648
Paul Bakkerfae35f02013-03-13 10:33:51 +0100649static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000650{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000651 ((void) key_length);
652
Paul Bakker8123e9d2011-01-06 15:37:30 +0000653 return des3_set2key_dec( (des3_context *) ctx, key );
654}
655
Paul Bakkerfae35f02013-03-13 10:33:51 +0100656static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000657{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000658 ((void) key_length);
659
Paul Bakker8123e9d2011-01-06 15:37:30 +0000660 return des3_set2key_enc( (des3_context *) ctx, key );
661}
662
Paul Bakkerfae35f02013-03-13 10:33:51 +0100663static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000664{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000665 ((void) key_length);
666
Paul Bakker8123e9d2011-01-06 15:37:30 +0000667 return des3_set3key_dec( (des3_context *) ctx, key );
668}
669
Paul Bakkerfae35f02013-03-13 10:33:51 +0100670static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000671{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000672 ((void) key_length);
673
Paul Bakker8123e9d2011-01-06 15:37:30 +0000674 return des3_set3key_enc( (des3_context *) ctx, key );
675}
676
677static void * des_ctx_alloc( void )
678{
Paul Bakker6e339b52013-07-03 13:37:05 +0200679 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000680}
681
682static void * des3_ctx_alloc( void )
683{
Paul Bakker6e339b52013-07-03 13:37:05 +0200684 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000685}
686
687static void des_ctx_free( void *ctx )
688{
Paul Bakker6e339b52013-07-03 13:37:05 +0200689 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000690}
691
Paul Bakker343a8702011-06-09 14:27:58 +0000692const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000693 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200694 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000695 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000696 des_crypt_cfb128_wrap,
697 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200698 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000699 des_setkey_enc_wrap,
700 des_setkey_dec_wrap,
701 des_ctx_alloc,
702 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000703};
704
Paul Bakker5e0efa72013-09-08 23:04:04 +0200705const cipher_info_t des_ecb_info = {
706 POLARSSL_CIPHER_DES_ECB,
707 POLARSSL_MODE_ECB,
708 POLARSSL_KEY_LENGTH_DES,
709 "DES-ECB",
710 8,
711 0,
712 8,
713 &des_info
714};
715
Paul Bakker343a8702011-06-09 14:27:58 +0000716const cipher_info_t des_cbc_info = {
717 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000718 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000719 POLARSSL_KEY_LENGTH_DES,
720 "DES-CBC",
721 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200722 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000723 8,
724 &des_info
725};
726
727const cipher_base_t des_ede_info = {
728 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200729 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000730 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000731 des_crypt_cfb128_wrap,
732 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200733 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000734 des3_set2key_enc_wrap,
735 des3_set2key_dec_wrap,
736 des3_ctx_alloc,
737 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000738};
739
Paul Bakker5e0efa72013-09-08 23:04:04 +0200740const cipher_info_t des_ede_ecb_info = {
741 POLARSSL_CIPHER_DES_EDE_ECB,
742 POLARSSL_MODE_ECB,
743 POLARSSL_KEY_LENGTH_DES_EDE,
744 "DES-EDE-ECB",
745 8,
746 0,
747 8,
748 &des_ede_info
749};
750
Paul Bakker343a8702011-06-09 14:27:58 +0000751const cipher_info_t des_ede_cbc_info = {
752 POLARSSL_CIPHER_DES_EDE_CBC,
753 POLARSSL_MODE_CBC,
754 POLARSSL_KEY_LENGTH_DES_EDE,
755 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +0200756 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200757 0,
Paul Bakker0e342352013-06-24 19:33:02 +0200758 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000759 &des_ede_info
760};
761
762const cipher_base_t des_ede3_info = {
763 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200764 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000765 des3_crypt_cbc_wrap,
766 des_crypt_cfb128_wrap,
767 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200768 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000769 des3_set3key_enc_wrap,
770 des3_set3key_dec_wrap,
771 des3_ctx_alloc,
772 des_ctx_free
773};
774
Paul Bakker5e0efa72013-09-08 23:04:04 +0200775const cipher_info_t des_ede3_ecb_info = {
776 POLARSSL_CIPHER_DES_EDE3_ECB,
777 POLARSSL_MODE_ECB,
778 POLARSSL_KEY_LENGTH_DES_EDE3,
779 "DES-EDE3-ECB",
780 8,
781 0,
782 8,
783 &des_ede3_info
784};
Paul Bakker8123e9d2011-01-06 15:37:30 +0000785const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000786 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000787 POLARSSL_MODE_CBC,
788 POLARSSL_KEY_LENGTH_DES_EDE3,
789 "DES-EDE3-CBC",
790 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200791 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000792 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000793 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000794};
795#endif
796
Paul Bakker6132d0a2012-07-04 17:10:40 +0000797#if defined(POLARSSL_BLOWFISH_C)
798
Paul Bakker5e0efa72013-09-08 23:04:04 +0200799static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
800 const unsigned char *input, unsigned char *output )
801{
802 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
803}
804
Paul Bakkerfae35f02013-03-13 10:33:51 +0100805static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000806 unsigned char *iv, const unsigned char *input, unsigned char *output )
807{
808 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
809}
810
Paul Bakkerfae35f02013-03-13 10:33:51 +0100811static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000812 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
813{
814#if defined(POLARSSL_CIPHER_MODE_CFB)
815 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
816#else
817 ((void) ctx);
818 ((void) operation);
819 ((void) length);
820 ((void) iv_off);
821 ((void) iv);
822 ((void) input);
823 ((void) output);
824
825 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
826#endif
827}
828
Paul Bakkerfae35f02013-03-13 10:33:51 +0100829static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000830 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
831 const unsigned char *input, unsigned char *output )
832{
833#if defined(POLARSSL_CIPHER_MODE_CTR)
834 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
835 stream_block, input, output );
836#else
837 ((void) ctx);
838 ((void) length);
839 ((void) nc_off);
840 ((void) nonce_counter);
841 ((void) stream_block);
842 ((void) input);
843 ((void) output);
844
845 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
846#endif
847}
848
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200849static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000850{
851 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
852}
853
854static void * blowfish_ctx_alloc( void )
855{
Paul Bakker6e339b52013-07-03 13:37:05 +0200856 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000857}
858
859static void blowfish_ctx_free( void *ctx )
860{
Paul Bakker6e339b52013-07-03 13:37:05 +0200861 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000862}
863
864const cipher_base_t blowfish_info = {
865 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200866 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000867 blowfish_crypt_cbc_wrap,
868 blowfish_crypt_cfb64_wrap,
869 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200870 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200871 blowfish_setkey_wrap,
872 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000873 blowfish_ctx_alloc,
874 blowfish_ctx_free
875};
876
Paul Bakker5e0efa72013-09-08 23:04:04 +0200877const cipher_info_t blowfish_ecb_info = {
878 POLARSSL_CIPHER_BLOWFISH_ECB,
879 POLARSSL_MODE_ECB,
880 128,
881 "BLOWFISH-ECB",
882 8,
883 0,
884 8,
885 &blowfish_info
886};
887
Paul Bakker6132d0a2012-07-04 17:10:40 +0000888const cipher_info_t blowfish_cbc_info = {
889 POLARSSL_CIPHER_BLOWFISH_CBC,
890 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200891 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000892 "BLOWFISH-CBC",
893 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200894 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000895 8,
896 &blowfish_info
897};
898
899#if defined(POLARSSL_CIPHER_MODE_CFB)
900const cipher_info_t blowfish_cfb64_info = {
901 POLARSSL_CIPHER_BLOWFISH_CFB64,
902 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200903 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000904 "BLOWFISH-CFB64",
905 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200906 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000907 8,
908 &blowfish_info
909};
910#endif /* POLARSSL_CIPHER_MODE_CFB */
911
912#if defined(POLARSSL_CIPHER_MODE_CTR)
913const cipher_info_t blowfish_ctr_info = {
914 POLARSSL_CIPHER_BLOWFISH_CTR,
915 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200916 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000917 "BLOWFISH-CTR",
918 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200919 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000920 8,
921 &blowfish_info
922};
923#endif /* POLARSSL_CIPHER_MODE_CTR */
924#endif /* POLARSSL_BLOWFISH_C */
925
Paul Bakker68884e32013-01-07 18:20:04 +0100926#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200927static int arc4_crypt_stream_wrap( void *ctx, size_t length,
928 const unsigned char *input,
929 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +0100930{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200931 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +0100932}
933
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200934static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
935 unsigned int key_length )
936{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +0200937 /* we get key_length in bits, arc4 expects it in bytes */
938 if( key_length % 8 != 0)
939 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
940
941 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200942 return( 0 );
943}
944
945static void * arc4_ctx_alloc( void )
946{
947 return polarssl_malloc( sizeof( arc4_context ) );
948}
Paul Bakker68884e32013-01-07 18:20:04 +0100949
950static void arc4_ctx_free( void *ctx )
951{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200952 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +0100953}
954
955const cipher_base_t arc4_base_info = {
956 POLARSSL_CIPHER_ID_ARC4,
957 NULL,
958 NULL,
959 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200960 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200961 arc4_crypt_stream_wrap,
962 arc4_setkey_wrap,
963 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +0100964 arc4_ctx_alloc,
965 arc4_ctx_free
966};
967
968const cipher_info_t arc4_128_info = {
969 POLARSSL_CIPHER_ARC4_128,
970 POLARSSL_MODE_STREAM,
971 128,
972 "ARC4-128",
973 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200974 0,
Paul Bakker68884e32013-01-07 18:20:04 +0100975 1,
976 &arc4_base_info
977};
978#endif /* POLARSSL_ARC4_C */
979
Paul Bakkerfab5c822012-02-06 16:45:10 +0000980#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200981static int null_crypt_stream( void *ctx, size_t length,
982 const unsigned char *input,
983 unsigned char *output )
984{
985 ((void) ctx);
986 memmove( output, input, length );
987 return( 0 );
988}
989
990static int null_setkey( void *ctx, const unsigned char *key,
991 unsigned int key_length )
992{
993 ((void) ctx);
994 ((void) key);
995 ((void) key_length);
996
997 return( 0 );
998}
999
Paul Bakkerfab5c822012-02-06 16:45:10 +00001000static void * null_ctx_alloc( void )
1001{
1002 return (void *) 1;
1003}
1004
Paul Bakkerfab5c822012-02-06 16:45:10 +00001005static void null_ctx_free( void *ctx )
1006{
1007 ((void) ctx);
1008}
1009
1010const cipher_base_t null_base_info = {
1011 POLARSSL_CIPHER_ID_NULL,
1012 NULL,
1013 NULL,
1014 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001015 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001016 null_crypt_stream,
1017 null_setkey,
1018 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001019 null_ctx_alloc,
1020 null_ctx_free
1021};
1022
1023const cipher_info_t null_cipher_info = {
1024 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001025 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001026 0,
1027 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001028 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001029 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001030 1,
1031 &null_base_info
1032};
1033#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1034
Paul Bakker8123e9d2011-01-06 15:37:30 +00001035#endif