blob: c6f52ff9bb9fb9f54fab2cbdbd2f145a180a30b4 [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{
Manuel Pégourié-Gonnard4fe92002013-09-13 13:45:58 +0200298 gcm_free( ctx );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200299 polarssl_free( ctx );
300}
301
Paul Bakker43aff2a2013-09-09 00:10:27 +0200302static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200303{
Paul Bakker43aff2a2013-09-09 00:10:27 +0200304 return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
305 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200306}
307
308const cipher_base_t gcm_aes_info = {
309 POLARSSL_CIPHER_ID_AES,
310 NULL,
311 NULL,
312 NULL,
313 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200314 NULL,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200315 gcm_aes_setkey_wrap,
316 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200317 gcm_ctx_alloc,
318 gcm_ctx_free,
319};
320
Paul Bakker68884e32013-01-07 18:20:04 +0100321const cipher_info_t aes_128_gcm_info = {
322 POLARSSL_CIPHER_AES_128_GCM,
323 POLARSSL_MODE_GCM,
324 128,
325 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200326 12,
327 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100328 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200329 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100330};
331
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200332const cipher_info_t aes_192_gcm_info = {
333 POLARSSL_CIPHER_AES_192_GCM,
334 POLARSSL_MODE_GCM,
335 192,
336 "AES-192-GCM",
337 12,
338 1,
339 16,
340 &gcm_aes_info
341};
342
Paul Bakker68884e32013-01-07 18:20:04 +0100343const cipher_info_t aes_256_gcm_info = {
344 POLARSSL_CIPHER_AES_256_GCM,
345 POLARSSL_MODE_GCM,
346 256,
347 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200348 12,
349 1,
Paul Bakker68884e32013-01-07 18:20:04 +0100350 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200351 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100352};
353#endif /* POLARSSL_GCM_C */
354
Paul Bakker8123e9d2011-01-06 15:37:30 +0000355#endif
356
357#if defined(POLARSSL_CAMELLIA_C)
358
Paul Bakker5e0efa72013-09-08 23:04:04 +0200359static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
360 const unsigned char *input, unsigned char *output )
361{
362 return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
363}
364
Paul Bakkerfae35f02013-03-13 10:33:51 +0100365static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000366 unsigned char *iv, const unsigned char *input, unsigned char *output )
367{
368 return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
369}
370
Paul Bakkerfae35f02013-03-13 10:33:51 +0100371static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000372 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
373{
374#if defined(POLARSSL_CIPHER_MODE_CFB)
375 return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
376#else
377 ((void) ctx);
378 ((void) operation);
379 ((void) length);
380 ((void) iv_off);
381 ((void) iv);
382 ((void) input);
383 ((void) output);
384
385 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
386#endif
387}
388
Paul Bakkerfae35f02013-03-13 10:33:51 +0100389static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000390 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
391 const unsigned char *input, unsigned char *output )
392{
393#if defined(POLARSSL_CIPHER_MODE_CTR)
394 return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
395 stream_block, input, output );
396#else
397 ((void) ctx);
398 ((void) length);
399 ((void) nc_off);
400 ((void) nonce_counter);
401 ((void) stream_block);
402 ((void) input);
403 ((void) output);
404
405 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
406#endif
407}
408
Paul Bakkerfae35f02013-03-13 10:33:51 +0100409static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000410{
411 return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
412}
413
Paul Bakkerfae35f02013-03-13 10:33:51 +0100414static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000415{
416 return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
417}
418
419static void * camellia_ctx_alloc( void )
420{
Paul Bakker6e339b52013-07-03 13:37:05 +0200421 return polarssl_malloc( sizeof( camellia_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000422}
423
424static void camellia_ctx_free( void *ctx )
425{
Paul Bakker6e339b52013-07-03 13:37:05 +0200426 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000427}
428
Paul Bakker343a8702011-06-09 14:27:58 +0000429const cipher_base_t camellia_info = {
430 POLARSSL_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200431 camellia_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000432 camellia_crypt_cbc_wrap,
433 camellia_crypt_cfb128_wrap,
434 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200435 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000436 camellia_setkey_enc_wrap,
437 camellia_setkey_dec_wrap,
438 camellia_ctx_alloc,
439 camellia_ctx_free
440};
441
Paul Bakker5e0efa72013-09-08 23:04:04 +0200442const cipher_info_t camellia_128_ecb_info = {
443 POLARSSL_CIPHER_CAMELLIA_128_ECB,
444 POLARSSL_MODE_ECB,
445 128,
446 "CAMELLIA-128-ECB",
447 16,
448 0,
449 16,
450 &camellia_info
451};
452
453const cipher_info_t camellia_192_ecb_info = {
454 POLARSSL_CIPHER_CAMELLIA_192_ECB,
455 POLARSSL_MODE_ECB,
456 192,
457 "CAMELLIA-192-ECB",
458 16,
459 0,
460 16,
461 &camellia_info
462};
463
464const cipher_info_t camellia_256_ecb_info = {
465 POLARSSL_CIPHER_CAMELLIA_256_ECB,
466 POLARSSL_MODE_ECB,
467 256,
468 "CAMELLIA-256-ECB",
469 16,
470 0,
471 16,
472 &camellia_info
473};
474
Paul Bakker8123e9d2011-01-06 15:37:30 +0000475const cipher_info_t camellia_128_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000476 POLARSSL_CIPHER_CAMELLIA_128_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000477 POLARSSL_MODE_CBC,
478 128,
479 "CAMELLIA-128-CBC",
480 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200481 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000482 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000483 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000484};
485
486const cipher_info_t camellia_192_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000487 POLARSSL_CIPHER_CAMELLIA_192_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000488 POLARSSL_MODE_CBC,
489 192,
490 "CAMELLIA-192-CBC",
491 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200492 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000493 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000494 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000495};
496
497const cipher_info_t camellia_256_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000498 POLARSSL_CIPHER_CAMELLIA_256_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000499 POLARSSL_MODE_CBC,
500 256,
501 "CAMELLIA-256-CBC",
502 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200503 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000504 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000505 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000506};
Paul Bakker343a8702011-06-09 14:27:58 +0000507
508#if defined(POLARSSL_CIPHER_MODE_CFB)
509const cipher_info_t camellia_128_cfb128_info = {
510 POLARSSL_CIPHER_CAMELLIA_128_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000511 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000512 128,
513 "CAMELLIA-128-CFB128",
514 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200515 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000516 16,
517 &camellia_info
518};
519
520const cipher_info_t camellia_192_cfb128_info = {
521 POLARSSL_CIPHER_CAMELLIA_192_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000522 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000523 192,
524 "CAMELLIA-192-CFB128",
525 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200526 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000527 16,
528 &camellia_info
529};
530
531const cipher_info_t camellia_256_cfb128_info = {
532 POLARSSL_CIPHER_CAMELLIA_256_CFB128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000533 POLARSSL_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000534 256,
535 "CAMELLIA-256-CFB128",
536 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200537 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000538 16,
539 &camellia_info
540};
541#endif /* POLARSSL_CIPHER_MODE_CFB */
542
543#if defined(POLARSSL_CIPHER_MODE_CTR)
544const cipher_info_t camellia_128_ctr_info = {
545 POLARSSL_CIPHER_CAMELLIA_128_CTR,
546 POLARSSL_MODE_CTR,
547 128,
548 "CAMELLIA-128-CTR",
549 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200550 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000551 16,
552 &camellia_info
553};
554
555const cipher_info_t camellia_192_ctr_info = {
556 POLARSSL_CIPHER_CAMELLIA_192_CTR,
557 POLARSSL_MODE_CTR,
558 192,
559 "CAMELLIA-192-CTR",
560 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200561 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000562 16,
563 &camellia_info
564};
565
566const cipher_info_t camellia_256_ctr_info = {
567 POLARSSL_CIPHER_CAMELLIA_256_CTR,
568 POLARSSL_MODE_CTR,
569 256,
570 "CAMELLIA-256-CTR",
571 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200572 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000573 16,
574 &camellia_info
575};
576#endif /* POLARSSL_CIPHER_MODE_CTR */
577
Paul Bakker8123e9d2011-01-06 15:37:30 +0000578#endif
579
580#if defined(POLARSSL_DES_C)
581
Paul Bakker5e0efa72013-09-08 23:04:04 +0200582static int des_crypt_ecb_wrap( void *ctx, operation_t operation,
583 const unsigned char *input, unsigned char *output )
584{
585 ((void) operation);
586 return des_crypt_ecb( (des_context *) ctx, input, output );
587}
588
589static int des3_crypt_ecb_wrap( void *ctx, operation_t operation,
590 const unsigned char *input, unsigned char *output )
591{
592 ((void) operation);
593 return des3_crypt_ecb( (des3_context *) ctx, input, output );
594}
595
Paul Bakkerfae35f02013-03-13 10:33:51 +0100596static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000597 unsigned char *iv, const unsigned char *input, unsigned char *output )
598{
599 return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
600}
601
Paul Bakkerfae35f02013-03-13 10:33:51 +0100602static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000603 unsigned char *iv, const unsigned char *input, unsigned char *output )
604{
605 return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
606}
607
Paul Bakkerfae35f02013-03-13 10:33:51 +0100608static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000609 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
610{
611 ((void) ctx);
612 ((void) operation);
613 ((void) length);
614 ((void) iv_off);
615 ((void) iv);
616 ((void) input);
617 ((void) output);
618
619 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
620}
621
Paul Bakkerfae35f02013-03-13 10:33:51 +0100622static int des_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker343a8702011-06-09 14:27:58 +0000623 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
624 const unsigned char *input, unsigned char *output )
625{
626 ((void) ctx);
627 ((void) length);
628 ((void) nc_off);
629 ((void) nonce_counter);
630 ((void) stream_block);
631 ((void) input);
632 ((void) output);
633
634 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
635}
636
Paul Bakkerfae35f02013-03-13 10:33:51 +0100637static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000638{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000639 ((void) key_length);
640
Paul Bakker8123e9d2011-01-06 15:37:30 +0000641 return des_setkey_dec( (des_context *) ctx, key );
642}
643
Paul Bakkerfae35f02013-03-13 10:33:51 +0100644static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000645{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000646 ((void) key_length);
647
Paul Bakker8123e9d2011-01-06 15:37:30 +0000648 return des_setkey_enc( (des_context *) ctx, key );
649}
650
Paul Bakkerfae35f02013-03-13 10:33:51 +0100651static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000652{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000653 ((void) key_length);
654
Paul Bakker8123e9d2011-01-06 15:37:30 +0000655 return des3_set2key_dec( (des3_context *) ctx, key );
656}
657
Paul Bakkerfae35f02013-03-13 10:33:51 +0100658static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000659{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000660 ((void) key_length);
661
Paul Bakker8123e9d2011-01-06 15:37:30 +0000662 return des3_set2key_enc( (des3_context *) ctx, key );
663}
664
Paul Bakkerfae35f02013-03-13 10:33:51 +0100665static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000666{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000667 ((void) key_length);
668
Paul Bakker8123e9d2011-01-06 15:37:30 +0000669 return des3_set3key_dec( (des3_context *) ctx, key );
670}
671
Paul Bakkerfae35f02013-03-13 10:33:51 +0100672static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000673{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000674 ((void) key_length);
675
Paul Bakker8123e9d2011-01-06 15:37:30 +0000676 return des3_set3key_enc( (des3_context *) ctx, key );
677}
678
679static void * des_ctx_alloc( void )
680{
Paul Bakker6e339b52013-07-03 13:37:05 +0200681 return polarssl_malloc( sizeof( des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000682}
683
684static void * des3_ctx_alloc( void )
685{
Paul Bakker6e339b52013-07-03 13:37:05 +0200686 return polarssl_malloc( sizeof( des3_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000687}
688
689static void des_ctx_free( void *ctx )
690{
Paul Bakker6e339b52013-07-03 13:37:05 +0200691 polarssl_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000692}
693
Paul Bakker343a8702011-06-09 14:27:58 +0000694const cipher_base_t des_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000695 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200696 des_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000697 des_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000698 des_crypt_cfb128_wrap,
699 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200700 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000701 des_setkey_enc_wrap,
702 des_setkey_dec_wrap,
703 des_ctx_alloc,
704 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000705};
706
Paul Bakker5e0efa72013-09-08 23:04:04 +0200707const cipher_info_t des_ecb_info = {
708 POLARSSL_CIPHER_DES_ECB,
709 POLARSSL_MODE_ECB,
710 POLARSSL_KEY_LENGTH_DES,
711 "DES-ECB",
712 8,
713 0,
714 8,
715 &des_info
716};
717
Paul Bakker343a8702011-06-09 14:27:58 +0000718const cipher_info_t des_cbc_info = {
719 POLARSSL_CIPHER_DES_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000720 POLARSSL_MODE_CBC,
Paul Bakker343a8702011-06-09 14:27:58 +0000721 POLARSSL_KEY_LENGTH_DES,
722 "DES-CBC",
723 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200724 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000725 8,
726 &des_info
727};
728
729const cipher_base_t des_ede_info = {
730 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200731 des3_crypt_ecb_wrap,
Paul Bakker23986e52011-04-24 08:57:21 +0000732 des3_crypt_cbc_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000733 des_crypt_cfb128_wrap,
734 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200735 NULL,
Paul Bakker23986e52011-04-24 08:57:21 +0000736 des3_set2key_enc_wrap,
737 des3_set2key_dec_wrap,
738 des3_ctx_alloc,
739 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000740};
741
Paul Bakker5e0efa72013-09-08 23:04:04 +0200742const cipher_info_t des_ede_ecb_info = {
743 POLARSSL_CIPHER_DES_EDE_ECB,
744 POLARSSL_MODE_ECB,
745 POLARSSL_KEY_LENGTH_DES_EDE,
746 "DES-EDE-ECB",
747 8,
748 0,
749 8,
750 &des_ede_info
751};
752
Paul Bakker343a8702011-06-09 14:27:58 +0000753const cipher_info_t des_ede_cbc_info = {
754 POLARSSL_CIPHER_DES_EDE_CBC,
755 POLARSSL_MODE_CBC,
756 POLARSSL_KEY_LENGTH_DES_EDE,
757 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +0200758 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200759 0,
Paul Bakker0e342352013-06-24 19:33:02 +0200760 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000761 &des_ede_info
762};
763
764const cipher_base_t des_ede3_info = {
765 POLARSSL_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200766 des3_crypt_ecb_wrap,
Paul Bakker343a8702011-06-09 14:27:58 +0000767 des3_crypt_cbc_wrap,
768 des_crypt_cfb128_wrap,
769 des_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200770 NULL,
Paul Bakker343a8702011-06-09 14:27:58 +0000771 des3_set3key_enc_wrap,
772 des3_set3key_dec_wrap,
773 des3_ctx_alloc,
774 des_ctx_free
775};
776
Paul Bakker5e0efa72013-09-08 23:04:04 +0200777const cipher_info_t des_ede3_ecb_info = {
778 POLARSSL_CIPHER_DES_EDE3_ECB,
779 POLARSSL_MODE_ECB,
780 POLARSSL_KEY_LENGTH_DES_EDE3,
781 "DES-EDE3-ECB",
782 8,
783 0,
784 8,
785 &des_ede3_info
786};
Paul Bakker8123e9d2011-01-06 15:37:30 +0000787const cipher_info_t des_ede3_cbc_info = {
Paul Bakker23986e52011-04-24 08:57:21 +0000788 POLARSSL_CIPHER_DES_EDE3_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000789 POLARSSL_MODE_CBC,
790 POLARSSL_KEY_LENGTH_DES_EDE3,
791 "DES-EDE3-CBC",
792 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200793 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000794 8,
Paul Bakker343a8702011-06-09 14:27:58 +0000795 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000796};
797#endif
798
Paul Bakker6132d0a2012-07-04 17:10:40 +0000799#if defined(POLARSSL_BLOWFISH_C)
800
Paul Bakker5e0efa72013-09-08 23:04:04 +0200801static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
802 const unsigned char *input, unsigned char *output )
803{
804 return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
805}
806
Paul Bakkerfae35f02013-03-13 10:33:51 +0100807static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000808 unsigned char *iv, const unsigned char *input, unsigned char *output )
809{
810 return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
811}
812
Paul Bakkerfae35f02013-03-13 10:33:51 +0100813static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000814 size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
815{
816#if defined(POLARSSL_CIPHER_MODE_CFB)
817 return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
818#else
819 ((void) ctx);
820 ((void) operation);
821 ((void) length);
822 ((void) iv_off);
823 ((void) iv);
824 ((void) input);
825 ((void) output);
826
827 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
828#endif
829}
830
Paul Bakkerfae35f02013-03-13 10:33:51 +0100831static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000832 size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
833 const unsigned char *input, unsigned char *output )
834{
835#if defined(POLARSSL_CIPHER_MODE_CTR)
836 return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
837 stream_block, input, output );
838#else
839 ((void) ctx);
840 ((void) length);
841 ((void) nc_off);
842 ((void) nonce_counter);
843 ((void) stream_block);
844 ((void) input);
845 ((void) output);
846
847 return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
848#endif
849}
850
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200851static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +0000852{
853 return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
854}
855
856static void * blowfish_ctx_alloc( void )
857{
Paul Bakker6e339b52013-07-03 13:37:05 +0200858 return polarssl_malloc( sizeof( blowfish_context ) );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000859}
860
861static void blowfish_ctx_free( void *ctx )
862{
Paul Bakker6e339b52013-07-03 13:37:05 +0200863 polarssl_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +0000864}
865
866const cipher_base_t blowfish_info = {
867 POLARSSL_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200868 blowfish_crypt_ecb_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000869 blowfish_crypt_cbc_wrap,
870 blowfish_crypt_cfb64_wrap,
871 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200872 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200873 blowfish_setkey_wrap,
874 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000875 blowfish_ctx_alloc,
876 blowfish_ctx_free
877};
878
Paul Bakker5e0efa72013-09-08 23:04:04 +0200879const cipher_info_t blowfish_ecb_info = {
880 POLARSSL_CIPHER_BLOWFISH_ECB,
881 POLARSSL_MODE_ECB,
882 128,
883 "BLOWFISH-ECB",
884 8,
885 0,
886 8,
887 &blowfish_info
888};
889
Paul Bakker6132d0a2012-07-04 17:10:40 +0000890const cipher_info_t blowfish_cbc_info = {
891 POLARSSL_CIPHER_BLOWFISH_CBC,
892 POLARSSL_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200893 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000894 "BLOWFISH-CBC",
895 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200896 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000897 8,
898 &blowfish_info
899};
900
901#if defined(POLARSSL_CIPHER_MODE_CFB)
902const cipher_info_t blowfish_cfb64_info = {
903 POLARSSL_CIPHER_BLOWFISH_CFB64,
904 POLARSSL_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200905 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000906 "BLOWFISH-CFB64",
907 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200908 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000909 8,
910 &blowfish_info
911};
912#endif /* POLARSSL_CIPHER_MODE_CFB */
913
914#if defined(POLARSSL_CIPHER_MODE_CTR)
915const cipher_info_t blowfish_ctr_info = {
916 POLARSSL_CIPHER_BLOWFISH_CTR,
917 POLARSSL_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +0200918 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000919 "BLOWFISH-CTR",
920 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200921 0,
Paul Bakker6132d0a2012-07-04 17:10:40 +0000922 8,
923 &blowfish_info
924};
925#endif /* POLARSSL_CIPHER_MODE_CTR */
926#endif /* POLARSSL_BLOWFISH_C */
927
Paul Bakker68884e32013-01-07 18:20:04 +0100928#if defined(POLARSSL_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200929static int arc4_crypt_stream_wrap( void *ctx, size_t length,
930 const unsigned char *input,
931 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +0100932{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200933 return( arc4_crypt( (arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +0100934}
935
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200936static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
937 unsigned int key_length )
938{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +0200939 /* we get key_length in bits, arc4 expects it in bytes */
940 if( key_length % 8 != 0)
941 return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
942
943 arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200944 return( 0 );
945}
946
947static void * arc4_ctx_alloc( void )
948{
949 return polarssl_malloc( sizeof( arc4_context ) );
950}
Paul Bakker68884e32013-01-07 18:20:04 +0100951
952static void arc4_ctx_free( void *ctx )
953{
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200954 polarssl_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +0100955}
956
957const cipher_base_t arc4_base_info = {
958 POLARSSL_CIPHER_ID_ARC4,
959 NULL,
960 NULL,
961 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200962 NULL,
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200963 arc4_crypt_stream_wrap,
964 arc4_setkey_wrap,
965 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +0100966 arc4_ctx_alloc,
967 arc4_ctx_free
968};
969
970const cipher_info_t arc4_128_info = {
971 POLARSSL_CIPHER_ARC4_128,
972 POLARSSL_MODE_STREAM,
973 128,
974 "ARC4-128",
975 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200976 0,
Paul Bakker68884e32013-01-07 18:20:04 +0100977 1,
978 &arc4_base_info
979};
980#endif /* POLARSSL_ARC4_C */
981
Paul Bakkerfab5c822012-02-06 16:45:10 +0000982#if defined(POLARSSL_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +0200983static int null_crypt_stream( void *ctx, size_t length,
984 const unsigned char *input,
985 unsigned char *output )
986{
987 ((void) ctx);
988 memmove( output, input, length );
989 return( 0 );
990}
991
992static int null_setkey( void *ctx, const unsigned char *key,
993 unsigned int key_length )
994{
995 ((void) ctx);
996 ((void) key);
997 ((void) key_length);
998
999 return( 0 );
1000}
1001
Paul Bakkerfab5c822012-02-06 16:45:10 +00001002static void * null_ctx_alloc( void )
1003{
1004 return (void *) 1;
1005}
1006
Paul Bakkerfab5c822012-02-06 16:45:10 +00001007static void null_ctx_free( void *ctx )
1008{
1009 ((void) ctx);
1010}
1011
1012const cipher_base_t null_base_info = {
1013 POLARSSL_CIPHER_ID_NULL,
1014 NULL,
1015 NULL,
1016 NULL,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001017 NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001018 null_crypt_stream,
1019 null_setkey,
1020 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001021 null_ctx_alloc,
1022 null_ctx_free
1023};
1024
1025const cipher_info_t null_cipher_info = {
1026 POLARSSL_CIPHER_NULL,
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001027 POLARSSL_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001028 0,
1029 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001030 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001031 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001032 1,
1033 &null_base_info
1034};
1035#endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */
1036
Paul Bakker8123e9d2011-01-06 15:37:30 +00001037#endif