blob: 070f1d820ce8627bb0f92101f3fe82439a7eadf2 [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é-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker8123e9d2011-01-06 15:37:30 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000024 */
25
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000033
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020034#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000037#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000050#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000054#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000065#include <string.h>
66#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020070#else
Rich Evans00ab4702015-02-06 13:43:58 +000071#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020072#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020074#endif
75
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020077/* shared by all GCM ciphers */
78static void *gcm_ctx_alloc( void )
79{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020080 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
81
82 if( ctx != NULL )
83 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
84
85 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020086}
87
88static void gcm_ctx_free( void *ctx )
89{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090 mbedtls_gcm_free( ctx );
91 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020092}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020094
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020096/* shared by all CCM ciphers */
97static void *ccm_ctx_alloc( void )
98{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020099 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
100
101 if( ctx != NULL )
102 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
103
104 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200105}
106
107static void ccm_ctx_free( void *ctx )
108{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109 mbedtls_ccm_free( ctx );
110 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200111}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200113
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200117 const unsigned char *input, unsigned char *output )
118{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200120}
121
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122#if defined(MBEDTLS_CIPHER_MODE_CBC)
123static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000124 unsigned char *iv, const unsigned char *input, unsigned char *output )
125{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200127 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000128}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_CIPHER_MODE_CFB)
132static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200133 size_t length, size_t *iv_off, unsigned char *iv,
134 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000135{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200137 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000138}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000140
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200142static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
143 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000144 const unsigned char *input, unsigned char *output )
145{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000147 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000148}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000150
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100151#if defined(MBEDTLS_CIPHER_MODE_XTS)
152static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
153 size_t length,
154 const unsigned char data_unit[16],
155 const unsigned char *input,
156 unsigned char *output )
157{
158 mbedtls_aes_xts_context *xts_ctx = ctx;
159 int mode;
160
161 switch (operation)
162 {
163 case MBEDTLS_ENCRYPT:
164 mode = MBEDTLS_AES_ENCRYPT;
165 break;
166 case MBEDTLS_DECRYPT:
167 mode = MBEDTLS_AES_DECRYPT;
168 break;
169 default:
170 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
171 }
172
173 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
174 data_unit, input, output );
175}
176#endif /* MBEDTLS_CIPHER_MODE_XTS */
177
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200178static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200179 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000180{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200181 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000182}
183
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200184static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200185 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000186{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200187 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000188}
189
190static void * aes_ctx_alloc( void )
191{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200192 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200193
194 if( aes == NULL )
195 return( NULL );
196
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200198
199 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000200}
201
202static void aes_ctx_free( void *ctx )
203{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200204 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
205 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000206}
207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200208static const mbedtls_cipher_base_t aes_info = {
209 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200210 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000212 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100213#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000215 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100216#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000218 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100219#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100220#if defined(MBEDTLS_CIPHER_MODE_XTS)
221 NULL,
222#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200224 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100225#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000226 aes_setkey_enc_wrap,
227 aes_setkey_dec_wrap,
228 aes_ctx_alloc,
229 aes_ctx_free
230};
231
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232static const mbedtls_cipher_info_t aes_128_ecb_info = {
233 MBEDTLS_CIPHER_AES_128_ECB,
234 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200235 128,
236 "AES-128-ECB",
237 16,
238 0,
239 16,
240 &aes_info
241};
242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243static const mbedtls_cipher_info_t aes_192_ecb_info = {
244 MBEDTLS_CIPHER_AES_192_ECB,
245 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200246 192,
247 "AES-192-ECB",
248 16,
249 0,
250 16,
251 &aes_info
252};
253
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200254static const mbedtls_cipher_info_t aes_256_ecb_info = {
255 MBEDTLS_CIPHER_AES_256_ECB,
256 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200257 256,
258 "AES-256-ECB",
259 16,
260 0,
261 16,
262 &aes_info
263};
264
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200265#if defined(MBEDTLS_CIPHER_MODE_CBC)
266static const mbedtls_cipher_info_t aes_128_cbc_info = {
267 MBEDTLS_CIPHER_AES_128_CBC,
268 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000269 128,
270 "AES-128-CBC",
271 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200272 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000273 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000274 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000275};
276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277static const mbedtls_cipher_info_t aes_192_cbc_info = {
278 MBEDTLS_CIPHER_AES_192_CBC,
279 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000280 192,
281 "AES-192-CBC",
282 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200283 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000284 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000285 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000286};
287
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200288static const mbedtls_cipher_info_t aes_256_cbc_info = {
289 MBEDTLS_CIPHER_AES_256_CBC,
290 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000291 256,
292 "AES-256-CBC",
293 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200294 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000295 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000296 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000297};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000299
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300#if defined(MBEDTLS_CIPHER_MODE_CFB)
301static const mbedtls_cipher_info_t aes_128_cfb128_info = {
302 MBEDTLS_CIPHER_AES_128_CFB128,
303 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000304 128,
305 "AES-128-CFB128",
306 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200307 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000308 16,
309 &aes_info
310};
311
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312static const mbedtls_cipher_info_t aes_192_cfb128_info = {
313 MBEDTLS_CIPHER_AES_192_CFB128,
314 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000315 192,
316 "AES-192-CFB128",
317 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200318 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000319 16,
320 &aes_info
321};
322
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323static const mbedtls_cipher_info_t aes_256_cfb128_info = {
324 MBEDTLS_CIPHER_AES_256_CFB128,
325 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000326 256,
327 "AES-256-CFB128",
328 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200329 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000330 16,
331 &aes_info
332};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200333#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000334
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335#if defined(MBEDTLS_CIPHER_MODE_CTR)
336static const mbedtls_cipher_info_t aes_128_ctr_info = {
337 MBEDTLS_CIPHER_AES_128_CTR,
338 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000339 128,
340 "AES-128-CTR",
341 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200342 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 16,
344 &aes_info
345};
346
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347static const mbedtls_cipher_info_t aes_192_ctr_info = {
348 MBEDTLS_CIPHER_AES_192_CTR,
349 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000350 192,
351 "AES-192-CTR",
352 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200353 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000354 16,
355 &aes_info
356};
357
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358static const mbedtls_cipher_info_t aes_256_ctr_info = {
359 MBEDTLS_CIPHER_AES_256_CTR,
360 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000361 256,
362 "AES-256-CTR",
363 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200364 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000365 16,
366 &aes_info
367};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000369
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100370#if defined(MBEDTLS_CIPHER_MODE_XTS)
371static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
372 unsigned int key_bitlen )
373{
374 mbedtls_aes_xts_context *xts_ctx = ctx;
375 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
376}
377
378static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
379 unsigned int key_bitlen )
380{
381 mbedtls_aes_xts_context *xts_ctx = ctx;
382 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
383}
384
385static void *xts_aes_ctx_alloc( void )
386{
387 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
388
389 if( xts_ctx )
390 mbedtls_aes_xts_init( xts_ctx );
391
392 return( xts_ctx );
393}
394
395static void xts_aes_ctx_free( void *ctx )
396{
397 mbedtls_aes_xts_context *xts_ctx = ctx;
398
399 if ( !xts_ctx )
400 return;
401
402 mbedtls_aes_xts_free( xts_ctx );
403 mbedtls_free( xts_ctx );
404}
405
406static const mbedtls_cipher_base_t xts_aes_info = {
407 MBEDTLS_CIPHER_ID_AES,
408 NULL,
409#if defined(MBEDTLS_CIPHER_MODE_CBC)
410 NULL,
411#endif
412#if defined(MBEDTLS_CIPHER_MODE_CFB)
413 NULL,
414#endif
415#if defined(MBEDTLS_CIPHER_MODE_CTR)
416 NULL,
417#endif
418#if defined(MBEDTLS_CIPHER_MODE_XTS)
419 aes_crypt_xts_wrap,
420#endif
421#if defined(MBEDTLS_CIPHER_MODE_STREAM)
422 NULL,
423#endif
424 xts_aes_setkey_enc_wrap,
425 xts_aes_setkey_dec_wrap,
426 xts_aes_ctx_alloc,
427 xts_aes_ctx_free
428};
429
430static const mbedtls_cipher_info_t aes_128_xts_info = {
431 MBEDTLS_CIPHER_AES_128_XTS,
432 MBEDTLS_MODE_XTS,
433 256,
434 "AES-128-XTS",
435 16,
436 0,
437 16,
438 &xts_aes_info
439};
440
441static const mbedtls_cipher_info_t aes_256_xts_info = {
442 MBEDTLS_CIPHER_AES_256_XTS,
443 MBEDTLS_MODE_XTS,
444 512,
445 "AES-256-XTS",
446 16,
447 0,
448 16,
449 &xts_aes_info
450};
451#endif /* MBEDTLS_CIPHER_MODE_XTS */
452
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200453#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200454static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200455 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200456{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200457 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200458 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200459}
460
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200461static const mbedtls_cipher_base_t gcm_aes_info = {
462 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200463 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200464#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200465 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100466#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200467#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200468 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100469#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200470#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200471 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100472#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100473#if defined(MBEDTLS_CIPHER_MODE_XTS)
474 NULL,
475#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200477 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100478#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200479 gcm_aes_setkey_wrap,
480 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200481 gcm_ctx_alloc,
482 gcm_ctx_free,
483};
484
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200485static const mbedtls_cipher_info_t aes_128_gcm_info = {
486 MBEDTLS_CIPHER_AES_128_GCM,
487 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100488 128,
489 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200490 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100492 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200493 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100494};
495
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200496static const mbedtls_cipher_info_t aes_192_gcm_info = {
497 MBEDTLS_CIPHER_AES_192_GCM,
498 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200499 192,
500 "AES-192-GCM",
501 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200502 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200503 16,
504 &gcm_aes_info
505};
506
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200507static const mbedtls_cipher_info_t aes_256_gcm_info = {
508 MBEDTLS_CIPHER_AES_256_GCM,
509 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100510 256,
511 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200512 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200513 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100514 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200515 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100516};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200517#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100518
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200519#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200520static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200521 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200522{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200523 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200524 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200525}
526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527static const mbedtls_cipher_base_t ccm_aes_info = {
528 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200529 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200531 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100532#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200533#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200534 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100535#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200537 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100538#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100539#if defined(MBEDTLS_CIPHER_MODE_XTS)
540 NULL,
541#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200542#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200543 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100544#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200545 ccm_aes_setkey_wrap,
546 ccm_aes_setkey_wrap,
547 ccm_ctx_alloc,
548 ccm_ctx_free,
549};
550
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551static const mbedtls_cipher_info_t aes_128_ccm_info = {
552 MBEDTLS_CIPHER_AES_128_CCM,
553 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200554 128,
555 "AES-128-CCM",
556 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200557 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200558 16,
559 &ccm_aes_info
560};
561
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562static const mbedtls_cipher_info_t aes_192_ccm_info = {
563 MBEDTLS_CIPHER_AES_192_CCM,
564 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200565 192,
566 "AES-192-CCM",
567 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200568 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200569 16,
570 &ccm_aes_info
571};
572
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200573static const mbedtls_cipher_info_t aes_256_ccm_info = {
574 MBEDTLS_CIPHER_AES_256_CCM,
575 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200576 256,
577 "AES-256-CCM",
578 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200579 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200580 16,
581 &ccm_aes_info
582};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200585#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000586
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200587#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000588
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200589static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200590 const unsigned char *input, unsigned char *output )
591{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200592 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200593 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200594}
595
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596#if defined(MBEDTLS_CIPHER_MODE_CBC)
597static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200598 size_t length, unsigned char *iv,
599 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000600{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200602 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000603}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200604#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000605
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200606#if defined(MBEDTLS_CIPHER_MODE_CFB)
607static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200608 size_t length, size_t *iv_off, unsigned char *iv,
609 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000610{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200611 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200612 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000613}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200614#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000615
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200616#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200617static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
618 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000619 const unsigned char *input, unsigned char *output )
620{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200621 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200622 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000623}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200624#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000625
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200626static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200627 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000628{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200629 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000630}
631
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200632static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200633 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000634{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200635 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000636}
637
638static void * camellia_ctx_alloc( void )
639{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200640 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200641 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200642
643 if( ctx == NULL )
644 return( NULL );
645
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200647
648 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000649}
650
651static void camellia_ctx_free( void *ctx )
652{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200653 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
654 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000655}
656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657static const mbedtls_cipher_base_t camellia_info = {
658 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200659 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200660#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000661 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100662#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200663#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000664 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100665#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200666#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000667 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100668#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100669#if defined(MBEDTLS_CIPHER_MODE_XTS)
670 NULL,
671#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200673 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100674#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000675 camellia_setkey_enc_wrap,
676 camellia_setkey_dec_wrap,
677 camellia_ctx_alloc,
678 camellia_ctx_free
679};
680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200681static const mbedtls_cipher_info_t camellia_128_ecb_info = {
682 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
683 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200684 128,
685 "CAMELLIA-128-ECB",
686 16,
687 0,
688 16,
689 &camellia_info
690};
691
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692static const mbedtls_cipher_info_t camellia_192_ecb_info = {
693 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
694 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200695 192,
696 "CAMELLIA-192-ECB",
697 16,
698 0,
699 16,
700 &camellia_info
701};
702
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200703static const mbedtls_cipher_info_t camellia_256_ecb_info = {
704 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
705 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200706 256,
707 "CAMELLIA-256-ECB",
708 16,
709 0,
710 16,
711 &camellia_info
712};
713
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200714#if defined(MBEDTLS_CIPHER_MODE_CBC)
715static const mbedtls_cipher_info_t camellia_128_cbc_info = {
716 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
717 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000718 128,
719 "CAMELLIA-128-CBC",
720 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200721 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000722 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000723 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000724};
725
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200726static const mbedtls_cipher_info_t camellia_192_cbc_info = {
727 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
728 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000729 192,
730 "CAMELLIA-192-CBC",
731 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200732 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000733 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000734 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000735};
736
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200737static const mbedtls_cipher_info_t camellia_256_cbc_info = {
738 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
739 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000740 256,
741 "CAMELLIA-256-CBC",
742 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200743 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000744 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000745 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000746};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200747#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000748
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200749#if defined(MBEDTLS_CIPHER_MODE_CFB)
750static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
751 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
752 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000753 128,
754 "CAMELLIA-128-CFB128",
755 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200756 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000757 16,
758 &camellia_info
759};
760
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200761static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
762 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
763 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000764 192,
765 "CAMELLIA-192-CFB128",
766 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200767 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000768 16,
769 &camellia_info
770};
771
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200772static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
773 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
774 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000775 256,
776 "CAMELLIA-256-CFB128",
777 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200778 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000779 16,
780 &camellia_info
781};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200782#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000783
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200784#if defined(MBEDTLS_CIPHER_MODE_CTR)
785static const mbedtls_cipher_info_t camellia_128_ctr_info = {
786 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
787 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000788 128,
789 "CAMELLIA-128-CTR",
790 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200791 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000792 16,
793 &camellia_info
794};
795
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200796static const mbedtls_cipher_info_t camellia_192_ctr_info = {
797 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
798 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000799 192,
800 "CAMELLIA-192-CTR",
801 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200802 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000803 16,
804 &camellia_info
805};
806
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200807static const mbedtls_cipher_info_t camellia_256_ctr_info = {
808 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
809 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000810 256,
811 "CAMELLIA-256-CTR",
812 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200813 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000814 16,
815 &camellia_info
816};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200817#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000818
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200819#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200820static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200821 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200822{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200823 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200824 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200825}
826
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200827static const mbedtls_cipher_base_t gcm_camellia_info = {
828 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200829 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200830#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200831 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100832#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200833#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200834 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100835#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200837 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100838#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100839#if defined(MBEDTLS_CIPHER_MODE_XTS)
840 NULL,
841#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200842#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200843 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100844#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200845 gcm_camellia_setkey_wrap,
846 gcm_camellia_setkey_wrap,
847 gcm_ctx_alloc,
848 gcm_ctx_free,
849};
850
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200851static const mbedtls_cipher_info_t camellia_128_gcm_info = {
852 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
853 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200854 128,
855 "CAMELLIA-128-GCM",
856 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200857 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200858 16,
859 &gcm_camellia_info
860};
861
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200862static const mbedtls_cipher_info_t camellia_192_gcm_info = {
863 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
864 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200865 192,
866 "CAMELLIA-192-GCM",
867 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200868 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200869 16,
870 &gcm_camellia_info
871};
872
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200873static const mbedtls_cipher_info_t camellia_256_gcm_info = {
874 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
875 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200876 256,
877 "CAMELLIA-256-GCM",
878 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200879 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200880 16,
881 &gcm_camellia_info
882};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200883#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200884
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200885#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200886static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200887 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200888{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200889 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200890 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200891}
892
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200893static const mbedtls_cipher_base_t ccm_camellia_info = {
894 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200895 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200896#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200897 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100898#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200899#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200900 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100901#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200903 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100904#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100905#if defined(MBEDTLS_CIPHER_MODE_XTS)
906 NULL,
907#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200908#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200909 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100910#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200911 ccm_camellia_setkey_wrap,
912 ccm_camellia_setkey_wrap,
913 ccm_ctx_alloc,
914 ccm_ctx_free,
915};
916
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200917static const mbedtls_cipher_info_t camellia_128_ccm_info = {
918 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
919 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200920 128,
921 "CAMELLIA-128-CCM",
922 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200923 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200924 16,
925 &ccm_camellia_info
926};
927
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200928static const mbedtls_cipher_info_t camellia_192_ccm_info = {
929 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
930 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200931 192,
932 "CAMELLIA-192-CCM",
933 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200934 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200935 16,
936 &ccm_camellia_info
937};
938
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200939static const mbedtls_cipher_info_t camellia_256_ccm_info = {
940 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
941 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200942 256,
943 "CAMELLIA-256-CCM",
944 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200945 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200946 16,
947 &ccm_camellia_info
948};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200949#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200950
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200951#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000952
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200953#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000954
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200955static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200956 const unsigned char *input, unsigned char *output )
957{
958 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200959 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200960}
961
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200962static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200963 const unsigned char *input, unsigned char *output )
964{
965 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200966 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200967}
968
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200969#if defined(MBEDTLS_CIPHER_MODE_CBC)
970static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000971 unsigned char *iv, const unsigned char *input, unsigned char *output )
972{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200973 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200974 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000975}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200976#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000977
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200978#if defined(MBEDTLS_CIPHER_MODE_CBC)
979static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000980 unsigned char *iv, const unsigned char *input, unsigned char *output )
981{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200982 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200983 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000984}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200985#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000986
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200987static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200988 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000989{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200990 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000991
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200992 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000993}
994
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200995static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200996 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000997{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200998 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +0000999
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001000 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001001}
1002
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001003static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001004 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001005{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001006 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001007
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001008 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001009}
1010
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001011static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001012 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001013{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001014 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001015
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001016 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001017}
1018
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001019static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001020 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001021{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001022 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001023
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001024 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001025}
1026
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001027static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001028 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001029{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001030 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001032 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001033}
1034
1035static void * des_ctx_alloc( void )
1036{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001037 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001038
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001039 if( des == NULL )
1040 return( NULL );
1041
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001042 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001043
1044 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001045}
1046
1047static void des_ctx_free( void *ctx )
1048{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001049 mbedtls_des_free( (mbedtls_des_context *) ctx );
1050 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001051}
1052
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001053static void * des3_ctx_alloc( void )
1054{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001055 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001056 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001057
1058 if( des3 == NULL )
1059 return( NULL );
1060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001061 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001062
1063 return( des3 );
1064}
1065
Paul Bakker34617722014-06-13 17:20:13 +02001066static void des3_ctx_free( void *ctx )
1067{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001068 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1069 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001070}
1071
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001072static const mbedtls_cipher_base_t des_info = {
1073 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001074 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001075#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001076 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001077#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001078#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001079 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001080#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001081#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001082 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001083#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001084#if defined(MBEDTLS_CIPHER_MODE_XTS)
1085 NULL,
1086#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001087#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001088 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001089#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001090 des_setkey_enc_wrap,
1091 des_setkey_dec_wrap,
1092 des_ctx_alloc,
1093 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001094};
1095
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001096static const mbedtls_cipher_info_t des_ecb_info = {
1097 MBEDTLS_CIPHER_DES_ECB,
1098 MBEDTLS_MODE_ECB,
1099 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001100 "DES-ECB",
1101 8,
1102 0,
1103 8,
1104 &des_info
1105};
1106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001107#if defined(MBEDTLS_CIPHER_MODE_CBC)
1108static const mbedtls_cipher_info_t des_cbc_info = {
1109 MBEDTLS_CIPHER_DES_CBC,
1110 MBEDTLS_MODE_CBC,
1111 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001112 "DES-CBC",
1113 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001114 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001115 8,
1116 &des_info
1117};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001118#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001120static const mbedtls_cipher_base_t des_ede_info = {
1121 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001122 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001123#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001124 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001125#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001126#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001127 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001128#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001129#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001130 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001131#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001132#if defined(MBEDTLS_CIPHER_MODE_XTS)
1133 NULL,
1134#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001135#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001136 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001137#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001138 des3_set2key_enc_wrap,
1139 des3_set2key_dec_wrap,
1140 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001141 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001142};
1143
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001144static const mbedtls_cipher_info_t des_ede_ecb_info = {
1145 MBEDTLS_CIPHER_DES_EDE_ECB,
1146 MBEDTLS_MODE_ECB,
1147 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001148 "DES-EDE-ECB",
1149 8,
1150 0,
1151 8,
1152 &des_ede_info
1153};
1154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001155#if defined(MBEDTLS_CIPHER_MODE_CBC)
1156static const mbedtls_cipher_info_t des_ede_cbc_info = {
1157 MBEDTLS_CIPHER_DES_EDE_CBC,
1158 MBEDTLS_MODE_CBC,
1159 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001160 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001161 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001162 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001163 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001164 &des_ede_info
1165};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001166#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001168static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001169 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001170 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001171#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001172 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001173#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001174#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001175 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001176#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001177#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001178 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001179#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001180#if defined(MBEDTLS_CIPHER_MODE_XTS)
1181 NULL,
1182#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001183#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001184 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001185#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001186 des3_set3key_enc_wrap,
1187 des3_set3key_dec_wrap,
1188 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001189 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001190};
1191
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001192static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1193 MBEDTLS_CIPHER_DES_EDE3_ECB,
1194 MBEDTLS_MODE_ECB,
1195 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001196 "DES-EDE3-ECB",
1197 8,
1198 0,
1199 8,
1200 &des_ede3_info
1201};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001202#if defined(MBEDTLS_CIPHER_MODE_CBC)
1203static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1204 MBEDTLS_CIPHER_DES_EDE3_CBC,
1205 MBEDTLS_MODE_CBC,
1206 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001207 "DES-EDE3-CBC",
1208 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001209 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001210 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001211 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001212};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001213#endif /* MBEDTLS_CIPHER_MODE_CBC */
1214#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001215
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001216#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001218static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001219 const unsigned char *input, unsigned char *output )
1220{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001221 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001222 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001223}
1224
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001225#if defined(MBEDTLS_CIPHER_MODE_CBC)
1226static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001227 size_t length, unsigned char *iv, const unsigned char *input,
1228 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001229{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001230 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001231 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001232}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001233#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001234
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001235#if defined(MBEDTLS_CIPHER_MODE_CFB)
1236static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001237 size_t length, size_t *iv_off, unsigned char *iv,
1238 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001239{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001240 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001241 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001242}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001243#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001244
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001245#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001246static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1247 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001248 const unsigned char *input, unsigned char *output )
1249{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001250 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001251 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001252}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001253#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001254
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001255static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001256 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001257{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001258 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001259}
1260
1261static void * blowfish_ctx_alloc( void )
1262{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001263 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001264 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001265
1266 if( ctx == NULL )
1267 return( NULL );
1268
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001269 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001270
1271 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001272}
1273
1274static void blowfish_ctx_free( void *ctx )
1275{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001276 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1277 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001278}
1279
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001280static const mbedtls_cipher_base_t blowfish_info = {
1281 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001282 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001283#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001284 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001285#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001286#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001287 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001288#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001289#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001290 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001291#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001292#if defined(MBEDTLS_CIPHER_MODE_XTS)
1293 NULL,
1294#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001295#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001296 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001297#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001298 blowfish_setkey_wrap,
1299 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001300 blowfish_ctx_alloc,
1301 blowfish_ctx_free
1302};
1303
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001304static const mbedtls_cipher_info_t blowfish_ecb_info = {
1305 MBEDTLS_CIPHER_BLOWFISH_ECB,
1306 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001307 128,
1308 "BLOWFISH-ECB",
1309 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001310 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001311 8,
1312 &blowfish_info
1313};
1314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001315#if defined(MBEDTLS_CIPHER_MODE_CBC)
1316static const mbedtls_cipher_info_t blowfish_cbc_info = {
1317 MBEDTLS_CIPHER_BLOWFISH_CBC,
1318 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001319 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001320 "BLOWFISH-CBC",
1321 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001322 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001323 8,
1324 &blowfish_info
1325};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001326#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001328#if defined(MBEDTLS_CIPHER_MODE_CFB)
1329static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1330 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1331 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001332 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001333 "BLOWFISH-CFB64",
1334 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001335 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001336 8,
1337 &blowfish_info
1338};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001339#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001340
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001341#if defined(MBEDTLS_CIPHER_MODE_CTR)
1342static const mbedtls_cipher_info_t blowfish_ctr_info = {
1343 MBEDTLS_CIPHER_BLOWFISH_CTR,
1344 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001345 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001346 "BLOWFISH-CTR",
1347 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001348 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001349 8,
1350 &blowfish_info
1351};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001352#endif /* MBEDTLS_CIPHER_MODE_CTR */
1353#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001354
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001355#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001356static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1357 const unsigned char *input,
1358 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001359{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001360 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001361}
1362
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001363static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001364 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001365{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001366 /* we get key_bitlen in bits, arc4 expects it in bytes */
1367 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001368 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001369
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001370 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001371 return( 0 );
1372}
1373
1374static void * arc4_ctx_alloc( void )
1375{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001376 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001377 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001378
1379 if( ctx == NULL )
1380 return( NULL );
1381
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001382 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001383
1384 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001385}
Paul Bakker68884e32013-01-07 18:20:04 +01001386
1387static void arc4_ctx_free( void *ctx )
1388{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001389 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1390 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001391}
1392
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001393static const mbedtls_cipher_base_t arc4_base_info = {
1394 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001395 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001396#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001397 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001398#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001399#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001400 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001401#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001402#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001403 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001404#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001405#if defined(MBEDTLS_CIPHER_MODE_XTS)
1406 NULL,
1407#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001408#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001409 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001410#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001411 arc4_setkey_wrap,
1412 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001413 arc4_ctx_alloc,
1414 arc4_ctx_free
1415};
1416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001417static const mbedtls_cipher_info_t arc4_128_info = {
1418 MBEDTLS_CIPHER_ARC4_128,
1419 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001420 128,
1421 "ARC4-128",
1422 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001423 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001424 1,
1425 &arc4_base_info
1426};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001427#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001428
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001429#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001430static int null_crypt_stream( void *ctx, size_t length,
1431 const unsigned char *input,
1432 unsigned char *output )
1433{
1434 ((void) ctx);
1435 memmove( output, input, length );
1436 return( 0 );
1437}
1438
1439static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001440 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001441{
1442 ((void) ctx);
1443 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001444 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001445
1446 return( 0 );
1447}
1448
Paul Bakkerfab5c822012-02-06 16:45:10 +00001449static void * null_ctx_alloc( void )
1450{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001451 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001452}
1453
Paul Bakkerfab5c822012-02-06 16:45:10 +00001454static void null_ctx_free( void *ctx )
1455{
1456 ((void) ctx);
1457}
1458
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001459static const mbedtls_cipher_base_t null_base_info = {
1460 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001461 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001462#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001463 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001464#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001465#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001466 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001467#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001468#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001469 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001470#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001471#if defined(MBEDTLS_CIPHER_MODE_XTS)
1472 NULL,
1473#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001474#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001475 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001476#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001477 null_setkey,
1478 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001479 null_ctx_alloc,
1480 null_ctx_free
1481};
1482
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001483static const mbedtls_cipher_info_t null_cipher_info = {
1484 MBEDTLS_CIPHER_NULL,
1485 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001486 0,
1487 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001488 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001489 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001490 1,
1491 &null_base_info
1492};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001493#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001494
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001495const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001496{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001497#if defined(MBEDTLS_AES_C)
1498 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1499 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1500 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1501#if defined(MBEDTLS_CIPHER_MODE_CBC)
1502 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1503 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1504 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001505#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001506#if defined(MBEDTLS_CIPHER_MODE_CFB)
1507 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1508 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1509 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001510#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001511#if defined(MBEDTLS_CIPHER_MODE_CTR)
1512 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1513 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1514 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001515#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001516#if defined(MBEDTLS_CIPHER_MODE_XTS)
1517 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
1518 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
1519#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001520#if defined(MBEDTLS_GCM_C)
1521 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1522 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1523 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001524#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001525#if defined(MBEDTLS_CCM_C)
1526 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1527 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1528 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001529#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001530#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001531
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001532#if defined(MBEDTLS_ARC4_C)
1533 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001534#endif
1535
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001536#if defined(MBEDTLS_BLOWFISH_C)
1537 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1538#if defined(MBEDTLS_CIPHER_MODE_CBC)
1539 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001540#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001541#if defined(MBEDTLS_CIPHER_MODE_CFB)
1542 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001543#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001544#if defined(MBEDTLS_CIPHER_MODE_CTR)
1545 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001546#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001547#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001548
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001549#if defined(MBEDTLS_CAMELLIA_C)
1550 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1551 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1552 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1553#if defined(MBEDTLS_CIPHER_MODE_CBC)
1554 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1555 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1556 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001557#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001558#if defined(MBEDTLS_CIPHER_MODE_CFB)
1559 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1560 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1561 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001562#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001563#if defined(MBEDTLS_CIPHER_MODE_CTR)
1564 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1565 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1566 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001567#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001568#if defined(MBEDTLS_GCM_C)
1569 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1570 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1571 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001572#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001573#if defined(MBEDTLS_CCM_C)
1574 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1575 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1576 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001577#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001578#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001579
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001580#if defined(MBEDTLS_DES_C)
1581 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1582 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1583 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1584#if defined(MBEDTLS_CIPHER_MODE_CBC)
1585 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1586 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1587 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001588#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001589#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001590
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001591#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1592 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1593#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001594
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001595 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001596};
1597
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1599int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001600
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001601#endif /* MBEDTLS_CIPHER_C */