blob: 7fc40b5f0cc26ca9980da02895dacc66439af55d [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief Generic cipher wrapper for mbed TLS
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker8123e9d2011-01-06 15:37:30 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000024 */
25
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000033
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020034#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020036#if defined(MBEDTLS_CHACHAPOLY_C)
37#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020046#endif
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000050#endif
51
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000052#if defined(MBEDTLS_ARIA_C)
53#include "mbedtls/aria.h"
54#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000058#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000062#endif
63
Daniel Kingbd920622016-05-15 19:56:20 -030064#if defined(MBEDTLS_CHACHA20_C)
65#include "mbedtls/chacha20.h"
66#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020074#endif
75
Jack Lloydffdf2882019-03-07 17:00:32 -050076#if defined(MBEDTLS_NIST_KW_C)
77#include "mbedtls/nist_kw.h"
78#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000081#include <string.h>
82#endif
83
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000085#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020086#else
Rich Evans00ab4702015-02-06 13:43:58 +000087#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020088#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020089#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020090#endif
91
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020093/* shared by all GCM ciphers */
94static void *gcm_ctx_alloc( void )
95{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020096 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
97
98 if( ctx != NULL )
99 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
100
101 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200102}
103
104static void gcm_ctx_free( void *ctx )
105{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200106 mbedtls_gcm_free( ctx );
107 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200108}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200110
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200112/* shared by all CCM ciphers */
113static void *ccm_ctx_alloc( void )
114{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200115 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
116
117 if( ctx != NULL )
118 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
119
120 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200121}
122
123static void ccm_ctx_free( void *ctx )
124{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125 mbedtls_ccm_free( ctx );
126 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200127}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200129
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200133 const unsigned char *input, unsigned char *output )
134{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200136}
137
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138#if defined(MBEDTLS_CIPHER_MODE_CBC)
139static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000140 unsigned char *iv, const unsigned char *input, unsigned char *output )
141{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200143 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000144}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000146
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200147#if defined(MBEDTLS_CIPHER_MODE_CFB)
148static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200149 size_t length, size_t *iv_off, unsigned char *iv,
150 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000151{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200153 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000154}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000156
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100157#if defined(MBEDTLS_CIPHER_MODE_OFB)
158static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
159 unsigned char *iv, const unsigned char *input, unsigned char *output )
160{
161 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
162 iv, input, output );
163}
164#endif /* MBEDTLS_CIPHER_MODE_OFB */
165
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200167static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
168 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000169 const unsigned char *input, unsigned char *output )
170{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000172 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000173}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000175
Jaeden Ameroc6539902018-04-30 17:17:41 +0100176#if defined(MBEDTLS_CIPHER_MODE_XTS)
177static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
178 size_t length,
179 const unsigned char data_unit[16],
180 const unsigned char *input,
181 unsigned char *output )
182{
183 mbedtls_aes_xts_context *xts_ctx = ctx;
184 int mode;
185
186 switch( operation )
187 {
188 case MBEDTLS_ENCRYPT:
189 mode = MBEDTLS_AES_ENCRYPT;
190 break;
191 case MBEDTLS_DECRYPT:
192 mode = MBEDTLS_AES_DECRYPT;
193 break;
194 default:
195 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
196 }
197
198 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
199 data_unit, input, output );
200}
201#endif /* MBEDTLS_CIPHER_MODE_XTS */
202
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200203static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200204 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000205{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200206 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000207}
208
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200209static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200210 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000211{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200212 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000213}
214
215static void * aes_ctx_alloc( void )
216{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200217 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200218
219 if( aes == NULL )
220 return( NULL );
221
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200223
224 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000225}
226
227static void aes_ctx_free( void *ctx )
228{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
230 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000231}
232
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200233static const mbedtls_cipher_base_t aes_info = {
234 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200235 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000237 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100238#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000240 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100241#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100242#if defined(MBEDTLS_CIPHER_MODE_OFB)
243 aes_crypt_ofb_wrap,
244#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000246 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100247#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100248#if defined(MBEDTLS_CIPHER_MODE_XTS)
249 NULL,
250#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200252 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100253#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000254 aes_setkey_enc_wrap,
255 aes_setkey_dec_wrap,
256 aes_ctx_alloc,
257 aes_ctx_free
258};
259
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260static const mbedtls_cipher_info_t aes_128_ecb_info = {
261 MBEDTLS_CIPHER_AES_128_ECB,
262 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200263 128,
264 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300265 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200266 0,
267 16,
268 &aes_info
269};
270
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271static const mbedtls_cipher_info_t aes_192_ecb_info = {
272 MBEDTLS_CIPHER_AES_192_ECB,
273 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200274 192,
275 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300276 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200277 0,
278 16,
279 &aes_info
280};
281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282static const mbedtls_cipher_info_t aes_256_ecb_info = {
283 MBEDTLS_CIPHER_AES_256_ECB,
284 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200285 256,
286 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300287 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200288 0,
289 16,
290 &aes_info
291};
292
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200293#if defined(MBEDTLS_CIPHER_MODE_CBC)
294static const mbedtls_cipher_info_t aes_128_cbc_info = {
295 MBEDTLS_CIPHER_AES_128_CBC,
296 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000297 128,
298 "AES-128-CBC",
299 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200300 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000301 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000302 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000303};
304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305static const mbedtls_cipher_info_t aes_192_cbc_info = {
306 MBEDTLS_CIPHER_AES_192_CBC,
307 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000308 192,
309 "AES-192-CBC",
310 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200311 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000312 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000313 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000314};
315
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316static const mbedtls_cipher_info_t aes_256_cbc_info = {
317 MBEDTLS_CIPHER_AES_256_CBC,
318 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000319 256,
320 "AES-256-CBC",
321 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200322 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000323 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000324 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000325};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328#if defined(MBEDTLS_CIPHER_MODE_CFB)
329static const mbedtls_cipher_info_t aes_128_cfb128_info = {
330 MBEDTLS_CIPHER_AES_128_CFB128,
331 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000332 128,
333 "AES-128-CFB128",
334 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200335 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000336 16,
337 &aes_info
338};
339
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340static const mbedtls_cipher_info_t aes_192_cfb128_info = {
341 MBEDTLS_CIPHER_AES_192_CFB128,
342 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 192,
344 "AES-192-CFB128",
345 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200346 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000347 16,
348 &aes_info
349};
350
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351static const mbedtls_cipher_info_t aes_256_cfb128_info = {
352 MBEDTLS_CIPHER_AES_256_CFB128,
353 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000354 256,
355 "AES-256-CFB128",
356 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200357 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000358 16,
359 &aes_info
360};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000362
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100363#if defined(MBEDTLS_CIPHER_MODE_OFB)
364static const mbedtls_cipher_info_t aes_128_ofb_info = {
365 MBEDTLS_CIPHER_AES_128_OFB,
366 MBEDTLS_MODE_OFB,
367 128,
368 "AES-128-OFB",
369 16,
370 0,
371 16,
372 &aes_info
373};
374
375static const mbedtls_cipher_info_t aes_192_ofb_info = {
376 MBEDTLS_CIPHER_AES_192_OFB,
377 MBEDTLS_MODE_OFB,
378 192,
379 "AES-192-OFB",
380 16,
381 0,
382 16,
383 &aes_info
384};
385
386static const mbedtls_cipher_info_t aes_256_ofb_info = {
387 MBEDTLS_CIPHER_AES_256_OFB,
388 MBEDTLS_MODE_OFB,
389 256,
390 "AES-256-OFB",
391 16,
392 0,
393 16,
394 &aes_info
395};
396#endif /* MBEDTLS_CIPHER_MODE_OFB */
397
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200398#if defined(MBEDTLS_CIPHER_MODE_CTR)
399static const mbedtls_cipher_info_t aes_128_ctr_info = {
400 MBEDTLS_CIPHER_AES_128_CTR,
401 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000402 128,
403 "AES-128-CTR",
404 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200405 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000406 16,
407 &aes_info
408};
409
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200410static const mbedtls_cipher_info_t aes_192_ctr_info = {
411 MBEDTLS_CIPHER_AES_192_CTR,
412 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000413 192,
414 "AES-192-CTR",
415 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200416 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000417 16,
418 &aes_info
419};
420
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200421static const mbedtls_cipher_info_t aes_256_ctr_info = {
422 MBEDTLS_CIPHER_AES_256_CTR,
423 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000424 256,
425 "AES-256-CTR",
426 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200427 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000428 16,
429 &aes_info
430};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200431#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000432
Jaeden Ameroc6539902018-04-30 17:17:41 +0100433#if defined(MBEDTLS_CIPHER_MODE_XTS)
434static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
435 unsigned int key_bitlen )
436{
437 mbedtls_aes_xts_context *xts_ctx = ctx;
438 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
439}
440
441static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
442 unsigned int key_bitlen )
443{
444 mbedtls_aes_xts_context *xts_ctx = ctx;
445 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
446}
447
448static void *xts_aes_ctx_alloc( void )
449{
450 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
451
452 if( xts_ctx != NULL )
453 mbedtls_aes_xts_init( xts_ctx );
454
455 return( xts_ctx );
456}
457
458static void xts_aes_ctx_free( void *ctx )
459{
460 mbedtls_aes_xts_context *xts_ctx = ctx;
461
462 if( xts_ctx == NULL )
463 return;
464
465 mbedtls_aes_xts_free( xts_ctx );
466 mbedtls_free( xts_ctx );
467}
468
469static const mbedtls_cipher_base_t xts_aes_info = {
470 MBEDTLS_CIPHER_ID_AES,
471 NULL,
472#if defined(MBEDTLS_CIPHER_MODE_CBC)
473 NULL,
474#endif
475#if defined(MBEDTLS_CIPHER_MODE_CFB)
476 NULL,
477#endif
478#if defined(MBEDTLS_CIPHER_MODE_OFB)
479 NULL,
480#endif
481#if defined(MBEDTLS_CIPHER_MODE_CTR)
482 NULL,
483#endif
484#if defined(MBEDTLS_CIPHER_MODE_XTS)
485 aes_crypt_xts_wrap,
486#endif
487#if defined(MBEDTLS_CIPHER_MODE_STREAM)
488 NULL,
489#endif
490 xts_aes_setkey_enc_wrap,
491 xts_aes_setkey_dec_wrap,
492 xts_aes_ctx_alloc,
493 xts_aes_ctx_free
494};
495
496static const mbedtls_cipher_info_t aes_128_xts_info = {
497 MBEDTLS_CIPHER_AES_128_XTS,
498 MBEDTLS_MODE_XTS,
499 256,
500 "AES-128-XTS",
501 16,
502 0,
503 16,
504 &xts_aes_info
505};
506
507static const mbedtls_cipher_info_t aes_256_xts_info = {
508 MBEDTLS_CIPHER_AES_256_XTS,
509 MBEDTLS_MODE_XTS,
510 512,
511 "AES-256-XTS",
512 16,
513 0,
514 16,
515 &xts_aes_info
516};
517#endif /* MBEDTLS_CIPHER_MODE_XTS */
518
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200519#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200520static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200521 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200522{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200523 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200524 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200525}
526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527static const mbedtls_cipher_base_t gcm_aes_info = {
528 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200529 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200531 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100532#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200533#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200534 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100535#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100536#if defined(MBEDTLS_CIPHER_MODE_OFB)
537 NULL,
538#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200540 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100541#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100542#if defined(MBEDTLS_CIPHER_MODE_XTS)
543 NULL,
544#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200545#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200546 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100547#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200548 gcm_aes_setkey_wrap,
549 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200550 gcm_ctx_alloc,
551 gcm_ctx_free,
552};
553
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554static const mbedtls_cipher_info_t aes_128_gcm_info = {
555 MBEDTLS_CIPHER_AES_128_GCM,
556 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100557 128,
558 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200559 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100561 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200562 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100563};
564
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200565static const mbedtls_cipher_info_t aes_192_gcm_info = {
566 MBEDTLS_CIPHER_AES_192_GCM,
567 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200568 192,
569 "AES-192-GCM",
570 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200571 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200572 16,
573 &gcm_aes_info
574};
575
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200576static const mbedtls_cipher_info_t aes_256_gcm_info = {
577 MBEDTLS_CIPHER_AES_256_GCM,
578 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100579 256,
580 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200581 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200582 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100583 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200584 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100585};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100587
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200588#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200589static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200590 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200591{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200592 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200593 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200594}
595
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596static const mbedtls_cipher_base_t ccm_aes_info = {
597 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200598 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200599#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200600 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100601#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200602#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200603 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100604#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100605#if defined(MBEDTLS_CIPHER_MODE_OFB)
606 NULL,
607#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200609 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100610#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100611#if defined(MBEDTLS_CIPHER_MODE_XTS)
612 NULL,
613#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200614#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200615 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100616#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200617 ccm_aes_setkey_wrap,
618 ccm_aes_setkey_wrap,
619 ccm_ctx_alloc,
620 ccm_ctx_free,
621};
622
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200623static const mbedtls_cipher_info_t aes_128_ccm_info = {
624 MBEDTLS_CIPHER_AES_128_CCM,
625 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200626 128,
627 "AES-128-CCM",
628 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200629 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200630 16,
631 &ccm_aes_info
632};
633
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200634static const mbedtls_cipher_info_t aes_192_ccm_info = {
635 MBEDTLS_CIPHER_AES_192_CCM,
636 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200637 192,
638 "AES-192-CCM",
639 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200640 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200641 16,
642 &ccm_aes_info
643};
644
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200645static const mbedtls_cipher_info_t aes_256_ccm_info = {
646 MBEDTLS_CIPHER_AES_256_CCM,
647 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200648 256,
649 "AES-256-CCM",
650 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200652 16,
653 &ccm_aes_info
654};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200655#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000658
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200659#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000660
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200662 const unsigned char *input, unsigned char *output )
663{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200664 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200665 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200666}
667
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200668#if defined(MBEDTLS_CIPHER_MODE_CBC)
669static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200670 size_t length, unsigned char *iv,
671 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000672{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200673 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200674 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000675}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678#if defined(MBEDTLS_CIPHER_MODE_CFB)
679static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200680 size_t length, size_t *iv_off, unsigned char *iv,
681 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000682{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200683 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200684 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000685}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200686#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000687
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200688#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200689static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
690 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000691 const unsigned char *input, unsigned char *output )
692{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200693 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200694 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000695}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000697
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200698static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200699 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000700{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200701 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000702}
703
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200704static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200705 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000706{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200707 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000708}
709
710static void * camellia_ctx_alloc( void )
711{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200712 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200713 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200714
715 if( ctx == NULL )
716 return( NULL );
717
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200718 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200719
720 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000721}
722
723static void camellia_ctx_free( void *ctx )
724{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
726 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000727}
728
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729static const mbedtls_cipher_base_t camellia_info = {
730 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200731 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200732#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000733 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100734#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000736 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100737#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100738#if defined(MBEDTLS_CIPHER_MODE_OFB)
739 NULL,
740#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000742 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100743#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100744#if defined(MBEDTLS_CIPHER_MODE_XTS)
745 NULL,
746#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200747#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200748 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100749#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000750 camellia_setkey_enc_wrap,
751 camellia_setkey_dec_wrap,
752 camellia_ctx_alloc,
753 camellia_ctx_free
754};
755
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200756static const mbedtls_cipher_info_t camellia_128_ecb_info = {
757 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
758 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200759 128,
760 "CAMELLIA-128-ECB",
761 16,
762 0,
763 16,
764 &camellia_info
765};
766
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200767static const mbedtls_cipher_info_t camellia_192_ecb_info = {
768 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
769 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200770 192,
771 "CAMELLIA-192-ECB",
772 16,
773 0,
774 16,
775 &camellia_info
776};
777
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200778static const mbedtls_cipher_info_t camellia_256_ecb_info = {
779 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
780 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200781 256,
782 "CAMELLIA-256-ECB",
783 16,
784 0,
785 16,
786 &camellia_info
787};
788
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200789#if defined(MBEDTLS_CIPHER_MODE_CBC)
790static const mbedtls_cipher_info_t camellia_128_cbc_info = {
791 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
792 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000793 128,
794 "CAMELLIA-128-CBC",
795 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200796 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000797 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000798 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000799};
800
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200801static const mbedtls_cipher_info_t camellia_192_cbc_info = {
802 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
803 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000804 192,
805 "CAMELLIA-192-CBC",
806 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200807 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000808 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000809 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000810};
811
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200812static const mbedtls_cipher_info_t camellia_256_cbc_info = {
813 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
814 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000815 256,
816 "CAMELLIA-256-CBC",
817 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200818 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000819 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000820 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000821};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200822#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000823
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200824#if defined(MBEDTLS_CIPHER_MODE_CFB)
825static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
826 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
827 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000828 128,
829 "CAMELLIA-128-CFB128",
830 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200831 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000832 16,
833 &camellia_info
834};
835
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200836static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
837 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
838 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000839 192,
840 "CAMELLIA-192-CFB128",
841 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200842 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000843 16,
844 &camellia_info
845};
846
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200847static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
848 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
849 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000850 256,
851 "CAMELLIA-256-CFB128",
852 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200853 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000854 16,
855 &camellia_info
856};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200857#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000858
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200859#if defined(MBEDTLS_CIPHER_MODE_CTR)
860static const mbedtls_cipher_info_t camellia_128_ctr_info = {
861 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
862 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000863 128,
864 "CAMELLIA-128-CTR",
865 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200866 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000867 16,
868 &camellia_info
869};
870
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200871static const mbedtls_cipher_info_t camellia_192_ctr_info = {
872 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
873 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000874 192,
875 "CAMELLIA-192-CTR",
876 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200877 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000878 16,
879 &camellia_info
880};
881
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200882static const mbedtls_cipher_info_t camellia_256_ctr_info = {
883 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
884 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000885 256,
886 "CAMELLIA-256-CTR",
887 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200888 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000889 16,
890 &camellia_info
891};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200892#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000893
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200894#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200895static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200896 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200897{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200898 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200899 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200900}
901
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902static const mbedtls_cipher_base_t gcm_camellia_info = {
903 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200904 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200905#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200906 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100907#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200908#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200909 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100910#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100911#if defined(MBEDTLS_CIPHER_MODE_OFB)
912 NULL,
913#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200914#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200915 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100916#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100917#if defined(MBEDTLS_CIPHER_MODE_XTS)
918 NULL,
919#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200920#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200921 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100922#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200923 gcm_camellia_setkey_wrap,
924 gcm_camellia_setkey_wrap,
925 gcm_ctx_alloc,
926 gcm_ctx_free,
927};
928
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200929static const mbedtls_cipher_info_t camellia_128_gcm_info = {
930 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
931 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200932 128,
933 "CAMELLIA-128-GCM",
934 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200935 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200936 16,
937 &gcm_camellia_info
938};
939
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200940static const mbedtls_cipher_info_t camellia_192_gcm_info = {
941 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
942 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200943 192,
944 "CAMELLIA-192-GCM",
945 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200946 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200947 16,
948 &gcm_camellia_info
949};
950
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200951static const mbedtls_cipher_info_t camellia_256_gcm_info = {
952 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
953 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200954 256,
955 "CAMELLIA-256-GCM",
956 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200957 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200958 16,
959 &gcm_camellia_info
960};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200961#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200962
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200963#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200964static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200965 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200966{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200967 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200968 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200969}
970
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200971static const mbedtls_cipher_base_t ccm_camellia_info = {
972 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200973 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200974#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200975 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100976#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200977#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200978 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100979#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100980#if defined(MBEDTLS_CIPHER_MODE_OFB)
981 NULL,
982#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200983#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200984 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100985#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100986#if defined(MBEDTLS_CIPHER_MODE_XTS)
987 NULL,
988#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200989#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200990 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100991#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200992 ccm_camellia_setkey_wrap,
993 ccm_camellia_setkey_wrap,
994 ccm_ctx_alloc,
995 ccm_ctx_free,
996};
997
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200998static const mbedtls_cipher_info_t camellia_128_ccm_info = {
999 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1000 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001001 128,
1002 "CAMELLIA-128-CCM",
1003 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001004 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001005 16,
1006 &ccm_camellia_info
1007};
1008
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001009static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1010 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1011 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001012 192,
1013 "CAMELLIA-192-CCM",
1014 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001015 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001016 16,
1017 &ccm_camellia_info
1018};
1019
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001020static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1021 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1022 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001023 256,
1024 "CAMELLIA-256-CCM",
1025 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001026 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001027 16,
1028 &ccm_camellia_info
1029};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001030#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001032#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001033
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001034#if defined(MBEDTLS_ARIA_C)
1035
1036static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1037 const unsigned char *input, unsigned char *output )
1038{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001039 (void) operation;
1040 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001041 output );
1042}
1043
1044#if defined(MBEDTLS_CIPHER_MODE_CBC)
1045static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1046 size_t length, unsigned char *iv,
1047 const unsigned char *input, unsigned char *output )
1048{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001049 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001050 input, output );
1051}
1052#endif /* MBEDTLS_CIPHER_MODE_CBC */
1053
1054#if defined(MBEDTLS_CIPHER_MODE_CFB)
1055static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1056 size_t length, size_t *iv_off, unsigned char *iv,
1057 const unsigned char *input, unsigned char *output )
1058{
1059 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1060 iv_off, iv, input, output );
1061}
1062#endif /* MBEDTLS_CIPHER_MODE_CFB */
1063
1064#if defined(MBEDTLS_CIPHER_MODE_CTR)
1065static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1066 unsigned char *nonce_counter, unsigned char *stream_block,
1067 const unsigned char *input, unsigned char *output )
1068{
1069 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1070 nonce_counter, stream_block, input, output );
1071}
1072#endif /* MBEDTLS_CIPHER_MODE_CTR */
1073
1074static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1075 unsigned int key_bitlen )
1076{
1077 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1078}
1079
1080static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1081 unsigned int key_bitlen )
1082{
1083 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1084}
1085
1086static void * aria_ctx_alloc( void )
1087{
1088 mbedtls_aria_context *ctx;
1089 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1090
1091 if( ctx == NULL )
1092 return( NULL );
1093
1094 mbedtls_aria_init( ctx );
1095
1096 return( ctx );
1097}
1098
1099static void aria_ctx_free( void *ctx )
1100{
1101 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1102 mbedtls_free( ctx );
1103}
1104
1105static const mbedtls_cipher_base_t aria_info = {
1106 MBEDTLS_CIPHER_ID_ARIA,
1107 aria_crypt_ecb_wrap,
1108#if defined(MBEDTLS_CIPHER_MODE_CBC)
1109 aria_crypt_cbc_wrap,
1110#endif
1111#if defined(MBEDTLS_CIPHER_MODE_CFB)
1112 aria_crypt_cfb128_wrap,
1113#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001114#if defined(MBEDTLS_CIPHER_MODE_OFB)
1115 NULL,
1116#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001117#if defined(MBEDTLS_CIPHER_MODE_CTR)
1118 aria_crypt_ctr_wrap,
1119#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001120#if defined(MBEDTLS_CIPHER_MODE_XTS)
1121 NULL,
1122#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001123#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1124 NULL,
1125#endif
1126 aria_setkey_enc_wrap,
1127 aria_setkey_dec_wrap,
1128 aria_ctx_alloc,
1129 aria_ctx_free
1130};
1131
1132static const mbedtls_cipher_info_t aria_128_ecb_info = {
1133 MBEDTLS_CIPHER_ARIA_128_ECB,
1134 MBEDTLS_MODE_ECB,
1135 128,
1136 "ARIA-128-ECB",
1137 16,
1138 0,
1139 16,
1140 &aria_info
1141};
1142
1143static const mbedtls_cipher_info_t aria_192_ecb_info = {
1144 MBEDTLS_CIPHER_ARIA_192_ECB,
1145 MBEDTLS_MODE_ECB,
1146 192,
1147 "ARIA-192-ECB",
1148 16,
1149 0,
1150 16,
1151 &aria_info
1152};
1153
1154static const mbedtls_cipher_info_t aria_256_ecb_info = {
1155 MBEDTLS_CIPHER_ARIA_256_ECB,
1156 MBEDTLS_MODE_ECB,
1157 256,
1158 "ARIA-256-ECB",
1159 16,
1160 0,
1161 16,
1162 &aria_info
1163};
1164
1165#if defined(MBEDTLS_CIPHER_MODE_CBC)
1166static const mbedtls_cipher_info_t aria_128_cbc_info = {
1167 MBEDTLS_CIPHER_ARIA_128_CBC,
1168 MBEDTLS_MODE_CBC,
1169 128,
1170 "ARIA-128-CBC",
1171 16,
1172 0,
1173 16,
1174 &aria_info
1175};
1176
1177static const mbedtls_cipher_info_t aria_192_cbc_info = {
1178 MBEDTLS_CIPHER_ARIA_192_CBC,
1179 MBEDTLS_MODE_CBC,
1180 192,
1181 "ARIA-192-CBC",
1182 16,
1183 0,
1184 16,
1185 &aria_info
1186};
1187
1188static const mbedtls_cipher_info_t aria_256_cbc_info = {
1189 MBEDTLS_CIPHER_ARIA_256_CBC,
1190 MBEDTLS_MODE_CBC,
1191 256,
1192 "ARIA-256-CBC",
1193 16,
1194 0,
1195 16,
1196 &aria_info
1197};
1198#endif /* MBEDTLS_CIPHER_MODE_CBC */
1199
1200#if defined(MBEDTLS_CIPHER_MODE_CFB)
1201static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1202 MBEDTLS_CIPHER_ARIA_128_CFB128,
1203 MBEDTLS_MODE_CFB,
1204 128,
1205 "ARIA-128-CFB128",
1206 16,
1207 0,
1208 16,
1209 &aria_info
1210};
1211
1212static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1213 MBEDTLS_CIPHER_ARIA_192_CFB128,
1214 MBEDTLS_MODE_CFB,
1215 192,
1216 "ARIA-192-CFB128",
1217 16,
1218 0,
1219 16,
1220 &aria_info
1221};
1222
1223static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1224 MBEDTLS_CIPHER_ARIA_256_CFB128,
1225 MBEDTLS_MODE_CFB,
1226 256,
1227 "ARIA-256-CFB128",
1228 16,
1229 0,
1230 16,
1231 &aria_info
1232};
1233#endif /* MBEDTLS_CIPHER_MODE_CFB */
1234
1235#if defined(MBEDTLS_CIPHER_MODE_CTR)
1236static const mbedtls_cipher_info_t aria_128_ctr_info = {
1237 MBEDTLS_CIPHER_ARIA_128_CTR,
1238 MBEDTLS_MODE_CTR,
1239 128,
1240 "ARIA-128-CTR",
1241 16,
1242 0,
1243 16,
1244 &aria_info
1245};
1246
1247static const mbedtls_cipher_info_t aria_192_ctr_info = {
1248 MBEDTLS_CIPHER_ARIA_192_CTR,
1249 MBEDTLS_MODE_CTR,
1250 192,
1251 "ARIA-192-CTR",
1252 16,
1253 0,
1254 16,
1255 &aria_info
1256};
1257
1258static const mbedtls_cipher_info_t aria_256_ctr_info = {
1259 MBEDTLS_CIPHER_ARIA_256_CTR,
1260 MBEDTLS_MODE_CTR,
1261 256,
1262 "ARIA-256-CTR",
1263 16,
1264 0,
1265 16,
1266 &aria_info
1267};
1268#endif /* MBEDTLS_CIPHER_MODE_CTR */
1269
1270#if defined(MBEDTLS_GCM_C)
1271static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1272 unsigned int key_bitlen )
1273{
1274 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1275 key, key_bitlen );
1276}
1277
1278static const mbedtls_cipher_base_t gcm_aria_info = {
1279 MBEDTLS_CIPHER_ID_ARIA,
1280 NULL,
1281#if defined(MBEDTLS_CIPHER_MODE_CBC)
1282 NULL,
1283#endif
1284#if defined(MBEDTLS_CIPHER_MODE_CFB)
1285 NULL,
1286#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001287#if defined(MBEDTLS_CIPHER_MODE_OFB)
1288 NULL,
1289#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001290#if defined(MBEDTLS_CIPHER_MODE_CTR)
1291 NULL,
1292#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001293#if defined(MBEDTLS_CIPHER_MODE_XTS)
1294 NULL,
1295#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001296#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1297 NULL,
1298#endif
1299 gcm_aria_setkey_wrap,
1300 gcm_aria_setkey_wrap,
1301 gcm_ctx_alloc,
1302 gcm_ctx_free,
1303};
1304
1305static const mbedtls_cipher_info_t aria_128_gcm_info = {
1306 MBEDTLS_CIPHER_ARIA_128_GCM,
1307 MBEDTLS_MODE_GCM,
1308 128,
1309 "ARIA-128-GCM",
1310 12,
1311 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1312 16,
1313 &gcm_aria_info
1314};
1315
1316static const mbedtls_cipher_info_t aria_192_gcm_info = {
1317 MBEDTLS_CIPHER_ARIA_192_GCM,
1318 MBEDTLS_MODE_GCM,
1319 192,
1320 "ARIA-192-GCM",
1321 12,
1322 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1323 16,
1324 &gcm_aria_info
1325};
1326
1327static const mbedtls_cipher_info_t aria_256_gcm_info = {
1328 MBEDTLS_CIPHER_ARIA_256_GCM,
1329 MBEDTLS_MODE_GCM,
1330 256,
1331 "ARIA-256-GCM",
1332 12,
1333 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1334 16,
1335 &gcm_aria_info
1336};
1337#endif /* MBEDTLS_GCM_C */
1338
1339#if defined(MBEDTLS_CCM_C)
1340static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1341 unsigned int key_bitlen )
1342{
1343 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1344 key, key_bitlen );
1345}
1346
1347static const mbedtls_cipher_base_t ccm_aria_info = {
1348 MBEDTLS_CIPHER_ID_ARIA,
1349 NULL,
1350#if defined(MBEDTLS_CIPHER_MODE_CBC)
1351 NULL,
1352#endif
1353#if defined(MBEDTLS_CIPHER_MODE_CFB)
1354 NULL,
1355#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001356#if defined(MBEDTLS_CIPHER_MODE_OFB)
1357 NULL,
1358#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001359#if defined(MBEDTLS_CIPHER_MODE_CTR)
1360 NULL,
1361#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001362#if defined(MBEDTLS_CIPHER_MODE_XTS)
1363 NULL,
1364#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001365#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1366 NULL,
1367#endif
1368 ccm_aria_setkey_wrap,
1369 ccm_aria_setkey_wrap,
1370 ccm_ctx_alloc,
1371 ccm_ctx_free,
1372};
1373
1374static const mbedtls_cipher_info_t aria_128_ccm_info = {
1375 MBEDTLS_CIPHER_ARIA_128_CCM,
1376 MBEDTLS_MODE_CCM,
1377 128,
1378 "ARIA-128-CCM",
1379 12,
1380 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1381 16,
1382 &ccm_aria_info
1383};
1384
1385static const mbedtls_cipher_info_t aria_192_ccm_info = {
1386 MBEDTLS_CIPHER_ARIA_192_CCM,
1387 MBEDTLS_MODE_CCM,
1388 192,
1389 "ARIA-192-CCM",
1390 12,
1391 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1392 16,
1393 &ccm_aria_info
1394};
1395
1396static const mbedtls_cipher_info_t aria_256_ccm_info = {
1397 MBEDTLS_CIPHER_ARIA_256_CCM,
1398 MBEDTLS_MODE_CCM,
1399 256,
1400 "ARIA-256-CCM",
1401 12,
1402 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1403 16,
1404 &ccm_aria_info
1405};
1406#endif /* MBEDTLS_CCM_C */
1407
1408#endif /* MBEDTLS_ARIA_C */
1409
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001410#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001411
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001412static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001413 const unsigned char *input, unsigned char *output )
1414{
1415 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001416 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001417}
1418
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001419static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001420 const unsigned char *input, unsigned char *output )
1421{
1422 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001423 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001424}
1425
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001426#if defined(MBEDTLS_CIPHER_MODE_CBC)
1427static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001428 unsigned char *iv, const unsigned char *input, unsigned char *output )
1429{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001430 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001431 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001432}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001433#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001434
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001435#if defined(MBEDTLS_CIPHER_MODE_CBC)
1436static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001437 unsigned char *iv, const unsigned char *input, unsigned char *output )
1438{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001439 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001440 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001441}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001442#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001443
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001444static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001445 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001446{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001447 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001448
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001449 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001450}
1451
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001452static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001453 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001454{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001455 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001456
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001457 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001458}
1459
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001460static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001461 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001462{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001463 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001464
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001465 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001466}
1467
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001468static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001469 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001470{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001471 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001472
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001473 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001474}
1475
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001476static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001477 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001478{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001479 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001480
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001481 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001482}
1483
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001484static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001485 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001486{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001487 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001488
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001489 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001490}
1491
1492static void * des_ctx_alloc( void )
1493{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001494 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001495
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001496 if( des == NULL )
1497 return( NULL );
1498
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001499 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001500
1501 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001502}
1503
1504static void des_ctx_free( void *ctx )
1505{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001506 mbedtls_des_free( (mbedtls_des_context *) ctx );
1507 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001508}
1509
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001510static void * des3_ctx_alloc( void )
1511{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001512 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001513 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001514
1515 if( des3 == NULL )
1516 return( NULL );
1517
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001518 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001519
1520 return( des3 );
1521}
1522
Paul Bakker34617722014-06-13 17:20:13 +02001523static void des3_ctx_free( void *ctx )
1524{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001525 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1526 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001527}
1528
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529static const mbedtls_cipher_base_t des_info = {
1530 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001531 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001532#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001533 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001534#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001535#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001536 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001537#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001538#if defined(MBEDTLS_CIPHER_MODE_OFB)
1539 NULL,
1540#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001541#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001542 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001543#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001544#if defined(MBEDTLS_CIPHER_MODE_XTS)
1545 NULL,
1546#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001547#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001548 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001549#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001550 des_setkey_enc_wrap,
1551 des_setkey_dec_wrap,
1552 des_ctx_alloc,
1553 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001554};
1555
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001556static const mbedtls_cipher_info_t des_ecb_info = {
1557 MBEDTLS_CIPHER_DES_ECB,
1558 MBEDTLS_MODE_ECB,
1559 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001560 "DES-ECB",
1561 8,
1562 0,
1563 8,
1564 &des_info
1565};
1566
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001567#if defined(MBEDTLS_CIPHER_MODE_CBC)
1568static const mbedtls_cipher_info_t des_cbc_info = {
1569 MBEDTLS_CIPHER_DES_CBC,
1570 MBEDTLS_MODE_CBC,
1571 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001572 "DES-CBC",
1573 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001574 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001575 8,
1576 &des_info
1577};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001578#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001579
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001580static const mbedtls_cipher_base_t des_ede_info = {
1581 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001582 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001583#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001584 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001585#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001586#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001587 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001588#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001589#if defined(MBEDTLS_CIPHER_MODE_OFB)
1590 NULL,
1591#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001592#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001593 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001594#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001595#if defined(MBEDTLS_CIPHER_MODE_XTS)
1596 NULL,
1597#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001599 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001600#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001601 des3_set2key_enc_wrap,
1602 des3_set2key_dec_wrap,
1603 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001604 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001605};
1606
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001607static const mbedtls_cipher_info_t des_ede_ecb_info = {
1608 MBEDTLS_CIPHER_DES_EDE_ECB,
1609 MBEDTLS_MODE_ECB,
1610 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001611 "DES-EDE-ECB",
1612 8,
1613 0,
1614 8,
1615 &des_ede_info
1616};
1617
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618#if defined(MBEDTLS_CIPHER_MODE_CBC)
1619static const mbedtls_cipher_info_t des_ede_cbc_info = {
1620 MBEDTLS_CIPHER_DES_EDE_CBC,
1621 MBEDTLS_MODE_CBC,
1622 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001623 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001624 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001625 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001626 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001627 &des_ede_info
1628};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001629#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001630
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001631static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001632 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001633 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001634#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001635 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001636#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001637#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001638 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001639#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001640#if defined(MBEDTLS_CIPHER_MODE_OFB)
1641 NULL,
1642#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001643#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001644 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001645#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001646#if defined(MBEDTLS_CIPHER_MODE_XTS)
1647 NULL,
1648#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001649#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001650 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001651#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001652 des3_set3key_enc_wrap,
1653 des3_set3key_dec_wrap,
1654 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001655 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001656};
1657
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001658static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1659 MBEDTLS_CIPHER_DES_EDE3_ECB,
1660 MBEDTLS_MODE_ECB,
1661 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001662 "DES-EDE3-ECB",
1663 8,
1664 0,
1665 8,
1666 &des_ede3_info
1667};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001668#if defined(MBEDTLS_CIPHER_MODE_CBC)
1669static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1670 MBEDTLS_CIPHER_DES_EDE3_CBC,
1671 MBEDTLS_MODE_CBC,
1672 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001673 "DES-EDE3-CBC",
1674 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001675 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001676 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001677 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001678};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001679#endif /* MBEDTLS_CIPHER_MODE_CBC */
1680#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001681
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001682#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001683
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001684static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001685 const unsigned char *input, unsigned char *output )
1686{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001687 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001688 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001689}
1690
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001691#if defined(MBEDTLS_CIPHER_MODE_CBC)
1692static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001693 size_t length, unsigned char *iv, const unsigned char *input,
1694 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001695{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001696 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001697 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001698}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001699#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001700
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001701#if defined(MBEDTLS_CIPHER_MODE_CFB)
1702static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001703 size_t length, size_t *iv_off, unsigned char *iv,
1704 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001705{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001706 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001707 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001708}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001709#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001710
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001711#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001712static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1713 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001714 const unsigned char *input, unsigned char *output )
1715{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001716 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001717 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001718}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001719#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001720
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001721static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001722 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001723{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001724 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001725}
1726
1727static void * blowfish_ctx_alloc( void )
1728{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001729 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001730 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001731
1732 if( ctx == NULL )
1733 return( NULL );
1734
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001735 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001736
1737 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001738}
1739
1740static void blowfish_ctx_free( void *ctx )
1741{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001742 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1743 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001744}
1745
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001746static const mbedtls_cipher_base_t blowfish_info = {
1747 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001748 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001749#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001750 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001751#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001752#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001753 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001754#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001755#if defined(MBEDTLS_CIPHER_MODE_OFB)
1756 NULL,
1757#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001758#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001759 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001760#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001761#if defined(MBEDTLS_CIPHER_MODE_XTS)
1762 NULL,
1763#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001764#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001765 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001766#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001767 blowfish_setkey_wrap,
1768 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001769 blowfish_ctx_alloc,
1770 blowfish_ctx_free
1771};
1772
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001773static const mbedtls_cipher_info_t blowfish_ecb_info = {
1774 MBEDTLS_CIPHER_BLOWFISH_ECB,
1775 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001776 128,
1777 "BLOWFISH-ECB",
1778 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001779 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001780 8,
1781 &blowfish_info
1782};
1783
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001784#if defined(MBEDTLS_CIPHER_MODE_CBC)
1785static const mbedtls_cipher_info_t blowfish_cbc_info = {
1786 MBEDTLS_CIPHER_BLOWFISH_CBC,
1787 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001788 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001789 "BLOWFISH-CBC",
1790 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001791 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001792 8,
1793 &blowfish_info
1794};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001795#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001796
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001797#if defined(MBEDTLS_CIPHER_MODE_CFB)
1798static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1799 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1800 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001801 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001802 "BLOWFISH-CFB64",
1803 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001804 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001805 8,
1806 &blowfish_info
1807};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001808#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001809
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001810#if defined(MBEDTLS_CIPHER_MODE_CTR)
1811static const mbedtls_cipher_info_t blowfish_ctr_info = {
1812 MBEDTLS_CIPHER_BLOWFISH_CTR,
1813 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001814 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001815 "BLOWFISH-CTR",
1816 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001817 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001818 8,
1819 &blowfish_info
1820};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001821#endif /* MBEDTLS_CIPHER_MODE_CTR */
1822#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001823
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001824#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001825static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1826 const unsigned char *input,
1827 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001828{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001829 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001830}
1831
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001832static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001833 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001834{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001835 /* we get key_bitlen in bits, arc4 expects it in bytes */
1836 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001837 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001838
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001839 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001840 return( 0 );
1841}
1842
1843static void * arc4_ctx_alloc( void )
1844{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001845 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001846 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001847
1848 if( ctx == NULL )
1849 return( NULL );
1850
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001851 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001852
1853 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001854}
Paul Bakker68884e32013-01-07 18:20:04 +01001855
1856static void arc4_ctx_free( void *ctx )
1857{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001858 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1859 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001860}
1861
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001862static const mbedtls_cipher_base_t arc4_base_info = {
1863 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001864 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001865#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001866 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001867#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001868#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001869 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001870#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001871#if defined(MBEDTLS_CIPHER_MODE_OFB)
1872 NULL,
1873#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001874#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001875 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001876#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001877#if defined(MBEDTLS_CIPHER_MODE_XTS)
1878 NULL,
1879#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001880#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001881 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001882#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001883 arc4_setkey_wrap,
1884 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001885 arc4_ctx_alloc,
1886 arc4_ctx_free
1887};
1888
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001889static const mbedtls_cipher_info_t arc4_128_info = {
1890 MBEDTLS_CIPHER_ARC4_128,
1891 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001892 128,
1893 "ARC4-128",
1894 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001895 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001896 1,
1897 &arc4_base_info
1898};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001899#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001900
Daniel Kingbd920622016-05-15 19:56:20 -03001901#if defined(MBEDTLS_CHACHA20_C)
1902
1903static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1904 unsigned int key_bitlen )
1905{
1906 if( key_bitlen != 256U )
1907 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1908
1909 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1910 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1911
1912 return( 0 );
1913}
1914
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001915static int chacha20_stream_wrap( void *ctx, size_t length,
1916 const unsigned char *input,
1917 unsigned char *output )
1918{
1919 int ret;
1920
1921 ret = mbedtls_chacha20_update( ctx, length, input, output );
1922 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1923 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1924
1925 return( ret );
1926}
1927
Daniel Kingbd920622016-05-15 19:56:20 -03001928static void * chacha20_ctx_alloc( void )
1929{
1930 mbedtls_chacha20_context *ctx;
1931 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1932
1933 if( ctx == NULL )
1934 return( NULL );
1935
1936 mbedtls_chacha20_init( ctx );
1937
1938 return( ctx );
1939}
1940
1941static void chacha20_ctx_free( void *ctx )
1942{
1943 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1944 mbedtls_free( ctx );
1945}
1946
1947static const mbedtls_cipher_base_t chacha20_base_info = {
1948 MBEDTLS_CIPHER_ID_CHACHA20,
1949 NULL,
1950#if defined(MBEDTLS_CIPHER_MODE_CBC)
1951 NULL,
1952#endif
1953#if defined(MBEDTLS_CIPHER_MODE_CFB)
1954 NULL,
1955#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001956#if defined(MBEDTLS_CIPHER_MODE_OFB)
1957 NULL,
1958#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001959#if defined(MBEDTLS_CIPHER_MODE_CTR)
1960 NULL,
1961#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001962#if defined(MBEDTLS_CIPHER_MODE_XTS)
1963 NULL,
1964#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001965#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001966 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001967#endif
1968 chacha20_setkey_wrap,
1969 chacha20_setkey_wrap,
1970 chacha20_ctx_alloc,
1971 chacha20_ctx_free
1972};
1973static const mbedtls_cipher_info_t chacha20_info = {
1974 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001975 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001976 256,
1977 "CHACHA20",
1978 12,
1979 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001980 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001981 &chacha20_base_info
1982};
1983#endif /* MBEDTLS_CHACHA20_C */
1984
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001985#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001986
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001987static int chachapoly_setkey_wrap( void *ctx,
1988 const unsigned char *key,
1989 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001990{
1991 if( key_bitlen != 256U )
1992 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1993
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001994 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001995 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1996
1997 return( 0 );
1998}
1999
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002000static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03002001{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002002 mbedtls_chachapoly_context *ctx;
2003 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03002004
2005 if( ctx == NULL )
2006 return( NULL );
2007
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002008 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002009
2010 return( ctx );
2011}
2012
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002013static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002014{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002015 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002016 mbedtls_free( ctx );
2017}
2018
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002019static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002020 MBEDTLS_CIPHER_ID_CHACHA20,
2021 NULL,
2022#if defined(MBEDTLS_CIPHER_MODE_CBC)
2023 NULL,
2024#endif
2025#if defined(MBEDTLS_CIPHER_MODE_CFB)
2026 NULL,
2027#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002028#if defined(MBEDTLS_CIPHER_MODE_OFB)
2029 NULL,
2030#endif
Daniel King8fe47012016-05-17 20:33:28 -03002031#if defined(MBEDTLS_CIPHER_MODE_CTR)
2032 NULL,
2033#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002034#if defined(MBEDTLS_CIPHER_MODE_XTS)
2035 NULL,
2036#endif
Daniel King8fe47012016-05-17 20:33:28 -03002037#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2038 NULL,
2039#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002040 chachapoly_setkey_wrap,
2041 chachapoly_setkey_wrap,
2042 chachapoly_ctx_alloc,
2043 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002044};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002045static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002046 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002047 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002048 256,
2049 "CHACHA20-POLY1305",
2050 12,
2051 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002052 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002053 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002054};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002055#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002057#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002058static int null_crypt_stream( void *ctx, size_t length,
2059 const unsigned char *input,
2060 unsigned char *output )
2061{
2062 ((void) ctx);
2063 memmove( output, input, length );
2064 return( 0 );
2065}
2066
2067static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002068 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002069{
2070 ((void) ctx);
2071 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002072 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002073
2074 return( 0 );
2075}
2076
Paul Bakkerfab5c822012-02-06 16:45:10 +00002077static void * null_ctx_alloc( void )
2078{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002079 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002080}
2081
Paul Bakkerfab5c822012-02-06 16:45:10 +00002082static void null_ctx_free( void *ctx )
2083{
2084 ((void) ctx);
2085}
2086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002087static const mbedtls_cipher_base_t null_base_info = {
2088 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002089 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002090#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002091 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002092#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002093#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002094 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002095#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002096#if defined(MBEDTLS_CIPHER_MODE_OFB)
2097 NULL,
2098#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002099#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002100 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002101#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002102#if defined(MBEDTLS_CIPHER_MODE_XTS)
2103 NULL,
2104#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002105#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002106 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002107#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002108 null_setkey,
2109 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002110 null_ctx_alloc,
2111 null_ctx_free
2112};
2113
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002114static const mbedtls_cipher_info_t null_cipher_info = {
2115 MBEDTLS_CIPHER_NULL,
2116 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002117 0,
2118 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002119 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002120 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002121 1,
2122 &null_base_info
2123};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002124#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002125
Jack Lloydffdf2882019-03-07 17:00:32 -05002126#if defined(MBEDTLS_NIST_KW_C)
2127static void *kw_ctx_alloc( void )
2128{
2129 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
2130
2131 if( ctx != NULL )
2132 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
2133
2134 return( ctx );
2135}
2136
2137static void kw_ctx_free( void *ctx )
2138{
2139 mbedtls_nist_kw_free( ctx );
2140 mbedtls_free( ctx );
2141}
2142
2143static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
2144 unsigned int key_bitlen )
2145{
Jack Lloyd5f289992019-04-02 10:07:28 -07002146 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2147 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002148}
2149
2150static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
2151 unsigned int key_bitlen )
2152{
Jack Lloyd5f289992019-04-02 10:07:28 -07002153 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2154 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
Jack Lloydffdf2882019-03-07 17:00:32 -05002155}
2156
2157static const mbedtls_cipher_base_t kw_aes_info = {
2158 MBEDTLS_CIPHER_ID_AES,
2159 NULL,
2160#if defined(MBEDTLS_CIPHER_MODE_CBC)
2161 NULL,
2162#endif
2163#if defined(MBEDTLS_CIPHER_MODE_CFB)
2164 NULL,
2165#endif
2166#if defined(MBEDTLS_CIPHER_MODE_OFB)
2167 NULL,
2168#endif
2169#if defined(MBEDTLS_CIPHER_MODE_CTR)
2170 NULL,
2171#endif
2172#if defined(MBEDTLS_CIPHER_MODE_XTS)
2173 NULL,
2174#endif
2175#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2176 NULL,
2177#endif
2178 kw_aes_setkey_wrap,
2179 kw_aes_setkey_unwrap,
2180 kw_ctx_alloc,
2181 kw_ctx_free,
2182};
2183
2184static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
2185 MBEDTLS_CIPHER_AES_128_KW,
2186 MBEDTLS_MODE_KW,
2187 128,
2188 "AES-128-KW",
2189 0,
2190 0,
2191 16,
2192 &kw_aes_info
2193};
2194
2195static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
2196 MBEDTLS_CIPHER_AES_192_KW,
2197 MBEDTLS_MODE_KW,
2198 192,
2199 "AES-192-KW",
2200 0,
2201 0,
2202 16,
2203 &kw_aes_info
2204};
2205
2206static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
2207 MBEDTLS_CIPHER_AES_256_KW,
2208 MBEDTLS_MODE_KW,
2209 256,
2210 "AES-256-KW",
2211 0,
2212 0,
2213 16,
2214 &kw_aes_info
2215};
2216
2217static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
2218 MBEDTLS_CIPHER_AES_128_KWP,
2219 MBEDTLS_MODE_KWP,
2220 128,
2221 "AES-128-KWP",
2222 0,
2223 0,
2224 16,
2225 &kw_aes_info
2226};
2227
2228static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
2229 MBEDTLS_CIPHER_AES_192_KWP,
2230 MBEDTLS_MODE_KWP,
2231 192,
2232 "AES-192-KWP",
2233 0,
2234 0,
2235 16,
2236 &kw_aes_info
2237};
2238
2239static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
2240 MBEDTLS_CIPHER_AES_256_KWP,
2241 MBEDTLS_MODE_KWP,
2242 256,
2243 "AES-256-KWP",
2244 0,
2245 0,
2246 16,
2247 &kw_aes_info
2248};
2249#endif /* MBEDTLS_NIST_KW_C */
2250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002251const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002252{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002253#if defined(MBEDTLS_AES_C)
2254 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2255 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2256 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2257#if defined(MBEDTLS_CIPHER_MODE_CBC)
2258 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2259 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2260 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002261#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002262#if defined(MBEDTLS_CIPHER_MODE_CFB)
2263 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2264 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2265 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002266#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002267#if defined(MBEDTLS_CIPHER_MODE_OFB)
2268 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2269 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2270 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2271#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002272#if defined(MBEDTLS_CIPHER_MODE_CTR)
2273 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2274 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2275 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002276#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002277#if defined(MBEDTLS_CIPHER_MODE_XTS)
2278 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2279 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2280#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002281#if defined(MBEDTLS_GCM_C)
2282 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2283 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2284 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002285#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002286#if defined(MBEDTLS_CCM_C)
2287 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2288 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2289 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002290#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002291#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002292
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002293#if defined(MBEDTLS_ARC4_C)
2294 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002295#endif
2296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002297#if defined(MBEDTLS_BLOWFISH_C)
2298 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2299#if defined(MBEDTLS_CIPHER_MODE_CBC)
2300 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002301#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002302#if defined(MBEDTLS_CIPHER_MODE_CFB)
2303 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002304#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002305#if defined(MBEDTLS_CIPHER_MODE_CTR)
2306 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002307#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002308#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002309
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002310#if defined(MBEDTLS_CAMELLIA_C)
2311 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2312 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2313 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2314#if defined(MBEDTLS_CIPHER_MODE_CBC)
2315 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2316 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2317 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002318#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002319#if defined(MBEDTLS_CIPHER_MODE_CFB)
2320 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2321 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2322 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002323#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002324#if defined(MBEDTLS_CIPHER_MODE_CTR)
2325 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2326 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2327 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002328#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002329#if defined(MBEDTLS_GCM_C)
2330 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2331 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2332 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002333#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002334#if defined(MBEDTLS_CCM_C)
2335 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2336 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2337 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002338#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002339#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002340
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002341#if defined(MBEDTLS_ARIA_C)
2342 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2343 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2344 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2345#if defined(MBEDTLS_CIPHER_MODE_CBC)
2346 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2347 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2348 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2349#endif
2350#if defined(MBEDTLS_CIPHER_MODE_CFB)
2351 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2352 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2353 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2354#endif
2355#if defined(MBEDTLS_CIPHER_MODE_CTR)
2356 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2357 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2358 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2359#endif
2360#if defined(MBEDTLS_GCM_C)
2361 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2362 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2363 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2364#endif
2365#if defined(MBEDTLS_CCM_C)
2366 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2367 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2368 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2369#endif
2370#endif /* MBEDTLS_ARIA_C */
2371
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002372#if defined(MBEDTLS_DES_C)
2373 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2374 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2375 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2376#if defined(MBEDTLS_CIPHER_MODE_CBC)
2377 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2378 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2379 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002380#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002381#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002382
Daniel Kingbd920622016-05-15 19:56:20 -03002383#if defined(MBEDTLS_CHACHA20_C)
2384 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2385#endif
2386
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002387#if defined(MBEDTLS_CHACHAPOLY_C)
2388 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002389#endif
2390
Jack Lloydffdf2882019-03-07 17:00:32 -05002391#if defined(MBEDTLS_NIST_KW_C)
2392 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
2393 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
2394 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
2395 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
2396 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
2397 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
2398#endif
2399
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002400#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2401 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2402#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002403
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002404 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002405};
2406
Hanno Beckerc3d25b32018-11-08 16:01:22 +00002407#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
2408 sizeof(mbedtls_cipher_definitions[0]) )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002409int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002410
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002411#endif /* MBEDTLS_CIPHER_C */