blob: 59d77df45c7a6a1073182e45aad461712b4db287 [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief Generic cipher wrapper for mbed TLS
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00008 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakker8123e9d2011-01-06 15:37:30 +00009 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000010 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000011 *
Paul Bakker8123e9d2011-01-06 15:37:30 +000012 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000028#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000032
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000034
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020035#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000036
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000038#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000039#endif
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000042#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020043#endif
44
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000046#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000047#endif
48
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000050#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000051#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000054#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000055#endif
56
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000058#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020059#endif
60
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000062#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020063#endif
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000066#include <string.h>
67#endif
68
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020071#else
Rich Evans00ab4702015-02-06 13:43:58 +000072#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020073#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020074#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020075#endif
76
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020078/* shared by all GCM ciphers */
79static void *gcm_ctx_alloc( void )
80{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020081 return mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020082}
83
84static void gcm_ctx_free( void *ctx )
85{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086 mbedtls_gcm_free( ctx );
87 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020088}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020090
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020092/* shared by all CCM ciphers */
93static void *ccm_ctx_alloc( void )
94{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020095 return mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020096}
97
98static void ccm_ctx_free( void *ctx )
99{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100 mbedtls_ccm_free( ctx );
101 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200102}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200104
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200108 const unsigned char *input, unsigned char *output )
109{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200111}
112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113#if defined(MBEDTLS_CIPHER_MODE_CBC)
114static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000115 unsigned char *iv, const unsigned char *input, unsigned char *output )
116{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200118 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000119}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000121
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122#if defined(MBEDTLS_CIPHER_MODE_CFB)
123static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200124 size_t length, size_t *iv_off, unsigned char *iv,
125 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000126{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200128 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000129}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200133static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
134 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000135 const unsigned char *input, unsigned char *output )
136{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000138 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000139}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000141
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200142static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
143 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000144{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_length );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000146}
147
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200148static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
149 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000150{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_length );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000152}
153
154static void * aes_ctx_alloc( void )
155{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200156 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200157
158 if( aes == NULL )
159 return( NULL );
160
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200162
163 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000164}
165
166static void aes_ctx_free( void *ctx )
167{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
169 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000170}
171
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200172static const mbedtls_cipher_base_t aes_info = {
173 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200174 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000176 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100177#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200178#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000179 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100180#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000182 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100183#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200184#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200185 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100186#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000187 aes_setkey_enc_wrap,
188 aes_setkey_dec_wrap,
189 aes_ctx_alloc,
190 aes_ctx_free
191};
192
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193static const mbedtls_cipher_info_t aes_128_ecb_info = {
194 MBEDTLS_CIPHER_AES_128_ECB,
195 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200196 128,
197 "AES-128-ECB",
198 16,
199 0,
200 16,
201 &aes_info
202};
203
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204static const mbedtls_cipher_info_t aes_192_ecb_info = {
205 MBEDTLS_CIPHER_AES_192_ECB,
206 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200207 192,
208 "AES-192-ECB",
209 16,
210 0,
211 16,
212 &aes_info
213};
214
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200215static const mbedtls_cipher_info_t aes_256_ecb_info = {
216 MBEDTLS_CIPHER_AES_256_ECB,
217 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200218 256,
219 "AES-256-ECB",
220 16,
221 0,
222 16,
223 &aes_info
224};
225
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226#if defined(MBEDTLS_CIPHER_MODE_CBC)
227static const mbedtls_cipher_info_t aes_128_cbc_info = {
228 MBEDTLS_CIPHER_AES_128_CBC,
229 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000230 128,
231 "AES-128-CBC",
232 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200233 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000234 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000235 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000236};
237
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238static const mbedtls_cipher_info_t aes_192_cbc_info = {
239 MBEDTLS_CIPHER_AES_192_CBC,
240 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000241 192,
242 "AES-192-CBC",
243 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200244 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000245 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000246 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000247};
248
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249static const mbedtls_cipher_info_t aes_256_cbc_info = {
250 MBEDTLS_CIPHER_AES_256_CBC,
251 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000252 256,
253 "AES-256-CBC",
254 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200255 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000256 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000257 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000258};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000260
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200261#if defined(MBEDTLS_CIPHER_MODE_CFB)
262static const mbedtls_cipher_info_t aes_128_cfb128_info = {
263 MBEDTLS_CIPHER_AES_128_CFB128,
264 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000265 128,
266 "AES-128-CFB128",
267 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200268 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000269 16,
270 &aes_info
271};
272
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200273static const mbedtls_cipher_info_t aes_192_cfb128_info = {
274 MBEDTLS_CIPHER_AES_192_CFB128,
275 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000276 192,
277 "AES-192-CFB128",
278 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200279 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000280 16,
281 &aes_info
282};
283
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284static const mbedtls_cipher_info_t aes_256_cfb128_info = {
285 MBEDTLS_CIPHER_AES_256_CFB128,
286 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000287 256,
288 "AES-256-CFB128",
289 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200290 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000291 16,
292 &aes_info
293};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000295
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200296#if defined(MBEDTLS_CIPHER_MODE_CTR)
297static const mbedtls_cipher_info_t aes_128_ctr_info = {
298 MBEDTLS_CIPHER_AES_128_CTR,
299 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000300 128,
301 "AES-128-CTR",
302 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200303 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000304 16,
305 &aes_info
306};
307
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200308static const mbedtls_cipher_info_t aes_192_ctr_info = {
309 MBEDTLS_CIPHER_AES_192_CTR,
310 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000311 192,
312 "AES-192-CTR",
313 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200314 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000315 16,
316 &aes_info
317};
318
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319static const mbedtls_cipher_info_t aes_256_ctr_info = {
320 MBEDTLS_CIPHER_AES_256_CTR,
321 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000322 256,
323 "AES-256-CTR",
324 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200325 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000326 16,
327 &aes_info
328};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000330
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200331#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200332static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
333 unsigned int key_length )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200334{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200335 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Paul Bakker43aff2a2013-09-09 00:10:27 +0200336 key, key_length );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200337}
338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339static const mbedtls_cipher_base_t gcm_aes_info = {
340 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200341 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200343 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100344#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200346 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100347#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200348#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200349 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100350#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200352 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100353#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200354 gcm_aes_setkey_wrap,
355 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200356 gcm_ctx_alloc,
357 gcm_ctx_free,
358};
359
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200360static const mbedtls_cipher_info_t aes_128_gcm_info = {
361 MBEDTLS_CIPHER_AES_128_GCM,
362 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100363 128,
364 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200365 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200366 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100367 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200368 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100369};
370
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200371static const mbedtls_cipher_info_t aes_192_gcm_info = {
372 MBEDTLS_CIPHER_AES_192_GCM,
373 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200374 192,
375 "AES-192-GCM",
376 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200377 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200378 16,
379 &gcm_aes_info
380};
381
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200382static const mbedtls_cipher_info_t aes_256_gcm_info = {
383 MBEDTLS_CIPHER_AES_256_GCM,
384 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100385 256,
386 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200387 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200388 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100389 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200390 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100391};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200392#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100393
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200394#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200395static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
396 unsigned int key_length )
397{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200398 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200399 key, key_length );
400}
401
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402static const mbedtls_cipher_base_t ccm_aes_info = {
403 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200404 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200406 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100407#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200408#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200409 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100410#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200411#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200412 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100413#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200414#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200415 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100416#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200417 ccm_aes_setkey_wrap,
418 ccm_aes_setkey_wrap,
419 ccm_ctx_alloc,
420 ccm_ctx_free,
421};
422
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200423static const mbedtls_cipher_info_t aes_128_ccm_info = {
424 MBEDTLS_CIPHER_AES_128_CCM,
425 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200426 128,
427 "AES-128-CCM",
428 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200429 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200430 16,
431 &ccm_aes_info
432};
433
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200434static const mbedtls_cipher_info_t aes_192_ccm_info = {
435 MBEDTLS_CIPHER_AES_192_CCM,
436 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200437 192,
438 "AES-192-CCM",
439 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200440 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200441 16,
442 &ccm_aes_info
443};
444
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200445static const mbedtls_cipher_info_t aes_256_ccm_info = {
446 MBEDTLS_CIPHER_AES_256_CCM,
447 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200448 256,
449 "AES-256-CCM",
450 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200451 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200452 16,
453 &ccm_aes_info
454};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200455#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200456
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000458
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200459#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000460
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200461static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200462 const unsigned char *input, unsigned char *output )
463{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200464 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200465 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200466}
467
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468#if defined(MBEDTLS_CIPHER_MODE_CBC)
469static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200470 size_t length, unsigned char *iv,
471 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000472{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200473 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200474 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000475}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000477
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200478#if defined(MBEDTLS_CIPHER_MODE_CFB)
479static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200480 size_t length, size_t *iv_off, unsigned char *iv,
481 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000482{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200483 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200484 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000485}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200486#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000487
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200488#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200489static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
490 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000491 const unsigned char *input, unsigned char *output )
492{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200493 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200494 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000495}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200496#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000497
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200498static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
499 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000500{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200501 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_length );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000502}
503
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200504static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
505 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000506{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200507 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_length );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000508}
509
510static void * camellia_ctx_alloc( void )
511{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200512 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200513 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200514
515 if( ctx == NULL )
516 return( NULL );
517
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200518 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200519
520 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000521}
522
523static void camellia_ctx_free( void *ctx )
524{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200525 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
526 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000527}
528
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200529static const mbedtls_cipher_base_t camellia_info = {
530 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200531 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000533 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100534#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200535#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000536 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100537#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200538#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000539 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100540#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200541#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200542 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100543#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000544 camellia_setkey_enc_wrap,
545 camellia_setkey_dec_wrap,
546 camellia_ctx_alloc,
547 camellia_ctx_free
548};
549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200550static const mbedtls_cipher_info_t camellia_128_ecb_info = {
551 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
552 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200553 128,
554 "CAMELLIA-128-ECB",
555 16,
556 0,
557 16,
558 &camellia_info
559};
560
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561static const mbedtls_cipher_info_t camellia_192_ecb_info = {
562 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
563 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200564 192,
565 "CAMELLIA-192-ECB",
566 16,
567 0,
568 16,
569 &camellia_info
570};
571
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200572static const mbedtls_cipher_info_t camellia_256_ecb_info = {
573 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
574 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200575 256,
576 "CAMELLIA-256-ECB",
577 16,
578 0,
579 16,
580 &camellia_info
581};
582
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583#if defined(MBEDTLS_CIPHER_MODE_CBC)
584static const mbedtls_cipher_info_t camellia_128_cbc_info = {
585 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
586 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000587 128,
588 "CAMELLIA-128-CBC",
589 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200590 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000591 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000592 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000593};
594
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595static const mbedtls_cipher_info_t camellia_192_cbc_info = {
596 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
597 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000598 192,
599 "CAMELLIA-192-CBC",
600 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200601 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000602 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000603 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000604};
605
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200606static const mbedtls_cipher_info_t camellia_256_cbc_info = {
607 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
608 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000609 256,
610 "CAMELLIA-256-CBC",
611 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200612 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000613 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000614 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000615};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200616#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000617
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200618#if defined(MBEDTLS_CIPHER_MODE_CFB)
619static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
620 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
621 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000622 128,
623 "CAMELLIA-128-CFB128",
624 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200625 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000626 16,
627 &camellia_info
628};
629
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200630static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
631 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
632 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000633 192,
634 "CAMELLIA-192-CFB128",
635 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200636 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000637 16,
638 &camellia_info
639};
640
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200641static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
642 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
643 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000644 256,
645 "CAMELLIA-256-CFB128",
646 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200647 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000648 16,
649 &camellia_info
650};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000652
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200653#if defined(MBEDTLS_CIPHER_MODE_CTR)
654static const mbedtls_cipher_info_t camellia_128_ctr_info = {
655 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
656 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000657 128,
658 "CAMELLIA-128-CTR",
659 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200660 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000661 16,
662 &camellia_info
663};
664
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200665static const mbedtls_cipher_info_t camellia_192_ctr_info = {
666 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
667 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000668 192,
669 "CAMELLIA-192-CTR",
670 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200671 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000672 16,
673 &camellia_info
674};
675
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676static const mbedtls_cipher_info_t camellia_256_ctr_info = {
677 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
678 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000679 256,
680 "CAMELLIA-256-CTR",
681 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200682 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000683 16,
684 &camellia_info
685};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200686#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200689static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
690 unsigned int key_length )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200691{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200692 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200693 key, key_length );
694}
695
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696static const mbedtls_cipher_base_t gcm_camellia_info = {
697 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200698 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200700 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100701#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200702#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200703 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100704#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200705#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200706 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100707#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200709 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100710#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200711 gcm_camellia_setkey_wrap,
712 gcm_camellia_setkey_wrap,
713 gcm_ctx_alloc,
714 gcm_ctx_free,
715};
716
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200717static const mbedtls_cipher_info_t camellia_128_gcm_info = {
718 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
719 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200720 128,
721 "CAMELLIA-128-GCM",
722 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200723 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200724 16,
725 &gcm_camellia_info
726};
727
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200728static const mbedtls_cipher_info_t camellia_192_gcm_info = {
729 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
730 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200731 192,
732 "CAMELLIA-192-GCM",
733 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200734 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200735 16,
736 &gcm_camellia_info
737};
738
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739static const mbedtls_cipher_info_t camellia_256_gcm_info = {
740 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
741 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200742 256,
743 "CAMELLIA-256-GCM",
744 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200746 16,
747 &gcm_camellia_info
748};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200749#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200750
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200751#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200752static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
753 unsigned int key_length )
754{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200755 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200756 key, key_length );
757}
758
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200759static const mbedtls_cipher_base_t ccm_camellia_info = {
760 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200761 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200762#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200763 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100764#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200765#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200766 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100767#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200769 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100770#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200771#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200772 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100773#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200774 ccm_camellia_setkey_wrap,
775 ccm_camellia_setkey_wrap,
776 ccm_ctx_alloc,
777 ccm_ctx_free,
778};
779
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200780static const mbedtls_cipher_info_t camellia_128_ccm_info = {
781 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
782 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200783 128,
784 "CAMELLIA-128-CCM",
785 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200786 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200787 16,
788 &ccm_camellia_info
789};
790
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200791static const mbedtls_cipher_info_t camellia_192_ccm_info = {
792 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
793 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200794 192,
795 "CAMELLIA-192-CCM",
796 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200797 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200798 16,
799 &ccm_camellia_info
800};
801
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200802static const mbedtls_cipher_info_t camellia_256_ccm_info = {
803 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
804 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200805 256,
806 "CAMELLIA-256-CCM",
807 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200808 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200809 16,
810 &ccm_camellia_info
811};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200812#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200813
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200814#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000815
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200816#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000817
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200818static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200819 const unsigned char *input, unsigned char *output )
820{
821 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200822 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200823}
824
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200825static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200826 const unsigned char *input, unsigned char *output )
827{
828 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200829 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200830}
831
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200832#if defined(MBEDTLS_CIPHER_MODE_CBC)
833static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000834 unsigned char *iv, const unsigned char *input, unsigned char *output )
835{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200837 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000838}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200839#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000840
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200841#if defined(MBEDTLS_CIPHER_MODE_CBC)
842static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000843 unsigned char *iv, const unsigned char *input, unsigned char *output )
844{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200845 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200846 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000847}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200848#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000849
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200850static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
851 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000852{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000853 ((void) key_length);
854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000856}
857
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200858static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
859 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000860{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000861 ((void) key_length);
862
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200863 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000864}
865
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200866static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
867 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000868{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000869 ((void) key_length);
870
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200871 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000872}
873
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200874static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
875 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000876{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000877 ((void) key_length);
878
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200879 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000880}
881
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200882static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
883 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000884{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000885 ((void) key_length);
886
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200887 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000888}
889
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200890static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
891 unsigned int key_length )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000892{
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000893 ((void) key_length);
894
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200895 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000896}
897
898static void * des_ctx_alloc( void )
899{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200900 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000901
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200902 if( des == NULL )
903 return( NULL );
904
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200905 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200906
907 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000908}
909
910static void des_ctx_free( void *ctx )
911{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200912 mbedtls_des_free( (mbedtls_des_context *) ctx );
913 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +0200914}
915
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200916static void * des3_ctx_alloc( void )
917{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200918 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200919 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200920
921 if( des3 == NULL )
922 return( NULL );
923
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200924 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200925
926 return( des3 );
927}
928
Paul Bakker34617722014-06-13 17:20:13 +0200929static void des3_ctx_free( void *ctx )
930{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200931 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
932 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000933}
934
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200935static const mbedtls_cipher_base_t des_info = {
936 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200937 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200938#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +0000939 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100940#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200941#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200942 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100943#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200944#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200945 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100946#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200948 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100949#endif
Paul Bakker23986e52011-04-24 08:57:21 +0000950 des_setkey_enc_wrap,
951 des_setkey_dec_wrap,
952 des_ctx_alloc,
953 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000954};
955
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200956static const mbedtls_cipher_info_t des_ecb_info = {
957 MBEDTLS_CIPHER_DES_ECB,
958 MBEDTLS_MODE_ECB,
959 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200960 "DES-ECB",
961 8,
962 0,
963 8,
964 &des_info
965};
966
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200967#if defined(MBEDTLS_CIPHER_MODE_CBC)
968static const mbedtls_cipher_info_t des_cbc_info = {
969 MBEDTLS_CIPHER_DES_CBC,
970 MBEDTLS_MODE_CBC,
971 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +0000972 "DES-CBC",
973 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200974 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000975 8,
976 &des_info
977};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200978#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000979
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200980static const mbedtls_cipher_base_t des_ede_info = {
981 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200982 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200983#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +0000984 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100985#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200986#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200987 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100988#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200989#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +0200990 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100991#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200992#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200993 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100994#endif
Paul Bakker23986e52011-04-24 08:57:21 +0000995 des3_set2key_enc_wrap,
996 des3_set2key_dec_wrap,
997 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +0200998 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +0000999};
1000
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001001static const mbedtls_cipher_info_t des_ede_ecb_info = {
1002 MBEDTLS_CIPHER_DES_EDE_ECB,
1003 MBEDTLS_MODE_ECB,
1004 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001005 "DES-EDE-ECB",
1006 8,
1007 0,
1008 8,
1009 &des_ede_info
1010};
1011
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001012#if defined(MBEDTLS_CIPHER_MODE_CBC)
1013static const mbedtls_cipher_info_t des_ede_cbc_info = {
1014 MBEDTLS_CIPHER_DES_EDE_CBC,
1015 MBEDTLS_MODE_CBC,
1016 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001017 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001018 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001019 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001020 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001021 &des_ede_info
1022};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001023#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001024
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001025static const mbedtls_cipher_base_t des_ede3_info = {
1026 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001027 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001028#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001029 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001030#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001031#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001032 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001033#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001034#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001035 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001036#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001037#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001038 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001039#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001040 des3_set3key_enc_wrap,
1041 des3_set3key_dec_wrap,
1042 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001043 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001044};
1045
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001046static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1047 MBEDTLS_CIPHER_DES_EDE3_ECB,
1048 MBEDTLS_MODE_ECB,
1049 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001050 "DES-EDE3-ECB",
1051 8,
1052 0,
1053 8,
1054 &des_ede3_info
1055};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001056#if defined(MBEDTLS_CIPHER_MODE_CBC)
1057static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1058 MBEDTLS_CIPHER_DES_EDE3_CBC,
1059 MBEDTLS_MODE_CBC,
1060 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001061 "DES-EDE3-CBC",
1062 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001063 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001064 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001065 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001066};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001067#endif /* MBEDTLS_CIPHER_MODE_CBC */
1068#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001069
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001070#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001071
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001072static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001073 const unsigned char *input, unsigned char *output )
1074{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001075 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001076 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001077}
1078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001079#if defined(MBEDTLS_CIPHER_MODE_CBC)
1080static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001081 size_t length, unsigned char *iv, const unsigned char *input,
1082 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001083{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001084 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001085 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001086}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001087#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001088
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001089#if defined(MBEDTLS_CIPHER_MODE_CFB)
1090static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001091 size_t length, size_t *iv_off, unsigned char *iv,
1092 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001093{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001094 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001095 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001096}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001097#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001098
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001099#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001100static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1101 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001102 const unsigned char *input, unsigned char *output )
1103{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001104 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001105 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001106}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001107#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001108
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001109static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1110 unsigned int key_length )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001111{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001112 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_length );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001113}
1114
1115static void * blowfish_ctx_alloc( void )
1116{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001117 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001118 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001119
1120 if( ctx == NULL )
1121 return( NULL );
1122
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001123 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001124
1125 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001126}
1127
1128static void blowfish_ctx_free( void *ctx )
1129{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001130 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1131 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001132}
1133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001134static const mbedtls_cipher_base_t blowfish_info = {
1135 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001136 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001137#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001138 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001139#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001140#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001141 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001142#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001143#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001144 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001145#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001146#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001147 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001148#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001149 blowfish_setkey_wrap,
1150 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001151 blowfish_ctx_alloc,
1152 blowfish_ctx_free
1153};
1154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001155static const mbedtls_cipher_info_t blowfish_ecb_info = {
1156 MBEDTLS_CIPHER_BLOWFISH_ECB,
1157 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001158 128,
1159 "BLOWFISH-ECB",
1160 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001161 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001162 8,
1163 &blowfish_info
1164};
1165
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001166#if defined(MBEDTLS_CIPHER_MODE_CBC)
1167static const mbedtls_cipher_info_t blowfish_cbc_info = {
1168 MBEDTLS_CIPHER_BLOWFISH_CBC,
1169 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001170 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001171 "BLOWFISH-CBC",
1172 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001173 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001174 8,
1175 &blowfish_info
1176};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001177#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001178
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001179#if defined(MBEDTLS_CIPHER_MODE_CFB)
1180static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1181 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1182 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001183 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001184 "BLOWFISH-CFB64",
1185 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001186 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001187 8,
1188 &blowfish_info
1189};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001190#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001191
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001192#if defined(MBEDTLS_CIPHER_MODE_CTR)
1193static const mbedtls_cipher_info_t blowfish_ctr_info = {
1194 MBEDTLS_CIPHER_BLOWFISH_CTR,
1195 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001196 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001197 "BLOWFISH-CTR",
1198 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001199 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001200 8,
1201 &blowfish_info
1202};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001203#endif /* MBEDTLS_CIPHER_MODE_CTR */
1204#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001206#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001207static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1208 const unsigned char *input,
1209 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001210{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001211 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001212}
1213
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001214static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1215 unsigned int key_length )
1216{
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001217 /* we get key_length in bits, arc4 expects it in bytes */
Paul Bakker66d5d072014-06-17 16:39:18 +02001218 if( key_length % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001219 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001220
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001221 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_length / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001222 return( 0 );
1223}
1224
1225static void * arc4_ctx_alloc( void )
1226{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001227 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001228 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001229
1230 if( ctx == NULL )
1231 return( NULL );
1232
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001233 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001234
1235 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001236}
Paul Bakker68884e32013-01-07 18:20:04 +01001237
1238static void arc4_ctx_free( void *ctx )
1239{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001240 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1241 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001242}
1243
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001244static const mbedtls_cipher_base_t arc4_base_info = {
1245 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001246 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001247#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001248 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001249#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001250#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001251 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001252#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001253#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001254 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001255#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001256#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001257 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001258#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001259 arc4_setkey_wrap,
1260 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001261 arc4_ctx_alloc,
1262 arc4_ctx_free
1263};
1264
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001265static const mbedtls_cipher_info_t arc4_128_info = {
1266 MBEDTLS_CIPHER_ARC4_128,
1267 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001268 128,
1269 "ARC4-128",
1270 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001271 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001272 1,
1273 &arc4_base_info
1274};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001275#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001277#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001278static int null_crypt_stream( void *ctx, size_t length,
1279 const unsigned char *input,
1280 unsigned char *output )
1281{
1282 ((void) ctx);
1283 memmove( output, input, length );
1284 return( 0 );
1285}
1286
1287static int null_setkey( void *ctx, const unsigned char *key,
1288 unsigned int key_length )
1289{
1290 ((void) ctx);
1291 ((void) key);
1292 ((void) key_length);
1293
1294 return( 0 );
1295}
1296
Paul Bakkerfab5c822012-02-06 16:45:10 +00001297static void * null_ctx_alloc( void )
1298{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001299 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001300}
1301
Paul Bakkerfab5c822012-02-06 16:45:10 +00001302static void null_ctx_free( void *ctx )
1303{
1304 ((void) ctx);
1305}
1306
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001307static const mbedtls_cipher_base_t null_base_info = {
1308 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001309 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001310#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001311 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001312#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001313#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001314 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001315#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001316#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001317 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001318#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001319#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001320 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001321#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001322 null_setkey,
1323 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001324 null_ctx_alloc,
1325 null_ctx_free
1326};
1327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001328static const mbedtls_cipher_info_t null_cipher_info = {
1329 MBEDTLS_CIPHER_NULL,
1330 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001331 0,
1332 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001333 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001334 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001335 1,
1336 &null_base_info
1337};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001338#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001339
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001340const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001341{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001342#if defined(MBEDTLS_AES_C)
1343 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1344 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1345 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1346#if defined(MBEDTLS_CIPHER_MODE_CBC)
1347 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1348 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1349 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001350#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001351#if defined(MBEDTLS_CIPHER_MODE_CFB)
1352 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1353 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1354 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001355#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001356#if defined(MBEDTLS_CIPHER_MODE_CTR)
1357 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1358 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1359 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001360#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001361#if defined(MBEDTLS_GCM_C)
1362 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1363 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1364 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001365#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001366#if defined(MBEDTLS_CCM_C)
1367 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1368 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1369 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001370#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001371#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001372
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001373#if defined(MBEDTLS_ARC4_C)
1374 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001375#endif
1376
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001377#if defined(MBEDTLS_BLOWFISH_C)
1378 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1379#if defined(MBEDTLS_CIPHER_MODE_CBC)
1380 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001381#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001382#if defined(MBEDTLS_CIPHER_MODE_CFB)
1383 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001384#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001385#if defined(MBEDTLS_CIPHER_MODE_CTR)
1386 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001387#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001388#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001389
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001390#if defined(MBEDTLS_CAMELLIA_C)
1391 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1392 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1393 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1394#if defined(MBEDTLS_CIPHER_MODE_CBC)
1395 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1396 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1397 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001398#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001399#if defined(MBEDTLS_CIPHER_MODE_CFB)
1400 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1401 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1402 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001403#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001404#if defined(MBEDTLS_CIPHER_MODE_CTR)
1405 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1406 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1407 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001408#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001409#if defined(MBEDTLS_GCM_C)
1410 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1411 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1412 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001413#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001414#if defined(MBEDTLS_CCM_C)
1415 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1416 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1417 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001418#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001419#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001420
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001421#if defined(MBEDTLS_DES_C)
1422 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1423 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1424 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1425#if defined(MBEDTLS_CIPHER_MODE_CBC)
1426 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1427 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1428 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001429#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001430#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001431
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001432#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1433 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1434#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001435
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001436 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001437};
1438
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001439#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1440int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001441
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001442#endif /* MBEDTLS_CIPHER_C */