blob: c76bdcc0f80dcc936c85948b2e3a4b32524489c8 [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 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02008 * Copyright The Mbed TLS Contributors
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 */
23
Gilles Peskinedb09ef62020-06-03 01:43:33 +020024#include "common.h"
Paul Bakker8123e9d2011-01-06 15:37:30 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000027
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020028#include "mbedtls/cipher_internal.h"
Janos Follath24eed8d2019-11-22 13:21:35 +000029#include "mbedtls/error.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000030
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020031#if defined(MBEDTLS_CHACHAPOLY_C)
32#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030033#endif
34
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000036#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000037#endif
38
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020039#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000040#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020041#endif
42
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000044#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000045#endif
46
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000047#if defined(MBEDTLS_ARIA_C)
48#include "mbedtls/aria.h"
49#endif
50
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000052#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000053#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000057#endif
58
Daniel Kingbd920622016-05-15 19:56:20 -030059#if defined(MBEDTLS_CHACHA20_C)
60#include "mbedtls/chacha20.h"
61#endif
62
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000064#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020065#endif
66
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000068#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020069#endif
70
Jack Lloydffdf2882019-03-07 17:00:32 -050071#if defined(MBEDTLS_NIST_KW_C)
72#include "mbedtls/nist_kw.h"
73#endif
74
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000076#include <string.h>
77#endif
78
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000079#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020080
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020082/* shared by all GCM ciphers */
83static void *gcm_ctx_alloc( void )
84{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020085 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
86
87 if( ctx != NULL )
88 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
89
90 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020091}
92
93static void gcm_ctx_free( void *ctx )
94{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095 mbedtls_gcm_free( ctx );
96 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020097}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020099
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200100#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200101/* shared by all CCM ciphers */
102static void *ccm_ctx_alloc( void )
103{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200104 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
105
106 if( ctx != NULL )
107 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
108
109 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200110}
111
112static void ccm_ctx_free( void *ctx )
113{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114 mbedtls_ccm_free( ctx );
115 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200116}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200118
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000120
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200122 const unsigned char *input, unsigned char *output )
123{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200125}
126
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127#if defined(MBEDTLS_CIPHER_MODE_CBC)
128static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000129 unsigned char *iv, const unsigned char *input, unsigned char *output )
130{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200132 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000133}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#if defined(MBEDTLS_CIPHER_MODE_CFB)
137static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200138 size_t length, size_t *iv_off, unsigned char *iv,
139 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000140{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200142 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000143}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200144#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000145
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100146#if defined(MBEDTLS_CIPHER_MODE_OFB)
147static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
148 unsigned char *iv, const unsigned char *input, unsigned char *output )
149{
150 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
151 iv, input, output );
152}
153#endif /* MBEDTLS_CIPHER_MODE_OFB */
154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200156static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
157 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000158 const unsigned char *input, unsigned char *output )
159{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000161 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000162}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000164
Jaeden Ameroc6539902018-04-30 17:17:41 +0100165#if defined(MBEDTLS_CIPHER_MODE_XTS)
166static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
167 size_t length,
168 const unsigned char data_unit[16],
169 const unsigned char *input,
170 unsigned char *output )
171{
172 mbedtls_aes_xts_context *xts_ctx = ctx;
173 int mode;
174
175 switch( operation )
176 {
177 case MBEDTLS_ENCRYPT:
178 mode = MBEDTLS_AES_ENCRYPT;
179 break;
180 case MBEDTLS_DECRYPT:
181 mode = MBEDTLS_AES_DECRYPT;
182 break;
183 default:
184 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
185 }
186
187 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
188 data_unit, input, output );
189}
190#endif /* MBEDTLS_CIPHER_MODE_XTS */
191
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200192static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200193 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000194{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200195 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000196}
197
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200198static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200199 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000200{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200201 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000202}
203
204static void * aes_ctx_alloc( void )
205{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200206 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200207
208 if( aes == NULL )
209 return( NULL );
210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200211 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200212
213 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000214}
215
216static void aes_ctx_free( void *ctx )
217{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
219 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000220}
221
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222static const mbedtls_cipher_base_t aes_info = {
223 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200224 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000226 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100227#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000229 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100230#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100231#if defined(MBEDTLS_CIPHER_MODE_OFB)
232 aes_crypt_ofb_wrap,
233#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200234#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000235 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100236#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100237#if defined(MBEDTLS_CIPHER_MODE_XTS)
238 NULL,
239#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200241 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100242#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000243 aes_setkey_enc_wrap,
244 aes_setkey_dec_wrap,
245 aes_ctx_alloc,
246 aes_ctx_free
247};
248
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200249static const mbedtls_cipher_info_t aes_128_ecb_info = {
250 MBEDTLS_CIPHER_AES_128_ECB,
251 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200252 128,
253 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300254 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200255 0,
256 16,
257 &aes_info
258};
259
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260static const mbedtls_cipher_info_t aes_192_ecb_info = {
261 MBEDTLS_CIPHER_AES_192_ECB,
262 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200263 192,
264 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300265 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200266 0,
267 16,
268 &aes_info
269};
270
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271static const mbedtls_cipher_info_t aes_256_ecb_info = {
272 MBEDTLS_CIPHER_AES_256_ECB,
273 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200274 256,
275 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300276 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200277 0,
278 16,
279 &aes_info
280};
281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282#if defined(MBEDTLS_CIPHER_MODE_CBC)
283static const mbedtls_cipher_info_t aes_128_cbc_info = {
284 MBEDTLS_CIPHER_AES_128_CBC,
285 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000286 128,
287 "AES-128-CBC",
288 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200289 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000290 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000291 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000292};
293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294static const mbedtls_cipher_info_t aes_192_cbc_info = {
295 MBEDTLS_CIPHER_AES_192_CBC,
296 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000297 192,
298 "AES-192-CBC",
299 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200300 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000301 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000302 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000303};
304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305static const mbedtls_cipher_info_t aes_256_cbc_info = {
306 MBEDTLS_CIPHER_AES_256_CBC,
307 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000308 256,
309 "AES-256-CBC",
310 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200311 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000312 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000313 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000314};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000316
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317#if defined(MBEDTLS_CIPHER_MODE_CFB)
318static const mbedtls_cipher_info_t aes_128_cfb128_info = {
319 MBEDTLS_CIPHER_AES_128_CFB128,
320 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000321 128,
322 "AES-128-CFB128",
323 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200324 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000325 16,
326 &aes_info
327};
328
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329static const mbedtls_cipher_info_t aes_192_cfb128_info = {
330 MBEDTLS_CIPHER_AES_192_CFB128,
331 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000332 192,
333 "AES-192-CFB128",
334 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200335 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000336 16,
337 &aes_info
338};
339
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340static const mbedtls_cipher_info_t aes_256_cfb128_info = {
341 MBEDTLS_CIPHER_AES_256_CFB128,
342 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 256,
344 "AES-256-CFB128",
345 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200346 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000347 16,
348 &aes_info
349};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200350#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000351
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100352#if defined(MBEDTLS_CIPHER_MODE_OFB)
353static const mbedtls_cipher_info_t aes_128_ofb_info = {
354 MBEDTLS_CIPHER_AES_128_OFB,
355 MBEDTLS_MODE_OFB,
356 128,
357 "AES-128-OFB",
358 16,
359 0,
360 16,
361 &aes_info
362};
363
364static const mbedtls_cipher_info_t aes_192_ofb_info = {
365 MBEDTLS_CIPHER_AES_192_OFB,
366 MBEDTLS_MODE_OFB,
367 192,
368 "AES-192-OFB",
369 16,
370 0,
371 16,
372 &aes_info
373};
374
375static const mbedtls_cipher_info_t aes_256_ofb_info = {
376 MBEDTLS_CIPHER_AES_256_OFB,
377 MBEDTLS_MODE_OFB,
378 256,
379 "AES-256-OFB",
380 16,
381 0,
382 16,
383 &aes_info
384};
385#endif /* MBEDTLS_CIPHER_MODE_OFB */
386
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200387#if defined(MBEDTLS_CIPHER_MODE_CTR)
388static const mbedtls_cipher_info_t aes_128_ctr_info = {
389 MBEDTLS_CIPHER_AES_128_CTR,
390 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000391 128,
392 "AES-128-CTR",
393 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200394 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000395 16,
396 &aes_info
397};
398
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399static const mbedtls_cipher_info_t aes_192_ctr_info = {
400 MBEDTLS_CIPHER_AES_192_CTR,
401 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000402 192,
403 "AES-192-CTR",
404 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200405 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000406 16,
407 &aes_info
408};
409
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200410static const mbedtls_cipher_info_t aes_256_ctr_info = {
411 MBEDTLS_CIPHER_AES_256_CTR,
412 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000413 256,
414 "AES-256-CTR",
415 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200416 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000417 16,
418 &aes_info
419};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200420#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000421
Jaeden Ameroc6539902018-04-30 17:17:41 +0100422#if defined(MBEDTLS_CIPHER_MODE_XTS)
423static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
424 unsigned int key_bitlen )
425{
426 mbedtls_aes_xts_context *xts_ctx = ctx;
427 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
428}
429
430static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
431 unsigned int key_bitlen )
432{
433 mbedtls_aes_xts_context *xts_ctx = ctx;
434 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
435}
436
437static void *xts_aes_ctx_alloc( void )
438{
439 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
440
441 if( xts_ctx != NULL )
442 mbedtls_aes_xts_init( xts_ctx );
443
444 return( xts_ctx );
445}
446
447static void xts_aes_ctx_free( void *ctx )
448{
449 mbedtls_aes_xts_context *xts_ctx = ctx;
450
451 if( xts_ctx == NULL )
452 return;
453
454 mbedtls_aes_xts_free( xts_ctx );
455 mbedtls_free( xts_ctx );
456}
457
458static const mbedtls_cipher_base_t xts_aes_info = {
459 MBEDTLS_CIPHER_ID_AES,
460 NULL,
461#if defined(MBEDTLS_CIPHER_MODE_CBC)
462 NULL,
463#endif
464#if defined(MBEDTLS_CIPHER_MODE_CFB)
465 NULL,
466#endif
467#if defined(MBEDTLS_CIPHER_MODE_OFB)
468 NULL,
469#endif
470#if defined(MBEDTLS_CIPHER_MODE_CTR)
471 NULL,
472#endif
473#if defined(MBEDTLS_CIPHER_MODE_XTS)
474 aes_crypt_xts_wrap,
475#endif
476#if defined(MBEDTLS_CIPHER_MODE_STREAM)
477 NULL,
478#endif
479 xts_aes_setkey_enc_wrap,
480 xts_aes_setkey_dec_wrap,
481 xts_aes_ctx_alloc,
482 xts_aes_ctx_free
483};
484
485static const mbedtls_cipher_info_t aes_128_xts_info = {
486 MBEDTLS_CIPHER_AES_128_XTS,
487 MBEDTLS_MODE_XTS,
488 256,
489 "AES-128-XTS",
490 16,
491 0,
492 16,
493 &xts_aes_info
494};
495
496static const mbedtls_cipher_info_t aes_256_xts_info = {
497 MBEDTLS_CIPHER_AES_256_XTS,
498 MBEDTLS_MODE_XTS,
499 512,
500 "AES-256-XTS",
501 16,
502 0,
503 16,
504 &xts_aes_info
505};
506#endif /* MBEDTLS_CIPHER_MODE_XTS */
507
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200508#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200509static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200510 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200511{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200512 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200513 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200514}
515
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200516static const mbedtls_cipher_base_t gcm_aes_info = {
517 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200518 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200519#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200520 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100521#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200522#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200523 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100524#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100525#if defined(MBEDTLS_CIPHER_MODE_OFB)
526 NULL,
527#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200528#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200529 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100530#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100531#if defined(MBEDTLS_CIPHER_MODE_XTS)
532 NULL,
533#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200534#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200535 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100536#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200537 gcm_aes_setkey_wrap,
538 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200539 gcm_ctx_alloc,
540 gcm_ctx_free,
541};
542
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200543static const mbedtls_cipher_info_t aes_128_gcm_info = {
544 MBEDTLS_CIPHER_AES_128_GCM,
545 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100546 128,
547 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200548 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200549 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100550 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200551 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100552};
553
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554static const mbedtls_cipher_info_t aes_192_gcm_info = {
555 MBEDTLS_CIPHER_AES_192_GCM,
556 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200557 192,
558 "AES-192-GCM",
559 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200561 16,
562 &gcm_aes_info
563};
564
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200565static const mbedtls_cipher_info_t aes_256_gcm_info = {
566 MBEDTLS_CIPHER_AES_256_GCM,
567 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100568 256,
569 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200570 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200571 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100572 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200573 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100574};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200575#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200578static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200579 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200580{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200581 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200582 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200583}
584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200585static const mbedtls_cipher_base_t ccm_aes_info = {
586 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200587 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200588#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200589 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100590#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200591#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200592 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100593#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100594#if defined(MBEDTLS_CIPHER_MODE_OFB)
595 NULL,
596#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200597#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200598 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100599#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100600#if defined(MBEDTLS_CIPHER_MODE_XTS)
601 NULL,
602#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200603#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200604 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100605#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200606 ccm_aes_setkey_wrap,
607 ccm_aes_setkey_wrap,
608 ccm_ctx_alloc,
609 ccm_ctx_free,
610};
611
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200612static const mbedtls_cipher_info_t aes_128_ccm_info = {
613 MBEDTLS_CIPHER_AES_128_CCM,
614 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200615 128,
616 "AES-128-CCM",
617 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200618 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200619 16,
620 &ccm_aes_info
621};
622
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200623static const mbedtls_cipher_info_t aes_192_ccm_info = {
624 MBEDTLS_CIPHER_AES_192_CCM,
625 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200626 192,
627 "AES-192-CCM",
628 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200629 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200630 16,
631 &ccm_aes_info
632};
633
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200634static const mbedtls_cipher_info_t aes_256_ccm_info = {
635 MBEDTLS_CIPHER_AES_256_CCM,
636 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200637 256,
638 "AES-256-CCM",
639 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200640 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200641 16,
642 &ccm_aes_info
643};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200644#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200645
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000647
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000649
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200650static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200651 const unsigned char *input, unsigned char *output )
652{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200653 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200654 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200655}
656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657#if defined(MBEDTLS_CIPHER_MODE_CBC)
658static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200659 size_t length, unsigned char *iv,
660 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000661{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200662 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200663 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000664}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200665#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000666
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200667#if defined(MBEDTLS_CIPHER_MODE_CFB)
668static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200669 size_t length, size_t *iv_off, unsigned char *iv,
670 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000671{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200673 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000674}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000676
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200677#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200678static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
679 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000680 const unsigned char *input, unsigned char *output )
681{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200683 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000684}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000686
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200687static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200688 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000689{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200690 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000691}
692
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200693static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200694 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000695{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200696 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000697}
698
699static void * camellia_ctx_alloc( void )
700{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200702 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200703
704 if( ctx == NULL )
705 return( NULL );
706
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200708
709 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000710}
711
712static void camellia_ctx_free( void *ctx )
713{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200714 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
715 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000716}
717
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200718static const mbedtls_cipher_base_t camellia_info = {
719 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200720 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200721#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000722 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100723#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200724#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000725 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100726#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100727#if defined(MBEDTLS_CIPHER_MODE_OFB)
728 NULL,
729#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200730#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000731 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100732#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100733#if defined(MBEDTLS_CIPHER_MODE_XTS)
734 NULL,
735#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200736#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200737 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100738#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000739 camellia_setkey_enc_wrap,
740 camellia_setkey_dec_wrap,
741 camellia_ctx_alloc,
742 camellia_ctx_free
743};
744
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745static const mbedtls_cipher_info_t camellia_128_ecb_info = {
746 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
747 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200748 128,
749 "CAMELLIA-128-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100750 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200751 0,
752 16,
753 &camellia_info
754};
755
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200756static const mbedtls_cipher_info_t camellia_192_ecb_info = {
757 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
758 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200759 192,
760 "CAMELLIA-192-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100761 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200762 0,
763 16,
764 &camellia_info
765};
766
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200767static const mbedtls_cipher_info_t camellia_256_ecb_info = {
768 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
769 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200770 256,
771 "CAMELLIA-256-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100772 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200773 0,
774 16,
775 &camellia_info
776};
777
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200778#if defined(MBEDTLS_CIPHER_MODE_CBC)
779static const mbedtls_cipher_info_t camellia_128_cbc_info = {
780 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
781 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000782 128,
783 "CAMELLIA-128-CBC",
784 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200785 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000786 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000787 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000788};
789
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200790static const mbedtls_cipher_info_t camellia_192_cbc_info = {
791 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
792 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000793 192,
794 "CAMELLIA-192-CBC",
795 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200796 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000797 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000798 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000799};
800
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200801static const mbedtls_cipher_info_t camellia_256_cbc_info = {
802 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
803 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000804 256,
805 "CAMELLIA-256-CBC",
806 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200807 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000808 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000809 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000810};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200811#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000812
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200813#if defined(MBEDTLS_CIPHER_MODE_CFB)
814static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
815 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
816 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000817 128,
818 "CAMELLIA-128-CFB128",
819 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200820 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000821 16,
822 &camellia_info
823};
824
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200825static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
826 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
827 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000828 192,
829 "CAMELLIA-192-CFB128",
830 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200831 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000832 16,
833 &camellia_info
834};
835
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
837 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
838 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000839 256,
840 "CAMELLIA-256-CFB128",
841 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200842 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000843 16,
844 &camellia_info
845};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200846#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000847
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200848#if defined(MBEDTLS_CIPHER_MODE_CTR)
849static const mbedtls_cipher_info_t camellia_128_ctr_info = {
850 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
851 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000852 128,
853 "CAMELLIA-128-CTR",
854 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200855 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000856 16,
857 &camellia_info
858};
859
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200860static const mbedtls_cipher_info_t camellia_192_ctr_info = {
861 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
862 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000863 192,
864 "CAMELLIA-192-CTR",
865 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200866 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000867 16,
868 &camellia_info
869};
870
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200871static const mbedtls_cipher_info_t camellia_256_ctr_info = {
872 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
873 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000874 256,
875 "CAMELLIA-256-CTR",
876 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200877 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000878 16,
879 &camellia_info
880};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200881#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000882
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200883#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200884static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200885 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200886{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200887 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200888 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200889}
890
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200891static const mbedtls_cipher_base_t gcm_camellia_info = {
892 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200893 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200894#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200895 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100896#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200897#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200898 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100899#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100900#if defined(MBEDTLS_CIPHER_MODE_OFB)
901 NULL,
902#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200903#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200904 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100905#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100906#if defined(MBEDTLS_CIPHER_MODE_XTS)
907 NULL,
908#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200909#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200910 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100911#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200912 gcm_camellia_setkey_wrap,
913 gcm_camellia_setkey_wrap,
914 gcm_ctx_alloc,
915 gcm_ctx_free,
916};
917
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200918static const mbedtls_cipher_info_t camellia_128_gcm_info = {
919 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
920 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200921 128,
922 "CAMELLIA-128-GCM",
923 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200924 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200925 16,
926 &gcm_camellia_info
927};
928
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200929static const mbedtls_cipher_info_t camellia_192_gcm_info = {
930 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
931 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200932 192,
933 "CAMELLIA-192-GCM",
934 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200935 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200936 16,
937 &gcm_camellia_info
938};
939
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200940static const mbedtls_cipher_info_t camellia_256_gcm_info = {
941 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
942 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200943 256,
944 "CAMELLIA-256-GCM",
945 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200946 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200947 16,
948 &gcm_camellia_info
949};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200950#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200951
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200952#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200953static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200954 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200955{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200956 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200957 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200958}
959
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200960static const mbedtls_cipher_base_t ccm_camellia_info = {
961 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200962 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200963#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200964 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100965#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200966#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200967 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100968#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100969#if defined(MBEDTLS_CIPHER_MODE_OFB)
970 NULL,
971#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200972#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200973 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100974#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100975#if defined(MBEDTLS_CIPHER_MODE_XTS)
976 NULL,
977#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200978#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200979 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100980#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200981 ccm_camellia_setkey_wrap,
982 ccm_camellia_setkey_wrap,
983 ccm_ctx_alloc,
984 ccm_ctx_free,
985};
986
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200987static const mbedtls_cipher_info_t camellia_128_ccm_info = {
988 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
989 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200990 128,
991 "CAMELLIA-128-CCM",
992 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200993 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200994 16,
995 &ccm_camellia_info
996};
997
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200998static const mbedtls_cipher_info_t camellia_192_ccm_info = {
999 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1000 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001001 192,
1002 "CAMELLIA-192-CCM",
1003 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001004 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001005 16,
1006 &ccm_camellia_info
1007};
1008
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001009static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1010 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1011 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001012 256,
1013 "CAMELLIA-256-CCM",
1014 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001015 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001016 16,
1017 &ccm_camellia_info
1018};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001019#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001020
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001021#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001022
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001023#if defined(MBEDTLS_ARIA_C)
1024
1025static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1026 const unsigned char *input, unsigned char *output )
1027{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001028 (void) operation;
1029 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001030 output );
1031}
1032
1033#if defined(MBEDTLS_CIPHER_MODE_CBC)
1034static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1035 size_t length, unsigned char *iv,
1036 const unsigned char *input, unsigned char *output )
1037{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001038 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001039 input, output );
1040}
1041#endif /* MBEDTLS_CIPHER_MODE_CBC */
1042
1043#if defined(MBEDTLS_CIPHER_MODE_CFB)
1044static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1045 size_t length, size_t *iv_off, unsigned char *iv,
1046 const unsigned char *input, unsigned char *output )
1047{
1048 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1049 iv_off, iv, input, output );
1050}
1051#endif /* MBEDTLS_CIPHER_MODE_CFB */
1052
1053#if defined(MBEDTLS_CIPHER_MODE_CTR)
1054static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1055 unsigned char *nonce_counter, unsigned char *stream_block,
1056 const unsigned char *input, unsigned char *output )
1057{
1058 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1059 nonce_counter, stream_block, input, output );
1060}
1061#endif /* MBEDTLS_CIPHER_MODE_CTR */
1062
1063static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1064 unsigned int key_bitlen )
1065{
1066 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1067}
1068
1069static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1070 unsigned int key_bitlen )
1071{
1072 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1073}
1074
1075static void * aria_ctx_alloc( void )
1076{
1077 mbedtls_aria_context *ctx;
1078 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1079
1080 if( ctx == NULL )
1081 return( NULL );
1082
1083 mbedtls_aria_init( ctx );
1084
1085 return( ctx );
1086}
1087
1088static void aria_ctx_free( void *ctx )
1089{
1090 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1091 mbedtls_free( ctx );
1092}
1093
1094static const mbedtls_cipher_base_t aria_info = {
1095 MBEDTLS_CIPHER_ID_ARIA,
1096 aria_crypt_ecb_wrap,
1097#if defined(MBEDTLS_CIPHER_MODE_CBC)
1098 aria_crypt_cbc_wrap,
1099#endif
1100#if defined(MBEDTLS_CIPHER_MODE_CFB)
1101 aria_crypt_cfb128_wrap,
1102#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001103#if defined(MBEDTLS_CIPHER_MODE_OFB)
1104 NULL,
1105#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001106#if defined(MBEDTLS_CIPHER_MODE_CTR)
1107 aria_crypt_ctr_wrap,
1108#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001109#if defined(MBEDTLS_CIPHER_MODE_XTS)
1110 NULL,
1111#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001112#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1113 NULL,
1114#endif
1115 aria_setkey_enc_wrap,
1116 aria_setkey_dec_wrap,
1117 aria_ctx_alloc,
1118 aria_ctx_free
1119};
1120
1121static const mbedtls_cipher_info_t aria_128_ecb_info = {
1122 MBEDTLS_CIPHER_ARIA_128_ECB,
1123 MBEDTLS_MODE_ECB,
1124 128,
1125 "ARIA-128-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001126 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001127 0,
1128 16,
1129 &aria_info
1130};
1131
1132static const mbedtls_cipher_info_t aria_192_ecb_info = {
1133 MBEDTLS_CIPHER_ARIA_192_ECB,
1134 MBEDTLS_MODE_ECB,
1135 192,
1136 "ARIA-192-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001137 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001138 0,
1139 16,
1140 &aria_info
1141};
1142
1143static const mbedtls_cipher_info_t aria_256_ecb_info = {
1144 MBEDTLS_CIPHER_ARIA_256_ECB,
1145 MBEDTLS_MODE_ECB,
1146 256,
1147 "ARIA-256-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001148 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001149 0,
1150 16,
1151 &aria_info
1152};
1153
1154#if defined(MBEDTLS_CIPHER_MODE_CBC)
1155static const mbedtls_cipher_info_t aria_128_cbc_info = {
1156 MBEDTLS_CIPHER_ARIA_128_CBC,
1157 MBEDTLS_MODE_CBC,
1158 128,
1159 "ARIA-128-CBC",
1160 16,
1161 0,
1162 16,
1163 &aria_info
1164};
1165
1166static const mbedtls_cipher_info_t aria_192_cbc_info = {
1167 MBEDTLS_CIPHER_ARIA_192_CBC,
1168 MBEDTLS_MODE_CBC,
1169 192,
1170 "ARIA-192-CBC",
1171 16,
1172 0,
1173 16,
1174 &aria_info
1175};
1176
1177static const mbedtls_cipher_info_t aria_256_cbc_info = {
1178 MBEDTLS_CIPHER_ARIA_256_CBC,
1179 MBEDTLS_MODE_CBC,
1180 256,
1181 "ARIA-256-CBC",
1182 16,
1183 0,
1184 16,
1185 &aria_info
1186};
1187#endif /* MBEDTLS_CIPHER_MODE_CBC */
1188
1189#if defined(MBEDTLS_CIPHER_MODE_CFB)
1190static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1191 MBEDTLS_CIPHER_ARIA_128_CFB128,
1192 MBEDTLS_MODE_CFB,
1193 128,
1194 "ARIA-128-CFB128",
1195 16,
1196 0,
1197 16,
1198 &aria_info
1199};
1200
1201static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1202 MBEDTLS_CIPHER_ARIA_192_CFB128,
1203 MBEDTLS_MODE_CFB,
1204 192,
1205 "ARIA-192-CFB128",
1206 16,
1207 0,
1208 16,
1209 &aria_info
1210};
1211
1212static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1213 MBEDTLS_CIPHER_ARIA_256_CFB128,
1214 MBEDTLS_MODE_CFB,
1215 256,
1216 "ARIA-256-CFB128",
1217 16,
1218 0,
1219 16,
1220 &aria_info
1221};
1222#endif /* MBEDTLS_CIPHER_MODE_CFB */
1223
1224#if defined(MBEDTLS_CIPHER_MODE_CTR)
1225static const mbedtls_cipher_info_t aria_128_ctr_info = {
1226 MBEDTLS_CIPHER_ARIA_128_CTR,
1227 MBEDTLS_MODE_CTR,
1228 128,
1229 "ARIA-128-CTR",
1230 16,
1231 0,
1232 16,
1233 &aria_info
1234};
1235
1236static const mbedtls_cipher_info_t aria_192_ctr_info = {
1237 MBEDTLS_CIPHER_ARIA_192_CTR,
1238 MBEDTLS_MODE_CTR,
1239 192,
1240 "ARIA-192-CTR",
1241 16,
1242 0,
1243 16,
1244 &aria_info
1245};
1246
1247static const mbedtls_cipher_info_t aria_256_ctr_info = {
1248 MBEDTLS_CIPHER_ARIA_256_CTR,
1249 MBEDTLS_MODE_CTR,
1250 256,
1251 "ARIA-256-CTR",
1252 16,
1253 0,
1254 16,
1255 &aria_info
1256};
1257#endif /* MBEDTLS_CIPHER_MODE_CTR */
1258
1259#if defined(MBEDTLS_GCM_C)
1260static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1261 unsigned int key_bitlen )
1262{
1263 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1264 key, key_bitlen );
1265}
1266
1267static const mbedtls_cipher_base_t gcm_aria_info = {
1268 MBEDTLS_CIPHER_ID_ARIA,
1269 NULL,
1270#if defined(MBEDTLS_CIPHER_MODE_CBC)
1271 NULL,
1272#endif
1273#if defined(MBEDTLS_CIPHER_MODE_CFB)
1274 NULL,
1275#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001276#if defined(MBEDTLS_CIPHER_MODE_OFB)
1277 NULL,
1278#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001279#if defined(MBEDTLS_CIPHER_MODE_CTR)
1280 NULL,
1281#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001282#if defined(MBEDTLS_CIPHER_MODE_XTS)
1283 NULL,
1284#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001285#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1286 NULL,
1287#endif
1288 gcm_aria_setkey_wrap,
1289 gcm_aria_setkey_wrap,
1290 gcm_ctx_alloc,
1291 gcm_ctx_free,
1292};
1293
1294static const mbedtls_cipher_info_t aria_128_gcm_info = {
1295 MBEDTLS_CIPHER_ARIA_128_GCM,
1296 MBEDTLS_MODE_GCM,
1297 128,
1298 "ARIA-128-GCM",
1299 12,
1300 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1301 16,
1302 &gcm_aria_info
1303};
1304
1305static const mbedtls_cipher_info_t aria_192_gcm_info = {
1306 MBEDTLS_CIPHER_ARIA_192_GCM,
1307 MBEDTLS_MODE_GCM,
1308 192,
1309 "ARIA-192-GCM",
1310 12,
1311 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1312 16,
1313 &gcm_aria_info
1314};
1315
1316static const mbedtls_cipher_info_t aria_256_gcm_info = {
1317 MBEDTLS_CIPHER_ARIA_256_GCM,
1318 MBEDTLS_MODE_GCM,
1319 256,
1320 "ARIA-256-GCM",
1321 12,
1322 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1323 16,
1324 &gcm_aria_info
1325};
1326#endif /* MBEDTLS_GCM_C */
1327
1328#if defined(MBEDTLS_CCM_C)
1329static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1330 unsigned int key_bitlen )
1331{
1332 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1333 key, key_bitlen );
1334}
1335
1336static const mbedtls_cipher_base_t ccm_aria_info = {
1337 MBEDTLS_CIPHER_ID_ARIA,
1338 NULL,
1339#if defined(MBEDTLS_CIPHER_MODE_CBC)
1340 NULL,
1341#endif
1342#if defined(MBEDTLS_CIPHER_MODE_CFB)
1343 NULL,
1344#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001345#if defined(MBEDTLS_CIPHER_MODE_OFB)
1346 NULL,
1347#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001348#if defined(MBEDTLS_CIPHER_MODE_CTR)
1349 NULL,
1350#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001351#if defined(MBEDTLS_CIPHER_MODE_XTS)
1352 NULL,
1353#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001354#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1355 NULL,
1356#endif
1357 ccm_aria_setkey_wrap,
1358 ccm_aria_setkey_wrap,
1359 ccm_ctx_alloc,
1360 ccm_ctx_free,
1361};
1362
1363static const mbedtls_cipher_info_t aria_128_ccm_info = {
1364 MBEDTLS_CIPHER_ARIA_128_CCM,
1365 MBEDTLS_MODE_CCM,
1366 128,
1367 "ARIA-128-CCM",
1368 12,
1369 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1370 16,
1371 &ccm_aria_info
1372};
1373
1374static const mbedtls_cipher_info_t aria_192_ccm_info = {
1375 MBEDTLS_CIPHER_ARIA_192_CCM,
1376 MBEDTLS_MODE_CCM,
1377 192,
1378 "ARIA-192-CCM",
1379 12,
1380 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1381 16,
1382 &ccm_aria_info
1383};
1384
1385static const mbedtls_cipher_info_t aria_256_ccm_info = {
1386 MBEDTLS_CIPHER_ARIA_256_CCM,
1387 MBEDTLS_MODE_CCM,
1388 256,
1389 "ARIA-256-CCM",
1390 12,
1391 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1392 16,
1393 &ccm_aria_info
1394};
1395#endif /* MBEDTLS_CCM_C */
1396
1397#endif /* MBEDTLS_ARIA_C */
1398
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001399#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001400
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001401static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001402 const unsigned char *input, unsigned char *output )
1403{
1404 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001405 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001406}
1407
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001408static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001409 const unsigned char *input, unsigned char *output )
1410{
1411 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001412 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001413}
1414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001415#if defined(MBEDTLS_CIPHER_MODE_CBC)
1416static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001417 unsigned char *iv, const unsigned char *input, unsigned char *output )
1418{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001419 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001420 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001421}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001422#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001423
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001424#if defined(MBEDTLS_CIPHER_MODE_CBC)
1425static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001426 unsigned char *iv, const unsigned char *input, unsigned char *output )
1427{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001428 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001429 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001430}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001431#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001432
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001433static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001434 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001435{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001436 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001437
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001438 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001439}
1440
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001441static int des_setkey_enc_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_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001447}
1448
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001449static int des3_set2key_dec_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_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001455}
1456
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001457static int des3_set2key_enc_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_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001463}
1464
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001465static int des3_set3key_dec_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_set3key_dec( (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_enc_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_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001479}
1480
1481static void * des_ctx_alloc( void )
1482{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001483 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001484
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001485 if( des == NULL )
1486 return( NULL );
1487
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001488 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001489
1490 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001491}
1492
1493static void des_ctx_free( void *ctx )
1494{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001495 mbedtls_des_free( (mbedtls_des_context *) ctx );
1496 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001497}
1498
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001499static void * des3_ctx_alloc( void )
1500{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001501 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001502 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001503
1504 if( des3 == NULL )
1505 return( NULL );
1506
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001507 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001508
1509 return( des3 );
1510}
1511
Paul Bakker34617722014-06-13 17:20:13 +02001512static void des3_ctx_free( void *ctx )
1513{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001514 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1515 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001516}
1517
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001518static const mbedtls_cipher_base_t des_info = {
1519 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001520 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001521#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001522 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001523#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001524#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001525 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001526#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001527#if defined(MBEDTLS_CIPHER_MODE_OFB)
1528 NULL,
1529#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001530#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001531 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001532#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001533#if defined(MBEDTLS_CIPHER_MODE_XTS)
1534 NULL,
1535#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001536#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001537 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001538#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001539 des_setkey_enc_wrap,
1540 des_setkey_dec_wrap,
1541 des_ctx_alloc,
1542 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001543};
1544
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001545static const mbedtls_cipher_info_t des_ecb_info = {
1546 MBEDTLS_CIPHER_DES_ECB,
1547 MBEDTLS_MODE_ECB,
1548 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001549 "DES-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001550 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001551 0,
1552 8,
1553 &des_info
1554};
1555
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001556#if defined(MBEDTLS_CIPHER_MODE_CBC)
1557static const mbedtls_cipher_info_t des_cbc_info = {
1558 MBEDTLS_CIPHER_DES_CBC,
1559 MBEDTLS_MODE_CBC,
1560 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001561 "DES-CBC",
1562 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001563 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001564 8,
1565 &des_info
1566};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001567#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001568
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001569static const mbedtls_cipher_base_t des_ede_info = {
1570 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001571 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001572#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001573 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001574#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001575#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001576 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001577#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001578#if defined(MBEDTLS_CIPHER_MODE_OFB)
1579 NULL,
1580#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001581#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001582 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001583#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001584#if defined(MBEDTLS_CIPHER_MODE_XTS)
1585 NULL,
1586#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001587#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001588 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001589#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001590 des3_set2key_enc_wrap,
1591 des3_set2key_dec_wrap,
1592 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001593 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001594};
1595
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001596static const mbedtls_cipher_info_t des_ede_ecb_info = {
1597 MBEDTLS_CIPHER_DES_EDE_ECB,
1598 MBEDTLS_MODE_ECB,
1599 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001600 "DES-EDE-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001601 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001602 0,
1603 8,
1604 &des_ede_info
1605};
1606
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001607#if defined(MBEDTLS_CIPHER_MODE_CBC)
1608static const mbedtls_cipher_info_t des_ede_cbc_info = {
1609 MBEDTLS_CIPHER_DES_EDE_CBC,
1610 MBEDTLS_MODE_CBC,
1611 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001612 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001613 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001614 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001615 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001616 &des_ede_info
1617};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001619
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001620static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001621 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001622 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001623#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001624 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001625#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001626#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001627 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001628#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001629#if defined(MBEDTLS_CIPHER_MODE_OFB)
1630 NULL,
1631#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001632#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001633 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001634#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001635#if defined(MBEDTLS_CIPHER_MODE_XTS)
1636 NULL,
1637#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001638#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001639 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001640#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001641 des3_set3key_enc_wrap,
1642 des3_set3key_dec_wrap,
1643 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001644 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001645};
1646
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001647static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1648 MBEDTLS_CIPHER_DES_EDE3_ECB,
1649 MBEDTLS_MODE_ECB,
1650 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001651 "DES-EDE3-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001652 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001653 0,
1654 8,
1655 &des_ede3_info
1656};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001657#if defined(MBEDTLS_CIPHER_MODE_CBC)
1658static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1659 MBEDTLS_CIPHER_DES_EDE3_CBC,
1660 MBEDTLS_MODE_CBC,
1661 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001662 "DES-EDE3-CBC",
1663 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001664 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001665 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001666 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001667};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001668#endif /* MBEDTLS_CIPHER_MODE_CBC */
1669#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001670
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001671#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001672
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001673static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001674 const unsigned char *input, unsigned char *output )
1675{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001676 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001677 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001678}
1679
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001680#if defined(MBEDTLS_CIPHER_MODE_CBC)
1681static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001682 size_t length, unsigned char *iv, const unsigned char *input,
1683 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001684{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001685 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001686 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001687}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001688#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001689
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001690#if defined(MBEDTLS_CIPHER_MODE_CFB)
1691static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001692 size_t length, size_t *iv_off, unsigned char *iv,
1693 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001694{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001695 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001696 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001697}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001698#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001699
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001700#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001701static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1702 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001703 const unsigned char *input, unsigned char *output )
1704{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001705 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001706 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001707}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001708#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001709
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001710static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001711 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001712{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001713 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001714}
1715
1716static void * blowfish_ctx_alloc( void )
1717{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001718 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001719 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001720
1721 if( ctx == NULL )
1722 return( NULL );
1723
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001724 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001725
1726 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001727}
1728
1729static void blowfish_ctx_free( void *ctx )
1730{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001731 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1732 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001733}
1734
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001735static const mbedtls_cipher_base_t blowfish_info = {
1736 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001737 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001738#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001739 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001740#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001741#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001742 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001743#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001744#if defined(MBEDTLS_CIPHER_MODE_OFB)
1745 NULL,
1746#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001747#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001748 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001749#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001750#if defined(MBEDTLS_CIPHER_MODE_XTS)
1751 NULL,
1752#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001753#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001754 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001755#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001756 blowfish_setkey_wrap,
1757 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001758 blowfish_ctx_alloc,
1759 blowfish_ctx_free
1760};
1761
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001762static const mbedtls_cipher_info_t blowfish_ecb_info = {
1763 MBEDTLS_CIPHER_BLOWFISH_ECB,
1764 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001765 128,
1766 "BLOWFISH-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001767 0,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001768 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001769 8,
1770 &blowfish_info
1771};
1772
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001773#if defined(MBEDTLS_CIPHER_MODE_CBC)
1774static const mbedtls_cipher_info_t blowfish_cbc_info = {
1775 MBEDTLS_CIPHER_BLOWFISH_CBC,
1776 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001777 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001778 "BLOWFISH-CBC",
1779 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001780 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001781 8,
1782 &blowfish_info
1783};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001784#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001785
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001786#if defined(MBEDTLS_CIPHER_MODE_CFB)
1787static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1788 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1789 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001790 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001791 "BLOWFISH-CFB64",
1792 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001793 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001794 8,
1795 &blowfish_info
1796};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001797#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001798
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001799#if defined(MBEDTLS_CIPHER_MODE_CTR)
1800static const mbedtls_cipher_info_t blowfish_ctr_info = {
1801 MBEDTLS_CIPHER_BLOWFISH_CTR,
1802 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001803 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001804 "BLOWFISH-CTR",
1805 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001806 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001807 8,
1808 &blowfish_info
1809};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001810#endif /* MBEDTLS_CIPHER_MODE_CTR */
1811#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001812
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001813#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001814static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1815 const unsigned char *input,
1816 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001817{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001818 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001819}
1820
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001821static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001822 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001823{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001824 /* we get key_bitlen in bits, arc4 expects it in bytes */
1825 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001826 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001827
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001828 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001829 return( 0 );
1830}
1831
1832static void * arc4_ctx_alloc( void )
1833{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001834 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001835 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001836
1837 if( ctx == NULL )
1838 return( NULL );
1839
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001840 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001841
1842 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001843}
Paul Bakker68884e32013-01-07 18:20:04 +01001844
1845static void arc4_ctx_free( void *ctx )
1846{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001847 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1848 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001849}
1850
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001851static const mbedtls_cipher_base_t arc4_base_info = {
1852 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001853 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001854#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001855 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001856#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001857#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001858 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001859#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001860#if defined(MBEDTLS_CIPHER_MODE_OFB)
1861 NULL,
1862#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001863#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001864 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001865#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001866#if defined(MBEDTLS_CIPHER_MODE_XTS)
1867 NULL,
1868#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001869#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001870 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001871#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001872 arc4_setkey_wrap,
1873 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001874 arc4_ctx_alloc,
1875 arc4_ctx_free
1876};
1877
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001878static const mbedtls_cipher_info_t arc4_128_info = {
1879 MBEDTLS_CIPHER_ARC4_128,
1880 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001881 128,
1882 "ARC4-128",
1883 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001884 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001885 1,
1886 &arc4_base_info
1887};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001888#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001889
Daniel Kingbd920622016-05-15 19:56:20 -03001890#if defined(MBEDTLS_CHACHA20_C)
1891
1892static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1893 unsigned int key_bitlen )
1894{
1895 if( key_bitlen != 256U )
1896 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1897
1898 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1899 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1900
1901 return( 0 );
1902}
1903
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001904static int chacha20_stream_wrap( void *ctx, size_t length,
1905 const unsigned char *input,
1906 unsigned char *output )
1907{
Janos Follath24eed8d2019-11-22 13:21:35 +00001908 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001909
1910 ret = mbedtls_chacha20_update( ctx, length, input, output );
1911 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1912 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1913
1914 return( ret );
1915}
1916
Daniel Kingbd920622016-05-15 19:56:20 -03001917static void * chacha20_ctx_alloc( void )
1918{
1919 mbedtls_chacha20_context *ctx;
1920 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1921
1922 if( ctx == NULL )
1923 return( NULL );
1924
1925 mbedtls_chacha20_init( ctx );
1926
1927 return( ctx );
1928}
1929
1930static void chacha20_ctx_free( void *ctx )
1931{
1932 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1933 mbedtls_free( ctx );
1934}
1935
1936static const mbedtls_cipher_base_t chacha20_base_info = {
1937 MBEDTLS_CIPHER_ID_CHACHA20,
1938 NULL,
1939#if defined(MBEDTLS_CIPHER_MODE_CBC)
1940 NULL,
1941#endif
1942#if defined(MBEDTLS_CIPHER_MODE_CFB)
1943 NULL,
1944#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001945#if defined(MBEDTLS_CIPHER_MODE_OFB)
1946 NULL,
1947#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001948#if defined(MBEDTLS_CIPHER_MODE_CTR)
1949 NULL,
1950#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001951#if defined(MBEDTLS_CIPHER_MODE_XTS)
1952 NULL,
1953#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001954#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001955 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001956#endif
1957 chacha20_setkey_wrap,
1958 chacha20_setkey_wrap,
1959 chacha20_ctx_alloc,
1960 chacha20_ctx_free
1961};
1962static const mbedtls_cipher_info_t chacha20_info = {
1963 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001964 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001965 256,
1966 "CHACHA20",
1967 12,
1968 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001969 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001970 &chacha20_base_info
1971};
1972#endif /* MBEDTLS_CHACHA20_C */
1973
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001974#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001975
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001976static int chachapoly_setkey_wrap( void *ctx,
1977 const unsigned char *key,
1978 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001979{
1980 if( key_bitlen != 256U )
1981 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1982
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001983 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001984 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1985
1986 return( 0 );
1987}
1988
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001989static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03001990{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001991 mbedtls_chachapoly_context *ctx;
1992 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03001993
1994 if( ctx == NULL )
1995 return( NULL );
1996
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001997 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001998
1999 return( ctx );
2000}
2001
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002002static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002003{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002004 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002005 mbedtls_free( ctx );
2006}
2007
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002008static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002009 MBEDTLS_CIPHER_ID_CHACHA20,
2010 NULL,
2011#if defined(MBEDTLS_CIPHER_MODE_CBC)
2012 NULL,
2013#endif
2014#if defined(MBEDTLS_CIPHER_MODE_CFB)
2015 NULL,
2016#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002017#if defined(MBEDTLS_CIPHER_MODE_OFB)
2018 NULL,
2019#endif
Daniel King8fe47012016-05-17 20:33:28 -03002020#if defined(MBEDTLS_CIPHER_MODE_CTR)
2021 NULL,
2022#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002023#if defined(MBEDTLS_CIPHER_MODE_XTS)
2024 NULL,
2025#endif
Daniel King8fe47012016-05-17 20:33:28 -03002026#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2027 NULL,
2028#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002029 chachapoly_setkey_wrap,
2030 chachapoly_setkey_wrap,
2031 chachapoly_ctx_alloc,
2032 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002033};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002034static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002035 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002036 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002037 256,
2038 "CHACHA20-POLY1305",
2039 12,
2040 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002041 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002042 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002043};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002044#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002045
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002046#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002047static int null_crypt_stream( void *ctx, size_t length,
2048 const unsigned char *input,
2049 unsigned char *output )
2050{
2051 ((void) ctx);
2052 memmove( output, input, length );
2053 return( 0 );
2054}
2055
2056static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002057 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002058{
2059 ((void) ctx);
2060 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002061 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002062
2063 return( 0 );
2064}
2065
Paul Bakkerfab5c822012-02-06 16:45:10 +00002066static void * null_ctx_alloc( void )
2067{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002068 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002069}
2070
Paul Bakkerfab5c822012-02-06 16:45:10 +00002071static void null_ctx_free( void *ctx )
2072{
2073 ((void) ctx);
2074}
2075
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002076static const mbedtls_cipher_base_t null_base_info = {
2077 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002078 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002079#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002080 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002081#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002082#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002083 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002084#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002085#if defined(MBEDTLS_CIPHER_MODE_OFB)
2086 NULL,
2087#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002088#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002089 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002090#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002091#if defined(MBEDTLS_CIPHER_MODE_XTS)
2092 NULL,
2093#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002094#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002095 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002096#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002097 null_setkey,
2098 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002099 null_ctx_alloc,
2100 null_ctx_free
2101};
2102
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002103static const mbedtls_cipher_info_t null_cipher_info = {
2104 MBEDTLS_CIPHER_NULL,
2105 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002106 0,
2107 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002108 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002109 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002110 1,
2111 &null_base_info
2112};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002113#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002114
Jack Lloydffdf2882019-03-07 17:00:32 -05002115#if defined(MBEDTLS_NIST_KW_C)
2116static void *kw_ctx_alloc( void )
2117{
2118 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
2119
2120 if( ctx != NULL )
2121 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
2122
2123 return( ctx );
2124}
2125
2126static void kw_ctx_free( void *ctx )
2127{
2128 mbedtls_nist_kw_free( ctx );
2129 mbedtls_free( ctx );
2130}
2131
2132static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
2133 unsigned int key_bitlen )
2134{
Jack Lloyd5f289992019-04-02 10:07:28 -07002135 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2136 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002137}
2138
2139static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
2140 unsigned int key_bitlen )
2141{
Jack Lloyd5f289992019-04-02 10:07:28 -07002142 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2143 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002144}
2145
2146static const mbedtls_cipher_base_t kw_aes_info = {
2147 MBEDTLS_CIPHER_ID_AES,
2148 NULL,
2149#if defined(MBEDTLS_CIPHER_MODE_CBC)
2150 NULL,
2151#endif
2152#if defined(MBEDTLS_CIPHER_MODE_CFB)
2153 NULL,
2154#endif
2155#if defined(MBEDTLS_CIPHER_MODE_OFB)
2156 NULL,
2157#endif
2158#if defined(MBEDTLS_CIPHER_MODE_CTR)
2159 NULL,
2160#endif
2161#if defined(MBEDTLS_CIPHER_MODE_XTS)
2162 NULL,
2163#endif
2164#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2165 NULL,
2166#endif
2167 kw_aes_setkey_wrap,
2168 kw_aes_setkey_unwrap,
2169 kw_ctx_alloc,
2170 kw_ctx_free,
2171};
2172
2173static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
2174 MBEDTLS_CIPHER_AES_128_KW,
2175 MBEDTLS_MODE_KW,
2176 128,
2177 "AES-128-KW",
2178 0,
2179 0,
2180 16,
2181 &kw_aes_info
2182};
2183
2184static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
2185 MBEDTLS_CIPHER_AES_192_KW,
2186 MBEDTLS_MODE_KW,
2187 192,
2188 "AES-192-KW",
2189 0,
2190 0,
2191 16,
2192 &kw_aes_info
2193};
2194
2195static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
2196 MBEDTLS_CIPHER_AES_256_KW,
2197 MBEDTLS_MODE_KW,
2198 256,
2199 "AES-256-KW",
2200 0,
2201 0,
2202 16,
2203 &kw_aes_info
2204};
2205
2206static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
2207 MBEDTLS_CIPHER_AES_128_KWP,
2208 MBEDTLS_MODE_KWP,
2209 128,
2210 "AES-128-KWP",
2211 0,
2212 0,
2213 16,
2214 &kw_aes_info
2215};
2216
2217static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
2218 MBEDTLS_CIPHER_AES_192_KWP,
2219 MBEDTLS_MODE_KWP,
2220 192,
2221 "AES-192-KWP",
2222 0,
2223 0,
2224 16,
2225 &kw_aes_info
2226};
2227
2228static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
2229 MBEDTLS_CIPHER_AES_256_KWP,
2230 MBEDTLS_MODE_KWP,
2231 256,
2232 "AES-256-KWP",
2233 0,
2234 0,
2235 16,
2236 &kw_aes_info
2237};
2238#endif /* MBEDTLS_NIST_KW_C */
2239
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002240const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002241{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002242#if defined(MBEDTLS_AES_C)
2243 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2244 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2245 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2246#if defined(MBEDTLS_CIPHER_MODE_CBC)
2247 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2248 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2249 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002250#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002251#if defined(MBEDTLS_CIPHER_MODE_CFB)
2252 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2253 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2254 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002255#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002256#if defined(MBEDTLS_CIPHER_MODE_OFB)
2257 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2258 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2259 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2260#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002261#if defined(MBEDTLS_CIPHER_MODE_CTR)
2262 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2263 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2264 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002265#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002266#if defined(MBEDTLS_CIPHER_MODE_XTS)
2267 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2268 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2269#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002270#if defined(MBEDTLS_GCM_C)
2271 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2272 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2273 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002274#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002275#if defined(MBEDTLS_CCM_C)
2276 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2277 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2278 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002279#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002280#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002282#if defined(MBEDTLS_ARC4_C)
2283 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002284#endif
2285
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002286#if defined(MBEDTLS_BLOWFISH_C)
2287 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2288#if defined(MBEDTLS_CIPHER_MODE_CBC)
2289 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002290#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002291#if defined(MBEDTLS_CIPHER_MODE_CFB)
2292 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002293#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002294#if defined(MBEDTLS_CIPHER_MODE_CTR)
2295 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002296#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002297#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002298
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002299#if defined(MBEDTLS_CAMELLIA_C)
2300 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2301 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2302 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2303#if defined(MBEDTLS_CIPHER_MODE_CBC)
2304 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2305 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2306 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002307#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002308#if defined(MBEDTLS_CIPHER_MODE_CFB)
2309 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2310 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2311 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002312#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002313#if defined(MBEDTLS_CIPHER_MODE_CTR)
2314 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2315 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2316 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002317#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002318#if defined(MBEDTLS_GCM_C)
2319 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2320 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2321 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002322#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002323#if defined(MBEDTLS_CCM_C)
2324 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2325 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2326 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002327#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002328#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002329
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002330#if defined(MBEDTLS_ARIA_C)
2331 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2332 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2333 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2334#if defined(MBEDTLS_CIPHER_MODE_CBC)
2335 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2336 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2337 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2338#endif
2339#if defined(MBEDTLS_CIPHER_MODE_CFB)
2340 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2341 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2342 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2343#endif
2344#if defined(MBEDTLS_CIPHER_MODE_CTR)
2345 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2346 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2347 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2348#endif
2349#if defined(MBEDTLS_GCM_C)
2350 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2351 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2352 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2353#endif
2354#if defined(MBEDTLS_CCM_C)
2355 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2356 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2357 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2358#endif
2359#endif /* MBEDTLS_ARIA_C */
2360
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002361#if defined(MBEDTLS_DES_C)
2362 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2363 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2364 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2365#if defined(MBEDTLS_CIPHER_MODE_CBC)
2366 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2367 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2368 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002369#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002370#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002371
Daniel Kingbd920622016-05-15 19:56:20 -03002372#if defined(MBEDTLS_CHACHA20_C)
2373 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2374#endif
2375
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002376#if defined(MBEDTLS_CHACHAPOLY_C)
2377 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002378#endif
2379
Jack Lloydffdf2882019-03-07 17:00:32 -05002380#if defined(MBEDTLS_NIST_KW_C)
2381 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
2382 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
2383 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
2384 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
2385 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
2386 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
2387#endif
2388
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002389#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2390 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2391#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002392
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002393 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002394};
2395
Hanno Beckerc3d25b32018-11-08 16:01:22 +00002396#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
2397 sizeof(mbedtls_cipher_definitions[0]) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002398int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002399
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002400#endif /* MBEDTLS_CIPHER_C */