blob: e5ee7ff633775650a01b3e791376b18be2dd9f56 [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
Gilles Peskinedb09ef62020-06-03 01:43:33 +020026#include "common.h"
Paul Bakker8123e9d2011-01-06 15:37:30 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000029
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020030#include "mbedtls/cipher_internal.h"
Janos Follath24eed8d2019-11-22 13:21:35 +000031#include "mbedtls/error.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000032
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020033#if defined(MBEDTLS_CHACHAPOLY_C)
34#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030035#endif
36
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020037#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000038#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000039#endif
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000042#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020043#endif
44
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000046#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000047#endif
48
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000049#if defined(MBEDTLS_ARIA_C)
50#include "mbedtls/aria.h"
51#endif
52
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000054#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000055#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000058#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000059#endif
60
Daniel Kingbd920622016-05-15 19:56:20 -030061#if defined(MBEDTLS_CHACHA20_C)
62#include "mbedtls/chacha20.h"
63#endif
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000066#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020067#endif
68
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020071#endif
72
Jack Lloydffdf2882019-03-07 17:00:32 -050073#if defined(MBEDTLS_NIST_KW_C)
74#include "mbedtls/nist_kw.h"
75#endif
76
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000078#include <string.h>
79#endif
80
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000082#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020083#else
Rich Evans00ab4702015-02-06 13:43:58 +000084#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020085#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020087#endif
88
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020090/* shared by all GCM ciphers */
91static void *gcm_ctx_alloc( void )
92{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020093 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
94
95 if( ctx != NULL )
96 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
97
98 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020099}
100
101static void gcm_ctx_free( void *ctx )
102{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103 mbedtls_gcm_free( ctx );
104 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200105}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200109/* shared by all CCM ciphers */
110static void *ccm_ctx_alloc( void )
111{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200112 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
113
114 if( ctx != NULL )
115 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
116
117 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200118}
119
120static void ccm_ctx_free( void *ctx )
121{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122 mbedtls_ccm_free( ctx );
123 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200124}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000128
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200130 const unsigned char *input, unsigned char *output )
131{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200133}
134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if defined(MBEDTLS_CIPHER_MODE_CBC)
136static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000137 unsigned char *iv, const unsigned char *input, unsigned char *output )
138{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200140 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000141}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000143
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144#if defined(MBEDTLS_CIPHER_MODE_CFB)
145static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200146 size_t length, size_t *iv_off, unsigned char *iv,
147 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000148{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200150 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000151}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000153
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100154#if defined(MBEDTLS_CIPHER_MODE_OFB)
155static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
156 unsigned char *iv, const unsigned char *input, unsigned char *output )
157{
158 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
159 iv, input, output );
160}
161#endif /* MBEDTLS_CIPHER_MODE_OFB */
162
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200164static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
165 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000166 const unsigned char *input, unsigned char *output )
167{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000169 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000170}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000172
Jaeden Ameroc6539902018-04-30 17:17:41 +0100173#if defined(MBEDTLS_CIPHER_MODE_XTS)
174static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
175 size_t length,
176 const unsigned char data_unit[16],
177 const unsigned char *input,
178 unsigned char *output )
179{
180 mbedtls_aes_xts_context *xts_ctx = ctx;
181 int mode;
182
183 switch( operation )
184 {
185 case MBEDTLS_ENCRYPT:
186 mode = MBEDTLS_AES_ENCRYPT;
187 break;
188 case MBEDTLS_DECRYPT:
189 mode = MBEDTLS_AES_DECRYPT;
190 break;
191 default:
192 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
193 }
194
195 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
196 data_unit, input, output );
197}
198#endif /* MBEDTLS_CIPHER_MODE_XTS */
199
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200200static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200201 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000202{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200203 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000204}
205
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200206static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200207 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000208{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200209 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000210}
211
212static void * aes_ctx_alloc( void )
213{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200214 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200215
216 if( aes == NULL )
217 return( NULL );
218
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200219 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200220
221 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000222}
223
224static void aes_ctx_free( void *ctx )
225{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
227 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000228}
229
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200230static const mbedtls_cipher_base_t aes_info = {
231 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200232 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000234 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100235#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000237 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100238#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100239#if defined(MBEDTLS_CIPHER_MODE_OFB)
240 aes_crypt_ofb_wrap,
241#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200242#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000243 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100244#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100245#if defined(MBEDTLS_CIPHER_MODE_XTS)
246 NULL,
247#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200248#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200249 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100250#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000251 aes_setkey_enc_wrap,
252 aes_setkey_dec_wrap,
253 aes_ctx_alloc,
254 aes_ctx_free
255};
256
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257static const mbedtls_cipher_info_t aes_128_ecb_info = {
258 MBEDTLS_CIPHER_AES_128_ECB,
259 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200260 128,
261 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300262 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200263 0,
264 16,
265 &aes_info
266};
267
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};
289
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200290#if defined(MBEDTLS_CIPHER_MODE_CBC)
291static const mbedtls_cipher_info_t aes_128_cbc_info = {
292 MBEDTLS_CIPHER_AES_128_CBC,
293 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000294 128,
295 "AES-128-CBC",
296 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200297 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000298 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000299 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000300};
301
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200302static const mbedtls_cipher_info_t aes_192_cbc_info = {
303 MBEDTLS_CIPHER_AES_192_CBC,
304 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000305 192,
306 "AES-192-CBC",
307 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200308 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000309 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000310 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000311};
312
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313static const mbedtls_cipher_info_t aes_256_cbc_info = {
314 MBEDTLS_CIPHER_AES_256_CBC,
315 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000316 256,
317 "AES-256-CBC",
318 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200319 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000320 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000321 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000322};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200323#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000324
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200325#if defined(MBEDTLS_CIPHER_MODE_CFB)
326static const mbedtls_cipher_info_t aes_128_cfb128_info = {
327 MBEDTLS_CIPHER_AES_128_CFB128,
328 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000329 128,
330 "AES-128-CFB128",
331 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200332 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000333 16,
334 &aes_info
335};
336
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200337static const mbedtls_cipher_info_t aes_192_cfb128_info = {
338 MBEDTLS_CIPHER_AES_192_CFB128,
339 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000340 192,
341 "AES-192-CFB128",
342 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200343 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000344 16,
345 &aes_info
346};
347
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200348static const mbedtls_cipher_info_t aes_256_cfb128_info = {
349 MBEDTLS_CIPHER_AES_256_CFB128,
350 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000351 256,
352 "AES-256-CFB128",
353 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200354 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000355 16,
356 &aes_info
357};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000359
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100360#if defined(MBEDTLS_CIPHER_MODE_OFB)
361static const mbedtls_cipher_info_t aes_128_ofb_info = {
362 MBEDTLS_CIPHER_AES_128_OFB,
363 MBEDTLS_MODE_OFB,
364 128,
365 "AES-128-OFB",
366 16,
367 0,
368 16,
369 &aes_info
370};
371
372static const mbedtls_cipher_info_t aes_192_ofb_info = {
373 MBEDTLS_CIPHER_AES_192_OFB,
374 MBEDTLS_MODE_OFB,
375 192,
376 "AES-192-OFB",
377 16,
378 0,
379 16,
380 &aes_info
381};
382
383static const mbedtls_cipher_info_t aes_256_ofb_info = {
384 MBEDTLS_CIPHER_AES_256_OFB,
385 MBEDTLS_MODE_OFB,
386 256,
387 "AES-256-OFB",
388 16,
389 0,
390 16,
391 &aes_info
392};
393#endif /* MBEDTLS_CIPHER_MODE_OFB */
394
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395#if defined(MBEDTLS_CIPHER_MODE_CTR)
396static const mbedtls_cipher_info_t aes_128_ctr_info = {
397 MBEDTLS_CIPHER_AES_128_CTR,
398 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000399 128,
400 "AES-128-CTR",
401 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200402 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000403 16,
404 &aes_info
405};
406
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200407static const mbedtls_cipher_info_t aes_192_ctr_info = {
408 MBEDTLS_CIPHER_AES_192_CTR,
409 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000410 192,
411 "AES-192-CTR",
412 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200413 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000414 16,
415 &aes_info
416};
417
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200418static const mbedtls_cipher_info_t aes_256_ctr_info = {
419 MBEDTLS_CIPHER_AES_256_CTR,
420 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000421 256,
422 "AES-256-CTR",
423 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200424 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000425 16,
426 &aes_info
427};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200428#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000429
Jaeden Ameroc6539902018-04-30 17:17:41 +0100430#if defined(MBEDTLS_CIPHER_MODE_XTS)
431static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
432 unsigned int key_bitlen )
433{
434 mbedtls_aes_xts_context *xts_ctx = ctx;
435 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
436}
437
438static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
439 unsigned int key_bitlen )
440{
441 mbedtls_aes_xts_context *xts_ctx = ctx;
442 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
443}
444
445static void *xts_aes_ctx_alloc( void )
446{
447 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
448
449 if( xts_ctx != NULL )
450 mbedtls_aes_xts_init( xts_ctx );
451
452 return( xts_ctx );
453}
454
455static void xts_aes_ctx_free( void *ctx )
456{
457 mbedtls_aes_xts_context *xts_ctx = ctx;
458
459 if( xts_ctx == NULL )
460 return;
461
462 mbedtls_aes_xts_free( xts_ctx );
463 mbedtls_free( xts_ctx );
464}
465
466static const mbedtls_cipher_base_t xts_aes_info = {
467 MBEDTLS_CIPHER_ID_AES,
468 NULL,
469#if defined(MBEDTLS_CIPHER_MODE_CBC)
470 NULL,
471#endif
472#if defined(MBEDTLS_CIPHER_MODE_CFB)
473 NULL,
474#endif
475#if defined(MBEDTLS_CIPHER_MODE_OFB)
476 NULL,
477#endif
478#if defined(MBEDTLS_CIPHER_MODE_CTR)
479 NULL,
480#endif
481#if defined(MBEDTLS_CIPHER_MODE_XTS)
482 aes_crypt_xts_wrap,
483#endif
484#if defined(MBEDTLS_CIPHER_MODE_STREAM)
485 NULL,
486#endif
487 xts_aes_setkey_enc_wrap,
488 xts_aes_setkey_dec_wrap,
489 xts_aes_ctx_alloc,
490 xts_aes_ctx_free
491};
492
493static const mbedtls_cipher_info_t aes_128_xts_info = {
494 MBEDTLS_CIPHER_AES_128_XTS,
495 MBEDTLS_MODE_XTS,
496 256,
497 "AES-128-XTS",
498 16,
499 0,
500 16,
501 &xts_aes_info
502};
503
504static const mbedtls_cipher_info_t aes_256_xts_info = {
505 MBEDTLS_CIPHER_AES_256_XTS,
506 MBEDTLS_MODE_XTS,
507 512,
508 "AES-256-XTS",
509 16,
510 0,
511 16,
512 &xts_aes_info
513};
514#endif /* MBEDTLS_CIPHER_MODE_XTS */
515
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200516#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200517static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200518 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200519{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200520 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200521 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200522}
523
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200524static const mbedtls_cipher_base_t gcm_aes_info = {
525 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200526 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200528 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100529#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200531 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100532#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100533#if defined(MBEDTLS_CIPHER_MODE_OFB)
534 NULL,
535#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200536#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200537 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100538#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100539#if defined(MBEDTLS_CIPHER_MODE_XTS)
540 NULL,
541#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200542#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200543 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100544#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200545 gcm_aes_setkey_wrap,
546 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200547 gcm_ctx_alloc,
548 gcm_ctx_free,
549};
550
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551static const mbedtls_cipher_info_t aes_128_gcm_info = {
552 MBEDTLS_CIPHER_AES_128_GCM,
553 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100554 128,
555 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200556 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200557 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100558 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200559 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100560};
561
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562static const mbedtls_cipher_info_t aes_192_gcm_info = {
563 MBEDTLS_CIPHER_AES_192_GCM,
564 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200565 192,
566 "AES-192-GCM",
567 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200568 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200569 16,
570 &gcm_aes_info
571};
572
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200573static const mbedtls_cipher_info_t aes_256_gcm_info = {
574 MBEDTLS_CIPHER_AES_256_GCM,
575 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100576 256,
577 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200578 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200579 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100580 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200581 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100582};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200585#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200586static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200587 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200588{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200589 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200590 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200591}
592
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200593static const mbedtls_cipher_base_t ccm_aes_info = {
594 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200595 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200597 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100598#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200599#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200600 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100601#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100602#if defined(MBEDTLS_CIPHER_MODE_OFB)
603 NULL,
604#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200606 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100607#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100608#if defined(MBEDTLS_CIPHER_MODE_XTS)
609 NULL,
610#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200611#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200612 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100613#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200614 ccm_aes_setkey_wrap,
615 ccm_aes_setkey_wrap,
616 ccm_ctx_alloc,
617 ccm_ctx_free,
618};
619
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200620static const mbedtls_cipher_info_t aes_128_ccm_info = {
621 MBEDTLS_CIPHER_AES_128_CCM,
622 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200623 128,
624 "AES-128-CCM",
625 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200626 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200627 16,
628 &ccm_aes_info
629};
630
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200631static const mbedtls_cipher_info_t aes_192_ccm_info = {
632 MBEDTLS_CIPHER_AES_192_CCM,
633 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200634 192,
635 "AES-192-CCM",
636 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200637 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200638 16,
639 &ccm_aes_info
640};
641
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200642static const mbedtls_cipher_info_t aes_256_ccm_info = {
643 MBEDTLS_CIPHER_AES_256_CCM,
644 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200645 256,
646 "AES-256-CCM",
647 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200649 16,
650 &ccm_aes_info
651};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200653
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200654#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000655
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200656#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000657
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200658static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200659 const unsigned char *input, unsigned char *output )
660{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200662 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200663}
664
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200665#if defined(MBEDTLS_CIPHER_MODE_CBC)
666static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200667 size_t length, unsigned char *iv,
668 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000669{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200670 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200671 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000672}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000674
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675#if defined(MBEDTLS_CIPHER_MODE_CFB)
676static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200677 size_t length, size_t *iv_off, unsigned char *iv,
678 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000679{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200681 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000682}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000684
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200686static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
687 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000688 const unsigned char *input, unsigned char *output )
689{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200690 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200691 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000692}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200693#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000694
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200695static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200696 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000697{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200698 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000699}
700
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200701static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200702 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000703{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200704 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000705}
706
707static void * camellia_ctx_alloc( void )
708{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200709 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200710 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200711
712 if( ctx == NULL )
713 return( NULL );
714
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200715 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200716
717 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000718}
719
720static void camellia_ctx_free( void *ctx )
721{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200722 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
723 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000724}
725
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200726static const mbedtls_cipher_base_t camellia_info = {
727 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200728 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000730 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100731#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000733 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100734#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100735#if defined(MBEDTLS_CIPHER_MODE_OFB)
736 NULL,
737#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200738#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000739 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100740#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100741#if defined(MBEDTLS_CIPHER_MODE_XTS)
742 NULL,
743#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200744#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200745 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100746#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000747 camellia_setkey_enc_wrap,
748 camellia_setkey_dec_wrap,
749 camellia_ctx_alloc,
750 camellia_ctx_free
751};
752
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200753static const mbedtls_cipher_info_t camellia_128_ecb_info = {
754 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
755 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200756 128,
757 "CAMELLIA-128-ECB",
758 16,
759 0,
760 16,
761 &camellia_info
762};
763
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200764static const mbedtls_cipher_info_t camellia_192_ecb_info = {
765 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
766 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200767 192,
768 "CAMELLIA-192-ECB",
769 16,
770 0,
771 16,
772 &camellia_info
773};
774
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200775static const mbedtls_cipher_info_t camellia_256_ecb_info = {
776 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
777 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200778 256,
779 "CAMELLIA-256-ECB",
780 16,
781 0,
782 16,
783 &camellia_info
784};
785
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200786#if defined(MBEDTLS_CIPHER_MODE_CBC)
787static const mbedtls_cipher_info_t camellia_128_cbc_info = {
788 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
789 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000790 128,
791 "CAMELLIA-128-CBC",
792 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200793 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000794 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000795 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000796};
797
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200798static const mbedtls_cipher_info_t camellia_192_cbc_info = {
799 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
800 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000801 192,
802 "CAMELLIA-192-CBC",
803 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200804 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000805 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000806 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000807};
808
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200809static const mbedtls_cipher_info_t camellia_256_cbc_info = {
810 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
811 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000812 256,
813 "CAMELLIA-256-CBC",
814 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200815 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000816 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000817 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000818};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200819#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000820
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200821#if defined(MBEDTLS_CIPHER_MODE_CFB)
822static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
823 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
824 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000825 128,
826 "CAMELLIA-128-CFB128",
827 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200828 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000829 16,
830 &camellia_info
831};
832
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200833static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
834 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
835 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000836 192,
837 "CAMELLIA-192-CFB128",
838 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200839 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000840 16,
841 &camellia_info
842};
843
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200844static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
845 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
846 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000847 256,
848 "CAMELLIA-256-CFB128",
849 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200850 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000851 16,
852 &camellia_info
853};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200854#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000855
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200856#if defined(MBEDTLS_CIPHER_MODE_CTR)
857static const mbedtls_cipher_info_t camellia_128_ctr_info = {
858 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
859 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000860 128,
861 "CAMELLIA-128-CTR",
862 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200863 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000864 16,
865 &camellia_info
866};
867
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200868static const mbedtls_cipher_info_t camellia_192_ctr_info = {
869 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
870 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000871 192,
872 "CAMELLIA-192-CTR",
873 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200874 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000875 16,
876 &camellia_info
877};
878
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200879static const mbedtls_cipher_info_t camellia_256_ctr_info = {
880 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
881 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000882 256,
883 "CAMELLIA-256-CTR",
884 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200885 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000886 16,
887 &camellia_info
888};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200889#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000890
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200891#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200892static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200893 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200894{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200895 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200896 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200897}
898
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200899static const mbedtls_cipher_base_t gcm_camellia_info = {
900 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200901 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200903 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100904#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200905#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200906 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100907#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100908#if defined(MBEDTLS_CIPHER_MODE_OFB)
909 NULL,
910#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200911#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200912 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100913#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100914#if defined(MBEDTLS_CIPHER_MODE_XTS)
915 NULL,
916#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200917#if defined(MBEDTLS_CIPHER_MODE_STREAM)
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é-Gonnard87181d12013-10-24 14:02:40 +0200920 gcm_camellia_setkey_wrap,
921 gcm_camellia_setkey_wrap,
922 gcm_ctx_alloc,
923 gcm_ctx_free,
924};
925
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200926static const mbedtls_cipher_info_t camellia_128_gcm_info = {
927 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
928 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200929 128,
930 "CAMELLIA-128-GCM",
931 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200932 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200933 16,
934 &gcm_camellia_info
935};
936
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200937static const mbedtls_cipher_info_t camellia_192_gcm_info = {
938 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
939 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200940 192,
941 "CAMELLIA-192-GCM",
942 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200943 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200944 16,
945 &gcm_camellia_info
946};
947
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200948static const mbedtls_cipher_info_t camellia_256_gcm_info = {
949 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
950 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200951 256,
952 "CAMELLIA-256-GCM",
953 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200954 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200955 16,
956 &gcm_camellia_info
957};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200958#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200959
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200960#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200961static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200962 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200963{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200964 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200965 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200966}
967
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200968static const mbedtls_cipher_base_t ccm_camellia_info = {
969 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200970 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200971#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200972 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100973#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200974#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200975 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100976#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100977#if defined(MBEDTLS_CIPHER_MODE_OFB)
978 NULL,
979#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200980#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200981 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100982#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100983#if defined(MBEDTLS_CIPHER_MODE_XTS)
984 NULL,
985#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200986#if defined(MBEDTLS_CIPHER_MODE_STREAM)
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é-Gonnard41936952014-05-13 13:18:17 +0200989 ccm_camellia_setkey_wrap,
990 ccm_camellia_setkey_wrap,
991 ccm_ctx_alloc,
992 ccm_ctx_free,
993};
994
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200995static const mbedtls_cipher_info_t camellia_128_ccm_info = {
996 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
997 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200998 128,
999 "CAMELLIA-128-CCM",
1000 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001001 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001002 16,
1003 &ccm_camellia_info
1004};
1005
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001006static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1007 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1008 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001009 192,
1010 "CAMELLIA-192-CCM",
1011 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001012 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001013 16,
1014 &ccm_camellia_info
1015};
1016
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001017static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1018 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1019 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001020 256,
1021 "CAMELLIA-256-CCM",
1022 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001023 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001024 16,
1025 &ccm_camellia_info
1026};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001027#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001028
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001029#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001030
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001031#if defined(MBEDTLS_ARIA_C)
1032
1033static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1034 const unsigned char *input, unsigned char *output )
1035{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001036 (void) operation;
1037 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001038 output );
1039}
1040
1041#if defined(MBEDTLS_CIPHER_MODE_CBC)
1042static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1043 size_t length, unsigned char *iv,
1044 const unsigned char *input, unsigned char *output )
1045{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001046 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001047 input, output );
1048}
1049#endif /* MBEDTLS_CIPHER_MODE_CBC */
1050
1051#if defined(MBEDTLS_CIPHER_MODE_CFB)
1052static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1053 size_t length, size_t *iv_off, unsigned char *iv,
1054 const unsigned char *input, unsigned char *output )
1055{
1056 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1057 iv_off, iv, input, output );
1058}
1059#endif /* MBEDTLS_CIPHER_MODE_CFB */
1060
1061#if defined(MBEDTLS_CIPHER_MODE_CTR)
1062static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1063 unsigned char *nonce_counter, unsigned char *stream_block,
1064 const unsigned char *input, unsigned char *output )
1065{
1066 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1067 nonce_counter, stream_block, input, output );
1068}
1069#endif /* MBEDTLS_CIPHER_MODE_CTR */
1070
1071static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1072 unsigned int key_bitlen )
1073{
1074 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1075}
1076
1077static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1078 unsigned int key_bitlen )
1079{
1080 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1081}
1082
1083static void * aria_ctx_alloc( void )
1084{
1085 mbedtls_aria_context *ctx;
1086 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1087
1088 if( ctx == NULL )
1089 return( NULL );
1090
1091 mbedtls_aria_init( ctx );
1092
1093 return( ctx );
1094}
1095
1096static void aria_ctx_free( void *ctx )
1097{
1098 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1099 mbedtls_free( ctx );
1100}
1101
1102static const mbedtls_cipher_base_t aria_info = {
1103 MBEDTLS_CIPHER_ID_ARIA,
1104 aria_crypt_ecb_wrap,
1105#if defined(MBEDTLS_CIPHER_MODE_CBC)
1106 aria_crypt_cbc_wrap,
1107#endif
1108#if defined(MBEDTLS_CIPHER_MODE_CFB)
1109 aria_crypt_cfb128_wrap,
1110#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001111#if defined(MBEDTLS_CIPHER_MODE_OFB)
1112 NULL,
1113#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001114#if defined(MBEDTLS_CIPHER_MODE_CTR)
1115 aria_crypt_ctr_wrap,
1116#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001117#if defined(MBEDTLS_CIPHER_MODE_XTS)
1118 NULL,
1119#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001120#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1121 NULL,
1122#endif
1123 aria_setkey_enc_wrap,
1124 aria_setkey_dec_wrap,
1125 aria_ctx_alloc,
1126 aria_ctx_free
1127};
1128
1129static const mbedtls_cipher_info_t aria_128_ecb_info = {
1130 MBEDTLS_CIPHER_ARIA_128_ECB,
1131 MBEDTLS_MODE_ECB,
1132 128,
1133 "ARIA-128-ECB",
1134 16,
1135 0,
1136 16,
1137 &aria_info
1138};
1139
1140static const mbedtls_cipher_info_t aria_192_ecb_info = {
1141 MBEDTLS_CIPHER_ARIA_192_ECB,
1142 MBEDTLS_MODE_ECB,
1143 192,
1144 "ARIA-192-ECB",
1145 16,
1146 0,
1147 16,
1148 &aria_info
1149};
1150
1151static const mbedtls_cipher_info_t aria_256_ecb_info = {
1152 MBEDTLS_CIPHER_ARIA_256_ECB,
1153 MBEDTLS_MODE_ECB,
1154 256,
1155 "ARIA-256-ECB",
1156 16,
1157 0,
1158 16,
1159 &aria_info
1160};
1161
1162#if defined(MBEDTLS_CIPHER_MODE_CBC)
1163static const mbedtls_cipher_info_t aria_128_cbc_info = {
1164 MBEDTLS_CIPHER_ARIA_128_CBC,
1165 MBEDTLS_MODE_CBC,
1166 128,
1167 "ARIA-128-CBC",
1168 16,
1169 0,
1170 16,
1171 &aria_info
1172};
1173
1174static const mbedtls_cipher_info_t aria_192_cbc_info = {
1175 MBEDTLS_CIPHER_ARIA_192_CBC,
1176 MBEDTLS_MODE_CBC,
1177 192,
1178 "ARIA-192-CBC",
1179 16,
1180 0,
1181 16,
1182 &aria_info
1183};
1184
1185static const mbedtls_cipher_info_t aria_256_cbc_info = {
1186 MBEDTLS_CIPHER_ARIA_256_CBC,
1187 MBEDTLS_MODE_CBC,
1188 256,
1189 "ARIA-256-CBC",
1190 16,
1191 0,
1192 16,
1193 &aria_info
1194};
1195#endif /* MBEDTLS_CIPHER_MODE_CBC */
1196
1197#if defined(MBEDTLS_CIPHER_MODE_CFB)
1198static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1199 MBEDTLS_CIPHER_ARIA_128_CFB128,
1200 MBEDTLS_MODE_CFB,
1201 128,
1202 "ARIA-128-CFB128",
1203 16,
1204 0,
1205 16,
1206 &aria_info
1207};
1208
1209static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1210 MBEDTLS_CIPHER_ARIA_192_CFB128,
1211 MBEDTLS_MODE_CFB,
1212 192,
1213 "ARIA-192-CFB128",
1214 16,
1215 0,
1216 16,
1217 &aria_info
1218};
1219
1220static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1221 MBEDTLS_CIPHER_ARIA_256_CFB128,
1222 MBEDTLS_MODE_CFB,
1223 256,
1224 "ARIA-256-CFB128",
1225 16,
1226 0,
1227 16,
1228 &aria_info
1229};
1230#endif /* MBEDTLS_CIPHER_MODE_CFB */
1231
1232#if defined(MBEDTLS_CIPHER_MODE_CTR)
1233static const mbedtls_cipher_info_t aria_128_ctr_info = {
1234 MBEDTLS_CIPHER_ARIA_128_CTR,
1235 MBEDTLS_MODE_CTR,
1236 128,
1237 "ARIA-128-CTR",
1238 16,
1239 0,
1240 16,
1241 &aria_info
1242};
1243
1244static const mbedtls_cipher_info_t aria_192_ctr_info = {
1245 MBEDTLS_CIPHER_ARIA_192_CTR,
1246 MBEDTLS_MODE_CTR,
1247 192,
1248 "ARIA-192-CTR",
1249 16,
1250 0,
1251 16,
1252 &aria_info
1253};
1254
1255static const mbedtls_cipher_info_t aria_256_ctr_info = {
1256 MBEDTLS_CIPHER_ARIA_256_CTR,
1257 MBEDTLS_MODE_CTR,
1258 256,
1259 "ARIA-256-CTR",
1260 16,
1261 0,
1262 16,
1263 &aria_info
1264};
1265#endif /* MBEDTLS_CIPHER_MODE_CTR */
1266
1267#if defined(MBEDTLS_GCM_C)
1268static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1269 unsigned int key_bitlen )
1270{
1271 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1272 key, key_bitlen );
1273}
1274
1275static const mbedtls_cipher_base_t gcm_aria_info = {
1276 MBEDTLS_CIPHER_ID_ARIA,
1277 NULL,
1278#if defined(MBEDTLS_CIPHER_MODE_CBC)
1279 NULL,
1280#endif
1281#if defined(MBEDTLS_CIPHER_MODE_CFB)
1282 NULL,
1283#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001284#if defined(MBEDTLS_CIPHER_MODE_OFB)
1285 NULL,
1286#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001287#if defined(MBEDTLS_CIPHER_MODE_CTR)
1288 NULL,
1289#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001290#if defined(MBEDTLS_CIPHER_MODE_XTS)
1291 NULL,
1292#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001293#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1294 NULL,
1295#endif
1296 gcm_aria_setkey_wrap,
1297 gcm_aria_setkey_wrap,
1298 gcm_ctx_alloc,
1299 gcm_ctx_free,
1300};
1301
1302static const mbedtls_cipher_info_t aria_128_gcm_info = {
1303 MBEDTLS_CIPHER_ARIA_128_GCM,
1304 MBEDTLS_MODE_GCM,
1305 128,
1306 "ARIA-128-GCM",
1307 12,
1308 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1309 16,
1310 &gcm_aria_info
1311};
1312
1313static const mbedtls_cipher_info_t aria_192_gcm_info = {
1314 MBEDTLS_CIPHER_ARIA_192_GCM,
1315 MBEDTLS_MODE_GCM,
1316 192,
1317 "ARIA-192-GCM",
1318 12,
1319 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1320 16,
1321 &gcm_aria_info
1322};
1323
1324static const mbedtls_cipher_info_t aria_256_gcm_info = {
1325 MBEDTLS_CIPHER_ARIA_256_GCM,
1326 MBEDTLS_MODE_GCM,
1327 256,
1328 "ARIA-256-GCM",
1329 12,
1330 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1331 16,
1332 &gcm_aria_info
1333};
1334#endif /* MBEDTLS_GCM_C */
1335
1336#if defined(MBEDTLS_CCM_C)
1337static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1338 unsigned int key_bitlen )
1339{
1340 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1341 key, key_bitlen );
1342}
1343
1344static const mbedtls_cipher_base_t ccm_aria_info = {
1345 MBEDTLS_CIPHER_ID_ARIA,
1346 NULL,
1347#if defined(MBEDTLS_CIPHER_MODE_CBC)
1348 NULL,
1349#endif
1350#if defined(MBEDTLS_CIPHER_MODE_CFB)
1351 NULL,
1352#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001353#if defined(MBEDTLS_CIPHER_MODE_OFB)
1354 NULL,
1355#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001356#if defined(MBEDTLS_CIPHER_MODE_CTR)
1357 NULL,
1358#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001359#if defined(MBEDTLS_CIPHER_MODE_XTS)
1360 NULL,
1361#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001362#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1363 NULL,
1364#endif
1365 ccm_aria_setkey_wrap,
1366 ccm_aria_setkey_wrap,
1367 ccm_ctx_alloc,
1368 ccm_ctx_free,
1369};
1370
1371static const mbedtls_cipher_info_t aria_128_ccm_info = {
1372 MBEDTLS_CIPHER_ARIA_128_CCM,
1373 MBEDTLS_MODE_CCM,
1374 128,
1375 "ARIA-128-CCM",
1376 12,
1377 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1378 16,
1379 &ccm_aria_info
1380};
1381
1382static const mbedtls_cipher_info_t aria_192_ccm_info = {
1383 MBEDTLS_CIPHER_ARIA_192_CCM,
1384 MBEDTLS_MODE_CCM,
1385 192,
1386 "ARIA-192-CCM",
1387 12,
1388 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1389 16,
1390 &ccm_aria_info
1391};
1392
1393static const mbedtls_cipher_info_t aria_256_ccm_info = {
1394 MBEDTLS_CIPHER_ARIA_256_CCM,
1395 MBEDTLS_MODE_CCM,
1396 256,
1397 "ARIA-256-CCM",
1398 12,
1399 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1400 16,
1401 &ccm_aria_info
1402};
1403#endif /* MBEDTLS_CCM_C */
1404
1405#endif /* MBEDTLS_ARIA_C */
1406
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001407#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001408
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001409static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001410 const unsigned char *input, unsigned char *output )
1411{
1412 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001413 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001414}
1415
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001416static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001417 const unsigned char *input, unsigned char *output )
1418{
1419 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001420 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001421}
1422
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001423#if defined(MBEDTLS_CIPHER_MODE_CBC)
1424static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001425 unsigned char *iv, const unsigned char *input, unsigned char *output )
1426{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001427 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001428 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001429}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001430#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001431
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001432#if defined(MBEDTLS_CIPHER_MODE_CBC)
1433static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001434 unsigned char *iv, const unsigned char *input, unsigned char *output )
1435{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001436 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001437 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001438}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001439#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001440
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001441static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001442 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001443{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001444 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001445
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001446 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001447}
1448
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001449static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001450 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001451{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001452 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001453
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001454 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001455}
1456
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001457static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001458 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001459{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001460 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001461
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001462 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001463}
1464
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001465static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001466 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001467{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001468 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001469
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001470 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001471}
1472
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001473static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001474 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001475{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001476 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001477
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001478 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001479}
1480
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001481static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001482 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001483{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001484 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001485
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001486 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001487}
1488
1489static void * des_ctx_alloc( void )
1490{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001491 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001492
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001493 if( des == NULL )
1494 return( NULL );
1495
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001496 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001497
1498 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001499}
1500
1501static void des_ctx_free( void *ctx )
1502{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001503 mbedtls_des_free( (mbedtls_des_context *) ctx );
1504 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001505}
1506
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001507static void * des3_ctx_alloc( void )
1508{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001510 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001511
1512 if( des3 == NULL )
1513 return( NULL );
1514
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001515 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001516
1517 return( des3 );
1518}
1519
Paul Bakker34617722014-06-13 17:20:13 +02001520static void des3_ctx_free( void *ctx )
1521{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001522 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1523 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001524}
1525
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001526static const mbedtls_cipher_base_t des_info = {
1527 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001528 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001530 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001531#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001532#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001533 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001534#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001535#if defined(MBEDTLS_CIPHER_MODE_OFB)
1536 NULL,
1537#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001538#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001539 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001540#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001541#if defined(MBEDTLS_CIPHER_MODE_XTS)
1542 NULL,
1543#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001544#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001545 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001546#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001547 des_setkey_enc_wrap,
1548 des_setkey_dec_wrap,
1549 des_ctx_alloc,
1550 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001551};
1552
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001553static const mbedtls_cipher_info_t des_ecb_info = {
1554 MBEDTLS_CIPHER_DES_ECB,
1555 MBEDTLS_MODE_ECB,
1556 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001557 "DES-ECB",
1558 8,
1559 0,
1560 8,
1561 &des_info
1562};
1563
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001564#if defined(MBEDTLS_CIPHER_MODE_CBC)
1565static const mbedtls_cipher_info_t des_cbc_info = {
1566 MBEDTLS_CIPHER_DES_CBC,
1567 MBEDTLS_MODE_CBC,
1568 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001569 "DES-CBC",
1570 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001571 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001572 8,
1573 &des_info
1574};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001575#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001577static const mbedtls_cipher_base_t des_ede_info = {
1578 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001579 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001580#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001581 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001582#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001583#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001584 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001585#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001586#if defined(MBEDTLS_CIPHER_MODE_OFB)
1587 NULL,
1588#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001589#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001590 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001591#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001592#if defined(MBEDTLS_CIPHER_MODE_XTS)
1593 NULL,
1594#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001595#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001596 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001597#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001598 des3_set2key_enc_wrap,
1599 des3_set2key_dec_wrap,
1600 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001601 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001602};
1603
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001604static const mbedtls_cipher_info_t des_ede_ecb_info = {
1605 MBEDTLS_CIPHER_DES_EDE_ECB,
1606 MBEDTLS_MODE_ECB,
1607 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001608 "DES-EDE-ECB",
1609 8,
1610 0,
1611 8,
1612 &des_ede_info
1613};
1614
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001615#if defined(MBEDTLS_CIPHER_MODE_CBC)
1616static const mbedtls_cipher_info_t des_ede_cbc_info = {
1617 MBEDTLS_CIPHER_DES_EDE_CBC,
1618 MBEDTLS_MODE_CBC,
1619 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001620 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001621 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001622 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001623 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001624 &des_ede_info
1625};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001626#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001627
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001628static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001629 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001630 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001631#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001632 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001633#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001634#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001635 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001636#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001637#if defined(MBEDTLS_CIPHER_MODE_OFB)
1638 NULL,
1639#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001640#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001641 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001642#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001643#if defined(MBEDTLS_CIPHER_MODE_XTS)
1644 NULL,
1645#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001646#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001647 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001648#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001649 des3_set3key_enc_wrap,
1650 des3_set3key_dec_wrap,
1651 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001652 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001653};
1654
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001655static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1656 MBEDTLS_CIPHER_DES_EDE3_ECB,
1657 MBEDTLS_MODE_ECB,
1658 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001659 "DES-EDE3-ECB",
1660 8,
1661 0,
1662 8,
1663 &des_ede3_info
1664};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001665#if defined(MBEDTLS_CIPHER_MODE_CBC)
1666static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1667 MBEDTLS_CIPHER_DES_EDE3_CBC,
1668 MBEDTLS_MODE_CBC,
1669 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001670 "DES-EDE3-CBC",
1671 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001672 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001673 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001674 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001675};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001676#endif /* MBEDTLS_CIPHER_MODE_CBC */
1677#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001679#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001681static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001682 const unsigned char *input, unsigned char *output )
1683{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001684 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001685 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001686}
1687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001688#if defined(MBEDTLS_CIPHER_MODE_CBC)
1689static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001690 size_t length, unsigned char *iv, const unsigned char *input,
1691 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001692{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001693 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001694 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001695}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001696#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001697
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001698#if defined(MBEDTLS_CIPHER_MODE_CFB)
1699static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001700 size_t length, size_t *iv_off, unsigned char *iv,
1701 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001702{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001703 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001704 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001705}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001706#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001707
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001708#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001709static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1710 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001711 const unsigned char *input, unsigned char *output )
1712{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001713 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001714 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001715}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001716#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001717
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001718static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001719 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001720{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001721 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001722}
1723
1724static void * blowfish_ctx_alloc( void )
1725{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001726 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001727 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001728
1729 if( ctx == NULL )
1730 return( NULL );
1731
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001732 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001733
1734 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001735}
1736
1737static void blowfish_ctx_free( void *ctx )
1738{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001739 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1740 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001741}
1742
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001743static const mbedtls_cipher_base_t blowfish_info = {
1744 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001745 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001746#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001747 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001748#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001749#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001750 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001751#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001752#if defined(MBEDTLS_CIPHER_MODE_OFB)
1753 NULL,
1754#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001755#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001756 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001757#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001758#if defined(MBEDTLS_CIPHER_MODE_XTS)
1759 NULL,
1760#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001761#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001762 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001763#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001764 blowfish_setkey_wrap,
1765 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001766 blowfish_ctx_alloc,
1767 blowfish_ctx_free
1768};
1769
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001770static const mbedtls_cipher_info_t blowfish_ecb_info = {
1771 MBEDTLS_CIPHER_BLOWFISH_ECB,
1772 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001773 128,
1774 "BLOWFISH-ECB",
1775 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001776 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001777 8,
1778 &blowfish_info
1779};
1780
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001781#if defined(MBEDTLS_CIPHER_MODE_CBC)
1782static const mbedtls_cipher_info_t blowfish_cbc_info = {
1783 MBEDTLS_CIPHER_BLOWFISH_CBC,
1784 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001785 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001786 "BLOWFISH-CBC",
1787 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001788 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001789 8,
1790 &blowfish_info
1791};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001792#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001793
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001794#if defined(MBEDTLS_CIPHER_MODE_CFB)
1795static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1796 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1797 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001798 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001799 "BLOWFISH-CFB64",
1800 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001801 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001802 8,
1803 &blowfish_info
1804};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001805#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001806
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001807#if defined(MBEDTLS_CIPHER_MODE_CTR)
1808static const mbedtls_cipher_info_t blowfish_ctr_info = {
1809 MBEDTLS_CIPHER_BLOWFISH_CTR,
1810 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001811 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001812 "BLOWFISH-CTR",
1813 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001814 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001815 8,
1816 &blowfish_info
1817};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001818#endif /* MBEDTLS_CIPHER_MODE_CTR */
1819#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001820
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001821#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001822static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1823 const unsigned char *input,
1824 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001825{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001826 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001827}
1828
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001829static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001830 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001831{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001832 /* we get key_bitlen in bits, arc4 expects it in bytes */
1833 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001834 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001835
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001836 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001837 return( 0 );
1838}
1839
1840static void * arc4_ctx_alloc( void )
1841{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001842 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001843 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001844
1845 if( ctx == NULL )
1846 return( NULL );
1847
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001848 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001849
1850 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001851}
Paul Bakker68884e32013-01-07 18:20:04 +01001852
1853static void arc4_ctx_free( void *ctx )
1854{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001855 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1856 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001857}
1858
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001859static const mbedtls_cipher_base_t arc4_base_info = {
1860 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001861 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001862#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001863 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001864#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001865#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001866 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001867#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001868#if defined(MBEDTLS_CIPHER_MODE_OFB)
1869 NULL,
1870#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001871#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001872 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001873#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001874#if defined(MBEDTLS_CIPHER_MODE_XTS)
1875 NULL,
1876#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001877#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001878 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001879#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001880 arc4_setkey_wrap,
1881 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001882 arc4_ctx_alloc,
1883 arc4_ctx_free
1884};
1885
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001886static const mbedtls_cipher_info_t arc4_128_info = {
1887 MBEDTLS_CIPHER_ARC4_128,
1888 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001889 128,
1890 "ARC4-128",
1891 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001892 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001893 1,
1894 &arc4_base_info
1895};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001896#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001897
Daniel Kingbd920622016-05-15 19:56:20 -03001898#if defined(MBEDTLS_CHACHA20_C)
1899
1900static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1901 unsigned int key_bitlen )
1902{
1903 if( key_bitlen != 256U )
1904 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1905
1906 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1907 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1908
1909 return( 0 );
1910}
1911
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001912static int chacha20_stream_wrap( void *ctx, size_t length,
1913 const unsigned char *input,
1914 unsigned char *output )
1915{
Janos Follath24eed8d2019-11-22 13:21:35 +00001916 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001917
1918 ret = mbedtls_chacha20_update( ctx, length, input, output );
1919 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1920 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1921
1922 return( ret );
1923}
1924
Daniel Kingbd920622016-05-15 19:56:20 -03001925static void * chacha20_ctx_alloc( void )
1926{
1927 mbedtls_chacha20_context *ctx;
1928 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1929
1930 if( ctx == NULL )
1931 return( NULL );
1932
1933 mbedtls_chacha20_init( ctx );
1934
1935 return( ctx );
1936}
1937
1938static void chacha20_ctx_free( void *ctx )
1939{
1940 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1941 mbedtls_free( ctx );
1942}
1943
1944static const mbedtls_cipher_base_t chacha20_base_info = {
1945 MBEDTLS_CIPHER_ID_CHACHA20,
1946 NULL,
1947#if defined(MBEDTLS_CIPHER_MODE_CBC)
1948 NULL,
1949#endif
1950#if defined(MBEDTLS_CIPHER_MODE_CFB)
1951 NULL,
1952#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001953#if defined(MBEDTLS_CIPHER_MODE_OFB)
1954 NULL,
1955#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001956#if defined(MBEDTLS_CIPHER_MODE_CTR)
1957 NULL,
1958#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001959#if defined(MBEDTLS_CIPHER_MODE_XTS)
1960 NULL,
1961#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001962#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001963 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001964#endif
1965 chacha20_setkey_wrap,
1966 chacha20_setkey_wrap,
1967 chacha20_ctx_alloc,
1968 chacha20_ctx_free
1969};
1970static const mbedtls_cipher_info_t chacha20_info = {
1971 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001972 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001973 256,
1974 "CHACHA20",
1975 12,
1976 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001977 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001978 &chacha20_base_info
1979};
1980#endif /* MBEDTLS_CHACHA20_C */
1981
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001982#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001983
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001984static int chachapoly_setkey_wrap( void *ctx,
1985 const unsigned char *key,
1986 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001987{
1988 if( key_bitlen != 256U )
1989 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1990
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001991 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001992 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1993
1994 return( 0 );
1995}
1996
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001997static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03001998{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001999 mbedtls_chachapoly_context *ctx;
2000 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03002001
2002 if( ctx == NULL )
2003 return( NULL );
2004
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002005 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002006
2007 return( ctx );
2008}
2009
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002010static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002011{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002012 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002013 mbedtls_free( ctx );
2014}
2015
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002016static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002017 MBEDTLS_CIPHER_ID_CHACHA20,
2018 NULL,
2019#if defined(MBEDTLS_CIPHER_MODE_CBC)
2020 NULL,
2021#endif
2022#if defined(MBEDTLS_CIPHER_MODE_CFB)
2023 NULL,
2024#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002025#if defined(MBEDTLS_CIPHER_MODE_OFB)
2026 NULL,
2027#endif
Daniel King8fe47012016-05-17 20:33:28 -03002028#if defined(MBEDTLS_CIPHER_MODE_CTR)
2029 NULL,
2030#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002031#if defined(MBEDTLS_CIPHER_MODE_XTS)
2032 NULL,
2033#endif
Daniel King8fe47012016-05-17 20:33:28 -03002034#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2035 NULL,
2036#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002037 chachapoly_setkey_wrap,
2038 chachapoly_setkey_wrap,
2039 chachapoly_ctx_alloc,
2040 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002041};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002042static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002043 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002044 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002045 256,
2046 "CHACHA20-POLY1305",
2047 12,
2048 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002049 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002050 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002051};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002052#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002053
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002054#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002055static int null_crypt_stream( void *ctx, size_t length,
2056 const unsigned char *input,
2057 unsigned char *output )
2058{
2059 ((void) ctx);
2060 memmove( output, input, length );
2061 return( 0 );
2062}
2063
2064static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002065 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002066{
2067 ((void) ctx);
2068 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002069 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002070
2071 return( 0 );
2072}
2073
Paul Bakkerfab5c822012-02-06 16:45:10 +00002074static void * null_ctx_alloc( void )
2075{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002076 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002077}
2078
Paul Bakkerfab5c822012-02-06 16:45:10 +00002079static void null_ctx_free( void *ctx )
2080{
2081 ((void) ctx);
2082}
2083
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002084static const mbedtls_cipher_base_t null_base_info = {
2085 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002086 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002087#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002088 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002089#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002090#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002091 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002092#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002093#if defined(MBEDTLS_CIPHER_MODE_OFB)
2094 NULL,
2095#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002096#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002097 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002098#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002099#if defined(MBEDTLS_CIPHER_MODE_XTS)
2100 NULL,
2101#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002102#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002103 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002104#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002105 null_setkey,
2106 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002107 null_ctx_alloc,
2108 null_ctx_free
2109};
2110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002111static const mbedtls_cipher_info_t null_cipher_info = {
2112 MBEDTLS_CIPHER_NULL,
2113 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002114 0,
2115 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002116 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002117 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002118 1,
2119 &null_base_info
2120};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002121#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002122
Jack Lloydffdf2882019-03-07 17:00:32 -05002123#if defined(MBEDTLS_NIST_KW_C)
2124static void *kw_ctx_alloc( void )
2125{
2126 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
2127
2128 if( ctx != NULL )
2129 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
2130
2131 return( ctx );
2132}
2133
2134static void kw_ctx_free( void *ctx )
2135{
2136 mbedtls_nist_kw_free( ctx );
2137 mbedtls_free( ctx );
2138}
2139
2140static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
2141 unsigned int key_bitlen )
2142{
Jack Lloyd5f289992019-04-02 10:07:28 -07002143 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2144 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002145}
2146
2147static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
2148 unsigned int key_bitlen )
2149{
Jack Lloyd5f289992019-04-02 10:07:28 -07002150 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2151 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002152}
2153
2154static const mbedtls_cipher_base_t kw_aes_info = {
2155 MBEDTLS_CIPHER_ID_AES,
2156 NULL,
2157#if defined(MBEDTLS_CIPHER_MODE_CBC)
2158 NULL,
2159#endif
2160#if defined(MBEDTLS_CIPHER_MODE_CFB)
2161 NULL,
2162#endif
2163#if defined(MBEDTLS_CIPHER_MODE_OFB)
2164 NULL,
2165#endif
2166#if defined(MBEDTLS_CIPHER_MODE_CTR)
2167 NULL,
2168#endif
2169#if defined(MBEDTLS_CIPHER_MODE_XTS)
2170 NULL,
2171#endif
2172#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2173 NULL,
2174#endif
2175 kw_aes_setkey_wrap,
2176 kw_aes_setkey_unwrap,
2177 kw_ctx_alloc,
2178 kw_ctx_free,
2179};
2180
2181static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
2182 MBEDTLS_CIPHER_AES_128_KW,
2183 MBEDTLS_MODE_KW,
2184 128,
2185 "AES-128-KW",
2186 0,
2187 0,
2188 16,
2189 &kw_aes_info
2190};
2191
2192static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
2193 MBEDTLS_CIPHER_AES_192_KW,
2194 MBEDTLS_MODE_KW,
2195 192,
2196 "AES-192-KW",
2197 0,
2198 0,
2199 16,
2200 &kw_aes_info
2201};
2202
2203static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
2204 MBEDTLS_CIPHER_AES_256_KW,
2205 MBEDTLS_MODE_KW,
2206 256,
2207 "AES-256-KW",
2208 0,
2209 0,
2210 16,
2211 &kw_aes_info
2212};
2213
2214static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
2215 MBEDTLS_CIPHER_AES_128_KWP,
2216 MBEDTLS_MODE_KWP,
2217 128,
2218 "AES-128-KWP",
2219 0,
2220 0,
2221 16,
2222 &kw_aes_info
2223};
2224
2225static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
2226 MBEDTLS_CIPHER_AES_192_KWP,
2227 MBEDTLS_MODE_KWP,
2228 192,
2229 "AES-192-KWP",
2230 0,
2231 0,
2232 16,
2233 &kw_aes_info
2234};
2235
2236static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
2237 MBEDTLS_CIPHER_AES_256_KWP,
2238 MBEDTLS_MODE_KWP,
2239 256,
2240 "AES-256-KWP",
2241 0,
2242 0,
2243 16,
2244 &kw_aes_info
2245};
2246#endif /* MBEDTLS_NIST_KW_C */
2247
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002248const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002249{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002250#if defined(MBEDTLS_AES_C)
2251 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2252 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2253 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2254#if defined(MBEDTLS_CIPHER_MODE_CBC)
2255 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2256 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2257 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002258#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002259#if defined(MBEDTLS_CIPHER_MODE_CFB)
2260 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2261 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2262 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002263#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002264#if defined(MBEDTLS_CIPHER_MODE_OFB)
2265 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2266 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2267 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2268#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002269#if defined(MBEDTLS_CIPHER_MODE_CTR)
2270 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2271 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2272 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002273#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002274#if defined(MBEDTLS_CIPHER_MODE_XTS)
2275 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2276 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2277#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002278#if defined(MBEDTLS_GCM_C)
2279 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2280 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2281 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002282#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002283#if defined(MBEDTLS_CCM_C)
2284 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2285 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2286 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002287#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002288#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002289
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002290#if defined(MBEDTLS_ARC4_C)
2291 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002292#endif
2293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002294#if defined(MBEDTLS_BLOWFISH_C)
2295 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2296#if defined(MBEDTLS_CIPHER_MODE_CBC)
2297 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002298#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002299#if defined(MBEDTLS_CIPHER_MODE_CFB)
2300 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002301#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002302#if defined(MBEDTLS_CIPHER_MODE_CTR)
2303 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002304#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002305#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002306
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002307#if defined(MBEDTLS_CAMELLIA_C)
2308 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2309 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2310 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2311#if defined(MBEDTLS_CIPHER_MODE_CBC)
2312 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2313 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2314 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002315#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002316#if defined(MBEDTLS_CIPHER_MODE_CFB)
2317 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2318 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2319 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002320#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002321#if defined(MBEDTLS_CIPHER_MODE_CTR)
2322 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2323 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2324 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002325#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002326#if defined(MBEDTLS_GCM_C)
2327 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2328 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2329 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002330#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002331#if defined(MBEDTLS_CCM_C)
2332 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2333 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2334 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002335#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002336#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002337
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002338#if defined(MBEDTLS_ARIA_C)
2339 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2340 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2341 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2342#if defined(MBEDTLS_CIPHER_MODE_CBC)
2343 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2344 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2345 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2346#endif
2347#if defined(MBEDTLS_CIPHER_MODE_CFB)
2348 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2349 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2350 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2351#endif
2352#if defined(MBEDTLS_CIPHER_MODE_CTR)
2353 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2354 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2355 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2356#endif
2357#if defined(MBEDTLS_GCM_C)
2358 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2359 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2360 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2361#endif
2362#if defined(MBEDTLS_CCM_C)
2363 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2364 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2365 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2366#endif
2367#endif /* MBEDTLS_ARIA_C */
2368
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002369#if defined(MBEDTLS_DES_C)
2370 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2371 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2372 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2373#if defined(MBEDTLS_CIPHER_MODE_CBC)
2374 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2375 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2376 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002377#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002378#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002379
Daniel Kingbd920622016-05-15 19:56:20 -03002380#if defined(MBEDTLS_CHACHA20_C)
2381 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2382#endif
2383
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002384#if defined(MBEDTLS_CHACHAPOLY_C)
2385 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002386#endif
2387
Jack Lloydffdf2882019-03-07 17:00:32 -05002388#if defined(MBEDTLS_NIST_KW_C)
2389 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
2390 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
2391 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
2392 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
2393 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
2394 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
2395#endif
2396
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002397#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2398 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2399#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002400
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002401 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002402};
2403
Hanno Beckerc3d25b32018-11-08 16:01:22 +00002404#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
2405 sizeof(mbedtls_cipher_definitions[0]) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002406int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002407
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002408#endif /* MBEDTLS_CIPHER_C */