blob: 16e0a9d9bb5de4345206b64c7508e87100351d0e [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
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000048#if defined(MBEDTLS_ARIA_C)
49#include "mbedtls/aria.h"
50#endif
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000054#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000069#include <string.h>
70#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020074#else
Rich Evans00ab4702015-02-06 13:43:58 +000075#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020076#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020078#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020081/* shared by all GCM ciphers */
82static void *gcm_ctx_alloc( void )
83{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020084 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
85
86 if( ctx != NULL )
87 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
88
89 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020090}
91
92static void gcm_ctx_free( void *ctx )
93{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094 mbedtls_gcm_free( ctx );
95 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020096}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020098
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200100/* shared by all CCM ciphers */
101static void *ccm_ctx_alloc( void )
102{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200103 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
104
105 if( ctx != NULL )
106 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
107
108 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200109}
110
111static void ccm_ctx_free( void *ctx )
112{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113 mbedtls_ccm_free( ctx );
114 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200115}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200117
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200121 const unsigned char *input, unsigned char *output )
122{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200124}
125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_CIPHER_MODE_CBC)
127static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000128 unsigned char *iv, const unsigned char *input, unsigned char *output )
129{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200131 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000132}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if defined(MBEDTLS_CIPHER_MODE_CFB)
136static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200137 size_t length, size_t *iv_off, unsigned char *iv,
138 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000139{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200141 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000142}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000144
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100145#if defined(MBEDTLS_CIPHER_MODE_OFB)
146static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
147 unsigned char *iv, const unsigned char *input, unsigned char *output )
148{
149 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
150 iv, input, output );
151}
152#endif /* MBEDTLS_CIPHER_MODE_OFB */
153
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200155static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
156 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000157 const unsigned char *input, unsigned char *output )
158{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000160 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000161}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000163
Jaeden Ameroc6539902018-04-30 17:17:41 +0100164#if defined(MBEDTLS_CIPHER_MODE_XTS)
165static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
166 size_t length,
167 const unsigned char data_unit[16],
168 const unsigned char *input,
169 unsigned char *output )
170{
171 mbedtls_aes_xts_context *xts_ctx = ctx;
172 int mode;
173
174 switch( operation )
175 {
176 case MBEDTLS_ENCRYPT:
177 mode = MBEDTLS_AES_ENCRYPT;
178 break;
179 case MBEDTLS_DECRYPT:
180 mode = MBEDTLS_AES_DECRYPT;
181 break;
182 default:
183 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
184 }
185
186 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
187 data_unit, input, output );
188}
189#endif /* MBEDTLS_CIPHER_MODE_XTS */
190
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200191static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200192 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000193{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200194 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000195}
196
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200197static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200198 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000199{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200200 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000201}
202
203static void * aes_ctx_alloc( void )
204{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200205 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200206
207 if( aes == NULL )
208 return( NULL );
209
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200211
212 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000213}
214
215static void aes_ctx_free( void *ctx )
216{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
218 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000219}
220
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200221static const mbedtls_cipher_base_t aes_info = {
222 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200223 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200224#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000225 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100226#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200227#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000228 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100229#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100230#if defined(MBEDTLS_CIPHER_MODE_OFB)
231 aes_crypt_ofb_wrap,
232#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000234 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100235#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100236#if defined(MBEDTLS_CIPHER_MODE_XTS)
237 NULL,
238#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200240 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100241#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000242 aes_setkey_enc_wrap,
243 aes_setkey_dec_wrap,
244 aes_ctx_alloc,
245 aes_ctx_free
246};
247
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200248static const mbedtls_cipher_info_t aes_128_ecb_info = {
249 MBEDTLS_CIPHER_AES_128_ECB,
250 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200251 128,
252 "AES-128-ECB",
253 16,
254 0,
255 16,
256 &aes_info
257};
258
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259static const mbedtls_cipher_info_t aes_192_ecb_info = {
260 MBEDTLS_CIPHER_AES_192_ECB,
261 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200262 192,
263 "AES-192-ECB",
264 16,
265 0,
266 16,
267 &aes_info
268};
269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270static const mbedtls_cipher_info_t aes_256_ecb_info = {
271 MBEDTLS_CIPHER_AES_256_ECB,
272 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200273 256,
274 "AES-256-ECB",
275 16,
276 0,
277 16,
278 &aes_info
279};
280
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281#if defined(MBEDTLS_CIPHER_MODE_CBC)
282static const mbedtls_cipher_info_t aes_128_cbc_info = {
283 MBEDTLS_CIPHER_AES_128_CBC,
284 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000285 128,
286 "AES-128-CBC",
287 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200288 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000289 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000290 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000291};
292
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293static const mbedtls_cipher_info_t aes_192_cbc_info = {
294 MBEDTLS_CIPHER_AES_192_CBC,
295 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000296 192,
297 "AES-192-CBC",
298 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200299 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000300 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000301 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000302};
303
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304static const mbedtls_cipher_info_t aes_256_cbc_info = {
305 MBEDTLS_CIPHER_AES_256_CBC,
306 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000307 256,
308 "AES-256-CBC",
309 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200310 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000311 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000312 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000313};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000315
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316#if defined(MBEDTLS_CIPHER_MODE_CFB)
317static const mbedtls_cipher_info_t aes_128_cfb128_info = {
318 MBEDTLS_CIPHER_AES_128_CFB128,
319 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000320 128,
321 "AES-128-CFB128",
322 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200323 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000324 16,
325 &aes_info
326};
327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328static const mbedtls_cipher_info_t aes_192_cfb128_info = {
329 MBEDTLS_CIPHER_AES_192_CFB128,
330 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000331 192,
332 "AES-192-CFB128",
333 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200334 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000335 16,
336 &aes_info
337};
338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339static const mbedtls_cipher_info_t aes_256_cfb128_info = {
340 MBEDTLS_CIPHER_AES_256_CFB128,
341 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000342 256,
343 "AES-256-CFB128",
344 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200345 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000346 16,
347 &aes_info
348};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200349#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000350
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100351#if defined(MBEDTLS_CIPHER_MODE_OFB)
352static const mbedtls_cipher_info_t aes_128_ofb_info = {
353 MBEDTLS_CIPHER_AES_128_OFB,
354 MBEDTLS_MODE_OFB,
355 128,
356 "AES-128-OFB",
357 16,
358 0,
359 16,
360 &aes_info
361};
362
363static const mbedtls_cipher_info_t aes_192_ofb_info = {
364 MBEDTLS_CIPHER_AES_192_OFB,
365 MBEDTLS_MODE_OFB,
366 192,
367 "AES-192-OFB",
368 16,
369 0,
370 16,
371 &aes_info
372};
373
374static const mbedtls_cipher_info_t aes_256_ofb_info = {
375 MBEDTLS_CIPHER_AES_256_OFB,
376 MBEDTLS_MODE_OFB,
377 256,
378 "AES-256-OFB",
379 16,
380 0,
381 16,
382 &aes_info
383};
384#endif /* MBEDTLS_CIPHER_MODE_OFB */
385
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200386#if defined(MBEDTLS_CIPHER_MODE_CTR)
387static const mbedtls_cipher_info_t aes_128_ctr_info = {
388 MBEDTLS_CIPHER_AES_128_CTR,
389 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000390 128,
391 "AES-128-CTR",
392 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200393 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000394 16,
395 &aes_info
396};
397
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200398static const mbedtls_cipher_info_t aes_192_ctr_info = {
399 MBEDTLS_CIPHER_AES_192_CTR,
400 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000401 192,
402 "AES-192-CTR",
403 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200404 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000405 16,
406 &aes_info
407};
408
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200409static const mbedtls_cipher_info_t aes_256_ctr_info = {
410 MBEDTLS_CIPHER_AES_256_CTR,
411 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000412 256,
413 "AES-256-CTR",
414 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200415 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000416 16,
417 &aes_info
418};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200419#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000420
Jaeden Ameroc6539902018-04-30 17:17:41 +0100421#if defined(MBEDTLS_CIPHER_MODE_XTS)
422static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
423 unsigned int key_bitlen )
424{
425 mbedtls_aes_xts_context *xts_ctx = ctx;
426 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
427}
428
429static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
430 unsigned int key_bitlen )
431{
432 mbedtls_aes_xts_context *xts_ctx = ctx;
433 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
434}
435
436static void *xts_aes_ctx_alloc( void )
437{
438 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
439
440 if( xts_ctx != NULL )
441 mbedtls_aes_xts_init( xts_ctx );
442
443 return( xts_ctx );
444}
445
446static void xts_aes_ctx_free( void *ctx )
447{
448 mbedtls_aes_xts_context *xts_ctx = ctx;
449
450 if( xts_ctx == NULL )
451 return;
452
453 mbedtls_aes_xts_free( xts_ctx );
454 mbedtls_free( xts_ctx );
455}
456
457static const mbedtls_cipher_base_t xts_aes_info = {
458 MBEDTLS_CIPHER_ID_AES,
459 NULL,
460#if defined(MBEDTLS_CIPHER_MODE_CBC)
461 NULL,
462#endif
463#if defined(MBEDTLS_CIPHER_MODE_CFB)
464 NULL,
465#endif
466#if defined(MBEDTLS_CIPHER_MODE_OFB)
467 NULL,
468#endif
469#if defined(MBEDTLS_CIPHER_MODE_CTR)
470 NULL,
471#endif
472#if defined(MBEDTLS_CIPHER_MODE_XTS)
473 aes_crypt_xts_wrap,
474#endif
475#if defined(MBEDTLS_CIPHER_MODE_STREAM)
476 NULL,
477#endif
478 xts_aes_setkey_enc_wrap,
479 xts_aes_setkey_dec_wrap,
480 xts_aes_ctx_alloc,
481 xts_aes_ctx_free
482};
483
484static const mbedtls_cipher_info_t aes_128_xts_info = {
485 MBEDTLS_CIPHER_AES_128_XTS,
486 MBEDTLS_MODE_XTS,
487 256,
488 "AES-128-XTS",
489 16,
490 0,
491 16,
492 &xts_aes_info
493};
494
495static const mbedtls_cipher_info_t aes_256_xts_info = {
496 MBEDTLS_CIPHER_AES_256_XTS,
497 MBEDTLS_MODE_XTS,
498 512,
499 "AES-256-XTS",
500 16,
501 0,
502 16,
503 &xts_aes_info
504};
505#endif /* MBEDTLS_CIPHER_MODE_XTS */
506
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200507#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200508static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200509 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200510{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200511 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200512 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200513}
514
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200515static const mbedtls_cipher_base_t gcm_aes_info = {
516 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200517 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200518#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200519 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100520#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200522 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100523#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100524#if defined(MBEDTLS_CIPHER_MODE_OFB)
525 NULL,
526#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200528 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100529#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100530#if defined(MBEDTLS_CIPHER_MODE_XTS)
531 NULL,
532#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200533#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200534 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100535#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200536 gcm_aes_setkey_wrap,
537 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200538 gcm_ctx_alloc,
539 gcm_ctx_free,
540};
541
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200542static const mbedtls_cipher_info_t aes_128_gcm_info = {
543 MBEDTLS_CIPHER_AES_128_GCM,
544 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100545 128,
546 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200547 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200548 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100549 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200550 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100551};
552
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200553static const mbedtls_cipher_info_t aes_192_gcm_info = {
554 MBEDTLS_CIPHER_AES_192_GCM,
555 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200556 192,
557 "AES-192-GCM",
558 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200559 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200560 16,
561 &gcm_aes_info
562};
563
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200564static const mbedtls_cipher_info_t aes_256_gcm_info = {
565 MBEDTLS_CIPHER_AES_256_GCM,
566 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100567 256,
568 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200569 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200570 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100571 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200572 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100573};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100575
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200576#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200577static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200578 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200579{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200580 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200581 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200582}
583
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200584static const mbedtls_cipher_base_t ccm_aes_info = {
585 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200586 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200587#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200588 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100589#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200590#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200591 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100592#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100593#if defined(MBEDTLS_CIPHER_MODE_OFB)
594 NULL,
595#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200597 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100598#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100599#if defined(MBEDTLS_CIPHER_MODE_XTS)
600 NULL,
601#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200602#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200603 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100604#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200605 ccm_aes_setkey_wrap,
606 ccm_aes_setkey_wrap,
607 ccm_ctx_alloc,
608 ccm_ctx_free,
609};
610
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200611static const mbedtls_cipher_info_t aes_128_ccm_info = {
612 MBEDTLS_CIPHER_AES_128_CCM,
613 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200614 128,
615 "AES-128-CCM",
616 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200617 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200618 16,
619 &ccm_aes_info
620};
621
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200622static const mbedtls_cipher_info_t aes_192_ccm_info = {
623 MBEDTLS_CIPHER_AES_192_CCM,
624 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200625 192,
626 "AES-192-CCM",
627 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200628 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200629 16,
630 &ccm_aes_info
631};
632
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200633static const mbedtls_cipher_info_t aes_256_ccm_info = {
634 MBEDTLS_CIPHER_AES_256_CCM,
635 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200636 256,
637 "AES-256-CCM",
638 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200639 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200640 16,
641 &ccm_aes_info
642};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200643#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200644
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200645#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000646
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200647#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000648
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200649static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200650 const unsigned char *input, unsigned char *output )
651{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200653 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200654}
655
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200656#if defined(MBEDTLS_CIPHER_MODE_CBC)
657static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200658 size_t length, unsigned char *iv,
659 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000660{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200662 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000663}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200664#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000665
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200666#if defined(MBEDTLS_CIPHER_MODE_CFB)
667static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200668 size_t length, size_t *iv_off, unsigned char *iv,
669 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000670{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200671 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200672 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000673}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000675
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200677static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
678 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000679 const unsigned char *input, unsigned char *output )
680{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200681 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200682 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000683}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200684#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000685
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200686static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200687 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000688{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200689 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000690}
691
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200692static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200693 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000694{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200695 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000696}
697
698static void * camellia_ctx_alloc( void )
699{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200701 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200702
703 if( ctx == NULL )
704 return( NULL );
705
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200706 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200707
708 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000709}
710
711static void camellia_ctx_free( void *ctx )
712{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200713 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
714 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000715}
716
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200717static const mbedtls_cipher_base_t camellia_info = {
718 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200719 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200720#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000721 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100722#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200723#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000724 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100725#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100726#if defined(MBEDTLS_CIPHER_MODE_OFB)
727 NULL,
728#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000730 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100731#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100732#if defined(MBEDTLS_CIPHER_MODE_XTS)
733 NULL,
734#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200736 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100737#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000738 camellia_setkey_enc_wrap,
739 camellia_setkey_dec_wrap,
740 camellia_ctx_alloc,
741 camellia_ctx_free
742};
743
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200744static const mbedtls_cipher_info_t camellia_128_ecb_info = {
745 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
746 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200747 128,
748 "CAMELLIA-128-ECB",
749 16,
750 0,
751 16,
752 &camellia_info
753};
754
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755static const mbedtls_cipher_info_t camellia_192_ecb_info = {
756 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
757 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200758 192,
759 "CAMELLIA-192-ECB",
760 16,
761 0,
762 16,
763 &camellia_info
764};
765
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200766static const mbedtls_cipher_info_t camellia_256_ecb_info = {
767 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
768 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200769 256,
770 "CAMELLIA-256-ECB",
771 16,
772 0,
773 16,
774 &camellia_info
775};
776
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200777#if defined(MBEDTLS_CIPHER_MODE_CBC)
778static const mbedtls_cipher_info_t camellia_128_cbc_info = {
779 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
780 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000781 128,
782 "CAMELLIA-128-CBC",
783 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200784 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000785 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000786 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000787};
788
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200789static const mbedtls_cipher_info_t camellia_192_cbc_info = {
790 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
791 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000792 192,
793 "CAMELLIA-192-CBC",
794 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200795 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000796 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000797 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000798};
799
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200800static const mbedtls_cipher_info_t camellia_256_cbc_info = {
801 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
802 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000803 256,
804 "CAMELLIA-256-CBC",
805 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200806 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000807 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000808 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000809};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200810#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000811
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200812#if defined(MBEDTLS_CIPHER_MODE_CFB)
813static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
814 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
815 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000816 128,
817 "CAMELLIA-128-CFB128",
818 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200819 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000820 16,
821 &camellia_info
822};
823
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200824static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
825 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
826 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000827 192,
828 "CAMELLIA-192-CFB128",
829 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200830 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000831 16,
832 &camellia_info
833};
834
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200835static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
836 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
837 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000838 256,
839 "CAMELLIA-256-CFB128",
840 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200841 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000842 16,
843 &camellia_info
844};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200845#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000846
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200847#if defined(MBEDTLS_CIPHER_MODE_CTR)
848static const mbedtls_cipher_info_t camellia_128_ctr_info = {
849 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
850 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000851 128,
852 "CAMELLIA-128-CTR",
853 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200854 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000855 16,
856 &camellia_info
857};
858
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200859static const mbedtls_cipher_info_t camellia_192_ctr_info = {
860 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
861 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000862 192,
863 "CAMELLIA-192-CTR",
864 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200865 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000866 16,
867 &camellia_info
868};
869
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200870static const mbedtls_cipher_info_t camellia_256_ctr_info = {
871 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
872 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000873 256,
874 "CAMELLIA-256-CTR",
875 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200876 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000877 16,
878 &camellia_info
879};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200880#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000881
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200882#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200883static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200884 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200885{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200886 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200887 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200888}
889
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200890static const mbedtls_cipher_base_t gcm_camellia_info = {
891 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200892 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200893#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200894 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100895#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200896#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200897 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100898#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100899#if defined(MBEDTLS_CIPHER_MODE_OFB)
900 NULL,
901#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200903 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100904#endif
Jaeden Ameroc6539902018-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é-Gonnard87181d12013-10-24 14:02:40 +0200909 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100910#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200911 gcm_camellia_setkey_wrap,
912 gcm_camellia_setkey_wrap,
913 gcm_ctx_alloc,
914 gcm_ctx_free,
915};
916
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200917static const mbedtls_cipher_info_t camellia_128_gcm_info = {
918 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
919 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200920 128,
921 "CAMELLIA-128-GCM",
922 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200923 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200924 16,
925 &gcm_camellia_info
926};
927
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200928static const mbedtls_cipher_info_t camellia_192_gcm_info = {
929 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
930 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200931 192,
932 "CAMELLIA-192-GCM",
933 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200934 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200935 16,
936 &gcm_camellia_info
937};
938
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200939static const mbedtls_cipher_info_t camellia_256_gcm_info = {
940 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
941 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200942 256,
943 "CAMELLIA-256-GCM",
944 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200945 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200946 16,
947 &gcm_camellia_info
948};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200949#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200950
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200951#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200952static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200953 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200954{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200955 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200956 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200957}
958
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200959static const mbedtls_cipher_base_t ccm_camellia_info = {
960 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200961 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200962#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200963 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100964#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200965#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200966 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100967#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100968#if defined(MBEDTLS_CIPHER_MODE_OFB)
969 NULL,
970#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200971#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200972 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100973#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100974#if defined(MBEDTLS_CIPHER_MODE_XTS)
975 NULL,
976#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200977#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200978 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100979#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200980 ccm_camellia_setkey_wrap,
981 ccm_camellia_setkey_wrap,
982 ccm_ctx_alloc,
983 ccm_ctx_free,
984};
985
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200986static const mbedtls_cipher_info_t camellia_128_ccm_info = {
987 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
988 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200989 128,
990 "CAMELLIA-128-CCM",
991 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200992 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200993 16,
994 &ccm_camellia_info
995};
996
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200997static const mbedtls_cipher_info_t camellia_192_ccm_info = {
998 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
999 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001000 192,
1001 "CAMELLIA-192-CCM",
1002 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001003 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001004 16,
1005 &ccm_camellia_info
1006};
1007
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001008static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1009 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1010 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001011 256,
1012 "CAMELLIA-256-CCM",
1013 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001014 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001015 16,
1016 &ccm_camellia_info
1017};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001018#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001019
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001020#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001021
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001022#if defined(MBEDTLS_ARIA_C)
1023
1024static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1025 const unsigned char *input, unsigned char *output )
1026{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001027 (void) operation;
1028 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001029 output );
1030}
1031
1032#if defined(MBEDTLS_CIPHER_MODE_CBC)
1033static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1034 size_t length, unsigned char *iv,
1035 const unsigned char *input, unsigned char *output )
1036{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001037 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001038 input, output );
1039}
1040#endif /* MBEDTLS_CIPHER_MODE_CBC */
1041
1042#if defined(MBEDTLS_CIPHER_MODE_CFB)
1043static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1044 size_t length, size_t *iv_off, unsigned char *iv,
1045 const unsigned char *input, unsigned char *output )
1046{
1047 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1048 iv_off, iv, input, output );
1049}
1050#endif /* MBEDTLS_CIPHER_MODE_CFB */
1051
1052#if defined(MBEDTLS_CIPHER_MODE_CTR)
1053static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1054 unsigned char *nonce_counter, unsigned char *stream_block,
1055 const unsigned char *input, unsigned char *output )
1056{
1057 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1058 nonce_counter, stream_block, input, output );
1059}
1060#endif /* MBEDTLS_CIPHER_MODE_CTR */
1061
1062static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1063 unsigned int key_bitlen )
1064{
1065 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1066}
1067
1068static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1069 unsigned int key_bitlen )
1070{
1071 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1072}
1073
1074static void * aria_ctx_alloc( void )
1075{
1076 mbedtls_aria_context *ctx;
1077 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1078
1079 if( ctx == NULL )
1080 return( NULL );
1081
1082 mbedtls_aria_init( ctx );
1083
1084 return( ctx );
1085}
1086
1087static void aria_ctx_free( void *ctx )
1088{
1089 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1090 mbedtls_free( ctx );
1091}
1092
1093static const mbedtls_cipher_base_t aria_info = {
1094 MBEDTLS_CIPHER_ID_ARIA,
1095 aria_crypt_ecb_wrap,
1096#if defined(MBEDTLS_CIPHER_MODE_CBC)
1097 aria_crypt_cbc_wrap,
1098#endif
1099#if defined(MBEDTLS_CIPHER_MODE_CFB)
1100 aria_crypt_cfb128_wrap,
1101#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001102#if defined(MBEDTLS_CIPHER_MODE_OFB)
1103 NULL,
1104#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001105#if defined(MBEDTLS_CIPHER_MODE_CTR)
1106 aria_crypt_ctr_wrap,
1107#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001108#if defined(MBEDTLS_CIPHER_MODE_XTS)
1109 NULL,
1110#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001111#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1112 NULL,
1113#endif
1114 aria_setkey_enc_wrap,
1115 aria_setkey_dec_wrap,
1116 aria_ctx_alloc,
1117 aria_ctx_free
1118};
1119
1120static const mbedtls_cipher_info_t aria_128_ecb_info = {
1121 MBEDTLS_CIPHER_ARIA_128_ECB,
1122 MBEDTLS_MODE_ECB,
1123 128,
1124 "ARIA-128-ECB",
1125 16,
1126 0,
1127 16,
1128 &aria_info
1129};
1130
1131static const mbedtls_cipher_info_t aria_192_ecb_info = {
1132 MBEDTLS_CIPHER_ARIA_192_ECB,
1133 MBEDTLS_MODE_ECB,
1134 192,
1135 "ARIA-192-ECB",
1136 16,
1137 0,
1138 16,
1139 &aria_info
1140};
1141
1142static const mbedtls_cipher_info_t aria_256_ecb_info = {
1143 MBEDTLS_CIPHER_ARIA_256_ECB,
1144 MBEDTLS_MODE_ECB,
1145 256,
1146 "ARIA-256-ECB",
1147 16,
1148 0,
1149 16,
1150 &aria_info
1151};
1152
1153#if defined(MBEDTLS_CIPHER_MODE_CBC)
1154static const mbedtls_cipher_info_t aria_128_cbc_info = {
1155 MBEDTLS_CIPHER_ARIA_128_CBC,
1156 MBEDTLS_MODE_CBC,
1157 128,
1158 "ARIA-128-CBC",
1159 16,
1160 0,
1161 16,
1162 &aria_info
1163};
1164
1165static const mbedtls_cipher_info_t aria_192_cbc_info = {
1166 MBEDTLS_CIPHER_ARIA_192_CBC,
1167 MBEDTLS_MODE_CBC,
1168 192,
1169 "ARIA-192-CBC",
1170 16,
1171 0,
1172 16,
1173 &aria_info
1174};
1175
1176static const mbedtls_cipher_info_t aria_256_cbc_info = {
1177 MBEDTLS_CIPHER_ARIA_256_CBC,
1178 MBEDTLS_MODE_CBC,
1179 256,
1180 "ARIA-256-CBC",
1181 16,
1182 0,
1183 16,
1184 &aria_info
1185};
1186#endif /* MBEDTLS_CIPHER_MODE_CBC */
1187
1188#if defined(MBEDTLS_CIPHER_MODE_CFB)
1189static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1190 MBEDTLS_CIPHER_ARIA_128_CFB128,
1191 MBEDTLS_MODE_CFB,
1192 128,
1193 "ARIA-128-CFB128",
1194 16,
1195 0,
1196 16,
1197 &aria_info
1198};
1199
1200static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1201 MBEDTLS_CIPHER_ARIA_192_CFB128,
1202 MBEDTLS_MODE_CFB,
1203 192,
1204 "ARIA-192-CFB128",
1205 16,
1206 0,
1207 16,
1208 &aria_info
1209};
1210
1211static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1212 MBEDTLS_CIPHER_ARIA_256_CFB128,
1213 MBEDTLS_MODE_CFB,
1214 256,
1215 "ARIA-256-CFB128",
1216 16,
1217 0,
1218 16,
1219 &aria_info
1220};
1221#endif /* MBEDTLS_CIPHER_MODE_CFB */
1222
1223#if defined(MBEDTLS_CIPHER_MODE_CTR)
1224static const mbedtls_cipher_info_t aria_128_ctr_info = {
1225 MBEDTLS_CIPHER_ARIA_128_CTR,
1226 MBEDTLS_MODE_CTR,
1227 128,
1228 "ARIA-128-CTR",
1229 16,
1230 0,
1231 16,
1232 &aria_info
1233};
1234
1235static const mbedtls_cipher_info_t aria_192_ctr_info = {
1236 MBEDTLS_CIPHER_ARIA_192_CTR,
1237 MBEDTLS_MODE_CTR,
1238 192,
1239 "ARIA-192-CTR",
1240 16,
1241 0,
1242 16,
1243 &aria_info
1244};
1245
1246static const mbedtls_cipher_info_t aria_256_ctr_info = {
1247 MBEDTLS_CIPHER_ARIA_256_CTR,
1248 MBEDTLS_MODE_CTR,
1249 256,
1250 "ARIA-256-CTR",
1251 16,
1252 0,
1253 16,
1254 &aria_info
1255};
1256#endif /* MBEDTLS_CIPHER_MODE_CTR */
1257
1258#if defined(MBEDTLS_GCM_C)
1259static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1260 unsigned int key_bitlen )
1261{
1262 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1263 key, key_bitlen );
1264}
1265
1266static const mbedtls_cipher_base_t gcm_aria_info = {
1267 MBEDTLS_CIPHER_ID_ARIA,
1268 NULL,
1269#if defined(MBEDTLS_CIPHER_MODE_CBC)
1270 NULL,
1271#endif
1272#if defined(MBEDTLS_CIPHER_MODE_CFB)
1273 NULL,
1274#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001275#if defined(MBEDTLS_CIPHER_MODE_OFB)
1276 NULL,
1277#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001278#if defined(MBEDTLS_CIPHER_MODE_CTR)
1279 NULL,
1280#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001281#if defined(MBEDTLS_CIPHER_MODE_XTS)
1282 NULL,
1283#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001284#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1285 NULL,
1286#endif
1287 gcm_aria_setkey_wrap,
1288 gcm_aria_setkey_wrap,
1289 gcm_ctx_alloc,
1290 gcm_ctx_free,
1291};
1292
1293static const mbedtls_cipher_info_t aria_128_gcm_info = {
1294 MBEDTLS_CIPHER_ARIA_128_GCM,
1295 MBEDTLS_MODE_GCM,
1296 128,
1297 "ARIA-128-GCM",
1298 12,
1299 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1300 16,
1301 &gcm_aria_info
1302};
1303
1304static const mbedtls_cipher_info_t aria_192_gcm_info = {
1305 MBEDTLS_CIPHER_ARIA_192_GCM,
1306 MBEDTLS_MODE_GCM,
1307 192,
1308 "ARIA-192-GCM",
1309 12,
1310 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1311 16,
1312 &gcm_aria_info
1313};
1314
1315static const mbedtls_cipher_info_t aria_256_gcm_info = {
1316 MBEDTLS_CIPHER_ARIA_256_GCM,
1317 MBEDTLS_MODE_GCM,
1318 256,
1319 "ARIA-256-GCM",
1320 12,
1321 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1322 16,
1323 &gcm_aria_info
1324};
1325#endif /* MBEDTLS_GCM_C */
1326
1327#if defined(MBEDTLS_CCM_C)
1328static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1329 unsigned int key_bitlen )
1330{
1331 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1332 key, key_bitlen );
1333}
1334
1335static const mbedtls_cipher_base_t ccm_aria_info = {
1336 MBEDTLS_CIPHER_ID_ARIA,
1337 NULL,
1338#if defined(MBEDTLS_CIPHER_MODE_CBC)
1339 NULL,
1340#endif
1341#if defined(MBEDTLS_CIPHER_MODE_CFB)
1342 NULL,
1343#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001344#if defined(MBEDTLS_CIPHER_MODE_OFB)
1345 NULL,
1346#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001347#if defined(MBEDTLS_CIPHER_MODE_CTR)
1348 NULL,
1349#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001350#if defined(MBEDTLS_CIPHER_MODE_XTS)
1351 NULL,
1352#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001353#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1354 NULL,
1355#endif
1356 ccm_aria_setkey_wrap,
1357 ccm_aria_setkey_wrap,
1358 ccm_ctx_alloc,
1359 ccm_ctx_free,
1360};
1361
1362static const mbedtls_cipher_info_t aria_128_ccm_info = {
1363 MBEDTLS_CIPHER_ARIA_128_CCM,
1364 MBEDTLS_MODE_CCM,
1365 128,
1366 "ARIA-128-CCM",
1367 12,
1368 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1369 16,
1370 &ccm_aria_info
1371};
1372
1373static const mbedtls_cipher_info_t aria_192_ccm_info = {
1374 MBEDTLS_CIPHER_ARIA_192_CCM,
1375 MBEDTLS_MODE_CCM,
1376 192,
1377 "ARIA-192-CCM",
1378 12,
1379 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1380 16,
1381 &ccm_aria_info
1382};
1383
1384static const mbedtls_cipher_info_t aria_256_ccm_info = {
1385 MBEDTLS_CIPHER_ARIA_256_CCM,
1386 MBEDTLS_MODE_CCM,
1387 256,
1388 "ARIA-256-CCM",
1389 12,
1390 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1391 16,
1392 &ccm_aria_info
1393};
1394#endif /* MBEDTLS_CCM_C */
1395
1396#endif /* MBEDTLS_ARIA_C */
1397
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001398#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001399
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001400static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001401 const unsigned char *input, unsigned char *output )
1402{
1403 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001404 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001405}
1406
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001407static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001408 const unsigned char *input, unsigned char *output )
1409{
1410 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001411 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001412}
1413
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001414#if defined(MBEDTLS_CIPHER_MODE_CBC)
1415static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001416 unsigned char *iv, const unsigned char *input, unsigned char *output )
1417{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001418 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001419 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001420}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001421#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001422
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001423#if defined(MBEDTLS_CIPHER_MODE_CBC)
1424static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001425 unsigned char *iv, const unsigned char *input, unsigned char *output )
1426{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001427 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001428 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001429}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001430#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001431
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001432static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001433 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001434{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001435 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001436
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001437 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001438}
1439
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001440static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001441 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001442{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001443 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001444
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001445 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001446}
1447
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001448static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001449 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001450{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001451 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001452
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001453 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001454}
1455
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001456static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001457 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001458{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001459 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001460
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001461 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001462}
1463
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001464static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001465 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001466{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001467 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001468
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001469 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001470}
1471
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001472static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001473 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001474{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001475 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001476
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001477 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001478}
1479
1480static void * des_ctx_alloc( void )
1481{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001482 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001483
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001484 if( des == NULL )
1485 return( NULL );
1486
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001487 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001488
1489 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001490}
1491
1492static void des_ctx_free( void *ctx )
1493{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001494 mbedtls_des_free( (mbedtls_des_context *) ctx );
1495 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001496}
1497
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001498static void * des3_ctx_alloc( void )
1499{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001500 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001501 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001502
1503 if( des3 == NULL )
1504 return( NULL );
1505
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001506 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001507
1508 return( des3 );
1509}
1510
Paul Bakker34617722014-06-13 17:20:13 +02001511static void des3_ctx_free( void *ctx )
1512{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001513 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1514 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001515}
1516
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001517static const mbedtls_cipher_base_t des_info = {
1518 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001519 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001520#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001521 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001522#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001523#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001524 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001525#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001526#if defined(MBEDTLS_CIPHER_MODE_OFB)
1527 NULL,
1528#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001530 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001531#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001532#if defined(MBEDTLS_CIPHER_MODE_XTS)
1533 NULL,
1534#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001535#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001536 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001537#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001538 des_setkey_enc_wrap,
1539 des_setkey_dec_wrap,
1540 des_ctx_alloc,
1541 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001542};
1543
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001544static const mbedtls_cipher_info_t des_ecb_info = {
1545 MBEDTLS_CIPHER_DES_ECB,
1546 MBEDTLS_MODE_ECB,
1547 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001548 "DES-ECB",
1549 8,
1550 0,
1551 8,
1552 &des_info
1553};
1554
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001555#if defined(MBEDTLS_CIPHER_MODE_CBC)
1556static const mbedtls_cipher_info_t des_cbc_info = {
1557 MBEDTLS_CIPHER_DES_CBC,
1558 MBEDTLS_MODE_CBC,
1559 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001560 "DES-CBC",
1561 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001562 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001563 8,
1564 &des_info
1565};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001566#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001567
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001568static const mbedtls_cipher_base_t des_ede_info = {
1569 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001570 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001571#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001572 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001573#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001574#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001575 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001576#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001577#if defined(MBEDTLS_CIPHER_MODE_OFB)
1578 NULL,
1579#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001580#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001581 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001582#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001583#if defined(MBEDTLS_CIPHER_MODE_XTS)
1584 NULL,
1585#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001586#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001587 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001588#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001589 des3_set2key_enc_wrap,
1590 des3_set2key_dec_wrap,
1591 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001592 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001593};
1594
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001595static const mbedtls_cipher_info_t des_ede_ecb_info = {
1596 MBEDTLS_CIPHER_DES_EDE_ECB,
1597 MBEDTLS_MODE_ECB,
1598 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001599 "DES-EDE-ECB",
1600 8,
1601 0,
1602 8,
1603 &des_ede_info
1604};
1605
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001606#if defined(MBEDTLS_CIPHER_MODE_CBC)
1607static const mbedtls_cipher_info_t des_ede_cbc_info = {
1608 MBEDTLS_CIPHER_DES_EDE_CBC,
1609 MBEDTLS_MODE_CBC,
1610 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001611 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001612 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001613 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001614 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001615 &des_ede_info
1616};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001617#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001618
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001619static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001620 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001621 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001622#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001623 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001624#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001625#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001626 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001627#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001628#if defined(MBEDTLS_CIPHER_MODE_OFB)
1629 NULL,
1630#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001631#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001632 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001633#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001634#if defined(MBEDTLS_CIPHER_MODE_XTS)
1635 NULL,
1636#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001637#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001638 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001639#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001640 des3_set3key_enc_wrap,
1641 des3_set3key_dec_wrap,
1642 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001643 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001644};
1645
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001646static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1647 MBEDTLS_CIPHER_DES_EDE3_ECB,
1648 MBEDTLS_MODE_ECB,
1649 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001650 "DES-EDE3-ECB",
1651 8,
1652 0,
1653 8,
1654 &des_ede3_info
1655};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001656#if defined(MBEDTLS_CIPHER_MODE_CBC)
1657static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1658 MBEDTLS_CIPHER_DES_EDE3_CBC,
1659 MBEDTLS_MODE_CBC,
1660 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001661 "DES-EDE3-CBC",
1662 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001663 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001664 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001665 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001666};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001667#endif /* MBEDTLS_CIPHER_MODE_CBC */
1668#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001669
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001670#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001671
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001672static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001673 const unsigned char *input, unsigned char *output )
1674{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001675 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001676 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001677}
1678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001679#if defined(MBEDTLS_CIPHER_MODE_CBC)
1680static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001681 size_t length, unsigned char *iv, const unsigned char *input,
1682 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001683{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001684 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001685 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001686}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001687#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001688
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001689#if defined(MBEDTLS_CIPHER_MODE_CFB)
1690static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001691 size_t length, size_t *iv_off, unsigned char *iv,
1692 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001693{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001694 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001695 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001696}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001697#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001698
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001699#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001700static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1701 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001702 const unsigned char *input, unsigned char *output )
1703{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001704 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001705 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001706}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001707#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001708
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001709static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001710 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001711{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001712 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001713}
1714
1715static void * blowfish_ctx_alloc( void )
1716{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001717 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001718 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001719
1720 if( ctx == NULL )
1721 return( NULL );
1722
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001723 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001724
1725 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001726}
1727
1728static void blowfish_ctx_free( void *ctx )
1729{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001730 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1731 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001732}
1733
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001734static const mbedtls_cipher_base_t blowfish_info = {
1735 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001736 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001737#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001738 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001739#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001740#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001741 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001742#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001743#if defined(MBEDTLS_CIPHER_MODE_OFB)
1744 NULL,
1745#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001746#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001747 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001748#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001749#if defined(MBEDTLS_CIPHER_MODE_XTS)
1750 NULL,
1751#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001752#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001753 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001754#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001755 blowfish_setkey_wrap,
1756 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001757 blowfish_ctx_alloc,
1758 blowfish_ctx_free
1759};
1760
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001761static const mbedtls_cipher_info_t blowfish_ecb_info = {
1762 MBEDTLS_CIPHER_BLOWFISH_ECB,
1763 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001764 128,
1765 "BLOWFISH-ECB",
1766 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001767 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001768 8,
1769 &blowfish_info
1770};
1771
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001772#if defined(MBEDTLS_CIPHER_MODE_CBC)
1773static const mbedtls_cipher_info_t blowfish_cbc_info = {
1774 MBEDTLS_CIPHER_BLOWFISH_CBC,
1775 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001776 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001777 "BLOWFISH-CBC",
1778 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001779 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001780 8,
1781 &blowfish_info
1782};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001783#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001784
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001785#if defined(MBEDTLS_CIPHER_MODE_CFB)
1786static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1787 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1788 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001789 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001790 "BLOWFISH-CFB64",
1791 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001792 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001793 8,
1794 &blowfish_info
1795};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001796#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001797
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001798#if defined(MBEDTLS_CIPHER_MODE_CTR)
1799static const mbedtls_cipher_info_t blowfish_ctr_info = {
1800 MBEDTLS_CIPHER_BLOWFISH_CTR,
1801 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001802 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001803 "BLOWFISH-CTR",
1804 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001805 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001806 8,
1807 &blowfish_info
1808};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001809#endif /* MBEDTLS_CIPHER_MODE_CTR */
1810#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001811
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001812#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001813static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1814 const unsigned char *input,
1815 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001816{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001817 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001818}
1819
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001820static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001821 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001822{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001823 /* we get key_bitlen in bits, arc4 expects it in bytes */
1824 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001825 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001826
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001827 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001828 return( 0 );
1829}
1830
1831static void * arc4_ctx_alloc( void )
1832{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001834 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001835
1836 if( ctx == NULL )
1837 return( NULL );
1838
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001839 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001840
1841 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001842}
Paul Bakker68884e32013-01-07 18:20:04 +01001843
1844static void arc4_ctx_free( void *ctx )
1845{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001846 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1847 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001848}
1849
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001850static const mbedtls_cipher_base_t arc4_base_info = {
1851 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001852 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001853#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001854 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001855#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001856#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001857 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001858#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001859#if defined(MBEDTLS_CIPHER_MODE_OFB)
1860 NULL,
1861#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001862#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001863 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001864#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001865#if defined(MBEDTLS_CIPHER_MODE_XTS)
1866 NULL,
1867#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001868#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001869 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001870#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001871 arc4_setkey_wrap,
1872 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001873 arc4_ctx_alloc,
1874 arc4_ctx_free
1875};
1876
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001877static const mbedtls_cipher_info_t arc4_128_info = {
1878 MBEDTLS_CIPHER_ARC4_128,
1879 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001880 128,
1881 "ARC4-128",
1882 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001883 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001884 1,
1885 &arc4_base_info
1886};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001887#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001888
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001889#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001890static int null_crypt_stream( void *ctx, size_t length,
1891 const unsigned char *input,
1892 unsigned char *output )
1893{
1894 ((void) ctx);
1895 memmove( output, input, length );
1896 return( 0 );
1897}
1898
1899static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001900 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001901{
1902 ((void) ctx);
1903 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001904 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001905
1906 return( 0 );
1907}
1908
Paul Bakkerfab5c822012-02-06 16:45:10 +00001909static void * null_ctx_alloc( void )
1910{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001911 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001912}
1913
Paul Bakkerfab5c822012-02-06 16:45:10 +00001914static void null_ctx_free( void *ctx )
1915{
1916 ((void) ctx);
1917}
1918
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001919static const mbedtls_cipher_base_t null_base_info = {
1920 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001921 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001922#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001923 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001924#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001925#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001926 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001927#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001928#if defined(MBEDTLS_CIPHER_MODE_OFB)
1929 NULL,
1930#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001931#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001932 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001933#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001934#if defined(MBEDTLS_CIPHER_MODE_XTS)
1935 NULL,
1936#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001937#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001938 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001939#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001940 null_setkey,
1941 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001942 null_ctx_alloc,
1943 null_ctx_free
1944};
1945
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001946static const mbedtls_cipher_info_t null_cipher_info = {
1947 MBEDTLS_CIPHER_NULL,
1948 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001949 0,
1950 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001951 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001952 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001953 1,
1954 &null_base_info
1955};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001956#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001957
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001958const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001959{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001960#if defined(MBEDTLS_AES_C)
1961 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1962 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1963 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1964#if defined(MBEDTLS_CIPHER_MODE_CBC)
1965 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1966 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1967 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001968#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001969#if defined(MBEDTLS_CIPHER_MODE_CFB)
1970 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1971 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1972 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001973#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001974#if defined(MBEDTLS_CIPHER_MODE_OFB)
1975 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
1976 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
1977 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
1978#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001979#if defined(MBEDTLS_CIPHER_MODE_CTR)
1980 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1981 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1982 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001983#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001984#if defined(MBEDTLS_CIPHER_MODE_XTS)
1985 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
1986 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
1987#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001988#if defined(MBEDTLS_GCM_C)
1989 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1990 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1991 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001992#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001993#if defined(MBEDTLS_CCM_C)
1994 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1995 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1996 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001997#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001998#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001999
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002000#if defined(MBEDTLS_ARC4_C)
2001 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002002#endif
2003
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002004#if defined(MBEDTLS_BLOWFISH_C)
2005 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2006#if defined(MBEDTLS_CIPHER_MODE_CBC)
2007 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002008#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002009#if defined(MBEDTLS_CIPHER_MODE_CFB)
2010 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002011#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002012#if defined(MBEDTLS_CIPHER_MODE_CTR)
2013 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002014#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002015#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002016
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002017#if defined(MBEDTLS_CAMELLIA_C)
2018 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2019 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2020 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2021#if defined(MBEDTLS_CIPHER_MODE_CBC)
2022 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2023 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2024 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002025#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002026#if defined(MBEDTLS_CIPHER_MODE_CFB)
2027 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2028 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2029 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002030#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002031#if defined(MBEDTLS_CIPHER_MODE_CTR)
2032 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2033 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2034 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002035#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002036#if defined(MBEDTLS_GCM_C)
2037 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2038 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2039 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002040#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002041#if defined(MBEDTLS_CCM_C)
2042 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2043 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2044 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002045#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002046#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002047
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002048#if defined(MBEDTLS_ARIA_C)
2049 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2050 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2051 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2052#if defined(MBEDTLS_CIPHER_MODE_CBC)
2053 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2054 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2055 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2056#endif
2057#if defined(MBEDTLS_CIPHER_MODE_CFB)
2058 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2059 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2060 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2061#endif
2062#if defined(MBEDTLS_CIPHER_MODE_CTR)
2063 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2064 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2065 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2066#endif
2067#if defined(MBEDTLS_GCM_C)
2068 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2069 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2070 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2071#endif
2072#if defined(MBEDTLS_CCM_C)
2073 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2074 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2075 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2076#endif
2077#endif /* MBEDTLS_ARIA_C */
2078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002079#if defined(MBEDTLS_DES_C)
2080 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2081 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2082 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2083#if defined(MBEDTLS_CIPHER_MODE_CBC)
2084 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2085 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2086 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002087#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002088#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002089
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002090#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2091 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2092#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002093
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002094 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002095};
2096
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002097#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2098int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002099
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002100#endif /* MBEDTLS_CIPHER_C */