blob: 8e395b30144019f96827355fece78d576e4b6f63 [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é-Gonnard7f809972015-03-09 17:05:11 +000071#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020072
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020074/* shared by all GCM ciphers */
75static void *gcm_ctx_alloc( void )
76{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020077 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
78
79 if( ctx != NULL )
80 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
81
82 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020083}
84
85static void gcm_ctx_free( void *ctx )
86{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087 mbedtls_gcm_free( ctx );
88 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020089}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020091
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020093/* shared by all CCM ciphers */
94static void *ccm_ctx_alloc( void )
95{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020096 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
97
98 if( ctx != NULL )
99 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
100
101 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200102}
103
104static void ccm_ctx_free( void *ctx )
105{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106 mbedtls_ccm_free( ctx );
107 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200108}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200114 const unsigned char *input, unsigned char *output )
115{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200117}
118
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119#if defined(MBEDTLS_CIPHER_MODE_CBC)
120static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000121 unsigned char *iv, const unsigned char *input, unsigned char *output )
122{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200124 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000125}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#if defined(MBEDTLS_CIPHER_MODE_CFB)
129static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200130 size_t length, size_t *iv_off, unsigned char *iv,
131 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000132{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200134 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000135}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000137
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100138#if defined(MBEDTLS_CIPHER_MODE_OFB)
139static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
140 unsigned char *iv, const unsigned char *input, unsigned char *output )
141{
142 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
143 iv, input, output );
144}
145#endif /* MBEDTLS_CIPHER_MODE_OFB */
146
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200148static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
149 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000150 const unsigned char *input, unsigned char *output )
151{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000153 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000154}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000156
Jaeden Ameroc6539902018-04-30 17:17:41 +0100157#if defined(MBEDTLS_CIPHER_MODE_XTS)
158static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
159 size_t length,
160 const unsigned char data_unit[16],
161 const unsigned char *input,
162 unsigned char *output )
163{
164 mbedtls_aes_xts_context *xts_ctx = ctx;
165 int mode;
166
167 switch( operation )
168 {
169 case MBEDTLS_ENCRYPT:
170 mode = MBEDTLS_AES_ENCRYPT;
171 break;
172 case MBEDTLS_DECRYPT:
173 mode = MBEDTLS_AES_DECRYPT;
174 break;
175 default:
176 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
177 }
178
179 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
180 data_unit, input, output );
181}
182#endif /* MBEDTLS_CIPHER_MODE_XTS */
183
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200184static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200185 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000186{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200187 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000188}
189
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200190static int aes_setkey_enc_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_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000194}
195
196static void * aes_ctx_alloc( void )
197{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200198 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200199
200 if( aes == NULL )
201 return( NULL );
202
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200203 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200204
205 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000206}
207
208static void aes_ctx_free( void *ctx )
209{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200210 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
211 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000212}
213
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214static const mbedtls_cipher_base_t aes_info = {
215 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200216 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000218 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100219#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000221 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100222#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100223#if defined(MBEDTLS_CIPHER_MODE_OFB)
224 aes_crypt_ofb_wrap,
225#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000227 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100228#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100229#if defined(MBEDTLS_CIPHER_MODE_XTS)
230 NULL,
231#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200233 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100234#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000235 aes_setkey_enc_wrap,
236 aes_setkey_dec_wrap,
237 aes_ctx_alloc,
238 aes_ctx_free
239};
240
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241static const mbedtls_cipher_info_t aes_128_ecb_info = {
242 MBEDTLS_CIPHER_AES_128_ECB,
243 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200244 128,
245 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300246 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200247 0,
248 16,
249 &aes_info
250};
251
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252static const mbedtls_cipher_info_t aes_192_ecb_info = {
253 MBEDTLS_CIPHER_AES_192_ECB,
254 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200255 192,
256 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300257 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200258 0,
259 16,
260 &aes_info
261};
262
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263static const mbedtls_cipher_info_t aes_256_ecb_info = {
264 MBEDTLS_CIPHER_AES_256_ECB,
265 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200266 256,
267 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300268 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200269 0,
270 16,
271 &aes_info
272};
273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274#if defined(MBEDTLS_CIPHER_MODE_CBC)
275static const mbedtls_cipher_info_t aes_128_cbc_info = {
276 MBEDTLS_CIPHER_AES_128_CBC,
277 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000278 128,
279 "AES-128-CBC",
280 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200281 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000282 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000283 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000284};
285
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286static const mbedtls_cipher_info_t aes_192_cbc_info = {
287 MBEDTLS_CIPHER_AES_192_CBC,
288 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000289 192,
290 "AES-192-CBC",
291 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200292 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000293 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000294 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000295};
296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297static const mbedtls_cipher_info_t aes_256_cbc_info = {
298 MBEDTLS_CIPHER_AES_256_CBC,
299 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000300 256,
301 "AES-256-CBC",
302 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200303 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000304 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000305 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000306};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000308
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309#if defined(MBEDTLS_CIPHER_MODE_CFB)
310static const mbedtls_cipher_info_t aes_128_cfb128_info = {
311 MBEDTLS_CIPHER_AES_128_CFB128,
312 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000313 128,
314 "AES-128-CFB128",
315 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200316 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000317 16,
318 &aes_info
319};
320
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321static const mbedtls_cipher_info_t aes_192_cfb128_info = {
322 MBEDTLS_CIPHER_AES_192_CFB128,
323 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000324 192,
325 "AES-192-CFB128",
326 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200327 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000328 16,
329 &aes_info
330};
331
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332static const mbedtls_cipher_info_t aes_256_cfb128_info = {
333 MBEDTLS_CIPHER_AES_256_CFB128,
334 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000335 256,
336 "AES-256-CFB128",
337 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200338 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000339 16,
340 &aes_info
341};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000343
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100344#if defined(MBEDTLS_CIPHER_MODE_OFB)
345static const mbedtls_cipher_info_t aes_128_ofb_info = {
346 MBEDTLS_CIPHER_AES_128_OFB,
347 MBEDTLS_MODE_OFB,
348 128,
349 "AES-128-OFB",
350 16,
351 0,
352 16,
353 &aes_info
354};
355
356static const mbedtls_cipher_info_t aes_192_ofb_info = {
357 MBEDTLS_CIPHER_AES_192_OFB,
358 MBEDTLS_MODE_OFB,
359 192,
360 "AES-192-OFB",
361 16,
362 0,
363 16,
364 &aes_info
365};
366
367static const mbedtls_cipher_info_t aes_256_ofb_info = {
368 MBEDTLS_CIPHER_AES_256_OFB,
369 MBEDTLS_MODE_OFB,
370 256,
371 "AES-256-OFB",
372 16,
373 0,
374 16,
375 &aes_info
376};
377#endif /* MBEDTLS_CIPHER_MODE_OFB */
378
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379#if defined(MBEDTLS_CIPHER_MODE_CTR)
380static const mbedtls_cipher_info_t aes_128_ctr_info = {
381 MBEDTLS_CIPHER_AES_128_CTR,
382 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000383 128,
384 "AES-128-CTR",
385 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200386 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000387 16,
388 &aes_info
389};
390
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200391static const mbedtls_cipher_info_t aes_192_ctr_info = {
392 MBEDTLS_CIPHER_AES_192_CTR,
393 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000394 192,
395 "AES-192-CTR",
396 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200397 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000398 16,
399 &aes_info
400};
401
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402static const mbedtls_cipher_info_t aes_256_ctr_info = {
403 MBEDTLS_CIPHER_AES_256_CTR,
404 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000405 256,
406 "AES-256-CTR",
407 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200408 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000409 16,
410 &aes_info
411};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200412#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000413
Jaeden Ameroc6539902018-04-30 17:17:41 +0100414#if defined(MBEDTLS_CIPHER_MODE_XTS)
415static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
416 unsigned int key_bitlen )
417{
418 mbedtls_aes_xts_context *xts_ctx = ctx;
419 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
420}
421
422static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
423 unsigned int key_bitlen )
424{
425 mbedtls_aes_xts_context *xts_ctx = ctx;
426 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
427}
428
429static void *xts_aes_ctx_alloc( void )
430{
431 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
432
433 if( xts_ctx != NULL )
434 mbedtls_aes_xts_init( xts_ctx );
435
436 return( xts_ctx );
437}
438
439static void xts_aes_ctx_free( void *ctx )
440{
441 mbedtls_aes_xts_context *xts_ctx = ctx;
442
443 if( xts_ctx == NULL )
444 return;
445
446 mbedtls_aes_xts_free( xts_ctx );
447 mbedtls_free( xts_ctx );
448}
449
450static const mbedtls_cipher_base_t xts_aes_info = {
451 MBEDTLS_CIPHER_ID_AES,
452 NULL,
453#if defined(MBEDTLS_CIPHER_MODE_CBC)
454 NULL,
455#endif
456#if defined(MBEDTLS_CIPHER_MODE_CFB)
457 NULL,
458#endif
459#if defined(MBEDTLS_CIPHER_MODE_OFB)
460 NULL,
461#endif
462#if defined(MBEDTLS_CIPHER_MODE_CTR)
463 NULL,
464#endif
465#if defined(MBEDTLS_CIPHER_MODE_XTS)
466 aes_crypt_xts_wrap,
467#endif
468#if defined(MBEDTLS_CIPHER_MODE_STREAM)
469 NULL,
470#endif
471 xts_aes_setkey_enc_wrap,
472 xts_aes_setkey_dec_wrap,
473 xts_aes_ctx_alloc,
474 xts_aes_ctx_free
475};
476
477static const mbedtls_cipher_info_t aes_128_xts_info = {
478 MBEDTLS_CIPHER_AES_128_XTS,
479 MBEDTLS_MODE_XTS,
480 256,
481 "AES-128-XTS",
482 16,
483 0,
484 16,
485 &xts_aes_info
486};
487
488static const mbedtls_cipher_info_t aes_256_xts_info = {
489 MBEDTLS_CIPHER_AES_256_XTS,
490 MBEDTLS_MODE_XTS,
491 512,
492 "AES-256-XTS",
493 16,
494 0,
495 16,
496 &xts_aes_info
497};
498#endif /* MBEDTLS_CIPHER_MODE_XTS */
499
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200500#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200501static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200502 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200503{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200504 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200505 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200506}
507
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200508static const mbedtls_cipher_base_t gcm_aes_info = {
509 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200510 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200511#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200512 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100513#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200515 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100516#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100517#if defined(MBEDTLS_CIPHER_MODE_OFB)
518 NULL,
519#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200520#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200521 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100522#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100523#if defined(MBEDTLS_CIPHER_MODE_XTS)
524 NULL,
525#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200527 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100528#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200529 gcm_aes_setkey_wrap,
530 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200531 gcm_ctx_alloc,
532 gcm_ctx_free,
533};
534
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200535static const mbedtls_cipher_info_t aes_128_gcm_info = {
536 MBEDTLS_CIPHER_AES_128_GCM,
537 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100538 128,
539 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200540 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200541 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100542 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200543 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100544};
545
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200546static const mbedtls_cipher_info_t aes_192_gcm_info = {
547 MBEDTLS_CIPHER_AES_192_GCM,
548 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200549 192,
550 "AES-192-GCM",
551 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200553 16,
554 &gcm_aes_info
555};
556
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200557static const mbedtls_cipher_info_t aes_256_gcm_info = {
558 MBEDTLS_CIPHER_AES_256_GCM,
559 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100560 256,
561 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200562 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100564 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200565 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100566};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200567#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100568
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200569#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200570static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200571 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200572{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200573 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200574 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200575}
576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577static const mbedtls_cipher_base_t ccm_aes_info = {
578 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200579 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200581 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100582#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200584 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100585#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100586#if defined(MBEDTLS_CIPHER_MODE_OFB)
587 NULL,
588#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200589#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200590 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100591#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100592#if defined(MBEDTLS_CIPHER_MODE_XTS)
593 NULL,
594#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200596 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100597#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200598 ccm_aes_setkey_wrap,
599 ccm_aes_setkey_wrap,
600 ccm_ctx_alloc,
601 ccm_ctx_free,
602};
603
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200604static const mbedtls_cipher_info_t aes_128_ccm_info = {
605 MBEDTLS_CIPHER_AES_128_CCM,
606 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200607 128,
608 "AES-128-CCM",
609 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200611 16,
612 &ccm_aes_info
613};
614
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200615static const mbedtls_cipher_info_t aes_192_ccm_info = {
616 MBEDTLS_CIPHER_AES_192_CCM,
617 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200618 192,
619 "AES-192-CCM",
620 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200621 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200622 16,
623 &ccm_aes_info
624};
625
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200626static const mbedtls_cipher_info_t aes_256_ccm_info = {
627 MBEDTLS_CIPHER_AES_256_CCM,
628 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200629 256,
630 "AES-256-CCM",
631 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200632 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200633 16,
634 &ccm_aes_info
635};
Mateusz Starzyk4cb97392021-10-27 10:42:31 +0200636
637static const mbedtls_cipher_info_t aes_128_ccm_star_no_tag_info = {
638 MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG,
639 MBEDTLS_MODE_CCM_STAR_NO_TAG,
640 128,
641 "AES-128-CCM*-NO-TAG",
642 12,
643 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
644 16,
645 &ccm_aes_info
646};
647
648static const mbedtls_cipher_info_t aes_192_ccm_star_no_tag_info = {
649 MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG,
650 MBEDTLS_MODE_CCM_STAR_NO_TAG,
651 192,
652 "AES-192-CCM*-NO-TAG",
653 12,
654 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
655 16,
656 &ccm_aes_info
657};
658
659static const mbedtls_cipher_info_t aes_256_ccm_star_no_tag_info = {
660 MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG,
661 MBEDTLS_MODE_CCM_STAR_NO_TAG,
662 256,
663 "AES-256-CCM*-NO-TAG",
664 12,
665 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
666 16,
667 &ccm_aes_info
668};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200669#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200670
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200671#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000672
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000674
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200676 const unsigned char *input, unsigned char *output )
677{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200679 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200680}
681
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682#if defined(MBEDTLS_CIPHER_MODE_CBC)
683static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200684 size_t length, unsigned char *iv,
685 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000686{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200687 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200688 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000689}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200690#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000691
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692#if defined(MBEDTLS_CIPHER_MODE_CFB)
693static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200694 size_t length, size_t *iv_off, unsigned char *iv,
695 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000696{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200697 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200698 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000699}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200700#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000701
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200702#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200703static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
704 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000705 const unsigned char *input, unsigned char *output )
706{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200708 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000709}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200710#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000711
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200712static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200713 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000714{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200715 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000716}
717
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200718static int camellia_setkey_enc_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_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000722}
723
724static void * camellia_ctx_alloc( void )
725{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200726 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200727 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200728
729 if( ctx == NULL )
730 return( NULL );
731
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200733
734 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000735}
736
737static void camellia_ctx_free( void *ctx )
738{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
740 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000741}
742
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200743static const mbedtls_cipher_base_t camellia_info = {
744 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200745 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200746#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000747 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100748#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200749#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000750 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100751#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100752#if defined(MBEDTLS_CIPHER_MODE_OFB)
753 NULL,
754#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000756 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100757#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100758#if defined(MBEDTLS_CIPHER_MODE_XTS)
759 NULL,
760#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200761#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200762 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100763#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000764 camellia_setkey_enc_wrap,
765 camellia_setkey_dec_wrap,
766 camellia_ctx_alloc,
767 camellia_ctx_free
768};
769
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200770static const mbedtls_cipher_info_t camellia_128_ecb_info = {
771 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
772 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200773 128,
774 "CAMELLIA-128-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100775 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200776 0,
777 16,
778 &camellia_info
779};
780
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200781static const mbedtls_cipher_info_t camellia_192_ecb_info = {
782 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
783 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200784 192,
785 "CAMELLIA-192-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100786 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200787 0,
788 16,
789 &camellia_info
790};
791
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200792static const mbedtls_cipher_info_t camellia_256_ecb_info = {
793 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
794 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200795 256,
796 "CAMELLIA-256-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +0100797 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200798 0,
799 16,
800 &camellia_info
801};
802
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200803#if defined(MBEDTLS_CIPHER_MODE_CBC)
804static const mbedtls_cipher_info_t camellia_128_cbc_info = {
805 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
806 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000807 128,
808 "CAMELLIA-128-CBC",
809 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200810 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000811 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000812 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000813};
814
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200815static const mbedtls_cipher_info_t camellia_192_cbc_info = {
816 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
817 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000818 192,
819 "CAMELLIA-192-CBC",
820 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200821 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000822 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000823 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000824};
825
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200826static const mbedtls_cipher_info_t camellia_256_cbc_info = {
827 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
828 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000829 256,
830 "CAMELLIA-256-CBC",
831 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200832 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000833 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000834 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000835};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000837
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200838#if defined(MBEDTLS_CIPHER_MODE_CFB)
839static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
840 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
841 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000842 128,
843 "CAMELLIA-128-CFB128",
844 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200845 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000846 16,
847 &camellia_info
848};
849
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200850static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
851 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
852 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000853 192,
854 "CAMELLIA-192-CFB128",
855 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200856 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000857 16,
858 &camellia_info
859};
860
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200861static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
862 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
863 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000864 256,
865 "CAMELLIA-256-CFB128",
866 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200867 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000868 16,
869 &camellia_info
870};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200871#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000872
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200873#if defined(MBEDTLS_CIPHER_MODE_CTR)
874static const mbedtls_cipher_info_t camellia_128_ctr_info = {
875 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
876 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000877 128,
878 "CAMELLIA-128-CTR",
879 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200880 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000881 16,
882 &camellia_info
883};
884
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200885static const mbedtls_cipher_info_t camellia_192_ctr_info = {
886 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
887 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000888 192,
889 "CAMELLIA-192-CTR",
890 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200891 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000892 16,
893 &camellia_info
894};
895
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200896static const mbedtls_cipher_info_t camellia_256_ctr_info = {
897 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
898 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000899 256,
900 "CAMELLIA-256-CTR",
901 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200902 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000903 16,
904 &camellia_info
905};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200906#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000907
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200908#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200909static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200910 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200911{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200912 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200913 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200914}
915
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200916static const mbedtls_cipher_base_t gcm_camellia_info = {
917 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200918 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200919#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200920 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100921#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200922#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200923 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100924#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100925#if defined(MBEDTLS_CIPHER_MODE_OFB)
926 NULL,
927#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200928#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200929 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100930#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100931#if defined(MBEDTLS_CIPHER_MODE_XTS)
932 NULL,
933#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200934#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200935 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100936#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200937 gcm_camellia_setkey_wrap,
938 gcm_camellia_setkey_wrap,
939 gcm_ctx_alloc,
940 gcm_ctx_free,
941};
942
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200943static const mbedtls_cipher_info_t camellia_128_gcm_info = {
944 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
945 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200946 128,
947 "CAMELLIA-128-GCM",
948 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200949 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200950 16,
951 &gcm_camellia_info
952};
953
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200954static const mbedtls_cipher_info_t camellia_192_gcm_info = {
955 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
956 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200957 192,
958 "CAMELLIA-192-GCM",
959 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200960 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200961 16,
962 &gcm_camellia_info
963};
964
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200965static const mbedtls_cipher_info_t camellia_256_gcm_info = {
966 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
967 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200968 256,
969 "CAMELLIA-256-GCM",
970 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200971 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200972 16,
973 &gcm_camellia_info
974};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200975#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200976
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200977#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200978static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200979 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200980{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200981 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200982 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200983}
984
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200985static const mbedtls_cipher_base_t ccm_camellia_info = {
986 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200987 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200988#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200989 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100990#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200991#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200992 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100993#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100994#if defined(MBEDTLS_CIPHER_MODE_OFB)
995 NULL,
996#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200997#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200998 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100999#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001000#if defined(MBEDTLS_CIPHER_MODE_XTS)
1001 NULL,
1002#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001003#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001004 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001005#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001006 ccm_camellia_setkey_wrap,
1007 ccm_camellia_setkey_wrap,
1008 ccm_ctx_alloc,
1009 ccm_ctx_free,
1010};
1011
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001012static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1013 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1014 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001015 128,
1016 "CAMELLIA-128-CCM",
1017 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001018 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001019 16,
1020 &ccm_camellia_info
1021};
1022
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001023static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1024 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1025 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001026 192,
1027 "CAMELLIA-192-CCM",
1028 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001029 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001030 16,
1031 &ccm_camellia_info
1032};
1033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001034static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1035 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1036 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001037 256,
1038 "CAMELLIA-256-CCM",
1039 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001040 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001041 16,
1042 &ccm_camellia_info
1043};
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02001044
1045static const mbedtls_cipher_info_t camellia_128_ccm_star_no_tag_info = {
1046 MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG,
1047 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1048 128,
1049 "CAMELLIA-128-CCM*-NO-TAG",
1050 12,
1051 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1052 16,
1053 &ccm_camellia_info
1054};
1055
1056static const mbedtls_cipher_info_t camellia_192_ccm_star_no_tag_info = {
1057 MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG,
1058 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1059 192,
1060 "CAMELLIA-192-CCM*-NO-TAG",
1061 12,
1062 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1063 16,
1064 &ccm_camellia_info
1065};
1066
1067static const mbedtls_cipher_info_t camellia_256_ccm_star_no_tag_info = {
1068 MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG,
1069 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1070 256,
1071 "CAMELLIA-256-CCM*-NO-TAG",
1072 12,
1073 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1074 16,
1075 &ccm_camellia_info
1076};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001077#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001078
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001079#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001080
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001081#if defined(MBEDTLS_ARIA_C)
1082
1083static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1084 const unsigned char *input, unsigned char *output )
1085{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001086 (void) operation;
1087 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001088 output );
1089}
1090
1091#if defined(MBEDTLS_CIPHER_MODE_CBC)
1092static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1093 size_t length, unsigned char *iv,
1094 const unsigned char *input, unsigned char *output )
1095{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001096 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001097 input, output );
1098}
1099#endif /* MBEDTLS_CIPHER_MODE_CBC */
1100
1101#if defined(MBEDTLS_CIPHER_MODE_CFB)
1102static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1103 size_t length, size_t *iv_off, unsigned char *iv,
1104 const unsigned char *input, unsigned char *output )
1105{
1106 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1107 iv_off, iv, input, output );
1108}
1109#endif /* MBEDTLS_CIPHER_MODE_CFB */
1110
1111#if defined(MBEDTLS_CIPHER_MODE_CTR)
1112static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1113 unsigned char *nonce_counter, unsigned char *stream_block,
1114 const unsigned char *input, unsigned char *output )
1115{
1116 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1117 nonce_counter, stream_block, input, output );
1118}
1119#endif /* MBEDTLS_CIPHER_MODE_CTR */
1120
1121static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1122 unsigned int key_bitlen )
1123{
1124 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1125}
1126
1127static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1128 unsigned int key_bitlen )
1129{
1130 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1131}
1132
1133static void * aria_ctx_alloc( void )
1134{
1135 mbedtls_aria_context *ctx;
1136 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1137
1138 if( ctx == NULL )
1139 return( NULL );
1140
1141 mbedtls_aria_init( ctx );
1142
1143 return( ctx );
1144}
1145
1146static void aria_ctx_free( void *ctx )
1147{
1148 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1149 mbedtls_free( ctx );
1150}
1151
1152static const mbedtls_cipher_base_t aria_info = {
1153 MBEDTLS_CIPHER_ID_ARIA,
1154 aria_crypt_ecb_wrap,
1155#if defined(MBEDTLS_CIPHER_MODE_CBC)
1156 aria_crypt_cbc_wrap,
1157#endif
1158#if defined(MBEDTLS_CIPHER_MODE_CFB)
1159 aria_crypt_cfb128_wrap,
1160#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001161#if defined(MBEDTLS_CIPHER_MODE_OFB)
1162 NULL,
1163#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001164#if defined(MBEDTLS_CIPHER_MODE_CTR)
1165 aria_crypt_ctr_wrap,
1166#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001167#if defined(MBEDTLS_CIPHER_MODE_XTS)
1168 NULL,
1169#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001170#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1171 NULL,
1172#endif
1173 aria_setkey_enc_wrap,
1174 aria_setkey_dec_wrap,
1175 aria_ctx_alloc,
1176 aria_ctx_free
1177};
1178
1179static const mbedtls_cipher_info_t aria_128_ecb_info = {
1180 MBEDTLS_CIPHER_ARIA_128_ECB,
1181 MBEDTLS_MODE_ECB,
1182 128,
1183 "ARIA-128-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001184 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001185 0,
1186 16,
1187 &aria_info
1188};
1189
1190static const mbedtls_cipher_info_t aria_192_ecb_info = {
1191 MBEDTLS_CIPHER_ARIA_192_ECB,
1192 MBEDTLS_MODE_ECB,
1193 192,
1194 "ARIA-192-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001195 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001196 0,
1197 16,
1198 &aria_info
1199};
1200
1201static const mbedtls_cipher_info_t aria_256_ecb_info = {
1202 MBEDTLS_CIPHER_ARIA_256_ECB,
1203 MBEDTLS_MODE_ECB,
1204 256,
1205 "ARIA-256-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001206 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001207 0,
1208 16,
1209 &aria_info
1210};
1211
1212#if defined(MBEDTLS_CIPHER_MODE_CBC)
1213static const mbedtls_cipher_info_t aria_128_cbc_info = {
1214 MBEDTLS_CIPHER_ARIA_128_CBC,
1215 MBEDTLS_MODE_CBC,
1216 128,
1217 "ARIA-128-CBC",
1218 16,
1219 0,
1220 16,
1221 &aria_info
1222};
1223
1224static const mbedtls_cipher_info_t aria_192_cbc_info = {
1225 MBEDTLS_CIPHER_ARIA_192_CBC,
1226 MBEDTLS_MODE_CBC,
1227 192,
1228 "ARIA-192-CBC",
1229 16,
1230 0,
1231 16,
1232 &aria_info
1233};
1234
1235static const mbedtls_cipher_info_t aria_256_cbc_info = {
1236 MBEDTLS_CIPHER_ARIA_256_CBC,
1237 MBEDTLS_MODE_CBC,
1238 256,
1239 "ARIA-256-CBC",
1240 16,
1241 0,
1242 16,
1243 &aria_info
1244};
1245#endif /* MBEDTLS_CIPHER_MODE_CBC */
1246
1247#if defined(MBEDTLS_CIPHER_MODE_CFB)
1248static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1249 MBEDTLS_CIPHER_ARIA_128_CFB128,
1250 MBEDTLS_MODE_CFB,
1251 128,
1252 "ARIA-128-CFB128",
1253 16,
1254 0,
1255 16,
1256 &aria_info
1257};
1258
1259static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1260 MBEDTLS_CIPHER_ARIA_192_CFB128,
1261 MBEDTLS_MODE_CFB,
1262 192,
1263 "ARIA-192-CFB128",
1264 16,
1265 0,
1266 16,
1267 &aria_info
1268};
1269
1270static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1271 MBEDTLS_CIPHER_ARIA_256_CFB128,
1272 MBEDTLS_MODE_CFB,
1273 256,
1274 "ARIA-256-CFB128",
1275 16,
1276 0,
1277 16,
1278 &aria_info
1279};
1280#endif /* MBEDTLS_CIPHER_MODE_CFB */
1281
1282#if defined(MBEDTLS_CIPHER_MODE_CTR)
1283static const mbedtls_cipher_info_t aria_128_ctr_info = {
1284 MBEDTLS_CIPHER_ARIA_128_CTR,
1285 MBEDTLS_MODE_CTR,
1286 128,
1287 "ARIA-128-CTR",
1288 16,
1289 0,
1290 16,
1291 &aria_info
1292};
1293
1294static const mbedtls_cipher_info_t aria_192_ctr_info = {
1295 MBEDTLS_CIPHER_ARIA_192_CTR,
1296 MBEDTLS_MODE_CTR,
1297 192,
1298 "ARIA-192-CTR",
1299 16,
1300 0,
1301 16,
1302 &aria_info
1303};
1304
1305static const mbedtls_cipher_info_t aria_256_ctr_info = {
1306 MBEDTLS_CIPHER_ARIA_256_CTR,
1307 MBEDTLS_MODE_CTR,
1308 256,
1309 "ARIA-256-CTR",
1310 16,
1311 0,
1312 16,
1313 &aria_info
1314};
1315#endif /* MBEDTLS_CIPHER_MODE_CTR */
1316
1317#if defined(MBEDTLS_GCM_C)
1318static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1319 unsigned int key_bitlen )
1320{
1321 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1322 key, key_bitlen );
1323}
1324
1325static const mbedtls_cipher_base_t gcm_aria_info = {
1326 MBEDTLS_CIPHER_ID_ARIA,
1327 NULL,
1328#if defined(MBEDTLS_CIPHER_MODE_CBC)
1329 NULL,
1330#endif
1331#if defined(MBEDTLS_CIPHER_MODE_CFB)
1332 NULL,
1333#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001334#if defined(MBEDTLS_CIPHER_MODE_OFB)
1335 NULL,
1336#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001337#if defined(MBEDTLS_CIPHER_MODE_CTR)
1338 NULL,
1339#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001340#if defined(MBEDTLS_CIPHER_MODE_XTS)
1341 NULL,
1342#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001343#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1344 NULL,
1345#endif
1346 gcm_aria_setkey_wrap,
1347 gcm_aria_setkey_wrap,
1348 gcm_ctx_alloc,
1349 gcm_ctx_free,
1350};
1351
1352static const mbedtls_cipher_info_t aria_128_gcm_info = {
1353 MBEDTLS_CIPHER_ARIA_128_GCM,
1354 MBEDTLS_MODE_GCM,
1355 128,
1356 "ARIA-128-GCM",
1357 12,
1358 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1359 16,
1360 &gcm_aria_info
1361};
1362
1363static const mbedtls_cipher_info_t aria_192_gcm_info = {
1364 MBEDTLS_CIPHER_ARIA_192_GCM,
1365 MBEDTLS_MODE_GCM,
1366 192,
1367 "ARIA-192-GCM",
1368 12,
1369 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1370 16,
1371 &gcm_aria_info
1372};
1373
1374static const mbedtls_cipher_info_t aria_256_gcm_info = {
1375 MBEDTLS_CIPHER_ARIA_256_GCM,
1376 MBEDTLS_MODE_GCM,
1377 256,
1378 "ARIA-256-GCM",
1379 12,
1380 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1381 16,
1382 &gcm_aria_info
1383};
1384#endif /* MBEDTLS_GCM_C */
1385
1386#if defined(MBEDTLS_CCM_C)
1387static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1388 unsigned int key_bitlen )
1389{
1390 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1391 key, key_bitlen );
1392}
1393
1394static const mbedtls_cipher_base_t ccm_aria_info = {
1395 MBEDTLS_CIPHER_ID_ARIA,
1396 NULL,
1397#if defined(MBEDTLS_CIPHER_MODE_CBC)
1398 NULL,
1399#endif
1400#if defined(MBEDTLS_CIPHER_MODE_CFB)
1401 NULL,
1402#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001403#if defined(MBEDTLS_CIPHER_MODE_OFB)
1404 NULL,
1405#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001406#if defined(MBEDTLS_CIPHER_MODE_CTR)
1407 NULL,
1408#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001409#if defined(MBEDTLS_CIPHER_MODE_XTS)
1410 NULL,
1411#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001412#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1413 NULL,
1414#endif
1415 ccm_aria_setkey_wrap,
1416 ccm_aria_setkey_wrap,
1417 ccm_ctx_alloc,
1418 ccm_ctx_free,
1419};
1420
1421static const mbedtls_cipher_info_t aria_128_ccm_info = {
1422 MBEDTLS_CIPHER_ARIA_128_CCM,
1423 MBEDTLS_MODE_CCM,
1424 128,
1425 "ARIA-128-CCM",
1426 12,
1427 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1428 16,
1429 &ccm_aria_info
1430};
1431
1432static const mbedtls_cipher_info_t aria_192_ccm_info = {
1433 MBEDTLS_CIPHER_ARIA_192_CCM,
1434 MBEDTLS_MODE_CCM,
1435 192,
1436 "ARIA-192-CCM",
1437 12,
1438 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1439 16,
1440 &ccm_aria_info
1441};
1442
1443static const mbedtls_cipher_info_t aria_256_ccm_info = {
1444 MBEDTLS_CIPHER_ARIA_256_CCM,
1445 MBEDTLS_MODE_CCM,
1446 256,
1447 "ARIA-256-CCM",
1448 12,
1449 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1450 16,
1451 &ccm_aria_info
1452};
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02001453
1454static const mbedtls_cipher_info_t aria_128_ccm_star_no_tag_info = {
1455 MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG,
1456 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1457 128,
1458 "ARIA-128-CCM*-NO-TAG",
1459 12,
1460 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1461 16,
1462 &ccm_aria_info
1463};
1464
1465static const mbedtls_cipher_info_t aria_192_ccm_star_no_tag_info = {
1466 MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG,
1467 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1468 192,
1469 "ARIA-192-CCM*-NO-TAG",
1470 12,
1471 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1472 16,
1473 &ccm_aria_info
1474};
1475
1476static const mbedtls_cipher_info_t aria_256_ccm_star_no_tag_info = {
1477 MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG,
1478 MBEDTLS_MODE_CCM_STAR_NO_TAG,
1479 256,
1480 "ARIA-256-CCM*-NO-TAG",
1481 12,
1482 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1483 16,
1484 &ccm_aria_info
1485};
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001486#endif /* MBEDTLS_CCM_C */
1487
1488#endif /* MBEDTLS_ARIA_C */
1489
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001490#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001491
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001492static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001493 const unsigned char *input, unsigned char *output )
1494{
1495 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001496 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001497}
1498
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001499static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001500 const unsigned char *input, unsigned char *output )
1501{
1502 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001503 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001504}
1505
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001506#if defined(MBEDTLS_CIPHER_MODE_CBC)
1507static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001508 unsigned char *iv, const unsigned char *input, unsigned char *output )
1509{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001510 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001511 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001512}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001513#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001514
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001515#if defined(MBEDTLS_CIPHER_MODE_CBC)
1516static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001517 unsigned char *iv, const unsigned char *input, unsigned char *output )
1518{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001519 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001520 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001521}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001522#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001523
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001524static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001525 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001526{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001527 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001528
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001530}
1531
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001532static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001533 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001534{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001535 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001536
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001537 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001538}
1539
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001540static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001541 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001542{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001543 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001544
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001545 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001546}
1547
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001548static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001549 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001550{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001551 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001552
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001553 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001554}
1555
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001556static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001557 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001558{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001559 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001560
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001561 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001562}
1563
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001564static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001565 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001566{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001567 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001568
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001569 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001570}
1571
1572static void * des_ctx_alloc( void )
1573{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001574 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001575
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001576 if( des == NULL )
1577 return( NULL );
1578
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001579 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001580
1581 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001582}
1583
1584static void des_ctx_free( void *ctx )
1585{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001586 mbedtls_des_free( (mbedtls_des_context *) ctx );
1587 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001588}
1589
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001590static void * des3_ctx_alloc( void )
1591{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001592 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001593 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001594
1595 if( des3 == NULL )
1596 return( NULL );
1597
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001599
1600 return( des3 );
1601}
1602
Paul Bakker34617722014-06-13 17:20:13 +02001603static void des3_ctx_free( void *ctx )
1604{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001605 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1606 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001607}
1608
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001609static const mbedtls_cipher_base_t des_info = {
1610 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001611 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001612#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001613 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001614#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001615#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001616 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001617#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001618#if defined(MBEDTLS_CIPHER_MODE_OFB)
1619 NULL,
1620#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001621#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001622 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001623#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001624#if defined(MBEDTLS_CIPHER_MODE_XTS)
1625 NULL,
1626#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001627#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001628 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001629#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001630 des_setkey_enc_wrap,
1631 des_setkey_dec_wrap,
1632 des_ctx_alloc,
1633 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001634};
1635
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001636static const mbedtls_cipher_info_t des_ecb_info = {
1637 MBEDTLS_CIPHER_DES_ECB,
1638 MBEDTLS_MODE_ECB,
1639 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001640 "DES-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001641 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001642 0,
1643 8,
1644 &des_info
1645};
1646
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001647#if defined(MBEDTLS_CIPHER_MODE_CBC)
1648static const mbedtls_cipher_info_t des_cbc_info = {
1649 MBEDTLS_CIPHER_DES_CBC,
1650 MBEDTLS_MODE_CBC,
1651 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001652 "DES-CBC",
1653 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001654 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001655 8,
1656 &des_info
1657};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001658#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001659
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001660static const mbedtls_cipher_base_t des_ede_info = {
1661 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001662 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001663#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001664 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001665#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001666#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001667 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001668#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001669#if defined(MBEDTLS_CIPHER_MODE_OFB)
1670 NULL,
1671#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001672#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001673 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001674#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001675#if defined(MBEDTLS_CIPHER_MODE_XTS)
1676 NULL,
1677#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001678#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001679 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001680#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001681 des3_set2key_enc_wrap,
1682 des3_set2key_dec_wrap,
1683 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001684 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001685};
1686
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001687static const mbedtls_cipher_info_t des_ede_ecb_info = {
1688 MBEDTLS_CIPHER_DES_EDE_ECB,
1689 MBEDTLS_MODE_ECB,
1690 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001691 "DES-EDE-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001692 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001693 0,
1694 8,
1695 &des_ede_info
1696};
1697
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001698#if defined(MBEDTLS_CIPHER_MODE_CBC)
1699static const mbedtls_cipher_info_t des_ede_cbc_info = {
1700 MBEDTLS_CIPHER_DES_EDE_CBC,
1701 MBEDTLS_MODE_CBC,
1702 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001703 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001704 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001705 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001706 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001707 &des_ede_info
1708};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001709#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001710
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001711static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001712 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001713 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001714#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001715 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001716#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001717#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001718 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001719#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001720#if defined(MBEDTLS_CIPHER_MODE_OFB)
1721 NULL,
1722#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001723#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001724 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001725#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001726#if defined(MBEDTLS_CIPHER_MODE_XTS)
1727 NULL,
1728#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001729#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001730 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001731#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001732 des3_set3key_enc_wrap,
1733 des3_set3key_dec_wrap,
1734 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001735 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001736};
1737
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001738static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1739 MBEDTLS_CIPHER_DES_EDE3_ECB,
1740 MBEDTLS_MODE_ECB,
1741 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001742 "DES-EDE3-ECB",
Bence Szépkútia8e40dd2020-10-29 10:22:35 +01001743 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001744 0,
1745 8,
1746 &des_ede3_info
1747};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001748#if defined(MBEDTLS_CIPHER_MODE_CBC)
1749static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1750 MBEDTLS_CIPHER_DES_EDE3_CBC,
1751 MBEDTLS_MODE_CBC,
1752 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001753 "DES-EDE3-CBC",
1754 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001755 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001756 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001757 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001758};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001759#endif /* MBEDTLS_CIPHER_MODE_CBC */
1760#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001761
Daniel Kingbd920622016-05-15 19:56:20 -03001762#if defined(MBEDTLS_CHACHA20_C)
1763
1764static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1765 unsigned int key_bitlen )
1766{
1767 if( key_bitlen != 256U )
1768 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1769
1770 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1771 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1772
1773 return( 0 );
1774}
1775
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001776static int chacha20_stream_wrap( void *ctx, size_t length,
1777 const unsigned char *input,
1778 unsigned char *output )
1779{
Janos Follath24eed8d2019-11-22 13:21:35 +00001780 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001781
1782 ret = mbedtls_chacha20_update( ctx, length, input, output );
1783 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1784 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1785
1786 return( ret );
1787}
1788
Daniel Kingbd920622016-05-15 19:56:20 -03001789static void * chacha20_ctx_alloc( void )
1790{
1791 mbedtls_chacha20_context *ctx;
1792 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1793
1794 if( ctx == NULL )
1795 return( NULL );
1796
1797 mbedtls_chacha20_init( ctx );
1798
1799 return( ctx );
1800}
1801
1802static void chacha20_ctx_free( void *ctx )
1803{
1804 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1805 mbedtls_free( ctx );
1806}
1807
1808static const mbedtls_cipher_base_t chacha20_base_info = {
1809 MBEDTLS_CIPHER_ID_CHACHA20,
1810 NULL,
1811#if defined(MBEDTLS_CIPHER_MODE_CBC)
1812 NULL,
1813#endif
1814#if defined(MBEDTLS_CIPHER_MODE_CFB)
1815 NULL,
1816#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001817#if defined(MBEDTLS_CIPHER_MODE_OFB)
1818 NULL,
1819#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001820#if defined(MBEDTLS_CIPHER_MODE_CTR)
1821 NULL,
1822#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001823#if defined(MBEDTLS_CIPHER_MODE_XTS)
1824 NULL,
1825#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001826#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001827 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001828#endif
1829 chacha20_setkey_wrap,
1830 chacha20_setkey_wrap,
1831 chacha20_ctx_alloc,
1832 chacha20_ctx_free
1833};
1834static const mbedtls_cipher_info_t chacha20_info = {
1835 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001836 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001837 256,
1838 "CHACHA20",
1839 12,
1840 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001841 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001842 &chacha20_base_info
1843};
1844#endif /* MBEDTLS_CHACHA20_C */
1845
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001846#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001847
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001848static int chachapoly_setkey_wrap( void *ctx,
1849 const unsigned char *key,
1850 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001851{
1852 if( key_bitlen != 256U )
1853 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1854
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001855 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001856 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1857
1858 return( 0 );
1859}
1860
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001861static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03001862{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001863 mbedtls_chachapoly_context *ctx;
1864 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03001865
1866 if( ctx == NULL )
1867 return( NULL );
1868
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001869 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001870
1871 return( ctx );
1872}
1873
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001874static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03001875{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001876 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001877 mbedtls_free( ctx );
1878}
1879
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001880static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03001881 MBEDTLS_CIPHER_ID_CHACHA20,
1882 NULL,
1883#if defined(MBEDTLS_CIPHER_MODE_CBC)
1884 NULL,
1885#endif
1886#if defined(MBEDTLS_CIPHER_MODE_CFB)
1887 NULL,
1888#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001889#if defined(MBEDTLS_CIPHER_MODE_OFB)
1890 NULL,
1891#endif
Daniel King8fe47012016-05-17 20:33:28 -03001892#if defined(MBEDTLS_CIPHER_MODE_CTR)
1893 NULL,
1894#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001895#if defined(MBEDTLS_CIPHER_MODE_XTS)
1896 NULL,
1897#endif
Daniel King8fe47012016-05-17 20:33:28 -03001898#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1899 NULL,
1900#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001901 chachapoly_setkey_wrap,
1902 chachapoly_setkey_wrap,
1903 chachapoly_ctx_alloc,
1904 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03001905};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001906static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03001907 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02001908 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03001909 256,
1910 "CHACHA20-POLY1305",
1911 12,
1912 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001913 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001914 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03001915};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001916#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03001917
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001918#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001919static int null_crypt_stream( void *ctx, size_t length,
1920 const unsigned char *input,
1921 unsigned char *output )
1922{
1923 ((void) ctx);
1924 memmove( output, input, length );
1925 return( 0 );
1926}
1927
1928static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001929 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001930{
1931 ((void) ctx);
1932 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001933 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001934
1935 return( 0 );
1936}
1937
Paul Bakkerfab5c822012-02-06 16:45:10 +00001938static void * null_ctx_alloc( void )
1939{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001940 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001941}
1942
Paul Bakkerfab5c822012-02-06 16:45:10 +00001943static void null_ctx_free( void *ctx )
1944{
1945 ((void) ctx);
1946}
1947
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001948static const mbedtls_cipher_base_t null_base_info = {
1949 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001950 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001951#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001952 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001953#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001954#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001955 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001956#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001957#if defined(MBEDTLS_CIPHER_MODE_OFB)
1958 NULL,
1959#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001960#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001961 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001962#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001963#if defined(MBEDTLS_CIPHER_MODE_XTS)
1964 NULL,
1965#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001966#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001967 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001968#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001969 null_setkey,
1970 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001971 null_ctx_alloc,
1972 null_ctx_free
1973};
1974
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001975static const mbedtls_cipher_info_t null_cipher_info = {
1976 MBEDTLS_CIPHER_NULL,
1977 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001978 0,
1979 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001980 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001981 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001982 1,
1983 &null_base_info
1984};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001985#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001986
Jack Lloydffdf2882019-03-07 17:00:32 -05001987#if defined(MBEDTLS_NIST_KW_C)
1988static void *kw_ctx_alloc( void )
1989{
1990 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
1991
1992 if( ctx != NULL )
1993 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
1994
1995 return( ctx );
1996}
1997
1998static void kw_ctx_free( void *ctx )
1999{
2000 mbedtls_nist_kw_free( ctx );
2001 mbedtls_free( ctx );
2002}
2003
2004static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
2005 unsigned int key_bitlen )
2006{
Jack Lloyd5f289992019-04-02 10:07:28 -07002007 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2008 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002009}
2010
2011static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
2012 unsigned int key_bitlen )
2013{
Jack Lloyd5f289992019-04-02 10:07:28 -07002014 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2015 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002016}
2017
2018static const mbedtls_cipher_base_t kw_aes_info = {
2019 MBEDTLS_CIPHER_ID_AES,
2020 NULL,
2021#if defined(MBEDTLS_CIPHER_MODE_CBC)
2022 NULL,
2023#endif
2024#if defined(MBEDTLS_CIPHER_MODE_CFB)
2025 NULL,
2026#endif
2027#if defined(MBEDTLS_CIPHER_MODE_OFB)
2028 NULL,
2029#endif
2030#if defined(MBEDTLS_CIPHER_MODE_CTR)
2031 NULL,
2032#endif
2033#if defined(MBEDTLS_CIPHER_MODE_XTS)
2034 NULL,
2035#endif
2036#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2037 NULL,
2038#endif
2039 kw_aes_setkey_wrap,
2040 kw_aes_setkey_unwrap,
2041 kw_ctx_alloc,
2042 kw_ctx_free,
2043};
2044
2045static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
2046 MBEDTLS_CIPHER_AES_128_KW,
2047 MBEDTLS_MODE_KW,
2048 128,
2049 "AES-128-KW",
2050 0,
2051 0,
2052 16,
2053 &kw_aes_info
2054};
2055
2056static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
2057 MBEDTLS_CIPHER_AES_192_KW,
2058 MBEDTLS_MODE_KW,
2059 192,
2060 "AES-192-KW",
2061 0,
2062 0,
2063 16,
2064 &kw_aes_info
2065};
2066
2067static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
2068 MBEDTLS_CIPHER_AES_256_KW,
2069 MBEDTLS_MODE_KW,
2070 256,
2071 "AES-256-KW",
2072 0,
2073 0,
2074 16,
2075 &kw_aes_info
2076};
2077
2078static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
2079 MBEDTLS_CIPHER_AES_128_KWP,
2080 MBEDTLS_MODE_KWP,
2081 128,
2082 "AES-128-KWP",
2083 0,
2084 0,
2085 16,
2086 &kw_aes_info
2087};
2088
2089static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
2090 MBEDTLS_CIPHER_AES_192_KWP,
2091 MBEDTLS_MODE_KWP,
2092 192,
2093 "AES-192-KWP",
2094 0,
2095 0,
2096 16,
2097 &kw_aes_info
2098};
2099
2100static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
2101 MBEDTLS_CIPHER_AES_256_KWP,
2102 MBEDTLS_MODE_KWP,
2103 256,
2104 "AES-256-KWP",
2105 0,
2106 0,
2107 16,
2108 &kw_aes_info
2109};
2110#endif /* MBEDTLS_NIST_KW_C */
2111
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002112const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002113{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002114#if defined(MBEDTLS_AES_C)
2115 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2116 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2117 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2118#if defined(MBEDTLS_CIPHER_MODE_CBC)
2119 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2120 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2121 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002122#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002123#if defined(MBEDTLS_CIPHER_MODE_CFB)
2124 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2125 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2126 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002127#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002128#if defined(MBEDTLS_CIPHER_MODE_OFB)
2129 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2130 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2131 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2132#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002133#if defined(MBEDTLS_CIPHER_MODE_CTR)
2134 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2135 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2136 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002137#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002138#if defined(MBEDTLS_CIPHER_MODE_XTS)
2139 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2140 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2141#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002142#if defined(MBEDTLS_GCM_C)
2143 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2144 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2145 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002146#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002147#if defined(MBEDTLS_CCM_C)
2148 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2149 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2150 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02002151 { MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, &aes_128_ccm_star_no_tag_info },
2152 { MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, &aes_192_ccm_star_no_tag_info },
2153 { MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, &aes_256_ccm_star_no_tag_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002154#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002155#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002156
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002157#if defined(MBEDTLS_CAMELLIA_C)
2158 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2159 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2160 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2161#if defined(MBEDTLS_CIPHER_MODE_CBC)
2162 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2163 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2164 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002165#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002166#if defined(MBEDTLS_CIPHER_MODE_CFB)
2167 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2168 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2169 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002170#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002171#if defined(MBEDTLS_CIPHER_MODE_CTR)
2172 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2173 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2174 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002175#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002176#if defined(MBEDTLS_GCM_C)
2177 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2178 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2179 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002180#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002181#if defined(MBEDTLS_CCM_C)
2182 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2183 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2184 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02002185 { MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG, &camellia_128_ccm_star_no_tag_info },
2186 { MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG, &camellia_192_ccm_star_no_tag_info },
2187 { MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG, &camellia_256_ccm_star_no_tag_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002188#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002189#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002190
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002191#if defined(MBEDTLS_ARIA_C)
2192 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2193 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2194 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2195#if defined(MBEDTLS_CIPHER_MODE_CBC)
2196 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2197 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2198 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2199#endif
2200#if defined(MBEDTLS_CIPHER_MODE_CFB)
2201 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2202 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2203 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2204#endif
2205#if defined(MBEDTLS_CIPHER_MODE_CTR)
2206 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2207 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2208 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2209#endif
2210#if defined(MBEDTLS_GCM_C)
2211 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2212 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2213 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2214#endif
2215#if defined(MBEDTLS_CCM_C)
2216 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2217 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2218 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
Mateusz Starzyk4cb97392021-10-27 10:42:31 +02002219 { MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG, &aria_128_ccm_star_no_tag_info },
2220 { MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG, &aria_192_ccm_star_no_tag_info },
2221 { MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG, &aria_256_ccm_star_no_tag_info },
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002222#endif
2223#endif /* MBEDTLS_ARIA_C */
2224
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002225#if defined(MBEDTLS_DES_C)
2226 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2227 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2228 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2229#if defined(MBEDTLS_CIPHER_MODE_CBC)
2230 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2231 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2232 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002233#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002234#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002235
Daniel Kingbd920622016-05-15 19:56:20 -03002236#if defined(MBEDTLS_CHACHA20_C)
2237 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2238#endif
2239
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002240#if defined(MBEDTLS_CHACHAPOLY_C)
2241 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002242#endif
2243
Jack Lloydffdf2882019-03-07 17:00:32 -05002244#if defined(MBEDTLS_NIST_KW_C)
2245 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
2246 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
2247 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
2248 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
2249 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
2250 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
2251#endif
2252
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002253#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2254 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2255#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002256
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002257 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002258};
2259
Hanno Beckerc3d25b32018-11-08 16:01:22 +00002260#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
2261 sizeof(mbedtls_cipher_definitions[0]) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002262int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002263
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002264#endif /* MBEDTLS_CIPHER_C */