blob: 8c70a4225d1a1accb1a6a5daf318337c3edf82a4 [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é-Gonnarddca3a5d2018-05-07 10:43:27 +020036#if defined(MBEDTLS_CHACHAPOLY_C)
37#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020046#endif
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000050#endif
51
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000052#if defined(MBEDTLS_ARIA_C)
53#include "mbedtls/aria.h"
54#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000058#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000062#endif
63
Daniel Kingbd920622016-05-15 19:56:20 -030064#if defined(MBEDTLS_CHACHA20_C)
65#include "mbedtls/chacha20.h"
66#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020074#endif
75
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000077#include <string.h>
78#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020082#else
Rich Evans00ab4702015-02-06 13:43:58 +000083#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020084#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020089/* shared by all GCM ciphers */
90static void *gcm_ctx_alloc( void )
91{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020092 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
93
94 if( ctx != NULL )
95 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
96
97 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020098}
99
100static void gcm_ctx_free( void *ctx )
101{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102 mbedtls_gcm_free( ctx );
103 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200104}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200108/* shared by all CCM ciphers */
109static void *ccm_ctx_alloc( void )
110{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200111 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
112
113 if( ctx != NULL )
114 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
115
116 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200117}
118
119static void ccm_ctx_free( void *ctx )
120{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121 mbedtls_ccm_free( ctx );
122 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200123}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200129 const unsigned char *input, unsigned char *output )
130{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200132}
133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#if defined(MBEDTLS_CIPHER_MODE_CBC)
135static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000136 unsigned char *iv, const unsigned char *input, unsigned char *output )
137{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200139 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000140}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#if defined(MBEDTLS_CIPHER_MODE_CFB)
144static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200145 size_t length, size_t *iv_off, unsigned char *iv,
146 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000147{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200149 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000150}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000152
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100153#if defined(MBEDTLS_CIPHER_MODE_OFB)
154static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
155 unsigned char *iv, const unsigned char *input, unsigned char *output )
156{
157 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
158 iv, input, output );
159}
160#endif /* MBEDTLS_CIPHER_MODE_OFB */
161
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200163static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
164 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000165 const unsigned char *input, unsigned char *output )
166{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000168 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000169}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000171
Jaeden Ameroc6539902018-04-30 17:17:41 +0100172#if defined(MBEDTLS_CIPHER_MODE_XTS)
173static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
174 size_t length,
175 const unsigned char data_unit[16],
176 const unsigned char *input,
177 unsigned char *output )
178{
179 mbedtls_aes_xts_context *xts_ctx = ctx;
180 int mode;
181
182 switch( operation )
183 {
184 case MBEDTLS_ENCRYPT:
185 mode = MBEDTLS_AES_ENCRYPT;
186 break;
187 case MBEDTLS_DECRYPT:
188 mode = MBEDTLS_AES_DECRYPT;
189 break;
190 default:
191 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
192 }
193
194 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
195 data_unit, input, output );
196}
197#endif /* MBEDTLS_CIPHER_MODE_XTS */
198
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200199static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200200 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000201{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200202 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000203}
204
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200205static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200206 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000207{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200208 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000209}
210
211static void * aes_ctx_alloc( void )
212{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200213 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200214
215 if( aes == NULL )
216 return( NULL );
217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200219
220 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000221}
222
223static void aes_ctx_free( void *ctx )
224{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
226 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000227}
228
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229static const mbedtls_cipher_base_t aes_info = {
230 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200231 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000233 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100234#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000236 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100237#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100238#if defined(MBEDTLS_CIPHER_MODE_OFB)
239 aes_crypt_ofb_wrap,
240#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000242 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100243#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100244#if defined(MBEDTLS_CIPHER_MODE_XTS)
245 NULL,
246#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200248 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100249#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000250 aes_setkey_enc_wrap,
251 aes_setkey_dec_wrap,
252 aes_ctx_alloc,
253 aes_ctx_free
254};
255
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256static const mbedtls_cipher_info_t aes_128_ecb_info = {
257 MBEDTLS_CIPHER_AES_128_ECB,
258 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200259 128,
260 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300261 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200262 0,
263 16,
264 &aes_info
265};
266
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400267#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200268static const mbedtls_cipher_info_t aes_192_ecb_info = {
269 MBEDTLS_CIPHER_AES_192_ECB,
270 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200271 192,
272 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300273 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200274 0,
275 16,
276 &aes_info
277};
278
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200279static const mbedtls_cipher_info_t aes_256_ecb_info = {
280 MBEDTLS_CIPHER_AES_256_ECB,
281 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200282 256,
283 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300284 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200285 0,
286 16,
287 &aes_info
288};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400289#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Paul Bakker5e0efa72013-09-08 23:04:04 +0200290
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200291#if defined(MBEDTLS_CIPHER_MODE_CBC)
292static const mbedtls_cipher_info_t aes_128_cbc_info = {
293 MBEDTLS_CIPHER_AES_128_CBC,
294 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000295 128,
296 "AES-128-CBC",
297 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200298 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000299 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000300 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000301};
302
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400303#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200304static const mbedtls_cipher_info_t aes_192_cbc_info = {
305 MBEDTLS_CIPHER_AES_192_CBC,
306 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000307 192,
308 "AES-192-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};
314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315static const mbedtls_cipher_info_t aes_256_cbc_info = {
316 MBEDTLS_CIPHER_AES_256_CBC,
317 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000318 256,
319 "AES-256-CBC",
320 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200321 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000322 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000323 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000324};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400325#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328#if defined(MBEDTLS_CIPHER_MODE_CFB)
329static const mbedtls_cipher_info_t aes_128_cfb128_info = {
330 MBEDTLS_CIPHER_AES_128_CFB128,
331 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000332 128,
333 "AES-128-CFB128",
334 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200335 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000336 16,
337 &aes_info
338};
339
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400340#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200341static const mbedtls_cipher_info_t aes_192_cfb128_info = {
342 MBEDTLS_CIPHER_AES_192_CFB128,
343 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000344 192,
345 "AES-192-CFB128",
346 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200347 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000348 16,
349 &aes_info
350};
351
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352static const mbedtls_cipher_info_t aes_256_cfb128_info = {
353 MBEDTLS_CIPHER_AES_256_CFB128,
354 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000355 256,
356 "AES-256-CFB128",
357 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200358 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000359 16,
360 &aes_info
361};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400362#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200363#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000364
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100365#if defined(MBEDTLS_CIPHER_MODE_OFB)
366static const mbedtls_cipher_info_t aes_128_ofb_info = {
367 MBEDTLS_CIPHER_AES_128_OFB,
368 MBEDTLS_MODE_OFB,
369 128,
370 "AES-128-OFB",
371 16,
372 0,
373 16,
374 &aes_info
375};
376
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400377#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100378static const mbedtls_cipher_info_t aes_192_ofb_info = {
379 MBEDTLS_CIPHER_AES_192_OFB,
380 MBEDTLS_MODE_OFB,
381 192,
382 "AES-192-OFB",
383 16,
384 0,
385 16,
386 &aes_info
387};
388
389static const mbedtls_cipher_info_t aes_256_ofb_info = {
390 MBEDTLS_CIPHER_AES_256_OFB,
391 MBEDTLS_MODE_OFB,
392 256,
393 "AES-256-OFB",
394 16,
395 0,
396 16,
397 &aes_info
398};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400399#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100400#endif /* MBEDTLS_CIPHER_MODE_OFB */
401
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402#if defined(MBEDTLS_CIPHER_MODE_CTR)
403static const mbedtls_cipher_info_t aes_128_ctr_info = {
404 MBEDTLS_CIPHER_AES_128_CTR,
405 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000406 128,
407 "AES-128-CTR",
408 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200409 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000410 16,
411 &aes_info
412};
413
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400414#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415static const mbedtls_cipher_info_t aes_192_ctr_info = {
416 MBEDTLS_CIPHER_AES_192_CTR,
417 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000418 192,
419 "AES-192-CTR",
420 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200421 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000422 16,
423 &aes_info
424};
425
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426static const mbedtls_cipher_info_t aes_256_ctr_info = {
427 MBEDTLS_CIPHER_AES_256_CTR,
428 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000429 256,
430 "AES-256-CTR",
431 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200432 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000433 16,
434 &aes_info
435};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400436#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200437#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000438
Jaeden Ameroc6539902018-04-30 17:17:41 +0100439#if defined(MBEDTLS_CIPHER_MODE_XTS)
440static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
441 unsigned int key_bitlen )
442{
443 mbedtls_aes_xts_context *xts_ctx = ctx;
444 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
445}
446
447static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
448 unsigned int key_bitlen )
449{
450 mbedtls_aes_xts_context *xts_ctx = ctx;
451 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
452}
453
454static void *xts_aes_ctx_alloc( void )
455{
456 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
457
458 if( xts_ctx != NULL )
459 mbedtls_aes_xts_init( xts_ctx );
460
461 return( xts_ctx );
462}
463
464static void xts_aes_ctx_free( void *ctx )
465{
466 mbedtls_aes_xts_context *xts_ctx = ctx;
467
468 if( xts_ctx == NULL )
469 return;
470
471 mbedtls_aes_xts_free( xts_ctx );
472 mbedtls_free( xts_ctx );
473}
474
475static const mbedtls_cipher_base_t xts_aes_info = {
476 MBEDTLS_CIPHER_ID_AES,
477 NULL,
478#if defined(MBEDTLS_CIPHER_MODE_CBC)
479 NULL,
480#endif
481#if defined(MBEDTLS_CIPHER_MODE_CFB)
482 NULL,
483#endif
484#if defined(MBEDTLS_CIPHER_MODE_OFB)
485 NULL,
486#endif
487#if defined(MBEDTLS_CIPHER_MODE_CTR)
488 NULL,
489#endif
490#if defined(MBEDTLS_CIPHER_MODE_XTS)
491 aes_crypt_xts_wrap,
492#endif
493#if defined(MBEDTLS_CIPHER_MODE_STREAM)
494 NULL,
495#endif
496 xts_aes_setkey_enc_wrap,
497 xts_aes_setkey_dec_wrap,
498 xts_aes_ctx_alloc,
499 xts_aes_ctx_free
500};
501
502static const mbedtls_cipher_info_t aes_128_xts_info = {
503 MBEDTLS_CIPHER_AES_128_XTS,
504 MBEDTLS_MODE_XTS,
505 256,
506 "AES-128-XTS",
507 16,
508 0,
509 16,
510 &xts_aes_info
511};
512
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400513#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Jaeden Ameroc6539902018-04-30 17:17:41 +0100514static const mbedtls_cipher_info_t aes_256_xts_info = {
515 MBEDTLS_CIPHER_AES_256_XTS,
516 MBEDTLS_MODE_XTS,
517 512,
518 "AES-256-XTS",
519 16,
520 0,
521 16,
522 &xts_aes_info
523};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400524#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Jaeden Ameroc6539902018-04-30 17:17:41 +0100525#endif /* MBEDTLS_CIPHER_MODE_XTS */
526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200528static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200529 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200530{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200531 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200532 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200533}
534
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200535static const mbedtls_cipher_base_t gcm_aes_info = {
536 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200537 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200538#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200539 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100540#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200541#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200542 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100543#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100544#if defined(MBEDTLS_CIPHER_MODE_OFB)
545 NULL,
546#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200548 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100549#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100550#if defined(MBEDTLS_CIPHER_MODE_XTS)
551 NULL,
552#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200553#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200554 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100555#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200556 gcm_aes_setkey_wrap,
557 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200558 gcm_ctx_alloc,
559 gcm_ctx_free,
560};
561
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562static const mbedtls_cipher_info_t aes_128_gcm_info = {
563 MBEDTLS_CIPHER_AES_128_GCM,
564 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100565 128,
566 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200567 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200568 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100569 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200570 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100571};
572
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400573#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574static const mbedtls_cipher_info_t aes_192_gcm_info = {
575 MBEDTLS_CIPHER_AES_192_GCM,
576 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200577 192,
578 "AES-192-GCM",
579 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200581 16,
582 &gcm_aes_info
583};
584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200585static const mbedtls_cipher_info_t aes_256_gcm_info = {
586 MBEDTLS_CIPHER_AES_256_GCM,
587 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100588 256,
589 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200590 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200591 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100592 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200593 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100594};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400595#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100597
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200599static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200600 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200601{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200602 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200603 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200604}
605
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200606static const mbedtls_cipher_base_t ccm_aes_info = {
607 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200608 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200609#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200610 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100611#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200612#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200613 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100614#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100615#if defined(MBEDTLS_CIPHER_MODE_OFB)
616 NULL,
617#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200618#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200619 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100620#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100621#if defined(MBEDTLS_CIPHER_MODE_XTS)
622 NULL,
623#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200624#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200625 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100626#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200627 ccm_aes_setkey_wrap,
628 ccm_aes_setkey_wrap,
629 ccm_ctx_alloc,
630 ccm_ctx_free,
631};
632
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200633static const mbedtls_cipher_info_t aes_128_ccm_info = {
634 MBEDTLS_CIPHER_AES_128_CCM,
635 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200636 128,
637 "AES-128-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};
643
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400644#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200645static const mbedtls_cipher_info_t aes_192_ccm_info = {
646 MBEDTLS_CIPHER_AES_192_CCM,
647 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200648 192,
649 "AES-192-CCM",
650 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200652 16,
653 &ccm_aes_info
654};
655
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200656static const mbedtls_cipher_info_t aes_256_ccm_info = {
657 MBEDTLS_CIPHER_AES_256_CCM,
658 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200659 256,
660 "AES-256-CCM",
661 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200662 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200663 16,
664 &ccm_aes_info
665};
Andrzej Kurek77647bd2020-06-29 11:22:25 -0400666#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200667#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200668
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200669#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000670
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200671#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000672
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200674 const unsigned char *input, unsigned char *output )
675{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200677 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200678}
679
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680#if defined(MBEDTLS_CIPHER_MODE_CBC)
681static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200682 size_t length, unsigned char *iv,
683 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000684{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200686 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000687}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000689
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200690#if defined(MBEDTLS_CIPHER_MODE_CFB)
691static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200692 size_t length, size_t *iv_off, unsigned char *iv,
693 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000694{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200695 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200696 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000697}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200698#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000699
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200701static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
702 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000703 const unsigned char *input, unsigned char *output )
704{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200705 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200706 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000707}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000709
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200710static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200711 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000712{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200713 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000714}
715
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200716static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200717 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000718{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200719 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000720}
721
722static void * camellia_ctx_alloc( void )
723{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200724 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200725 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200726
727 if( ctx == NULL )
728 return( NULL );
729
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200730 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200731
732 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000733}
734
735static void camellia_ctx_free( void *ctx )
736{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200737 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
738 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000739}
740
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741static const mbedtls_cipher_base_t camellia_info = {
742 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200743 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200744#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000745 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100746#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200747#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000748 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100749#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100750#if defined(MBEDTLS_CIPHER_MODE_OFB)
751 NULL,
752#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200753#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000754 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100755#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100756#if defined(MBEDTLS_CIPHER_MODE_XTS)
757 NULL,
758#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200759#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200760 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100761#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000762 camellia_setkey_enc_wrap,
763 camellia_setkey_dec_wrap,
764 camellia_ctx_alloc,
765 camellia_ctx_free
766};
767
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768static const mbedtls_cipher_info_t camellia_128_ecb_info = {
769 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
770 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200771 128,
772 "CAMELLIA-128-ECB",
773 16,
774 0,
775 16,
776 &camellia_info
777};
778
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200779static const mbedtls_cipher_info_t camellia_192_ecb_info = {
780 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
781 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200782 192,
783 "CAMELLIA-192-ECB",
784 16,
785 0,
786 16,
787 &camellia_info
788};
789
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200790static const mbedtls_cipher_info_t camellia_256_ecb_info = {
791 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
792 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200793 256,
794 "CAMELLIA-256-ECB",
795 16,
796 0,
797 16,
798 &camellia_info
799};
800
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200801#if defined(MBEDTLS_CIPHER_MODE_CBC)
802static const mbedtls_cipher_info_t camellia_128_cbc_info = {
803 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
804 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000805 128,
806 "CAMELLIA-128-CBC",
807 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200808 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000809 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000810 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000811};
812
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200813static const mbedtls_cipher_info_t camellia_192_cbc_info = {
814 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
815 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000816 192,
817 "CAMELLIA-192-CBC",
818 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200819 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000820 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000821 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000822};
823
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200824static const mbedtls_cipher_info_t camellia_256_cbc_info = {
825 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
826 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000827 256,
828 "CAMELLIA-256-CBC",
829 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200830 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000831 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000832 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000833};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200834#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000835
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836#if defined(MBEDTLS_CIPHER_MODE_CFB)
837static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
838 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
839 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000840 128,
841 "CAMELLIA-128-CFB128",
842 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200843 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000844 16,
845 &camellia_info
846};
847
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200848static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
849 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
850 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000851 192,
852 "CAMELLIA-192-CFB128",
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_256_cfb128_info = {
860 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
861 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000862 256,
863 "CAMELLIA-256-CFB128",
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};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200869#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000870
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200871#if defined(MBEDTLS_CIPHER_MODE_CTR)
872static const mbedtls_cipher_info_t camellia_128_ctr_info = {
873 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
874 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000875 128,
876 "CAMELLIA-128-CTR",
877 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200878 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000879 16,
880 &camellia_info
881};
882
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200883static const mbedtls_cipher_info_t camellia_192_ctr_info = {
884 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
885 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000886 192,
887 "CAMELLIA-192-CTR",
888 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200889 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000890 16,
891 &camellia_info
892};
893
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200894static const mbedtls_cipher_info_t camellia_256_ctr_info = {
895 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
896 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000897 256,
898 "CAMELLIA-256-CTR",
899 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200900 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000901 16,
902 &camellia_info
903};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200904#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000905
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200906#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200907static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200908 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200909{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200910 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200911 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200912}
913
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200914static const mbedtls_cipher_base_t gcm_camellia_info = {
915 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200916 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200917#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200918 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100919#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200920#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200921 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100922#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100923#if defined(MBEDTLS_CIPHER_MODE_OFB)
924 NULL,
925#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200926#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200927 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100928#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100929#if defined(MBEDTLS_CIPHER_MODE_XTS)
930 NULL,
931#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200932#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200933 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100934#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200935 gcm_camellia_setkey_wrap,
936 gcm_camellia_setkey_wrap,
937 gcm_ctx_alloc,
938 gcm_ctx_free,
939};
940
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200941static const mbedtls_cipher_info_t camellia_128_gcm_info = {
942 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
943 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200944 128,
945 "CAMELLIA-128-GCM",
946 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200948 16,
949 &gcm_camellia_info
950};
951
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200952static const mbedtls_cipher_info_t camellia_192_gcm_info = {
953 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
954 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200955 192,
956 "CAMELLIA-192-GCM",
957 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200958 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200959 16,
960 &gcm_camellia_info
961};
962
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200963static const mbedtls_cipher_info_t camellia_256_gcm_info = {
964 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
965 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200966 256,
967 "CAMELLIA-256-GCM",
968 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200969 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200970 16,
971 &gcm_camellia_info
972};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200973#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200974
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200975#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200976static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200977 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200978{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200979 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200980 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200981}
982
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200983static const mbedtls_cipher_base_t ccm_camellia_info = {
984 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200985 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200986#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200987 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100988#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200989#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200990 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100991#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100992#if defined(MBEDTLS_CIPHER_MODE_OFB)
993 NULL,
994#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200995#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200996 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100997#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100998#if defined(MBEDTLS_CIPHER_MODE_XTS)
999 NULL,
1000#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001001#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001002 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001003#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001004 ccm_camellia_setkey_wrap,
1005 ccm_camellia_setkey_wrap,
1006 ccm_ctx_alloc,
1007 ccm_ctx_free,
1008};
1009
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001010static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1011 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1012 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001013 128,
1014 "CAMELLIA-128-CCM",
1015 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001016 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001017 16,
1018 &ccm_camellia_info
1019};
1020
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001021static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1022 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1023 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001024 192,
1025 "CAMELLIA-192-CCM",
1026 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001027 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001028 16,
1029 &ccm_camellia_info
1030};
1031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001032static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1033 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1034 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001035 256,
1036 "CAMELLIA-256-CCM",
1037 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001038 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001039 16,
1040 &ccm_camellia_info
1041};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001042#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001043
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001044#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001045
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001046#if defined(MBEDTLS_ARIA_C)
1047
1048static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1049 const unsigned char *input, unsigned char *output )
1050{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001051 (void) operation;
1052 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001053 output );
1054}
1055
1056#if defined(MBEDTLS_CIPHER_MODE_CBC)
1057static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1058 size_t length, unsigned char *iv,
1059 const unsigned char *input, unsigned char *output )
1060{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001061 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001062 input, output );
1063}
1064#endif /* MBEDTLS_CIPHER_MODE_CBC */
1065
1066#if defined(MBEDTLS_CIPHER_MODE_CFB)
1067static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1068 size_t length, size_t *iv_off, unsigned char *iv,
1069 const unsigned char *input, unsigned char *output )
1070{
1071 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1072 iv_off, iv, input, output );
1073}
1074#endif /* MBEDTLS_CIPHER_MODE_CFB */
1075
1076#if defined(MBEDTLS_CIPHER_MODE_CTR)
1077static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1078 unsigned char *nonce_counter, unsigned char *stream_block,
1079 const unsigned char *input, unsigned char *output )
1080{
1081 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1082 nonce_counter, stream_block, input, output );
1083}
1084#endif /* MBEDTLS_CIPHER_MODE_CTR */
1085
1086static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1087 unsigned int key_bitlen )
1088{
1089 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1090}
1091
1092static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1093 unsigned int key_bitlen )
1094{
1095 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1096}
1097
1098static void * aria_ctx_alloc( void )
1099{
1100 mbedtls_aria_context *ctx;
1101 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1102
1103 if( ctx == NULL )
1104 return( NULL );
1105
1106 mbedtls_aria_init( ctx );
1107
1108 return( ctx );
1109}
1110
1111static void aria_ctx_free( void *ctx )
1112{
1113 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1114 mbedtls_free( ctx );
1115}
1116
1117static const mbedtls_cipher_base_t aria_info = {
1118 MBEDTLS_CIPHER_ID_ARIA,
1119 aria_crypt_ecb_wrap,
1120#if defined(MBEDTLS_CIPHER_MODE_CBC)
1121 aria_crypt_cbc_wrap,
1122#endif
1123#if defined(MBEDTLS_CIPHER_MODE_CFB)
1124 aria_crypt_cfb128_wrap,
1125#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001126#if defined(MBEDTLS_CIPHER_MODE_OFB)
1127 NULL,
1128#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001129#if defined(MBEDTLS_CIPHER_MODE_CTR)
1130 aria_crypt_ctr_wrap,
1131#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001132#if defined(MBEDTLS_CIPHER_MODE_XTS)
1133 NULL,
1134#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001135#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1136 NULL,
1137#endif
1138 aria_setkey_enc_wrap,
1139 aria_setkey_dec_wrap,
1140 aria_ctx_alloc,
1141 aria_ctx_free
1142};
1143
1144static const mbedtls_cipher_info_t aria_128_ecb_info = {
1145 MBEDTLS_CIPHER_ARIA_128_ECB,
1146 MBEDTLS_MODE_ECB,
1147 128,
1148 "ARIA-128-ECB",
1149 16,
1150 0,
1151 16,
1152 &aria_info
1153};
1154
1155static const mbedtls_cipher_info_t aria_192_ecb_info = {
1156 MBEDTLS_CIPHER_ARIA_192_ECB,
1157 MBEDTLS_MODE_ECB,
1158 192,
1159 "ARIA-192-ECB",
1160 16,
1161 0,
1162 16,
1163 &aria_info
1164};
1165
1166static const mbedtls_cipher_info_t aria_256_ecb_info = {
1167 MBEDTLS_CIPHER_ARIA_256_ECB,
1168 MBEDTLS_MODE_ECB,
1169 256,
1170 "ARIA-256-ECB",
1171 16,
1172 0,
1173 16,
1174 &aria_info
1175};
1176
1177#if defined(MBEDTLS_CIPHER_MODE_CBC)
1178static const mbedtls_cipher_info_t aria_128_cbc_info = {
1179 MBEDTLS_CIPHER_ARIA_128_CBC,
1180 MBEDTLS_MODE_CBC,
1181 128,
1182 "ARIA-128-CBC",
1183 16,
1184 0,
1185 16,
1186 &aria_info
1187};
1188
1189static const mbedtls_cipher_info_t aria_192_cbc_info = {
1190 MBEDTLS_CIPHER_ARIA_192_CBC,
1191 MBEDTLS_MODE_CBC,
1192 192,
1193 "ARIA-192-CBC",
1194 16,
1195 0,
1196 16,
1197 &aria_info
1198};
1199
1200static const mbedtls_cipher_info_t aria_256_cbc_info = {
1201 MBEDTLS_CIPHER_ARIA_256_CBC,
1202 MBEDTLS_MODE_CBC,
1203 256,
1204 "ARIA-256-CBC",
1205 16,
1206 0,
1207 16,
1208 &aria_info
1209};
1210#endif /* MBEDTLS_CIPHER_MODE_CBC */
1211
1212#if defined(MBEDTLS_CIPHER_MODE_CFB)
1213static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1214 MBEDTLS_CIPHER_ARIA_128_CFB128,
1215 MBEDTLS_MODE_CFB,
1216 128,
1217 "ARIA-128-CFB128",
1218 16,
1219 0,
1220 16,
1221 &aria_info
1222};
1223
1224static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1225 MBEDTLS_CIPHER_ARIA_192_CFB128,
1226 MBEDTLS_MODE_CFB,
1227 192,
1228 "ARIA-192-CFB128",
1229 16,
1230 0,
1231 16,
1232 &aria_info
1233};
1234
1235static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1236 MBEDTLS_CIPHER_ARIA_256_CFB128,
1237 MBEDTLS_MODE_CFB,
1238 256,
1239 "ARIA-256-CFB128",
1240 16,
1241 0,
1242 16,
1243 &aria_info
1244};
1245#endif /* MBEDTLS_CIPHER_MODE_CFB */
1246
1247#if defined(MBEDTLS_CIPHER_MODE_CTR)
1248static const mbedtls_cipher_info_t aria_128_ctr_info = {
1249 MBEDTLS_CIPHER_ARIA_128_CTR,
1250 MBEDTLS_MODE_CTR,
1251 128,
1252 "ARIA-128-CTR",
1253 16,
1254 0,
1255 16,
1256 &aria_info
1257};
1258
1259static const mbedtls_cipher_info_t aria_192_ctr_info = {
1260 MBEDTLS_CIPHER_ARIA_192_CTR,
1261 MBEDTLS_MODE_CTR,
1262 192,
1263 "ARIA-192-CTR",
1264 16,
1265 0,
1266 16,
1267 &aria_info
1268};
1269
1270static const mbedtls_cipher_info_t aria_256_ctr_info = {
1271 MBEDTLS_CIPHER_ARIA_256_CTR,
1272 MBEDTLS_MODE_CTR,
1273 256,
1274 "ARIA-256-CTR",
1275 16,
1276 0,
1277 16,
1278 &aria_info
1279};
1280#endif /* MBEDTLS_CIPHER_MODE_CTR */
1281
1282#if defined(MBEDTLS_GCM_C)
1283static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1284 unsigned int key_bitlen )
1285{
1286 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1287 key, key_bitlen );
1288}
1289
1290static const mbedtls_cipher_base_t gcm_aria_info = {
1291 MBEDTLS_CIPHER_ID_ARIA,
1292 NULL,
1293#if defined(MBEDTLS_CIPHER_MODE_CBC)
1294 NULL,
1295#endif
1296#if defined(MBEDTLS_CIPHER_MODE_CFB)
1297 NULL,
1298#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001299#if defined(MBEDTLS_CIPHER_MODE_OFB)
1300 NULL,
1301#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001302#if defined(MBEDTLS_CIPHER_MODE_CTR)
1303 NULL,
1304#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001305#if defined(MBEDTLS_CIPHER_MODE_XTS)
1306 NULL,
1307#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001308#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1309 NULL,
1310#endif
1311 gcm_aria_setkey_wrap,
1312 gcm_aria_setkey_wrap,
1313 gcm_ctx_alloc,
1314 gcm_ctx_free,
1315};
1316
1317static const mbedtls_cipher_info_t aria_128_gcm_info = {
1318 MBEDTLS_CIPHER_ARIA_128_GCM,
1319 MBEDTLS_MODE_GCM,
1320 128,
1321 "ARIA-128-GCM",
1322 12,
1323 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1324 16,
1325 &gcm_aria_info
1326};
1327
1328static const mbedtls_cipher_info_t aria_192_gcm_info = {
1329 MBEDTLS_CIPHER_ARIA_192_GCM,
1330 MBEDTLS_MODE_GCM,
1331 192,
1332 "ARIA-192-GCM",
1333 12,
1334 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1335 16,
1336 &gcm_aria_info
1337};
1338
1339static const mbedtls_cipher_info_t aria_256_gcm_info = {
1340 MBEDTLS_CIPHER_ARIA_256_GCM,
1341 MBEDTLS_MODE_GCM,
1342 256,
1343 "ARIA-256-GCM",
1344 12,
1345 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1346 16,
1347 &gcm_aria_info
1348};
1349#endif /* MBEDTLS_GCM_C */
1350
1351#if defined(MBEDTLS_CCM_C)
1352static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1353 unsigned int key_bitlen )
1354{
1355 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1356 key, key_bitlen );
1357}
1358
1359static const mbedtls_cipher_base_t ccm_aria_info = {
1360 MBEDTLS_CIPHER_ID_ARIA,
1361 NULL,
1362#if defined(MBEDTLS_CIPHER_MODE_CBC)
1363 NULL,
1364#endif
1365#if defined(MBEDTLS_CIPHER_MODE_CFB)
1366 NULL,
1367#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001368#if defined(MBEDTLS_CIPHER_MODE_OFB)
1369 NULL,
1370#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001371#if defined(MBEDTLS_CIPHER_MODE_CTR)
1372 NULL,
1373#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001374#if defined(MBEDTLS_CIPHER_MODE_XTS)
1375 NULL,
1376#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001377#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1378 NULL,
1379#endif
1380 ccm_aria_setkey_wrap,
1381 ccm_aria_setkey_wrap,
1382 ccm_ctx_alloc,
1383 ccm_ctx_free,
1384};
1385
1386static const mbedtls_cipher_info_t aria_128_ccm_info = {
1387 MBEDTLS_CIPHER_ARIA_128_CCM,
1388 MBEDTLS_MODE_CCM,
1389 128,
1390 "ARIA-128-CCM",
1391 12,
1392 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1393 16,
1394 &ccm_aria_info
1395};
1396
1397static const mbedtls_cipher_info_t aria_192_ccm_info = {
1398 MBEDTLS_CIPHER_ARIA_192_CCM,
1399 MBEDTLS_MODE_CCM,
1400 192,
1401 "ARIA-192-CCM",
1402 12,
1403 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1404 16,
1405 &ccm_aria_info
1406};
1407
1408static const mbedtls_cipher_info_t aria_256_ccm_info = {
1409 MBEDTLS_CIPHER_ARIA_256_CCM,
1410 MBEDTLS_MODE_CCM,
1411 256,
1412 "ARIA-256-CCM",
1413 12,
1414 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1415 16,
1416 &ccm_aria_info
1417};
1418#endif /* MBEDTLS_CCM_C */
1419
1420#endif /* MBEDTLS_ARIA_C */
1421
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001422#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001423
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001424static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001425 const unsigned char *input, unsigned char *output )
1426{
1427 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001428 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001429}
1430
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001431static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001432 const unsigned char *input, unsigned char *output )
1433{
1434 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001435 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001436}
1437
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001438#if defined(MBEDTLS_CIPHER_MODE_CBC)
1439static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001440 unsigned char *iv, const unsigned char *input, unsigned char *output )
1441{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001442 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001443 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001444}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001445#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001446
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001447#if defined(MBEDTLS_CIPHER_MODE_CBC)
1448static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001449 unsigned char *iv, const unsigned char *input, unsigned char *output )
1450{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001451 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001452 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001453}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001454#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001455
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001456static int des_setkey_dec_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_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001462}
1463
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001464static int des_setkey_enc_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_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001470}
1471
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001472static int des3_set2key_dec_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_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001478}
1479
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001480static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001481 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001482{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001483 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001484
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001485 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001486}
1487
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001488static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001489 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001490{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001491 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001492
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001493 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001494}
1495
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001496static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001497 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001498{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001499 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001500
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001501 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001502}
1503
1504static void * des_ctx_alloc( void )
1505{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001506 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001507
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001508 if( des == NULL )
1509 return( NULL );
1510
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001511 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001512
1513 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001514}
1515
1516static void des_ctx_free( void *ctx )
1517{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001518 mbedtls_des_free( (mbedtls_des_context *) ctx );
1519 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001520}
1521
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001522static void * des3_ctx_alloc( void )
1523{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001524 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001525 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001526
1527 if( des3 == NULL )
1528 return( NULL );
1529
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001530 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001531
1532 return( des3 );
1533}
1534
Paul Bakker34617722014-06-13 17:20:13 +02001535static void des3_ctx_free( void *ctx )
1536{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001537 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1538 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001539}
1540
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001541static const mbedtls_cipher_base_t des_info = {
1542 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001543 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001544#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001545 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001546#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001547#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001548 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001549#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001550#if defined(MBEDTLS_CIPHER_MODE_OFB)
1551 NULL,
1552#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001553#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001554 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001555#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001556#if defined(MBEDTLS_CIPHER_MODE_XTS)
1557 NULL,
1558#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001559#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001560 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001561#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001562 des_setkey_enc_wrap,
1563 des_setkey_dec_wrap,
1564 des_ctx_alloc,
1565 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001566};
1567
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001568static const mbedtls_cipher_info_t des_ecb_info = {
1569 MBEDTLS_CIPHER_DES_ECB,
1570 MBEDTLS_MODE_ECB,
1571 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001572 "DES-ECB",
1573 8,
1574 0,
1575 8,
1576 &des_info
1577};
1578
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001579#if defined(MBEDTLS_CIPHER_MODE_CBC)
1580static const mbedtls_cipher_info_t des_cbc_info = {
1581 MBEDTLS_CIPHER_DES_CBC,
1582 MBEDTLS_MODE_CBC,
1583 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001584 "DES-CBC",
1585 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001586 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001587 8,
1588 &des_info
1589};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001590#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001591
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001592static const mbedtls_cipher_base_t des_ede_info = {
1593 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001594 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001595#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001596 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001597#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001599 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001600#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001601#if defined(MBEDTLS_CIPHER_MODE_OFB)
1602 NULL,
1603#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001604#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001605 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001606#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001607#if defined(MBEDTLS_CIPHER_MODE_XTS)
1608 NULL,
1609#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001610#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001611 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001612#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001613 des3_set2key_enc_wrap,
1614 des3_set2key_dec_wrap,
1615 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001616 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001617};
1618
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001619static const mbedtls_cipher_info_t des_ede_ecb_info = {
1620 MBEDTLS_CIPHER_DES_EDE_ECB,
1621 MBEDTLS_MODE_ECB,
1622 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001623 "DES-EDE-ECB",
1624 8,
1625 0,
1626 8,
1627 &des_ede_info
1628};
1629
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001630#if defined(MBEDTLS_CIPHER_MODE_CBC)
1631static const mbedtls_cipher_info_t des_ede_cbc_info = {
1632 MBEDTLS_CIPHER_DES_EDE_CBC,
1633 MBEDTLS_MODE_CBC,
1634 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001635 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001636 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001637 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001638 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001639 &des_ede_info
1640};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001641#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001642
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001643static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001644 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001645 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001646#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001647 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001648#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001649#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001650 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001651#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001652#if defined(MBEDTLS_CIPHER_MODE_OFB)
1653 NULL,
1654#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001655#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001656 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001657#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001658#if defined(MBEDTLS_CIPHER_MODE_XTS)
1659 NULL,
1660#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001661#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001662 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001663#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001664 des3_set3key_enc_wrap,
1665 des3_set3key_dec_wrap,
1666 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001667 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001668};
1669
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001670static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1671 MBEDTLS_CIPHER_DES_EDE3_ECB,
1672 MBEDTLS_MODE_ECB,
1673 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001674 "DES-EDE3-ECB",
1675 8,
1676 0,
1677 8,
1678 &des_ede3_info
1679};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001680#if defined(MBEDTLS_CIPHER_MODE_CBC)
1681static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1682 MBEDTLS_CIPHER_DES_EDE3_CBC,
1683 MBEDTLS_MODE_CBC,
1684 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001685 "DES-EDE3-CBC",
1686 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001687 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001688 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001689 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001690};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001691#endif /* MBEDTLS_CIPHER_MODE_CBC */
1692#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001693
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001694#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001695
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001696static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001697 const unsigned char *input, unsigned char *output )
1698{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001699 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001700 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001701}
1702
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001703#if defined(MBEDTLS_CIPHER_MODE_CBC)
1704static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001705 size_t length, unsigned char *iv, const unsigned char *input,
1706 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001707{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001708 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001709 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001710}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001711#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001712
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001713#if defined(MBEDTLS_CIPHER_MODE_CFB)
1714static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001715 size_t length, size_t *iv_off, unsigned char *iv,
1716 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001717{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001718 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001719 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001720}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001721#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001722
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001723#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001724static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1725 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001726 const unsigned char *input, unsigned char *output )
1727{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001728 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001729 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001730}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001731#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001732
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001733static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001734 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001735{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001736 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001737}
1738
1739static void * blowfish_ctx_alloc( void )
1740{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001741 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001742 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001743
1744 if( ctx == NULL )
1745 return( NULL );
1746
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001747 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001748
1749 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001750}
1751
1752static void blowfish_ctx_free( void *ctx )
1753{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001754 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1755 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001756}
1757
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001758static const mbedtls_cipher_base_t blowfish_info = {
1759 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001760 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001761#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001762 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001763#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001764#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001765 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001766#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001767#if defined(MBEDTLS_CIPHER_MODE_OFB)
1768 NULL,
1769#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001770#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001771 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001772#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001773#if defined(MBEDTLS_CIPHER_MODE_XTS)
1774 NULL,
1775#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001776#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001777 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001778#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001779 blowfish_setkey_wrap,
1780 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001781 blowfish_ctx_alloc,
1782 blowfish_ctx_free
1783};
1784
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001785static const mbedtls_cipher_info_t blowfish_ecb_info = {
1786 MBEDTLS_CIPHER_BLOWFISH_ECB,
1787 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001788 128,
1789 "BLOWFISH-ECB",
1790 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001791 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001792 8,
1793 &blowfish_info
1794};
1795
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001796#if defined(MBEDTLS_CIPHER_MODE_CBC)
1797static const mbedtls_cipher_info_t blowfish_cbc_info = {
1798 MBEDTLS_CIPHER_BLOWFISH_CBC,
1799 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001800 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001801 "BLOWFISH-CBC",
1802 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001803 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001804 8,
1805 &blowfish_info
1806};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001807#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001808
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001809#if defined(MBEDTLS_CIPHER_MODE_CFB)
1810static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1811 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1812 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001813 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001814 "BLOWFISH-CFB64",
1815 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001816 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001817 8,
1818 &blowfish_info
1819};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001820#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001821
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001822#if defined(MBEDTLS_CIPHER_MODE_CTR)
1823static const mbedtls_cipher_info_t blowfish_ctr_info = {
1824 MBEDTLS_CIPHER_BLOWFISH_CTR,
1825 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001826 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001827 "BLOWFISH-CTR",
1828 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001829 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001830 8,
1831 &blowfish_info
1832};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833#endif /* MBEDTLS_CIPHER_MODE_CTR */
1834#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001835
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001836#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001837static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1838 const unsigned char *input,
1839 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001840{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001841 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001842}
1843
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001844static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001845 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001846{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001847 /* we get key_bitlen in bits, arc4 expects it in bytes */
1848 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001849 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001850
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001851 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001852 return( 0 );
1853}
1854
1855static void * arc4_ctx_alloc( void )
1856{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001857 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001858 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001859
1860 if( ctx == NULL )
1861 return( NULL );
1862
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001863 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001864
1865 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001866}
Paul Bakker68884e32013-01-07 18:20:04 +01001867
1868static void arc4_ctx_free( void *ctx )
1869{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001870 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1871 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001872}
1873
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001874static const mbedtls_cipher_base_t arc4_base_info = {
1875 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001876 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001877#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001878 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001879#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001880#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001881 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001882#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001883#if defined(MBEDTLS_CIPHER_MODE_OFB)
1884 NULL,
1885#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001886#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001887 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001888#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001889#if defined(MBEDTLS_CIPHER_MODE_XTS)
1890 NULL,
1891#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001892#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001893 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001894#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001895 arc4_setkey_wrap,
1896 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001897 arc4_ctx_alloc,
1898 arc4_ctx_free
1899};
1900
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001901static const mbedtls_cipher_info_t arc4_128_info = {
1902 MBEDTLS_CIPHER_ARC4_128,
1903 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001904 128,
1905 "ARC4-128",
1906 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001907 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001908 1,
1909 &arc4_base_info
1910};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001911#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001912
Daniel Kingbd920622016-05-15 19:56:20 -03001913#if defined(MBEDTLS_CHACHA20_C)
1914
1915static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1916 unsigned int key_bitlen )
1917{
1918 if( key_bitlen != 256U )
1919 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1920
1921 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1922 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1923
1924 return( 0 );
1925}
1926
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001927static int chacha20_stream_wrap( void *ctx, size_t length,
1928 const unsigned char *input,
1929 unsigned char *output )
1930{
1931 int ret;
1932
1933 ret = mbedtls_chacha20_update( ctx, length, input, output );
1934 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1935 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1936
1937 return( ret );
1938}
1939
Daniel Kingbd920622016-05-15 19:56:20 -03001940static void * chacha20_ctx_alloc( void )
1941{
1942 mbedtls_chacha20_context *ctx;
1943 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1944
1945 if( ctx == NULL )
1946 return( NULL );
1947
1948 mbedtls_chacha20_init( ctx );
1949
1950 return( ctx );
1951}
1952
1953static void chacha20_ctx_free( void *ctx )
1954{
1955 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1956 mbedtls_free( ctx );
1957}
1958
1959static const mbedtls_cipher_base_t chacha20_base_info = {
1960 MBEDTLS_CIPHER_ID_CHACHA20,
1961 NULL,
1962#if defined(MBEDTLS_CIPHER_MODE_CBC)
1963 NULL,
1964#endif
1965#if defined(MBEDTLS_CIPHER_MODE_CFB)
1966 NULL,
1967#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001968#if defined(MBEDTLS_CIPHER_MODE_OFB)
1969 NULL,
1970#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001971#if defined(MBEDTLS_CIPHER_MODE_CTR)
1972 NULL,
1973#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001974#if defined(MBEDTLS_CIPHER_MODE_XTS)
1975 NULL,
1976#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001977#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001978 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001979#endif
1980 chacha20_setkey_wrap,
1981 chacha20_setkey_wrap,
1982 chacha20_ctx_alloc,
1983 chacha20_ctx_free
1984};
1985static const mbedtls_cipher_info_t chacha20_info = {
1986 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001987 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001988 256,
1989 "CHACHA20",
1990 12,
1991 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001992 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001993 &chacha20_base_info
1994};
1995#endif /* MBEDTLS_CHACHA20_C */
1996
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001997#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001998
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001999static int chachapoly_setkey_wrap( void *ctx,
2000 const unsigned char *key,
2001 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03002002{
2003 if( key_bitlen != 256U )
2004 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2005
Hanno Becker484caf02019-05-29 14:41:44 +01002006 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context *)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03002007 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2008
2009 return( 0 );
2010}
2011
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002012static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03002013{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002014 mbedtls_chachapoly_context *ctx;
2015 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03002016
2017 if( ctx == NULL )
2018 return( NULL );
2019
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002020 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002021
2022 return( ctx );
2023}
2024
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002025static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002026{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002027 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002028 mbedtls_free( ctx );
2029}
2030
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002031static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002032 MBEDTLS_CIPHER_ID_CHACHA20,
2033 NULL,
2034#if defined(MBEDTLS_CIPHER_MODE_CBC)
2035 NULL,
2036#endif
2037#if defined(MBEDTLS_CIPHER_MODE_CFB)
2038 NULL,
2039#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002040#if defined(MBEDTLS_CIPHER_MODE_OFB)
2041 NULL,
2042#endif
Daniel King8fe47012016-05-17 20:33:28 -03002043#if defined(MBEDTLS_CIPHER_MODE_CTR)
2044 NULL,
2045#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002046#if defined(MBEDTLS_CIPHER_MODE_XTS)
2047 NULL,
2048#endif
Daniel King8fe47012016-05-17 20:33:28 -03002049#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2050 NULL,
2051#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002052 chachapoly_setkey_wrap,
2053 chachapoly_setkey_wrap,
2054 chachapoly_ctx_alloc,
2055 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002056};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002057static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002058 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002059 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002060 256,
2061 "CHACHA20-POLY1305",
2062 12,
2063 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002064 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002065 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002066};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002067#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002068
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002069#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002070static int null_crypt_stream( void *ctx, size_t length,
2071 const unsigned char *input,
2072 unsigned char *output )
2073{
2074 ((void) ctx);
2075 memmove( output, input, length );
2076 return( 0 );
2077}
2078
2079static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002080 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002081{
2082 ((void) ctx);
2083 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002084 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002085
2086 return( 0 );
2087}
2088
Paul Bakkerfab5c822012-02-06 16:45:10 +00002089static void * null_ctx_alloc( void )
2090{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002091 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002092}
2093
Paul Bakkerfab5c822012-02-06 16:45:10 +00002094static void null_ctx_free( void *ctx )
2095{
2096 ((void) ctx);
2097}
2098
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002099static const mbedtls_cipher_base_t null_base_info = {
2100 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002101 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002102#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002103 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002104#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002105#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002106 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002107#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002108#if defined(MBEDTLS_CIPHER_MODE_OFB)
2109 NULL,
2110#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002111#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002112 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002113#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002114#if defined(MBEDTLS_CIPHER_MODE_XTS)
2115 NULL,
2116#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002117#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002118 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002119#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002120 null_setkey,
2121 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002122 null_ctx_alloc,
2123 null_ctx_free
2124};
2125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002126static const mbedtls_cipher_info_t null_cipher_info = {
2127 MBEDTLS_CIPHER_NULL,
2128 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002129 0,
2130 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002131 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002132 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002133 1,
2134 &null_base_info
2135};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002136#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002137
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002138const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002139{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002140#if defined(MBEDTLS_AES_C)
2141 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002142#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002143 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2144 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002145#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002146#if defined(MBEDTLS_CIPHER_MODE_CBC)
2147 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002148#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002149 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2150 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002151#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2152#endif /* MBEDTLS_CIPHER_MODE_CBC */
2153
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002154#if defined(MBEDTLS_CIPHER_MODE_CFB)
2155 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002156#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002157 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2158 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002159#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2160#endif /* MBEDTLS_CIPHER_MODE_CFB */
2161
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002162#if defined(MBEDTLS_CIPHER_MODE_OFB)
2163 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002164#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002165 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2166 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002167#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2168#endif /* MBEDTLS_CIPHER_MODE_OFB */
2169
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002170#if defined(MBEDTLS_CIPHER_MODE_CTR)
2171 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002172#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002173 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2174 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002175#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2176#endif /* MBEDTLS_CIPHER_MODE_CTR */
2177
Jaeden Ameroc6539902018-04-30 17:17:41 +01002178#if defined(MBEDTLS_CIPHER_MODE_XTS)
2179 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002180#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Jaeden Ameroc6539902018-04-30 17:17:41 +01002181 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002182#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2183#endif /* MBEDTLS_CIPHER_MODE_XTS */
2184
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002185#if defined(MBEDTLS_GCM_C)
2186 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002187#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002188 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2189 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002190#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2191#endif /* MBEDTLS_GCM_C */
2192
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002193#if defined(MBEDTLS_CCM_C)
2194 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002195#if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002196 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2197 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Andrzej Kurek77647bd2020-06-29 11:22:25 -04002198#endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
2199#endif /* MBEDTLS_CCM_C */
2200
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002201#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002202
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002203#if defined(MBEDTLS_ARC4_C)
2204 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002205#endif
2206
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002207#if defined(MBEDTLS_BLOWFISH_C)
2208 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2209#if defined(MBEDTLS_CIPHER_MODE_CBC)
2210 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002211#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002212#if defined(MBEDTLS_CIPHER_MODE_CFB)
2213 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002214#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002215#if defined(MBEDTLS_CIPHER_MODE_CTR)
2216 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002217#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002218#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002219
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002220#if defined(MBEDTLS_CAMELLIA_C)
2221 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2222 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2223 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2224#if defined(MBEDTLS_CIPHER_MODE_CBC)
2225 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2226 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2227 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002228#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002229#if defined(MBEDTLS_CIPHER_MODE_CFB)
2230 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2231 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2232 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002233#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002234#if defined(MBEDTLS_CIPHER_MODE_CTR)
2235 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2236 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2237 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002238#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002239#if defined(MBEDTLS_GCM_C)
2240 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2241 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2242 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002243#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002244#if defined(MBEDTLS_CCM_C)
2245 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2246 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2247 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002248#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002249#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002250
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002251#if defined(MBEDTLS_ARIA_C)
2252 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2253 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2254 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2255#if defined(MBEDTLS_CIPHER_MODE_CBC)
2256 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2257 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2258 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2259#endif
2260#if defined(MBEDTLS_CIPHER_MODE_CFB)
2261 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2262 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2263 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2264#endif
2265#if defined(MBEDTLS_CIPHER_MODE_CTR)
2266 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2267 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2268 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2269#endif
2270#if defined(MBEDTLS_GCM_C)
2271 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2272 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2273 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2274#endif
2275#if defined(MBEDTLS_CCM_C)
2276 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2277 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2278 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2279#endif
2280#endif /* MBEDTLS_ARIA_C */
2281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002282#if defined(MBEDTLS_DES_C)
2283 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2284 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2285 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2286#if defined(MBEDTLS_CIPHER_MODE_CBC)
2287 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2288 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2289 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002290#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002291#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002292
Daniel Kingbd920622016-05-15 19:56:20 -03002293#if defined(MBEDTLS_CHACHA20_C)
2294 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2295#endif
2296
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002297#if defined(MBEDTLS_CHACHAPOLY_C)
2298 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002299#endif
2300
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002301#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2302 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2303#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002305 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002306};
2307
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002308#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2309int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002310
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002311#endif /* MBEDTLS_CIPHER_C */