blob: 7da7d9d5229fdeee0179f3bb4e00609ba447646a [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
Chris Jonesdaacb592021-03-09 17:03:29 +000028#include "cipher_wrap.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_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000040#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000041#endif
42
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000043#if defined(MBEDTLS_ARIA_C)
44#include "mbedtls/aria.h"
45#endif
46
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020047#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000048#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000049#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000050
Daniel Kingbd920622016-05-15 19:56:20 -030051#if defined(MBEDTLS_CHACHA20_C)
52#include "mbedtls/chacha20.h"
53#endif
54
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020055#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000056#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020057#endif
58
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000060#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020061#endif
62
Jack Lloydffdf2882019-03-07 17:00:32 -050063#if defined(MBEDTLS_NIST_KW_C)
64#include "mbedtls/nist_kw.h"
65#endif
66
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000068#include <string.h>
69#endif
70
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000072#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020073#else
Rich Evans00ab4702015-02-06 13:43:58 +000074#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020075#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020077#endif
78
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020079#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020080/* shared by all GCM ciphers */
81static void *gcm_ctx_alloc( void )
82{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020083 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
84
85 if( ctx != NULL )
86 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
87
88 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020089}
90
91static void gcm_ctx_free( void *ctx )
92{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093 mbedtls_gcm_free( ctx );
94 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020095}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020097
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020098#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020099/* shared by all CCM ciphers */
100static void *ccm_ctx_alloc( void )
101{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200102 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
103
104 if( ctx != NULL )
105 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
106
107 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200108}
109
110static void ccm_ctx_free( void *ctx )
111{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112 mbedtls_ccm_free( ctx );
113 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200114}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200116
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200117#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000118
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200120 const unsigned char *input, unsigned char *output )
121{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200123}
124
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125#if defined(MBEDTLS_CIPHER_MODE_CBC)
126static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000127 unsigned char *iv, const unsigned char *input, unsigned char *output )
128{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200130 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000131}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#if defined(MBEDTLS_CIPHER_MODE_CFB)
135static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200136 size_t length, size_t *iv_off, unsigned char *iv,
137 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000138{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200140 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000141}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000143
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100144#if defined(MBEDTLS_CIPHER_MODE_OFB)
145static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
146 unsigned char *iv, const unsigned char *input, unsigned char *output )
147{
148 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
149 iv, input, output );
150}
151#endif /* MBEDTLS_CIPHER_MODE_OFB */
152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200154static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
155 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000156 const unsigned char *input, unsigned char *output )
157{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000159 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000160}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000162
Jaeden Ameroc6539902018-04-30 17:17:41 +0100163#if defined(MBEDTLS_CIPHER_MODE_XTS)
164static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
165 size_t length,
166 const unsigned char data_unit[16],
167 const unsigned char *input,
168 unsigned char *output )
169{
170 mbedtls_aes_xts_context *xts_ctx = ctx;
171 int mode;
172
173 switch( operation )
174 {
175 case MBEDTLS_ENCRYPT:
176 mode = MBEDTLS_AES_ENCRYPT;
177 break;
178 case MBEDTLS_DECRYPT:
179 mode = MBEDTLS_AES_DECRYPT;
180 break;
181 default:
182 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
183 }
184
185 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
186 data_unit, input, output );
187}
188#endif /* MBEDTLS_CIPHER_MODE_XTS */
189
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200190static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200191 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000192{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200193 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000194}
195
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200196static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200197 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000198{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200199 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000200}
201
202static void * aes_ctx_alloc( void )
203{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200204 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200205
206 if( aes == NULL )
207 return( NULL );
208
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200210
211 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000212}
213
214static void aes_ctx_free( void *ctx )
215{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200216 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
217 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000218}
219
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220static const mbedtls_cipher_base_t aes_info = {
221 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200222 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000224 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100225#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000227 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100228#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100229#if defined(MBEDTLS_CIPHER_MODE_OFB)
230 aes_crypt_ofb_wrap,
231#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000233 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100234#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100235#if defined(MBEDTLS_CIPHER_MODE_XTS)
236 NULL,
237#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200238#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200239 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100240#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000241 aes_setkey_enc_wrap,
242 aes_setkey_dec_wrap,
243 aes_ctx_alloc,
244 aes_ctx_free
245};
246
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247static const mbedtls_cipher_info_t aes_128_ecb_info = {
248 MBEDTLS_CIPHER_AES_128_ECB,
249 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200250 128,
251 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300252 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200253 0,
254 16,
255 &aes_info
256};
257
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258static const mbedtls_cipher_info_t aes_192_ecb_info = {
259 MBEDTLS_CIPHER_AES_192_ECB,
260 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200261 192,
262 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300263 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200264 0,
265 16,
266 &aes_info
267};
268
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200269static const mbedtls_cipher_info_t aes_256_ecb_info = {
270 MBEDTLS_CIPHER_AES_256_ECB,
271 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200272 256,
273 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300274 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200275 0,
276 16,
277 &aes_info
278};
279
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280#if defined(MBEDTLS_CIPHER_MODE_CBC)
281static const mbedtls_cipher_info_t aes_128_cbc_info = {
282 MBEDTLS_CIPHER_AES_128_CBC,
283 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000284 128,
285 "AES-128-CBC",
286 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200287 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000288 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000289 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000290};
291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292static const mbedtls_cipher_info_t aes_192_cbc_info = {
293 MBEDTLS_CIPHER_AES_192_CBC,
294 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000295 192,
296 "AES-192-CBC",
297 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200298 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000299 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000300 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000301};
302
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303static const mbedtls_cipher_info_t aes_256_cbc_info = {
304 MBEDTLS_CIPHER_AES_256_CBC,
305 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000306 256,
307 "AES-256-CBC",
308 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200309 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000310 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000311 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000312};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200313#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#if defined(MBEDTLS_CIPHER_MODE_CFB)
316static const mbedtls_cipher_info_t aes_128_cfb128_info = {
317 MBEDTLS_CIPHER_AES_128_CFB128,
318 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000319 128,
320 "AES-128-CFB128",
321 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200322 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000323 16,
324 &aes_info
325};
326
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200327static const mbedtls_cipher_info_t aes_192_cfb128_info = {
328 MBEDTLS_CIPHER_AES_192_CFB128,
329 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000330 192,
331 "AES-192-CFB128",
332 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200333 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000334 16,
335 &aes_info
336};
337
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200338static const mbedtls_cipher_info_t aes_256_cfb128_info = {
339 MBEDTLS_CIPHER_AES_256_CFB128,
340 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000341 256,
342 "AES-256-CFB128",
343 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200344 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000345 16,
346 &aes_info
347};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200348#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000349
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100350#if defined(MBEDTLS_CIPHER_MODE_OFB)
351static const mbedtls_cipher_info_t aes_128_ofb_info = {
352 MBEDTLS_CIPHER_AES_128_OFB,
353 MBEDTLS_MODE_OFB,
354 128,
355 "AES-128-OFB",
356 16,
357 0,
358 16,
359 &aes_info
360};
361
362static const mbedtls_cipher_info_t aes_192_ofb_info = {
363 MBEDTLS_CIPHER_AES_192_OFB,
364 MBEDTLS_MODE_OFB,
365 192,
366 "AES-192-OFB",
367 16,
368 0,
369 16,
370 &aes_info
371};
372
373static const mbedtls_cipher_info_t aes_256_ofb_info = {
374 MBEDTLS_CIPHER_AES_256_OFB,
375 MBEDTLS_MODE_OFB,
376 256,
377 "AES-256-OFB",
378 16,
379 0,
380 16,
381 &aes_info
382};
383#endif /* MBEDTLS_CIPHER_MODE_OFB */
384
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200385#if defined(MBEDTLS_CIPHER_MODE_CTR)
386static const mbedtls_cipher_info_t aes_128_ctr_info = {
387 MBEDTLS_CIPHER_AES_128_CTR,
388 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000389 128,
390 "AES-128-CTR",
391 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200392 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000393 16,
394 &aes_info
395};
396
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200397static const mbedtls_cipher_info_t aes_192_ctr_info = {
398 MBEDTLS_CIPHER_AES_192_CTR,
399 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000400 192,
401 "AES-192-CTR",
402 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200403 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000404 16,
405 &aes_info
406};
407
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200408static const mbedtls_cipher_info_t aes_256_ctr_info = {
409 MBEDTLS_CIPHER_AES_256_CTR,
410 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000411 256,
412 "AES-256-CTR",
413 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200414 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000415 16,
416 &aes_info
417};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200418#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000419
Jaeden Ameroc6539902018-04-30 17:17:41 +0100420#if defined(MBEDTLS_CIPHER_MODE_XTS)
421static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
422 unsigned int key_bitlen )
423{
424 mbedtls_aes_xts_context *xts_ctx = ctx;
425 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
426}
427
428static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
429 unsigned int key_bitlen )
430{
431 mbedtls_aes_xts_context *xts_ctx = ctx;
432 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
433}
434
435static void *xts_aes_ctx_alloc( void )
436{
437 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
438
439 if( xts_ctx != NULL )
440 mbedtls_aes_xts_init( xts_ctx );
441
442 return( xts_ctx );
443}
444
445static void xts_aes_ctx_free( void *ctx )
446{
447 mbedtls_aes_xts_context *xts_ctx = ctx;
448
449 if( xts_ctx == NULL )
450 return;
451
452 mbedtls_aes_xts_free( xts_ctx );
453 mbedtls_free( xts_ctx );
454}
455
456static const mbedtls_cipher_base_t xts_aes_info = {
457 MBEDTLS_CIPHER_ID_AES,
458 NULL,
459#if defined(MBEDTLS_CIPHER_MODE_CBC)
460 NULL,
461#endif
462#if defined(MBEDTLS_CIPHER_MODE_CFB)
463 NULL,
464#endif
465#if defined(MBEDTLS_CIPHER_MODE_OFB)
466 NULL,
467#endif
468#if defined(MBEDTLS_CIPHER_MODE_CTR)
469 NULL,
470#endif
471#if defined(MBEDTLS_CIPHER_MODE_XTS)
472 aes_crypt_xts_wrap,
473#endif
474#if defined(MBEDTLS_CIPHER_MODE_STREAM)
475 NULL,
476#endif
477 xts_aes_setkey_enc_wrap,
478 xts_aes_setkey_dec_wrap,
479 xts_aes_ctx_alloc,
480 xts_aes_ctx_free
481};
482
483static const mbedtls_cipher_info_t aes_128_xts_info = {
484 MBEDTLS_CIPHER_AES_128_XTS,
485 MBEDTLS_MODE_XTS,
486 256,
487 "AES-128-XTS",
488 16,
489 0,
490 16,
491 &xts_aes_info
492};
493
494static const mbedtls_cipher_info_t aes_256_xts_info = {
495 MBEDTLS_CIPHER_AES_256_XTS,
496 MBEDTLS_MODE_XTS,
497 512,
498 "AES-256-XTS",
499 16,
500 0,
501 16,
502 &xts_aes_info
503};
504#endif /* MBEDTLS_CIPHER_MODE_XTS */
505
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200506#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200507static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200508 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200509{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200510 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200511 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200512}
513
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514static const mbedtls_cipher_base_t gcm_aes_info = {
515 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200516 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200517#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200518 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100519#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200520#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200521 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100522#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100523#if defined(MBEDTLS_CIPHER_MODE_OFB)
524 NULL,
525#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200527 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100528#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100529#if defined(MBEDTLS_CIPHER_MODE_XTS)
530 NULL,
531#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200533 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100534#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200535 gcm_aes_setkey_wrap,
536 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200537 gcm_ctx_alloc,
538 gcm_ctx_free,
539};
540
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200541static const mbedtls_cipher_info_t aes_128_gcm_info = {
542 MBEDTLS_CIPHER_AES_128_GCM,
543 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100544 128,
545 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200546 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200547 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100548 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200549 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100550};
551
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552static const mbedtls_cipher_info_t aes_192_gcm_info = {
553 MBEDTLS_CIPHER_AES_192_GCM,
554 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200555 192,
556 "AES-192-GCM",
557 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200558 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200559 16,
560 &gcm_aes_info
561};
562
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563static const mbedtls_cipher_info_t aes_256_gcm_info = {
564 MBEDTLS_CIPHER_AES_256_GCM,
565 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100566 256,
567 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200568 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200569 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100570 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200571 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100572};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200573#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100574
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200575#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200576static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200577 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200578{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200579 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200580 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200581}
582
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583static const mbedtls_cipher_base_t ccm_aes_info = {
584 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200585 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200587 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100588#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200589#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200590 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100591#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100592#if defined(MBEDTLS_CIPHER_MODE_OFB)
593 NULL,
594#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200596 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100597#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100598#if defined(MBEDTLS_CIPHER_MODE_XTS)
599 NULL,
600#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200602 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100603#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200604 ccm_aes_setkey_wrap,
605 ccm_aes_setkey_wrap,
606 ccm_ctx_alloc,
607 ccm_ctx_free,
608};
609
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610static const mbedtls_cipher_info_t aes_128_ccm_info = {
611 MBEDTLS_CIPHER_AES_128_CCM,
612 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200613 128,
614 "AES-128-CCM",
615 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200616 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200617 16,
618 &ccm_aes_info
619};
620
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200621static const mbedtls_cipher_info_t aes_192_ccm_info = {
622 MBEDTLS_CIPHER_AES_192_CCM,
623 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200624 192,
625 "AES-192-CCM",
626 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200627 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200628 16,
629 &ccm_aes_info
630};
631
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200632static const mbedtls_cipher_info_t aes_256_ccm_info = {
633 MBEDTLS_CIPHER_AES_256_CCM,
634 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200635 256,
636 "AES-256-CCM",
637 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200638 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200639 16,
640 &ccm_aes_info
641};
Mateusz Starzyk4cb97392021-10-27 10:42:31 +0200642
643static const mbedtls_cipher_info_t aes_128_ccm_star_no_tag_info = {
644 MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG,
645 MBEDTLS_MODE_CCM_STAR_NO_TAG,
646 128,
647 "AES-128-CCM*-NO-TAG",
648 12,
649 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
650 16,
651 &ccm_aes_info
652};
653
654static const mbedtls_cipher_info_t aes_192_ccm_star_no_tag_info = {
655 MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG,
656 MBEDTLS_MODE_CCM_STAR_NO_TAG,
657 192,
658 "AES-192-CCM*-NO-TAG",
659 12,
660 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
661 16,
662 &ccm_aes_info
663};
664
665static const mbedtls_cipher_info_t aes_256_ccm_star_no_tag_info = {
666 MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG,
667 MBEDTLS_MODE_CCM_STAR_NO_TAG,
668 256,
669 "AES-256-CCM*-NO-TAG",
670 12,
671 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
672 16,
673 &ccm_aes_info
674};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200676
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200677#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200679#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200681static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200682 const unsigned char *input, unsigned char *output )
683{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200684 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200685 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200686}
687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#if defined(MBEDTLS_CIPHER_MODE_CBC)
689static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200690 size_t length, unsigned char *iv,
691 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000692{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200693 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200694 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000695}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000697
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200698#if defined(MBEDTLS_CIPHER_MODE_CFB)
699static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200700 size_t length, size_t *iv_off, unsigned char *iv,
701 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000702{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200703 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200704 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000705}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200706#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000707
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200709static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
710 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000711 const unsigned char *input, unsigned char *output )
712{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200713 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200714 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000715}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000717
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200718static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200719 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000720{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200721 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000722}
723
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200724static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200725 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000726{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200727 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000728}
729
730static void * camellia_ctx_alloc( void )
731{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200733 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200734
735 if( ctx == NULL )
736 return( NULL );
737
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200738 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200739
740 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000741}
742
743static void camellia_ctx_free( void *ctx )
744{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
746 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000747}
748
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200749static const mbedtls_cipher_base_t camellia_info = {
750 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200751 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200752#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000753 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100754#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000756 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100757#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100758#if defined(MBEDTLS_CIPHER_MODE_OFB)
759 NULL,
760#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200761#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000762 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100763#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100764#if defined(MBEDTLS_CIPHER_MODE_XTS)
765 NULL,
766#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200767#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200768 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100769#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000770 camellia_setkey_enc_wrap,
771 camellia_setkey_dec_wrap,
772 camellia_ctx_alloc,
773 camellia_ctx_free
774};
775
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200776static const mbedtls_cipher_info_t camellia_128_ecb_info = {
777 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
778 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200779 128,
780 "CAMELLIA-128-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100781 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200782 0,
783 16,
784 &camellia_info
785};
786
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200787static const mbedtls_cipher_info_t camellia_192_ecb_info = {
788 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
789 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200790 192,
791 "CAMELLIA-192-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100792 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200793 0,
794 16,
795 &camellia_info
796};
797
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200798static const mbedtls_cipher_info_t camellia_256_ecb_info = {
799 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
800 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200801 256,
802 "CAMELLIA-256-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100803 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200804 0,
805 16,
806 &camellia_info
807};
808
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200809#if defined(MBEDTLS_CIPHER_MODE_CBC)
810static const mbedtls_cipher_info_t camellia_128_cbc_info = {
811 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
812 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000813 128,
814 "CAMELLIA-128-CBC",
815 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200816 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000817 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000818 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000819};
820
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200821static const mbedtls_cipher_info_t camellia_192_cbc_info = {
822 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
823 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000824 192,
825 "CAMELLIA-192-CBC",
826 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200827 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000828 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000829 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000830};
831
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200832static const mbedtls_cipher_info_t camellia_256_cbc_info = {
833 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
834 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000835 256,
836 "CAMELLIA-256-CBC",
837 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200838 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000839 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000840 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000841};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200842#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000843
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200844#if defined(MBEDTLS_CIPHER_MODE_CFB)
845static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
846 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
847 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000848 128,
849 "CAMELLIA-128-CFB128",
850 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200851 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000852 16,
853 &camellia_info
854};
855
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200856static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
857 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
858 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000859 192,
860 "CAMELLIA-192-CFB128",
861 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200862 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000863 16,
864 &camellia_info
865};
866
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200867static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
868 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
869 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000870 256,
871 "CAMELLIA-256-CFB128",
872 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200873 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000874 16,
875 &camellia_info
876};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200877#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000878
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200879#if defined(MBEDTLS_CIPHER_MODE_CTR)
880static const mbedtls_cipher_info_t camellia_128_ctr_info = {
881 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
882 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000883 128,
884 "CAMELLIA-128-CTR",
885 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200886 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000887 16,
888 &camellia_info
889};
890
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200891static const mbedtls_cipher_info_t camellia_192_ctr_info = {
892 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
893 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000894 192,
895 "CAMELLIA-192-CTR",
896 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200897 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000898 16,
899 &camellia_info
900};
901
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902static const mbedtls_cipher_info_t camellia_256_ctr_info = {
903 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
904 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000905 256,
906 "CAMELLIA-256-CTR",
907 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200908 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000909 16,
910 &camellia_info
911};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200912#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000913
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200914#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200915static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200916 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200917{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200918 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200919 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200920}
921
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200922static const mbedtls_cipher_base_t gcm_camellia_info = {
923 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200924 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200925#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200926 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100927#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200928#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200929 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100930#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100931#if defined(MBEDTLS_CIPHER_MODE_OFB)
932 NULL,
933#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200934#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200935 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100936#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100937#if defined(MBEDTLS_CIPHER_MODE_XTS)
938 NULL,
939#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200940#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200941 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100942#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200943 gcm_camellia_setkey_wrap,
944 gcm_camellia_setkey_wrap,
945 gcm_ctx_alloc,
946 gcm_ctx_free,
947};
948
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200949static const mbedtls_cipher_info_t camellia_128_gcm_info = {
950 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
951 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200952 128,
953 "CAMELLIA-128-GCM",
954 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200955 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200956 16,
957 &gcm_camellia_info
958};
959
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200960static const mbedtls_cipher_info_t camellia_192_gcm_info = {
961 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
962 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200963 192,
964 "CAMELLIA-192-GCM",
965 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200966 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200967 16,
968 &gcm_camellia_info
969};
970
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200971static const mbedtls_cipher_info_t camellia_256_gcm_info = {
972 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
973 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200974 256,
975 "CAMELLIA-256-GCM",
976 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200977 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200978 16,
979 &gcm_camellia_info
980};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200981#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200982
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200983#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200984static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200985 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200986{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200987 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200988 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200989}
990
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200991static const mbedtls_cipher_base_t ccm_camellia_info = {
992 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200993 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200994#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200995 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100996#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200997#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200998 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100999#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001000#if defined(MBEDTLS_CIPHER_MODE_OFB)
1001 NULL,
1002#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001003#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001004 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001005#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001006#if defined(MBEDTLS_CIPHER_MODE_XTS)
1007 NULL,
1008#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001009#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001010 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001011#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001012 ccm_camellia_setkey_wrap,
1013 ccm_camellia_setkey_wrap,
1014 ccm_ctx_alloc,
1015 ccm_ctx_free,
1016};
1017
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001018static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1019 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1020 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001021 128,
1022 "CAMELLIA-128-CCM",
1023 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001024 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001025 16,
1026 &ccm_camellia_info
1027};
1028
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001029static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1030 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1031 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001032 192,
1033 "CAMELLIA-192-CCM",
1034 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001035 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001036 16,
1037 &ccm_camellia_info
1038};
1039
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001040static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1041 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1042 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001043 256,
1044 "CAMELLIA-256-CCM",
1045 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001046 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001047 16,
1048 &ccm_camellia_info
1049};
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02001050
1051static const mbedtls_cipher_info_t camellia_128_ccm_star_no_tag_info = {
1052 MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG,
1053 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1054 128,
1055 "CAMELLIA-128-CCM*-NO-TAG",
1056 12,
1057 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1058 16,
1059 &ccm_camellia_info
1060};
1061
1062static const mbedtls_cipher_info_t camellia_192_ccm_star_no_tag_info = {
1063 MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG,
1064 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1065 192,
1066 "CAMELLIA-192-CCM*-NO-TAG",
1067 12,
1068 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1069 16,
1070 &ccm_camellia_info
1071};
1072
1073static const mbedtls_cipher_info_t camellia_256_ccm_star_no_tag_info = {
1074 MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG,
1075 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1076 256,
1077 "CAMELLIA-256-CCM*-NO-TAG",
1078 12,
1079 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1080 16,
1081 &ccm_camellia_info
1082};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001083#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001084
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001085#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001086
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001087#if defined(MBEDTLS_ARIA_C)
1088
1089static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1090 const unsigned char *input, unsigned char *output )
1091{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001092 (void) operation;
1093 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001094 output );
1095}
1096
1097#if defined(MBEDTLS_CIPHER_MODE_CBC)
1098static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1099 size_t length, unsigned char *iv,
1100 const unsigned char *input, unsigned char *output )
1101{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001102 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001103 input, output );
1104}
1105#endif /* MBEDTLS_CIPHER_MODE_CBC */
1106
1107#if defined(MBEDTLS_CIPHER_MODE_CFB)
1108static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1109 size_t length, size_t *iv_off, unsigned char *iv,
1110 const unsigned char *input, unsigned char *output )
1111{
1112 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1113 iv_off, iv, input, output );
1114}
1115#endif /* MBEDTLS_CIPHER_MODE_CFB */
1116
1117#if defined(MBEDTLS_CIPHER_MODE_CTR)
1118static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1119 unsigned char *nonce_counter, unsigned char *stream_block,
1120 const unsigned char *input, unsigned char *output )
1121{
1122 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1123 nonce_counter, stream_block, input, output );
1124}
1125#endif /* MBEDTLS_CIPHER_MODE_CTR */
1126
1127static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1128 unsigned int key_bitlen )
1129{
1130 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1131}
1132
1133static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1134 unsigned int key_bitlen )
1135{
1136 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1137}
1138
1139static void * aria_ctx_alloc( void )
1140{
1141 mbedtls_aria_context *ctx;
1142 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1143
1144 if( ctx == NULL )
1145 return( NULL );
1146
1147 mbedtls_aria_init( ctx );
1148
1149 return( ctx );
1150}
1151
1152static void aria_ctx_free( void *ctx )
1153{
1154 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1155 mbedtls_free( ctx );
1156}
1157
1158static const mbedtls_cipher_base_t aria_info = {
1159 MBEDTLS_CIPHER_ID_ARIA,
1160 aria_crypt_ecb_wrap,
1161#if defined(MBEDTLS_CIPHER_MODE_CBC)
1162 aria_crypt_cbc_wrap,
1163#endif
1164#if defined(MBEDTLS_CIPHER_MODE_CFB)
1165 aria_crypt_cfb128_wrap,
1166#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001167#if defined(MBEDTLS_CIPHER_MODE_OFB)
1168 NULL,
1169#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001170#if defined(MBEDTLS_CIPHER_MODE_CTR)
1171 aria_crypt_ctr_wrap,
1172#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001173#if defined(MBEDTLS_CIPHER_MODE_XTS)
1174 NULL,
1175#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001176#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1177 NULL,
1178#endif
1179 aria_setkey_enc_wrap,
1180 aria_setkey_dec_wrap,
1181 aria_ctx_alloc,
1182 aria_ctx_free
1183};
1184
1185static const mbedtls_cipher_info_t aria_128_ecb_info = {
1186 MBEDTLS_CIPHER_ARIA_128_ECB,
1187 MBEDTLS_MODE_ECB,
1188 128,
1189 "ARIA-128-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001190 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001191 0,
1192 16,
1193 &aria_info
1194};
1195
1196static const mbedtls_cipher_info_t aria_192_ecb_info = {
1197 MBEDTLS_CIPHER_ARIA_192_ECB,
1198 MBEDTLS_MODE_ECB,
1199 192,
1200 "ARIA-192-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001201 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001202 0,
1203 16,
1204 &aria_info
1205};
1206
1207static const mbedtls_cipher_info_t aria_256_ecb_info = {
1208 MBEDTLS_CIPHER_ARIA_256_ECB,
1209 MBEDTLS_MODE_ECB,
1210 256,
1211 "ARIA-256-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001212 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001213 0,
1214 16,
1215 &aria_info
1216};
1217
1218#if defined(MBEDTLS_CIPHER_MODE_CBC)
1219static const mbedtls_cipher_info_t aria_128_cbc_info = {
1220 MBEDTLS_CIPHER_ARIA_128_CBC,
1221 MBEDTLS_MODE_CBC,
1222 128,
1223 "ARIA-128-CBC",
1224 16,
1225 0,
1226 16,
1227 &aria_info
1228};
1229
1230static const mbedtls_cipher_info_t aria_192_cbc_info = {
1231 MBEDTLS_CIPHER_ARIA_192_CBC,
1232 MBEDTLS_MODE_CBC,
1233 192,
1234 "ARIA-192-CBC",
1235 16,
1236 0,
1237 16,
1238 &aria_info
1239};
1240
1241static const mbedtls_cipher_info_t aria_256_cbc_info = {
1242 MBEDTLS_CIPHER_ARIA_256_CBC,
1243 MBEDTLS_MODE_CBC,
1244 256,
1245 "ARIA-256-CBC",
1246 16,
1247 0,
1248 16,
1249 &aria_info
1250};
1251#endif /* MBEDTLS_CIPHER_MODE_CBC */
1252
1253#if defined(MBEDTLS_CIPHER_MODE_CFB)
1254static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1255 MBEDTLS_CIPHER_ARIA_128_CFB128,
1256 MBEDTLS_MODE_CFB,
1257 128,
1258 "ARIA-128-CFB128",
1259 16,
1260 0,
1261 16,
1262 &aria_info
1263};
1264
1265static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1266 MBEDTLS_CIPHER_ARIA_192_CFB128,
1267 MBEDTLS_MODE_CFB,
1268 192,
1269 "ARIA-192-CFB128",
1270 16,
1271 0,
1272 16,
1273 &aria_info
1274};
1275
1276static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1277 MBEDTLS_CIPHER_ARIA_256_CFB128,
1278 MBEDTLS_MODE_CFB,
1279 256,
1280 "ARIA-256-CFB128",
1281 16,
1282 0,
1283 16,
1284 &aria_info
1285};
1286#endif /* MBEDTLS_CIPHER_MODE_CFB */
1287
1288#if defined(MBEDTLS_CIPHER_MODE_CTR)
1289static const mbedtls_cipher_info_t aria_128_ctr_info = {
1290 MBEDTLS_CIPHER_ARIA_128_CTR,
1291 MBEDTLS_MODE_CTR,
1292 128,
1293 "ARIA-128-CTR",
1294 16,
1295 0,
1296 16,
1297 &aria_info
1298};
1299
1300static const mbedtls_cipher_info_t aria_192_ctr_info = {
1301 MBEDTLS_CIPHER_ARIA_192_CTR,
1302 MBEDTLS_MODE_CTR,
1303 192,
1304 "ARIA-192-CTR",
1305 16,
1306 0,
1307 16,
1308 &aria_info
1309};
1310
1311static const mbedtls_cipher_info_t aria_256_ctr_info = {
1312 MBEDTLS_CIPHER_ARIA_256_CTR,
1313 MBEDTLS_MODE_CTR,
1314 256,
1315 "ARIA-256-CTR",
1316 16,
1317 0,
1318 16,
1319 &aria_info
1320};
1321#endif /* MBEDTLS_CIPHER_MODE_CTR */
1322
1323#if defined(MBEDTLS_GCM_C)
1324static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1325 unsigned int key_bitlen )
1326{
1327 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1328 key, key_bitlen );
1329}
1330
1331static const mbedtls_cipher_base_t gcm_aria_info = {
1332 MBEDTLS_CIPHER_ID_ARIA,
1333 NULL,
1334#if defined(MBEDTLS_CIPHER_MODE_CBC)
1335 NULL,
1336#endif
1337#if defined(MBEDTLS_CIPHER_MODE_CFB)
1338 NULL,
1339#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001340#if defined(MBEDTLS_CIPHER_MODE_OFB)
1341 NULL,
1342#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001343#if defined(MBEDTLS_CIPHER_MODE_CTR)
1344 NULL,
1345#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001346#if defined(MBEDTLS_CIPHER_MODE_XTS)
1347 NULL,
1348#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001349#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1350 NULL,
1351#endif
1352 gcm_aria_setkey_wrap,
1353 gcm_aria_setkey_wrap,
1354 gcm_ctx_alloc,
1355 gcm_ctx_free,
1356};
1357
1358static const mbedtls_cipher_info_t aria_128_gcm_info = {
1359 MBEDTLS_CIPHER_ARIA_128_GCM,
1360 MBEDTLS_MODE_GCM,
1361 128,
1362 "ARIA-128-GCM",
1363 12,
1364 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1365 16,
1366 &gcm_aria_info
1367};
1368
1369static const mbedtls_cipher_info_t aria_192_gcm_info = {
1370 MBEDTLS_CIPHER_ARIA_192_GCM,
1371 MBEDTLS_MODE_GCM,
1372 192,
1373 "ARIA-192-GCM",
1374 12,
1375 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1376 16,
1377 &gcm_aria_info
1378};
1379
1380static const mbedtls_cipher_info_t aria_256_gcm_info = {
1381 MBEDTLS_CIPHER_ARIA_256_GCM,
1382 MBEDTLS_MODE_GCM,
1383 256,
1384 "ARIA-256-GCM",
1385 12,
1386 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1387 16,
1388 &gcm_aria_info
1389};
1390#endif /* MBEDTLS_GCM_C */
1391
1392#if defined(MBEDTLS_CCM_C)
1393static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1394 unsigned int key_bitlen )
1395{
1396 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1397 key, key_bitlen );
1398}
1399
1400static const mbedtls_cipher_base_t ccm_aria_info = {
1401 MBEDTLS_CIPHER_ID_ARIA,
1402 NULL,
1403#if defined(MBEDTLS_CIPHER_MODE_CBC)
1404 NULL,
1405#endif
1406#if defined(MBEDTLS_CIPHER_MODE_CFB)
1407 NULL,
1408#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001409#if defined(MBEDTLS_CIPHER_MODE_OFB)
1410 NULL,
1411#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001412#if defined(MBEDTLS_CIPHER_MODE_CTR)
1413 NULL,
1414#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001415#if defined(MBEDTLS_CIPHER_MODE_XTS)
1416 NULL,
1417#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001418#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1419 NULL,
1420#endif
1421 ccm_aria_setkey_wrap,
1422 ccm_aria_setkey_wrap,
1423 ccm_ctx_alloc,
1424 ccm_ctx_free,
1425};
1426
1427static const mbedtls_cipher_info_t aria_128_ccm_info = {
1428 MBEDTLS_CIPHER_ARIA_128_CCM,
1429 MBEDTLS_MODE_CCM,
1430 128,
1431 "ARIA-128-CCM",
1432 12,
1433 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1434 16,
1435 &ccm_aria_info
1436};
1437
1438static const mbedtls_cipher_info_t aria_192_ccm_info = {
1439 MBEDTLS_CIPHER_ARIA_192_CCM,
1440 MBEDTLS_MODE_CCM,
1441 192,
1442 "ARIA-192-CCM",
1443 12,
1444 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1445 16,
1446 &ccm_aria_info
1447};
1448
1449static const mbedtls_cipher_info_t aria_256_ccm_info = {
1450 MBEDTLS_CIPHER_ARIA_256_CCM,
1451 MBEDTLS_MODE_CCM,
1452 256,
1453 "ARIA-256-CCM",
1454 12,
1455 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1456 16,
1457 &ccm_aria_info
1458};
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02001459
1460static const mbedtls_cipher_info_t aria_128_ccm_star_no_tag_info = {
1461 MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG,
1462 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1463 128,
1464 "ARIA-128-CCM*-NO-TAG",
1465 12,
1466 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1467 16,
1468 &ccm_aria_info
1469};
1470
1471static const mbedtls_cipher_info_t aria_192_ccm_star_no_tag_info = {
1472 MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG,
1473 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1474 192,
1475 "ARIA-192-CCM*-NO-TAG",
1476 12,
1477 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1478 16,
1479 &ccm_aria_info
1480};
1481
1482static const mbedtls_cipher_info_t aria_256_ccm_star_no_tag_info = {
1483 MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG,
1484 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1485 256,
1486 "ARIA-256-CCM*-NO-TAG",
1487 12,
1488 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1489 16,
1490 &ccm_aria_info
1491};
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001492#endif /* MBEDTLS_CCM_C */
1493
1494#endif /* MBEDTLS_ARIA_C */
1495
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001496#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001497
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001498static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001499 const unsigned char *input, unsigned char *output )
1500{
1501 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001502 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001503}
1504
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001505static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001506 const unsigned char *input, unsigned char *output )
1507{
1508 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001510}
1511
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001512#if defined(MBEDTLS_CIPHER_MODE_CBC)
1513static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001514 unsigned char *iv, const unsigned char *input, unsigned char *output )
1515{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001516 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001517 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001518}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001519#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001520
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001521#if defined(MBEDTLS_CIPHER_MODE_CBC)
1522static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001523 unsigned char *iv, const unsigned char *input, unsigned char *output )
1524{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001525 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001526 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001527}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001528#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001529
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001530static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001531 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001532{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001533 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001534
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001535 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001536}
1537
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001538static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001539 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001540{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001541 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001542
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001543 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001544}
1545
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001546static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001547 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001548{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001549 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001550
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001551 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001552}
1553
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001554static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001555 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001556{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001557 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001558
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001559 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001560}
1561
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001562static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001563 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001564{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001565 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001566
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001567 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001568}
1569
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001570static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001571 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001572{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001573 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001574
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001575 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001576}
1577
1578static void * des_ctx_alloc( void )
1579{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001580 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001581
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001582 if( des == NULL )
1583 return( NULL );
1584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001585 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001586
1587 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001588}
1589
1590static void des_ctx_free( void *ctx )
1591{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001592 mbedtls_des_free( (mbedtls_des_context *) ctx );
1593 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001594}
1595
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001596static void * des3_ctx_alloc( void )
1597{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001599 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001600
1601 if( des3 == NULL )
1602 return( NULL );
1603
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001604 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001605
1606 return( des3 );
1607}
1608
Paul Bakker34617722014-06-13 17:20:13 +02001609static void des3_ctx_free( void *ctx )
1610{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001611 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1612 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001613}
1614
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001615static const mbedtls_cipher_base_t des_info = {
1616 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001617 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001619 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001620#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001621#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001622 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001623#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001624#if defined(MBEDTLS_CIPHER_MODE_OFB)
1625 NULL,
1626#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001627#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001628 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001629#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001630#if defined(MBEDTLS_CIPHER_MODE_XTS)
1631 NULL,
1632#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001633#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001634 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001635#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001636 des_setkey_enc_wrap,
1637 des_setkey_dec_wrap,
1638 des_ctx_alloc,
1639 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001640};
1641
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001642static const mbedtls_cipher_info_t des_ecb_info = {
1643 MBEDTLS_CIPHER_DES_ECB,
1644 MBEDTLS_MODE_ECB,
1645 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001646 "DES-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001647 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001648 0,
1649 8,
1650 &des_info
1651};
1652
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001653#if defined(MBEDTLS_CIPHER_MODE_CBC)
1654static const mbedtls_cipher_info_t des_cbc_info = {
1655 MBEDTLS_CIPHER_DES_CBC,
1656 MBEDTLS_MODE_CBC,
1657 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001658 "DES-CBC",
1659 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001660 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001661 8,
1662 &des_info
1663};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001664#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001665
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001666static const mbedtls_cipher_base_t des_ede_info = {
1667 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001668 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001669#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001670 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001671#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001672#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001673 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001674#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001675#if defined(MBEDTLS_CIPHER_MODE_OFB)
1676 NULL,
1677#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001678#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001679 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001680#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001681#if defined(MBEDTLS_CIPHER_MODE_XTS)
1682 NULL,
1683#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001684#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001685 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001686#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001687 des3_set2key_enc_wrap,
1688 des3_set2key_dec_wrap,
1689 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001690 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001691};
1692
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001693static const mbedtls_cipher_info_t des_ede_ecb_info = {
1694 MBEDTLS_CIPHER_DES_EDE_ECB,
1695 MBEDTLS_MODE_ECB,
1696 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001697 "DES-EDE-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001698 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001699 0,
1700 8,
1701 &des_ede_info
1702};
1703
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001704#if defined(MBEDTLS_CIPHER_MODE_CBC)
1705static const mbedtls_cipher_info_t des_ede_cbc_info = {
1706 MBEDTLS_CIPHER_DES_EDE_CBC,
1707 MBEDTLS_MODE_CBC,
1708 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001709 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001710 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001711 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001712 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001713 &des_ede_info
1714};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001715#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001716
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001717static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001718 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001719 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001720#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001721 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001722#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001723#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001724 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001725#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001726#if defined(MBEDTLS_CIPHER_MODE_OFB)
1727 NULL,
1728#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001729#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001730 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001731#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001732#if defined(MBEDTLS_CIPHER_MODE_XTS)
1733 NULL,
1734#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001735#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001736 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001737#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001738 des3_set3key_enc_wrap,
1739 des3_set3key_dec_wrap,
1740 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001741 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001742};
1743
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001744static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1745 MBEDTLS_CIPHER_DES_EDE3_ECB,
1746 MBEDTLS_MODE_ECB,
1747 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001748 "DES-EDE3-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001749 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001750 0,
1751 8,
1752 &des_ede3_info
1753};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001754#if defined(MBEDTLS_CIPHER_MODE_CBC)
1755static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1756 MBEDTLS_CIPHER_DES_EDE3_CBC,
1757 MBEDTLS_MODE_CBC,
1758 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001759 "DES-EDE3-CBC",
1760 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001761 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001762 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001763 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001764};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001765#endif /* MBEDTLS_CIPHER_MODE_CBC */
1766#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001767
Daniel Kingbd920622016-05-15 19:56:20 -03001768#if defined(MBEDTLS_CHACHA20_C)
1769
1770static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1771 unsigned int key_bitlen )
1772{
1773 if( key_bitlen != 256U )
1774 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1775
1776 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1777 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1778
1779 return( 0 );
1780}
1781
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001782static int chacha20_stream_wrap( void *ctx, size_t length,
1783 const unsigned char *input,
1784 unsigned char *output )
1785{
Janos Follath24eed8d2019-11-22 13:21:35 +00001786 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001787
1788 ret = mbedtls_chacha20_update( ctx, length, input, output );
1789 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1790 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1791
1792 return( ret );
1793}
1794
Daniel Kingbd920622016-05-15 19:56:20 -03001795static void * chacha20_ctx_alloc( void )
1796{
1797 mbedtls_chacha20_context *ctx;
1798 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1799
1800 if( ctx == NULL )
1801 return( NULL );
1802
1803 mbedtls_chacha20_init( ctx );
1804
1805 return( ctx );
1806}
1807
1808static void chacha20_ctx_free( void *ctx )
1809{
1810 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1811 mbedtls_free( ctx );
1812}
1813
1814static const mbedtls_cipher_base_t chacha20_base_info = {
1815 MBEDTLS_CIPHER_ID_CHACHA20,
1816 NULL,
1817#if defined(MBEDTLS_CIPHER_MODE_CBC)
1818 NULL,
1819#endif
1820#if defined(MBEDTLS_CIPHER_MODE_CFB)
1821 NULL,
1822#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001823#if defined(MBEDTLS_CIPHER_MODE_OFB)
1824 NULL,
1825#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001826#if defined(MBEDTLS_CIPHER_MODE_CTR)
1827 NULL,
1828#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001829#if defined(MBEDTLS_CIPHER_MODE_XTS)
1830 NULL,
1831#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001832#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001833 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001834#endif
1835 chacha20_setkey_wrap,
1836 chacha20_setkey_wrap,
1837 chacha20_ctx_alloc,
1838 chacha20_ctx_free
1839};
1840static const mbedtls_cipher_info_t chacha20_info = {
1841 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001842 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001843 256,
1844 "CHACHA20",
1845 12,
1846 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001847 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001848 &chacha20_base_info
1849};
1850#endif /* MBEDTLS_CHACHA20_C */
1851
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001852#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001853
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001854static int chachapoly_setkey_wrap( void *ctx,
1855 const unsigned char *key,
1856 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001857{
1858 if( key_bitlen != 256U )
1859 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1860
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001861 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001862 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1863
1864 return( 0 );
1865}
1866
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001867static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03001868{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001869 mbedtls_chachapoly_context *ctx;
1870 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03001871
1872 if( ctx == NULL )
1873 return( NULL );
1874
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001875 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001876
1877 return( ctx );
1878}
1879
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001880static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03001881{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001882 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001883 mbedtls_free( ctx );
1884}
1885
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001886static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03001887 MBEDTLS_CIPHER_ID_CHACHA20,
1888 NULL,
1889#if defined(MBEDTLS_CIPHER_MODE_CBC)
1890 NULL,
1891#endif
1892#if defined(MBEDTLS_CIPHER_MODE_CFB)
1893 NULL,
1894#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001895#if defined(MBEDTLS_CIPHER_MODE_OFB)
1896 NULL,
1897#endif
Daniel King8fe47012016-05-17 20:33:28 -03001898#if defined(MBEDTLS_CIPHER_MODE_CTR)
1899 NULL,
1900#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001901#if defined(MBEDTLS_CIPHER_MODE_XTS)
1902 NULL,
1903#endif
Daniel King8fe47012016-05-17 20:33:28 -03001904#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1905 NULL,
1906#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001907 chachapoly_setkey_wrap,
1908 chachapoly_setkey_wrap,
1909 chachapoly_ctx_alloc,
1910 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03001911};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001912static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03001913 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02001914 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03001915 256,
1916 "CHACHA20-POLY1305",
1917 12,
1918 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001919 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001920 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03001921};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001922#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03001923
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001924#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001925static int null_crypt_stream( void *ctx, size_t length,
1926 const unsigned char *input,
1927 unsigned char *output )
1928{
1929 ((void) ctx);
1930 memmove( output, input, length );
1931 return( 0 );
1932}
1933
1934static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001935 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001936{
1937 ((void) ctx);
1938 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001939 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001940
1941 return( 0 );
1942}
1943
Paul Bakkerfab5c822012-02-06 16:45:10 +00001944static void * null_ctx_alloc( void )
1945{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001946 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001947}
1948
Paul Bakkerfab5c822012-02-06 16:45:10 +00001949static void null_ctx_free( void *ctx )
1950{
1951 ((void) ctx);
1952}
1953
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001954static const mbedtls_cipher_base_t null_base_info = {
1955 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001956 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001957#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001958 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001959#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001960#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001961 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001962#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001963#if defined(MBEDTLS_CIPHER_MODE_OFB)
1964 NULL,
1965#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001966#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001967 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001968#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001969#if defined(MBEDTLS_CIPHER_MODE_XTS)
1970 NULL,
1971#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001972#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001973 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001974#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001975 null_setkey,
1976 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001977 null_ctx_alloc,
1978 null_ctx_free
1979};
1980
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001981static const mbedtls_cipher_info_t null_cipher_info = {
1982 MBEDTLS_CIPHER_NULL,
1983 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001984 0,
1985 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001986 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001987 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001988 1,
1989 &null_base_info
1990};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001991#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001992
Jack Lloydffdf2882019-03-07 17:00:32 -05001993#if defined(MBEDTLS_NIST_KW_C)
1994static void *kw_ctx_alloc( void )
1995{
1996 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
1997
1998 if( ctx != NULL )
1999 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
2000
2001 return( ctx );
2002}
2003
2004static void kw_ctx_free( void *ctx )
2005{
2006 mbedtls_nist_kw_free( ctx );
2007 mbedtls_free( ctx );
2008}
2009
2010static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
2011 unsigned int key_bitlen )
2012{
Jack Lloyd5f289992019-04-02 10:07:28 -07002013 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2014 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002015}
2016
2017static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
2018 unsigned int key_bitlen )
2019{
Jack Lloyd5f289992019-04-02 10:07:28 -07002020 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2021 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002022}
2023
2024static const mbedtls_cipher_base_t kw_aes_info = {
2025 MBEDTLS_CIPHER_ID_AES,
2026 NULL,
2027#if defined(MBEDTLS_CIPHER_MODE_CBC)
2028 NULL,
2029#endif
2030#if defined(MBEDTLS_CIPHER_MODE_CFB)
2031 NULL,
2032#endif
2033#if defined(MBEDTLS_CIPHER_MODE_OFB)
2034 NULL,
2035#endif
2036#if defined(MBEDTLS_CIPHER_MODE_CTR)
2037 NULL,
2038#endif
2039#if defined(MBEDTLS_CIPHER_MODE_XTS)
2040 NULL,
2041#endif
2042#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2043 NULL,
2044#endif
2045 kw_aes_setkey_wrap,
2046 kw_aes_setkey_unwrap,
2047 kw_ctx_alloc,
2048 kw_ctx_free,
2049};
2050
2051static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
2052 MBEDTLS_CIPHER_AES_128_KW,
2053 MBEDTLS_MODE_KW,
2054 128,
2055 "AES-128-KW",
2056 0,
2057 0,
2058 16,
2059 &kw_aes_info
2060};
2061
2062static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
2063 MBEDTLS_CIPHER_AES_192_KW,
2064 MBEDTLS_MODE_KW,
2065 192,
2066 "AES-192-KW",
2067 0,
2068 0,
2069 16,
2070 &kw_aes_info
2071};
2072
2073static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
2074 MBEDTLS_CIPHER_AES_256_KW,
2075 MBEDTLS_MODE_KW,
2076 256,
2077 "AES-256-KW",
2078 0,
2079 0,
2080 16,
2081 &kw_aes_info
2082};
2083
2084static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
2085 MBEDTLS_CIPHER_AES_128_KWP,
2086 MBEDTLS_MODE_KWP,
2087 128,
2088 "AES-128-KWP",
2089 0,
2090 0,
2091 16,
2092 &kw_aes_info
2093};
2094
2095static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
2096 MBEDTLS_CIPHER_AES_192_KWP,
2097 MBEDTLS_MODE_KWP,
2098 192,
2099 "AES-192-KWP",
2100 0,
2101 0,
2102 16,
2103 &kw_aes_info
2104};
2105
2106static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
2107 MBEDTLS_CIPHER_AES_256_KWP,
2108 MBEDTLS_MODE_KWP,
2109 256,
2110 "AES-256-KWP",
2111 0,
2112 0,
2113 16,
2114 &kw_aes_info
2115};
2116#endif /* MBEDTLS_NIST_KW_C */
2117
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002118const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002119{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002120#if defined(MBEDTLS_AES_C)
2121 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2122 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2123 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2124#if defined(MBEDTLS_CIPHER_MODE_CBC)
2125 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2126 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2127 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002128#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002129#if defined(MBEDTLS_CIPHER_MODE_CFB)
2130 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2131 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2132 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002133#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002134#if defined(MBEDTLS_CIPHER_MODE_OFB)
2135 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2136 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2137 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2138#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002139#if defined(MBEDTLS_CIPHER_MODE_CTR)
2140 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2141 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2142 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002143#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002144#if defined(MBEDTLS_CIPHER_MODE_XTS)
2145 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2146 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2147#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002148#if defined(MBEDTLS_GCM_C)
2149 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2150 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2151 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002152#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002153#if defined(MBEDTLS_CCM_C)
2154 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2155 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2156 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02002157 { MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, &aes_128_ccm_star_no_tag_info },
2158 { MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, &aes_192_ccm_star_no_tag_info },
2159 { MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, &aes_256_ccm_star_no_tag_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002160#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002161#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002162
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002163#if defined(MBEDTLS_CAMELLIA_C)
2164 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2165 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2166 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2167#if defined(MBEDTLS_CIPHER_MODE_CBC)
2168 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2169 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2170 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002171#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002172#if defined(MBEDTLS_CIPHER_MODE_CFB)
2173 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2174 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2175 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002176#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002177#if defined(MBEDTLS_CIPHER_MODE_CTR)
2178 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2179 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2180 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002181#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002182#if defined(MBEDTLS_GCM_C)
2183 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2184 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2185 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002186#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002187#if defined(MBEDTLS_CCM_C)
2188 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2189 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2190 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02002191 { MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG, &camellia_128_ccm_star_no_tag_info },
2192 { MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG, &camellia_192_ccm_star_no_tag_info },
2193 { MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG, &camellia_256_ccm_star_no_tag_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002194#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002195#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002196
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002197#if defined(MBEDTLS_ARIA_C)
2198 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2199 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2200 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2201#if defined(MBEDTLS_CIPHER_MODE_CBC)
2202 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2203 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2204 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2205#endif
2206#if defined(MBEDTLS_CIPHER_MODE_CFB)
2207 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2208 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2209 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2210#endif
2211#if defined(MBEDTLS_CIPHER_MODE_CTR)
2212 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2213 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2214 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2215#endif
2216#if defined(MBEDTLS_GCM_C)
2217 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2218 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2219 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2220#endif
2221#if defined(MBEDTLS_CCM_C)
2222 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2223 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2224 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02002225 { MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG, &aria_128_ccm_star_no_tag_info },
2226 { MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG, &aria_192_ccm_star_no_tag_info },
2227 { MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG, &aria_256_ccm_star_no_tag_info },
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002228#endif
2229#endif /* MBEDTLS_ARIA_C */
2230
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002231#if defined(MBEDTLS_DES_C)
2232 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2233 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2234 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2235#if defined(MBEDTLS_CIPHER_MODE_CBC)
2236 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2237 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2238 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002239#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002240#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002241
Daniel Kingbd920622016-05-15 19:56:20 -03002242#if defined(MBEDTLS_CHACHA20_C)
2243 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2244#endif
2245
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002246#if defined(MBEDTLS_CHACHAPOLY_C)
2247 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002248#endif
2249
Jack Lloydffdf2882019-03-07 17:00:32 -05002250#if defined(MBEDTLS_NIST_KW_C)
2251 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
2252 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
2253 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
2254 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
2255 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
2256 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
2257#endif
2258
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002259#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2260 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2261#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002262
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002263 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002264};
2265
Hanno Beckerc3d25b32018-11-08 16:01:22 +00002266#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
2267 sizeof(mbedtls_cipher_definitions[0]) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002268int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002270#endif /* MBEDTLS_CIPHER_C */