blob: 893490acc83fbaeb668d44e69509fc1d353be82f [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
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000077#include <string.h>
78#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020082#else
Rich Evans00ab4702015-02-06 13:43:58 +000083#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020084#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020089/* shared by all GCM ciphers */
90static void *gcm_ctx_alloc( void )
91{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020092 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
93
94 if( ctx != NULL )
95 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
96
97 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020098}
99
100static void gcm_ctx_free( void *ctx )
101{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102 mbedtls_gcm_free( ctx );
103 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200104}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200108/* shared by all CCM ciphers */
109static void *ccm_ctx_alloc( void )
110{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200111 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
112
113 if( ctx != NULL )
114 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
115
116 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200117}
118
119static void ccm_ctx_free( void *ctx )
120{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121 mbedtls_ccm_free( ctx );
122 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200123}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200129 const unsigned char *input, unsigned char *output )
130{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200132}
133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#if defined(MBEDTLS_CIPHER_MODE_CBC)
135static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000136 unsigned char *iv, const unsigned char *input, unsigned char *output )
137{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200139 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000140}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#if defined(MBEDTLS_CIPHER_MODE_CFB)
144static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200145 size_t length, size_t *iv_off, unsigned char *iv,
146 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000147{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200149 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000150}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000152
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100153#if defined(MBEDTLS_CIPHER_MODE_OFB)
154static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
155 unsigned char *iv, const unsigned char *input, unsigned char *output )
156{
157 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
158 iv, input, output );
159}
160#endif /* MBEDTLS_CIPHER_MODE_OFB */
161
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200163static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
164 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000165 const unsigned char *input, unsigned char *output )
166{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000168 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000169}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000171
Jaeden Ameroc6539902018-04-30 17:17:41 +0100172#if defined(MBEDTLS_CIPHER_MODE_XTS)
173static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
174 size_t length,
175 const unsigned char data_unit[16],
176 const unsigned char *input,
177 unsigned char *output )
178{
179 mbedtls_aes_xts_context *xts_ctx = ctx;
180 int mode;
181
182 switch( operation )
183 {
184 case MBEDTLS_ENCRYPT:
185 mode = MBEDTLS_AES_ENCRYPT;
186 break;
187 case MBEDTLS_DECRYPT:
188 mode = MBEDTLS_AES_DECRYPT;
189 break;
190 default:
191 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
192 }
193
194 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
195 data_unit, input, output );
196}
197#endif /* MBEDTLS_CIPHER_MODE_XTS */
198
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200199static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200200 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000201{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200202 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000203}
204
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200205static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200206 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000207{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200208 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000209}
210
211static void * aes_ctx_alloc( void )
212{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200213 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200214
215 if( aes == NULL )
216 return( NULL );
217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200219
220 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000221}
222
223static void aes_ctx_free( void *ctx )
224{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
226 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000227}
228
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229static const mbedtls_cipher_base_t aes_info = {
230 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200231 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200232#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000233 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100234#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000236 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100237#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100238#if defined(MBEDTLS_CIPHER_MODE_OFB)
239 aes_crypt_ofb_wrap,
240#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200241#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000242 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100243#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100244#if defined(MBEDTLS_CIPHER_MODE_XTS)
245 NULL,
246#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200248 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100249#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000250 aes_setkey_enc_wrap,
251 aes_setkey_dec_wrap,
252 aes_ctx_alloc,
253 aes_ctx_free
254};
255
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256static const mbedtls_cipher_info_t aes_128_ecb_info = {
257 MBEDTLS_CIPHER_AES_128_ECB,
258 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200259 128,
260 "AES-128-ECB",
261 16,
262 0,
263 16,
264 &aes_info
265};
266
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200267static const mbedtls_cipher_info_t aes_192_ecb_info = {
268 MBEDTLS_CIPHER_AES_192_ECB,
269 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200270 192,
271 "AES-192-ECB",
272 16,
273 0,
274 16,
275 &aes_info
276};
277
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200278static const mbedtls_cipher_info_t aes_256_ecb_info = {
279 MBEDTLS_CIPHER_AES_256_ECB,
280 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200281 256,
282 "AES-256-ECB",
283 16,
284 0,
285 16,
286 &aes_info
287};
288
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200289#if defined(MBEDTLS_CIPHER_MODE_CBC)
290static const mbedtls_cipher_info_t aes_128_cbc_info = {
291 MBEDTLS_CIPHER_AES_128_CBC,
292 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000293 128,
294 "AES-128-CBC",
295 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200296 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000297 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000298 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000299};
300
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200301static const mbedtls_cipher_info_t aes_192_cbc_info = {
302 MBEDTLS_CIPHER_AES_192_CBC,
303 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000304 192,
305 "AES-192-CBC",
306 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200307 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000308 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000309 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000310};
311
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312static const mbedtls_cipher_info_t aes_256_cbc_info = {
313 MBEDTLS_CIPHER_AES_256_CBC,
314 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000315 256,
316 "AES-256-CBC",
317 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200318 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000319 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000320 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000321};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200322#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000323
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324#if defined(MBEDTLS_CIPHER_MODE_CFB)
325static const mbedtls_cipher_info_t aes_128_cfb128_info = {
326 MBEDTLS_CIPHER_AES_128_CFB128,
327 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000328 128,
329 "AES-128-CFB128",
330 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200331 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000332 16,
333 &aes_info
334};
335
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200336static const mbedtls_cipher_info_t aes_192_cfb128_info = {
337 MBEDTLS_CIPHER_AES_192_CFB128,
338 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000339 192,
340 "AES-192-CFB128",
341 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200342 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 16,
344 &aes_info
345};
346
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347static const mbedtls_cipher_info_t aes_256_cfb128_info = {
348 MBEDTLS_CIPHER_AES_256_CFB128,
349 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000350 256,
351 "AES-256-CFB128",
352 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200353 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000354 16,
355 &aes_info
356};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200357#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000358
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100359#if defined(MBEDTLS_CIPHER_MODE_OFB)
360static const mbedtls_cipher_info_t aes_128_ofb_info = {
361 MBEDTLS_CIPHER_AES_128_OFB,
362 MBEDTLS_MODE_OFB,
363 128,
364 "AES-128-OFB",
365 16,
366 0,
367 16,
368 &aes_info
369};
370
371static const mbedtls_cipher_info_t aes_192_ofb_info = {
372 MBEDTLS_CIPHER_AES_192_OFB,
373 MBEDTLS_MODE_OFB,
374 192,
375 "AES-192-OFB",
376 16,
377 0,
378 16,
379 &aes_info
380};
381
382static const mbedtls_cipher_info_t aes_256_ofb_info = {
383 MBEDTLS_CIPHER_AES_256_OFB,
384 MBEDTLS_MODE_OFB,
385 256,
386 "AES-256-OFB",
387 16,
388 0,
389 16,
390 &aes_info
391};
392#endif /* MBEDTLS_CIPHER_MODE_OFB */
393
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200394#if defined(MBEDTLS_CIPHER_MODE_CTR)
395static const mbedtls_cipher_info_t aes_128_ctr_info = {
396 MBEDTLS_CIPHER_AES_128_CTR,
397 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000398 128,
399 "AES-128-CTR",
400 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200401 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000402 16,
403 &aes_info
404};
405
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200406static const mbedtls_cipher_info_t aes_192_ctr_info = {
407 MBEDTLS_CIPHER_AES_192_CTR,
408 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000409 192,
410 "AES-192-CTR",
411 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200412 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000413 16,
414 &aes_info
415};
416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200417static const mbedtls_cipher_info_t aes_256_ctr_info = {
418 MBEDTLS_CIPHER_AES_256_CTR,
419 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000420 256,
421 "AES-256-CTR",
422 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200423 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000424 16,
425 &aes_info
426};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200427#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000428
Jaeden Ameroc6539902018-04-30 17:17:41 +0100429#if defined(MBEDTLS_CIPHER_MODE_XTS)
430static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
431 unsigned int key_bitlen )
432{
433 mbedtls_aes_xts_context *xts_ctx = ctx;
434 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
435}
436
437static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
438 unsigned int key_bitlen )
439{
440 mbedtls_aes_xts_context *xts_ctx = ctx;
441 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
442}
443
444static void *xts_aes_ctx_alloc( void )
445{
446 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
447
448 if( xts_ctx != NULL )
449 mbedtls_aes_xts_init( xts_ctx );
450
451 return( xts_ctx );
452}
453
454static void xts_aes_ctx_free( void *ctx )
455{
456 mbedtls_aes_xts_context *xts_ctx = ctx;
457
458 if( xts_ctx == NULL )
459 return;
460
461 mbedtls_aes_xts_free( xts_ctx );
462 mbedtls_free( xts_ctx );
463}
464
465static const mbedtls_cipher_base_t xts_aes_info = {
466 MBEDTLS_CIPHER_ID_AES,
467 NULL,
468#if defined(MBEDTLS_CIPHER_MODE_CBC)
469 NULL,
470#endif
471#if defined(MBEDTLS_CIPHER_MODE_CFB)
472 NULL,
473#endif
474#if defined(MBEDTLS_CIPHER_MODE_OFB)
475 NULL,
476#endif
477#if defined(MBEDTLS_CIPHER_MODE_CTR)
478 NULL,
479#endif
480#if defined(MBEDTLS_CIPHER_MODE_XTS)
481 aes_crypt_xts_wrap,
482#endif
483#if defined(MBEDTLS_CIPHER_MODE_STREAM)
484 NULL,
485#endif
486 xts_aes_setkey_enc_wrap,
487 xts_aes_setkey_dec_wrap,
488 xts_aes_ctx_alloc,
489 xts_aes_ctx_free
490};
491
492static const mbedtls_cipher_info_t aes_128_xts_info = {
493 MBEDTLS_CIPHER_AES_128_XTS,
494 MBEDTLS_MODE_XTS,
495 256,
496 "AES-128-XTS",
497 16,
498 0,
499 16,
500 &xts_aes_info
501};
502
503static const mbedtls_cipher_info_t aes_256_xts_info = {
504 MBEDTLS_CIPHER_AES_256_XTS,
505 MBEDTLS_MODE_XTS,
506 512,
507 "AES-256-XTS",
508 16,
509 0,
510 16,
511 &xts_aes_info
512};
513#endif /* MBEDTLS_CIPHER_MODE_XTS */
514
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200515#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200516static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200517 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200518{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200519 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200520 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200521}
522
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200523static const mbedtls_cipher_base_t gcm_aes_info = {
524 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200525 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200526#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200527 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100528#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200529#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200530 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100531#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100532#if defined(MBEDTLS_CIPHER_MODE_OFB)
533 NULL,
534#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200535#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200536 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100537#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100538#if defined(MBEDTLS_CIPHER_MODE_XTS)
539 NULL,
540#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200541#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200542 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100543#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200544 gcm_aes_setkey_wrap,
545 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200546 gcm_ctx_alloc,
547 gcm_ctx_free,
548};
549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200550static const mbedtls_cipher_info_t aes_128_gcm_info = {
551 MBEDTLS_CIPHER_AES_128_GCM,
552 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100553 128,
554 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200555 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100557 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200558 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100559};
560
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200561static const mbedtls_cipher_info_t aes_192_gcm_info = {
562 MBEDTLS_CIPHER_AES_192_GCM,
563 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200564 192,
565 "AES-192-GCM",
566 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200567 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200568 16,
569 &gcm_aes_info
570};
571
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200572static const mbedtls_cipher_info_t aes_256_gcm_info = {
573 MBEDTLS_CIPHER_AES_256_GCM,
574 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100575 256,
576 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200577 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200578 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100579 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200580 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100581};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200582#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100583
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200584#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200585static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200586 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200587{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200588 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200589 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200590}
591
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200592static const mbedtls_cipher_base_t ccm_aes_info = {
593 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200594 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200596 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100597#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200599 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100600#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100601#if defined(MBEDTLS_CIPHER_MODE_OFB)
602 NULL,
603#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200604#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200605 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100606#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100607#if defined(MBEDTLS_CIPHER_MODE_XTS)
608 NULL,
609#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200611 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100612#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200613 ccm_aes_setkey_wrap,
614 ccm_aes_setkey_wrap,
615 ccm_ctx_alloc,
616 ccm_ctx_free,
617};
618
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200619static const mbedtls_cipher_info_t aes_128_ccm_info = {
620 MBEDTLS_CIPHER_AES_128_CCM,
621 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200622 128,
623 "AES-128-CCM",
624 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200625 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200626 16,
627 &ccm_aes_info
628};
629
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200630static const mbedtls_cipher_info_t aes_192_ccm_info = {
631 MBEDTLS_CIPHER_AES_192_CCM,
632 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200633 192,
634 "AES-192-CCM",
635 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200636 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200637 16,
638 &ccm_aes_info
639};
640
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200641static const mbedtls_cipher_info_t aes_256_ccm_info = {
642 MBEDTLS_CIPHER_AES_256_CCM,
643 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200644 256,
645 "AES-256-CCM",
646 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200647 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200648 16,
649 &ccm_aes_info
650};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200652
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200653#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000654
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200655#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200658 const unsigned char *input, unsigned char *output )
659{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200660 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200661 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200662}
663
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200664#if defined(MBEDTLS_CIPHER_MODE_CBC)
665static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200666 size_t length, unsigned char *iv,
667 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000668{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200669 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200670 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000671}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000673
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674#if defined(MBEDTLS_CIPHER_MODE_CFB)
675static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200676 size_t length, size_t *iv_off, unsigned char *iv,
677 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000678{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200679 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200680 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000681}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000683
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200684#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200685static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
686 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000687 const unsigned char *input, unsigned char *output )
688{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200689 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200690 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000691}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200692#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000693
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200694static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200695 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000696{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200697 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000698}
699
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200700static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200701 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000702{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200703 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000704}
705
706static void * camellia_ctx_alloc( void )
707{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200708 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200709 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200710
711 if( ctx == NULL )
712 return( NULL );
713
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200714 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200715
716 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000717}
718
719static void camellia_ctx_free( void *ctx )
720{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200721 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
722 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000723}
724
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725static const mbedtls_cipher_base_t camellia_info = {
726 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200727 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200728#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000729 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100730#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200731#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000732 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100733#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100734#if defined(MBEDTLS_CIPHER_MODE_OFB)
735 NULL,
736#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200737#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000738 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100739#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100740#if defined(MBEDTLS_CIPHER_MODE_XTS)
741 NULL,
742#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200743#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200744 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100745#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000746 camellia_setkey_enc_wrap,
747 camellia_setkey_dec_wrap,
748 camellia_ctx_alloc,
749 camellia_ctx_free
750};
751
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200752static const mbedtls_cipher_info_t camellia_128_ecb_info = {
753 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
754 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200755 128,
756 "CAMELLIA-128-ECB",
757 16,
758 0,
759 16,
760 &camellia_info
761};
762
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200763static const mbedtls_cipher_info_t camellia_192_ecb_info = {
764 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
765 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200766 192,
767 "CAMELLIA-192-ECB",
768 16,
769 0,
770 16,
771 &camellia_info
772};
773
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200774static const mbedtls_cipher_info_t camellia_256_ecb_info = {
775 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
776 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200777 256,
778 "CAMELLIA-256-ECB",
779 16,
780 0,
781 16,
782 &camellia_info
783};
784
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200785#if defined(MBEDTLS_CIPHER_MODE_CBC)
786static const mbedtls_cipher_info_t camellia_128_cbc_info = {
787 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
788 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000789 128,
790 "CAMELLIA-128-CBC",
791 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200792 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000793 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000794 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000795};
796
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200797static const mbedtls_cipher_info_t camellia_192_cbc_info = {
798 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
799 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000800 192,
801 "CAMELLIA-192-CBC",
802 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200803 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000804 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000805 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000806};
807
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200808static const mbedtls_cipher_info_t camellia_256_cbc_info = {
809 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
810 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000811 256,
812 "CAMELLIA-256-CBC",
813 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200814 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000815 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000816 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000817};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200818#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000819
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200820#if defined(MBEDTLS_CIPHER_MODE_CFB)
821static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
822 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
823 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000824 128,
825 "CAMELLIA-128-CFB128",
826 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200827 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000828 16,
829 &camellia_info
830};
831
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200832static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
833 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
834 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000835 192,
836 "CAMELLIA-192-CFB128",
837 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200838 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000839 16,
840 &camellia_info
841};
842
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200843static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
844 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
845 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000846 256,
847 "CAMELLIA-256-CFB128",
848 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200849 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000850 16,
851 &camellia_info
852};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200853#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855#if defined(MBEDTLS_CIPHER_MODE_CTR)
856static const mbedtls_cipher_info_t camellia_128_ctr_info = {
857 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
858 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000859 128,
860 "CAMELLIA-128-CTR",
861 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200862 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000863 16,
864 &camellia_info
865};
866
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200867static const mbedtls_cipher_info_t camellia_192_ctr_info = {
868 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
869 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000870 192,
871 "CAMELLIA-192-CTR",
872 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200873 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000874 16,
875 &camellia_info
876};
877
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200878static const mbedtls_cipher_info_t camellia_256_ctr_info = {
879 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
880 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000881 256,
882 "CAMELLIA-256-CTR",
883 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200884 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000885 16,
886 &camellia_info
887};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200888#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000889
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200890#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200891static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200892 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200893{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200894 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200895 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200896}
897
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200898static const mbedtls_cipher_base_t gcm_camellia_info = {
899 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200900 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200901#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200902 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100903#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200904#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200905 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100906#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100907#if defined(MBEDTLS_CIPHER_MODE_OFB)
908 NULL,
909#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200910#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200911 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100912#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100913#if defined(MBEDTLS_CIPHER_MODE_XTS)
914 NULL,
915#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200916#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200917 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100918#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200919 gcm_camellia_setkey_wrap,
920 gcm_camellia_setkey_wrap,
921 gcm_ctx_alloc,
922 gcm_ctx_free,
923};
924
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200925static const mbedtls_cipher_info_t camellia_128_gcm_info = {
926 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
927 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200928 128,
929 "CAMELLIA-128-GCM",
930 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200931 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200932 16,
933 &gcm_camellia_info
934};
935
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200936static const mbedtls_cipher_info_t camellia_192_gcm_info = {
937 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
938 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200939 192,
940 "CAMELLIA-192-GCM",
941 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200942 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200943 16,
944 &gcm_camellia_info
945};
946
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947static const mbedtls_cipher_info_t camellia_256_gcm_info = {
948 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
949 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200950 256,
951 "CAMELLIA-256-GCM",
952 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200953 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200954 16,
955 &gcm_camellia_info
956};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200957#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200958
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200959#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200960static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200961 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200962{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200963 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200964 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200965}
966
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200967static const mbedtls_cipher_base_t ccm_camellia_info = {
968 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200969 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200970#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200971 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100972#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200973#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200974 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100975#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100976#if defined(MBEDTLS_CIPHER_MODE_OFB)
977 NULL,
978#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200979#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200980 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100981#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100982#if defined(MBEDTLS_CIPHER_MODE_XTS)
983 NULL,
984#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200985#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200986 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100987#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200988 ccm_camellia_setkey_wrap,
989 ccm_camellia_setkey_wrap,
990 ccm_ctx_alloc,
991 ccm_ctx_free,
992};
993
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200994static const mbedtls_cipher_info_t camellia_128_ccm_info = {
995 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
996 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200997 128,
998 "CAMELLIA-128-CCM",
999 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001000 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001001 16,
1002 &ccm_camellia_info
1003};
1004
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001005static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1006 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1007 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001008 192,
1009 "CAMELLIA-192-CCM",
1010 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001011 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001012 16,
1013 &ccm_camellia_info
1014};
1015
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001016static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1017 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1018 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001019 256,
1020 "CAMELLIA-256-CCM",
1021 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001022 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001023 16,
1024 &ccm_camellia_info
1025};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001026#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001028#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001029
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001030#if defined(MBEDTLS_ARIA_C)
1031
1032static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1033 const unsigned char *input, unsigned char *output )
1034{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001035 (void) operation;
1036 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001037 output );
1038}
1039
1040#if defined(MBEDTLS_CIPHER_MODE_CBC)
1041static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1042 size_t length, unsigned char *iv,
1043 const unsigned char *input, unsigned char *output )
1044{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001045 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001046 input, output );
1047}
1048#endif /* MBEDTLS_CIPHER_MODE_CBC */
1049
1050#if defined(MBEDTLS_CIPHER_MODE_CFB)
1051static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1052 size_t length, size_t *iv_off, unsigned char *iv,
1053 const unsigned char *input, unsigned char *output )
1054{
1055 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1056 iv_off, iv, input, output );
1057}
1058#endif /* MBEDTLS_CIPHER_MODE_CFB */
1059
1060#if defined(MBEDTLS_CIPHER_MODE_CTR)
1061static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1062 unsigned char *nonce_counter, unsigned char *stream_block,
1063 const unsigned char *input, unsigned char *output )
1064{
1065 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1066 nonce_counter, stream_block, input, output );
1067}
1068#endif /* MBEDTLS_CIPHER_MODE_CTR */
1069
1070static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1071 unsigned int key_bitlen )
1072{
1073 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1074}
1075
1076static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1077 unsigned int key_bitlen )
1078{
1079 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1080}
1081
1082static void * aria_ctx_alloc( void )
1083{
1084 mbedtls_aria_context *ctx;
1085 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1086
1087 if( ctx == NULL )
1088 return( NULL );
1089
1090 mbedtls_aria_init( ctx );
1091
1092 return( ctx );
1093}
1094
1095static void aria_ctx_free( void *ctx )
1096{
1097 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1098 mbedtls_free( ctx );
1099}
1100
1101static const mbedtls_cipher_base_t aria_info = {
1102 MBEDTLS_CIPHER_ID_ARIA,
1103 aria_crypt_ecb_wrap,
1104#if defined(MBEDTLS_CIPHER_MODE_CBC)
1105 aria_crypt_cbc_wrap,
1106#endif
1107#if defined(MBEDTLS_CIPHER_MODE_CFB)
1108 aria_crypt_cfb128_wrap,
1109#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001110#if defined(MBEDTLS_CIPHER_MODE_OFB)
1111 NULL,
1112#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001113#if defined(MBEDTLS_CIPHER_MODE_CTR)
1114 aria_crypt_ctr_wrap,
1115#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001116#if defined(MBEDTLS_CIPHER_MODE_XTS)
1117 NULL,
1118#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001119#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1120 NULL,
1121#endif
1122 aria_setkey_enc_wrap,
1123 aria_setkey_dec_wrap,
1124 aria_ctx_alloc,
1125 aria_ctx_free
1126};
1127
1128static const mbedtls_cipher_info_t aria_128_ecb_info = {
1129 MBEDTLS_CIPHER_ARIA_128_ECB,
1130 MBEDTLS_MODE_ECB,
1131 128,
1132 "ARIA-128-ECB",
1133 16,
1134 0,
1135 16,
1136 &aria_info
1137};
1138
1139static const mbedtls_cipher_info_t aria_192_ecb_info = {
1140 MBEDTLS_CIPHER_ARIA_192_ECB,
1141 MBEDTLS_MODE_ECB,
1142 192,
1143 "ARIA-192-ECB",
1144 16,
1145 0,
1146 16,
1147 &aria_info
1148};
1149
1150static const mbedtls_cipher_info_t aria_256_ecb_info = {
1151 MBEDTLS_CIPHER_ARIA_256_ECB,
1152 MBEDTLS_MODE_ECB,
1153 256,
1154 "ARIA-256-ECB",
1155 16,
1156 0,
1157 16,
1158 &aria_info
1159};
1160
1161#if defined(MBEDTLS_CIPHER_MODE_CBC)
1162static const mbedtls_cipher_info_t aria_128_cbc_info = {
1163 MBEDTLS_CIPHER_ARIA_128_CBC,
1164 MBEDTLS_MODE_CBC,
1165 128,
1166 "ARIA-128-CBC",
1167 16,
1168 0,
1169 16,
1170 &aria_info
1171};
1172
1173static const mbedtls_cipher_info_t aria_192_cbc_info = {
1174 MBEDTLS_CIPHER_ARIA_192_CBC,
1175 MBEDTLS_MODE_CBC,
1176 192,
1177 "ARIA-192-CBC",
1178 16,
1179 0,
1180 16,
1181 &aria_info
1182};
1183
1184static const mbedtls_cipher_info_t aria_256_cbc_info = {
1185 MBEDTLS_CIPHER_ARIA_256_CBC,
1186 MBEDTLS_MODE_CBC,
1187 256,
1188 "ARIA-256-CBC",
1189 16,
1190 0,
1191 16,
1192 &aria_info
1193};
1194#endif /* MBEDTLS_CIPHER_MODE_CBC */
1195
1196#if defined(MBEDTLS_CIPHER_MODE_CFB)
1197static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1198 MBEDTLS_CIPHER_ARIA_128_CFB128,
1199 MBEDTLS_MODE_CFB,
1200 128,
1201 "ARIA-128-CFB128",
1202 16,
1203 0,
1204 16,
1205 &aria_info
1206};
1207
1208static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1209 MBEDTLS_CIPHER_ARIA_192_CFB128,
1210 MBEDTLS_MODE_CFB,
1211 192,
1212 "ARIA-192-CFB128",
1213 16,
1214 0,
1215 16,
1216 &aria_info
1217};
1218
1219static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1220 MBEDTLS_CIPHER_ARIA_256_CFB128,
1221 MBEDTLS_MODE_CFB,
1222 256,
1223 "ARIA-256-CFB128",
1224 16,
1225 0,
1226 16,
1227 &aria_info
1228};
1229#endif /* MBEDTLS_CIPHER_MODE_CFB */
1230
1231#if defined(MBEDTLS_CIPHER_MODE_CTR)
1232static const mbedtls_cipher_info_t aria_128_ctr_info = {
1233 MBEDTLS_CIPHER_ARIA_128_CTR,
1234 MBEDTLS_MODE_CTR,
1235 128,
1236 "ARIA-128-CTR",
1237 16,
1238 0,
1239 16,
1240 &aria_info
1241};
1242
1243static const mbedtls_cipher_info_t aria_192_ctr_info = {
1244 MBEDTLS_CIPHER_ARIA_192_CTR,
1245 MBEDTLS_MODE_CTR,
1246 192,
1247 "ARIA-192-CTR",
1248 16,
1249 0,
1250 16,
1251 &aria_info
1252};
1253
1254static const mbedtls_cipher_info_t aria_256_ctr_info = {
1255 MBEDTLS_CIPHER_ARIA_256_CTR,
1256 MBEDTLS_MODE_CTR,
1257 256,
1258 "ARIA-256-CTR",
1259 16,
1260 0,
1261 16,
1262 &aria_info
1263};
1264#endif /* MBEDTLS_CIPHER_MODE_CTR */
1265
1266#if defined(MBEDTLS_GCM_C)
1267static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1268 unsigned int key_bitlen )
1269{
1270 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1271 key, key_bitlen );
1272}
1273
1274static const mbedtls_cipher_base_t gcm_aria_info = {
1275 MBEDTLS_CIPHER_ID_ARIA,
1276 NULL,
1277#if defined(MBEDTLS_CIPHER_MODE_CBC)
1278 NULL,
1279#endif
1280#if defined(MBEDTLS_CIPHER_MODE_CFB)
1281 NULL,
1282#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001283#if defined(MBEDTLS_CIPHER_MODE_OFB)
1284 NULL,
1285#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001286#if defined(MBEDTLS_CIPHER_MODE_CTR)
1287 NULL,
1288#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001289#if defined(MBEDTLS_CIPHER_MODE_XTS)
1290 NULL,
1291#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001292#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1293 NULL,
1294#endif
1295 gcm_aria_setkey_wrap,
1296 gcm_aria_setkey_wrap,
1297 gcm_ctx_alloc,
1298 gcm_ctx_free,
1299};
1300
1301static const mbedtls_cipher_info_t aria_128_gcm_info = {
1302 MBEDTLS_CIPHER_ARIA_128_GCM,
1303 MBEDTLS_MODE_GCM,
1304 128,
1305 "ARIA-128-GCM",
1306 12,
1307 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1308 16,
1309 &gcm_aria_info
1310};
1311
1312static const mbedtls_cipher_info_t aria_192_gcm_info = {
1313 MBEDTLS_CIPHER_ARIA_192_GCM,
1314 MBEDTLS_MODE_GCM,
1315 192,
1316 "ARIA-192-GCM",
1317 12,
1318 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1319 16,
1320 &gcm_aria_info
1321};
1322
1323static const mbedtls_cipher_info_t aria_256_gcm_info = {
1324 MBEDTLS_CIPHER_ARIA_256_GCM,
1325 MBEDTLS_MODE_GCM,
1326 256,
1327 "ARIA-256-GCM",
1328 12,
1329 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1330 16,
1331 &gcm_aria_info
1332};
1333#endif /* MBEDTLS_GCM_C */
1334
1335#if defined(MBEDTLS_CCM_C)
1336static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1337 unsigned int key_bitlen )
1338{
1339 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1340 key, key_bitlen );
1341}
1342
1343static const mbedtls_cipher_base_t ccm_aria_info = {
1344 MBEDTLS_CIPHER_ID_ARIA,
1345 NULL,
1346#if defined(MBEDTLS_CIPHER_MODE_CBC)
1347 NULL,
1348#endif
1349#if defined(MBEDTLS_CIPHER_MODE_CFB)
1350 NULL,
1351#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001352#if defined(MBEDTLS_CIPHER_MODE_OFB)
1353 NULL,
1354#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001355#if defined(MBEDTLS_CIPHER_MODE_CTR)
1356 NULL,
1357#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001358#if defined(MBEDTLS_CIPHER_MODE_XTS)
1359 NULL,
1360#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001361#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1362 NULL,
1363#endif
1364 ccm_aria_setkey_wrap,
1365 ccm_aria_setkey_wrap,
1366 ccm_ctx_alloc,
1367 ccm_ctx_free,
1368};
1369
1370static const mbedtls_cipher_info_t aria_128_ccm_info = {
1371 MBEDTLS_CIPHER_ARIA_128_CCM,
1372 MBEDTLS_MODE_CCM,
1373 128,
1374 "ARIA-128-CCM",
1375 12,
1376 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1377 16,
1378 &ccm_aria_info
1379};
1380
1381static const mbedtls_cipher_info_t aria_192_ccm_info = {
1382 MBEDTLS_CIPHER_ARIA_192_CCM,
1383 MBEDTLS_MODE_CCM,
1384 192,
1385 "ARIA-192-CCM",
1386 12,
1387 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1388 16,
1389 &ccm_aria_info
1390};
1391
1392static const mbedtls_cipher_info_t aria_256_ccm_info = {
1393 MBEDTLS_CIPHER_ARIA_256_CCM,
1394 MBEDTLS_MODE_CCM,
1395 256,
1396 "ARIA-256-CCM",
1397 12,
1398 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1399 16,
1400 &ccm_aria_info
1401};
1402#endif /* MBEDTLS_CCM_C */
1403
1404#endif /* MBEDTLS_ARIA_C */
1405
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001406#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001407
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001408static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001409 const unsigned char *input, unsigned char *output )
1410{
1411 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001412 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001413}
1414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001415static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001416 const unsigned char *input, unsigned char *output )
1417{
1418 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001419 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001420}
1421
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001422#if defined(MBEDTLS_CIPHER_MODE_CBC)
1423static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001424 unsigned char *iv, const unsigned char *input, unsigned char *output )
1425{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001426 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001427 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001428}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001429#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001430
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001431#if defined(MBEDTLS_CIPHER_MODE_CBC)
1432static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001433 unsigned char *iv, const unsigned char *input, unsigned char *output )
1434{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001435 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001436 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001437}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001438#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001439
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001440static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001441 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001442{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001443 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001444
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001445 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001446}
1447
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001448static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001449 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001450{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001451 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001452
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001453 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001454}
1455
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001456static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001457 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001458{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001459 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001460
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001461 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001462}
1463
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001464static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001465 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001466{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001467 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001468
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001469 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001470}
1471
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001472static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001473 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001474{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001475 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001476
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001477 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001478}
1479
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001480static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001481 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001482{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001483 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001484
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001485 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001486}
1487
1488static void * des_ctx_alloc( void )
1489{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001490 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001491
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001492 if( des == NULL )
1493 return( NULL );
1494
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001495 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001496
1497 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001498}
1499
1500static void des_ctx_free( void *ctx )
1501{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001502 mbedtls_des_free( (mbedtls_des_context *) ctx );
1503 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001504}
1505
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001506static void * des3_ctx_alloc( void )
1507{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001508 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001509 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001510
1511 if( des3 == NULL )
1512 return( NULL );
1513
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001514 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001515
1516 return( des3 );
1517}
1518
Paul Bakker34617722014-06-13 17:20:13 +02001519static void des3_ctx_free( void *ctx )
1520{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001521 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1522 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001523}
1524
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001525static const mbedtls_cipher_base_t des_info = {
1526 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001527 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001528#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001529 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001530#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001531#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001532 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001533#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001534#if defined(MBEDTLS_CIPHER_MODE_OFB)
1535 NULL,
1536#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001537#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001538 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001539#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001540#if defined(MBEDTLS_CIPHER_MODE_XTS)
1541 NULL,
1542#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001543#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001544 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001545#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001546 des_setkey_enc_wrap,
1547 des_setkey_dec_wrap,
1548 des_ctx_alloc,
1549 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001550};
1551
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001552static const mbedtls_cipher_info_t des_ecb_info = {
1553 MBEDTLS_CIPHER_DES_ECB,
1554 MBEDTLS_MODE_ECB,
1555 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001556 "DES-ECB",
1557 8,
1558 0,
1559 8,
1560 &des_info
1561};
1562
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001563#if defined(MBEDTLS_CIPHER_MODE_CBC)
1564static const mbedtls_cipher_info_t des_cbc_info = {
1565 MBEDTLS_CIPHER_DES_CBC,
1566 MBEDTLS_MODE_CBC,
1567 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001568 "DES-CBC",
1569 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001570 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001571 8,
1572 &des_info
1573};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001574#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001575
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001576static const mbedtls_cipher_base_t des_ede_info = {
1577 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001578 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001579#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001580 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001581#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001582#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001583 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001584#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001585#if defined(MBEDTLS_CIPHER_MODE_OFB)
1586 NULL,
1587#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001588#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001589 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001590#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001591#if defined(MBEDTLS_CIPHER_MODE_XTS)
1592 NULL,
1593#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001594#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001595 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001596#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001597 des3_set2key_enc_wrap,
1598 des3_set2key_dec_wrap,
1599 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001600 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001601};
1602
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001603static const mbedtls_cipher_info_t des_ede_ecb_info = {
1604 MBEDTLS_CIPHER_DES_EDE_ECB,
1605 MBEDTLS_MODE_ECB,
1606 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001607 "DES-EDE-ECB",
1608 8,
1609 0,
1610 8,
1611 &des_ede_info
1612};
1613
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001614#if defined(MBEDTLS_CIPHER_MODE_CBC)
1615static const mbedtls_cipher_info_t des_ede_cbc_info = {
1616 MBEDTLS_CIPHER_DES_EDE_CBC,
1617 MBEDTLS_MODE_CBC,
1618 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001619 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001620 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001621 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001622 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001623 &des_ede_info
1624};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001625#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001626
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001627static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001628 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001629 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001630#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001631 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001632#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001633#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001634 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001635#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001636#if defined(MBEDTLS_CIPHER_MODE_OFB)
1637 NULL,
1638#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001639#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001640 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001641#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001642#if defined(MBEDTLS_CIPHER_MODE_XTS)
1643 NULL,
1644#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001645#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001646 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001647#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001648 des3_set3key_enc_wrap,
1649 des3_set3key_dec_wrap,
1650 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001651 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001652};
1653
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001654static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1655 MBEDTLS_CIPHER_DES_EDE3_ECB,
1656 MBEDTLS_MODE_ECB,
1657 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001658 "DES-EDE3-ECB",
1659 8,
1660 0,
1661 8,
1662 &des_ede3_info
1663};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001664#if defined(MBEDTLS_CIPHER_MODE_CBC)
1665static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1666 MBEDTLS_CIPHER_DES_EDE3_CBC,
1667 MBEDTLS_MODE_CBC,
1668 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001669 "DES-EDE3-CBC",
1670 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001671 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001672 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001673 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001674};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001675#endif /* MBEDTLS_CIPHER_MODE_CBC */
1676#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001678#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001679
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001680static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001681 const unsigned char *input, unsigned char *output )
1682{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001683 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001684 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001685}
1686
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001687#if defined(MBEDTLS_CIPHER_MODE_CBC)
1688static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001689 size_t length, unsigned char *iv, const unsigned char *input,
1690 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001691{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001692 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001693 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001694}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001695#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001696
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001697#if defined(MBEDTLS_CIPHER_MODE_CFB)
1698static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001699 size_t length, size_t *iv_off, unsigned char *iv,
1700 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001701{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001702 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001703 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001704}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001705#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001706
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001707#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001708static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1709 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001710 const unsigned char *input, unsigned char *output )
1711{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001712 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001713 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001714}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001715#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001716
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001717static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001718 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001719{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001720 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001721}
1722
1723static void * blowfish_ctx_alloc( void )
1724{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001725 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001726 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001727
1728 if( ctx == NULL )
1729 return( NULL );
1730
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001731 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001732
1733 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001734}
1735
1736static void blowfish_ctx_free( void *ctx )
1737{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001738 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1739 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001740}
1741
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001742static const mbedtls_cipher_base_t blowfish_info = {
1743 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001744 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001745#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001746 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001747#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001748#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001749 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001750#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001751#if defined(MBEDTLS_CIPHER_MODE_OFB)
1752 NULL,
1753#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001754#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001755 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001756#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001757#if defined(MBEDTLS_CIPHER_MODE_XTS)
1758 NULL,
1759#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001760#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001761 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001762#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001763 blowfish_setkey_wrap,
1764 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001765 blowfish_ctx_alloc,
1766 blowfish_ctx_free
1767};
1768
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001769static const mbedtls_cipher_info_t blowfish_ecb_info = {
1770 MBEDTLS_CIPHER_BLOWFISH_ECB,
1771 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001772 128,
1773 "BLOWFISH-ECB",
1774 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001775 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001776 8,
1777 &blowfish_info
1778};
1779
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001780#if defined(MBEDTLS_CIPHER_MODE_CBC)
1781static const mbedtls_cipher_info_t blowfish_cbc_info = {
1782 MBEDTLS_CIPHER_BLOWFISH_CBC,
1783 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001784 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001785 "BLOWFISH-CBC",
1786 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001787 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001788 8,
1789 &blowfish_info
1790};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001791#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001792
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001793#if defined(MBEDTLS_CIPHER_MODE_CFB)
1794static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1795 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1796 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001797 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001798 "BLOWFISH-CFB64",
1799 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001800 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001801 8,
1802 &blowfish_info
1803};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001804#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001805
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001806#if defined(MBEDTLS_CIPHER_MODE_CTR)
1807static const mbedtls_cipher_info_t blowfish_ctr_info = {
1808 MBEDTLS_CIPHER_BLOWFISH_CTR,
1809 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001810 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001811 "BLOWFISH-CTR",
1812 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001813 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001814 8,
1815 &blowfish_info
1816};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001817#endif /* MBEDTLS_CIPHER_MODE_CTR */
1818#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001819
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001820#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001821static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1822 const unsigned char *input,
1823 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001824{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001825 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001826}
1827
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001828static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001829 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001830{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001831 /* we get key_bitlen in bits, arc4 expects it in bytes */
1832 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001834
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001835 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001836 return( 0 );
1837}
1838
1839static void * arc4_ctx_alloc( void )
1840{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001841 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001842 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001843
1844 if( ctx == NULL )
1845 return( NULL );
1846
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001847 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001848
1849 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001850}
Paul Bakker68884e32013-01-07 18:20:04 +01001851
1852static void arc4_ctx_free( void *ctx )
1853{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001854 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1855 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001856}
1857
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001858static const mbedtls_cipher_base_t arc4_base_info = {
1859 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001860 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001861#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001862 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001863#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001864#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001865 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001866#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001867#if defined(MBEDTLS_CIPHER_MODE_OFB)
1868 NULL,
1869#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001870#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001871 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001872#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001873#if defined(MBEDTLS_CIPHER_MODE_XTS)
1874 NULL,
1875#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001876#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001877 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001878#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001879 arc4_setkey_wrap,
1880 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001881 arc4_ctx_alloc,
1882 arc4_ctx_free
1883};
1884
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001885static const mbedtls_cipher_info_t arc4_128_info = {
1886 MBEDTLS_CIPHER_ARC4_128,
1887 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001888 128,
1889 "ARC4-128",
1890 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001891 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001892 1,
1893 &arc4_base_info
1894};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001895#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001896
Daniel Kingbd920622016-05-15 19:56:20 -03001897#if defined(MBEDTLS_CHACHA20_C)
1898
1899static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1900 unsigned int key_bitlen )
1901{
1902 if( key_bitlen != 256U )
1903 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1904
1905 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1906 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1907
1908 return( 0 );
1909}
1910
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001911static int chacha20_stream_wrap( void *ctx, size_t length,
1912 const unsigned char *input,
1913 unsigned char *output )
1914{
1915 int ret;
1916
1917 ret = mbedtls_chacha20_update( ctx, length, input, output );
1918 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1919 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1920
1921 return( ret );
1922}
1923
Daniel Kingbd920622016-05-15 19:56:20 -03001924static void * chacha20_ctx_alloc( void )
1925{
1926 mbedtls_chacha20_context *ctx;
1927 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1928
1929 if( ctx == NULL )
1930 return( NULL );
1931
1932 mbedtls_chacha20_init( ctx );
1933
1934 return( ctx );
1935}
1936
1937static void chacha20_ctx_free( void *ctx )
1938{
1939 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1940 mbedtls_free( ctx );
1941}
1942
1943static const mbedtls_cipher_base_t chacha20_base_info = {
1944 MBEDTLS_CIPHER_ID_CHACHA20,
1945 NULL,
1946#if defined(MBEDTLS_CIPHER_MODE_CBC)
1947 NULL,
1948#endif
1949#if defined(MBEDTLS_CIPHER_MODE_CFB)
1950 NULL,
1951#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001952#if defined(MBEDTLS_CIPHER_MODE_OFB)
1953 NULL,
1954#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001955#if defined(MBEDTLS_CIPHER_MODE_CTR)
1956 NULL,
1957#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001958#if defined(MBEDTLS_CIPHER_MODE_XTS)
1959 NULL,
1960#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001961#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001962 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001963#endif
1964 chacha20_setkey_wrap,
1965 chacha20_setkey_wrap,
1966 chacha20_ctx_alloc,
1967 chacha20_ctx_free
1968};
1969static const mbedtls_cipher_info_t chacha20_info = {
1970 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001971 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001972 256,
1973 "CHACHA20",
1974 12,
1975 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001976 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001977 &chacha20_base_info
1978};
1979#endif /* MBEDTLS_CHACHA20_C */
1980
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001981#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001982
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001983static int chachapoly_setkey_wrap( void *ctx,
1984 const unsigned char *key,
1985 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001986{
1987 if( key_bitlen != 256U )
1988 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1989
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001990 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001991 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1992
1993 return( 0 );
1994}
1995
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001996static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03001997{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001998 mbedtls_chachapoly_context *ctx;
1999 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03002000
2001 if( ctx == NULL )
2002 return( NULL );
2003
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002004 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002005
2006 return( ctx );
2007}
2008
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002009static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002010{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002011 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002012 mbedtls_free( ctx );
2013}
2014
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002015static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002016 MBEDTLS_CIPHER_ID_CHACHA20,
2017 NULL,
2018#if defined(MBEDTLS_CIPHER_MODE_CBC)
2019 NULL,
2020#endif
2021#if defined(MBEDTLS_CIPHER_MODE_CFB)
2022 NULL,
2023#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002024#if defined(MBEDTLS_CIPHER_MODE_OFB)
2025 NULL,
2026#endif
Daniel King8fe47012016-05-17 20:33:28 -03002027#if defined(MBEDTLS_CIPHER_MODE_CTR)
2028 NULL,
2029#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002030#if defined(MBEDTLS_CIPHER_MODE_XTS)
2031 NULL,
2032#endif
Daniel King8fe47012016-05-17 20:33:28 -03002033#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2034 NULL,
2035#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002036 chachapoly_setkey_wrap,
2037 chachapoly_setkey_wrap,
2038 chachapoly_ctx_alloc,
2039 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002040};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002041static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002042 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002043 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002044 256,
2045 "CHACHA20-POLY1305",
2046 12,
2047 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002048 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002049 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002050};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002051#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002053#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002054static int null_crypt_stream( void *ctx, size_t length,
2055 const unsigned char *input,
2056 unsigned char *output )
2057{
2058 ((void) ctx);
2059 memmove( output, input, length );
2060 return( 0 );
2061}
2062
2063static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002064 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002065{
2066 ((void) ctx);
2067 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002068 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002069
2070 return( 0 );
2071}
2072
Paul Bakkerfab5c822012-02-06 16:45:10 +00002073static void * null_ctx_alloc( void )
2074{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002075 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002076}
2077
Paul Bakkerfab5c822012-02-06 16:45:10 +00002078static void null_ctx_free( void *ctx )
2079{
2080 ((void) ctx);
2081}
2082
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002083static const mbedtls_cipher_base_t null_base_info = {
2084 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002085 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002086#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002087 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002088#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002089#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002090 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002091#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002092#if defined(MBEDTLS_CIPHER_MODE_OFB)
2093 NULL,
2094#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002095#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002096 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002097#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002098#if defined(MBEDTLS_CIPHER_MODE_XTS)
2099 NULL,
2100#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002101#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002102 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002103#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002104 null_setkey,
2105 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002106 null_ctx_alloc,
2107 null_ctx_free
2108};
2109
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002110static const mbedtls_cipher_info_t null_cipher_info = {
2111 MBEDTLS_CIPHER_NULL,
2112 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002113 0,
2114 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002115 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002116 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002117 1,
2118 &null_base_info
2119};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002120#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002121
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002122const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002123{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002124#if defined(MBEDTLS_AES_C)
2125 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2126 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2127 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2128#if defined(MBEDTLS_CIPHER_MODE_CBC)
2129 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2130 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2131 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002132#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002133#if defined(MBEDTLS_CIPHER_MODE_CFB)
2134 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2135 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2136 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002137#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002138#if defined(MBEDTLS_CIPHER_MODE_OFB)
2139 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2140 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2141 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2142#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002143#if defined(MBEDTLS_CIPHER_MODE_CTR)
2144 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2145 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2146 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002147#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002148#if defined(MBEDTLS_CIPHER_MODE_XTS)
2149 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2150 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2151#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002152#if defined(MBEDTLS_GCM_C)
2153 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2154 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2155 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002156#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002157#if defined(MBEDTLS_CCM_C)
2158 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2159 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2160 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002161#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002162#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002163
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002164#if defined(MBEDTLS_ARC4_C)
2165 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002166#endif
2167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002168#if defined(MBEDTLS_BLOWFISH_C)
2169 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2170#if defined(MBEDTLS_CIPHER_MODE_CBC)
2171 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002172#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002173#if defined(MBEDTLS_CIPHER_MODE_CFB)
2174 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002175#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002176#if defined(MBEDTLS_CIPHER_MODE_CTR)
2177 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002178#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002179#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002180
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002181#if defined(MBEDTLS_CAMELLIA_C)
2182 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2183 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2184 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2185#if defined(MBEDTLS_CIPHER_MODE_CBC)
2186 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2187 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2188 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002189#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002190#if defined(MBEDTLS_CIPHER_MODE_CFB)
2191 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2192 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2193 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002194#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002195#if defined(MBEDTLS_CIPHER_MODE_CTR)
2196 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2197 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2198 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002199#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002200#if defined(MBEDTLS_GCM_C)
2201 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2202 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2203 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002204#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002205#if defined(MBEDTLS_CCM_C)
2206 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2207 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2208 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002209#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002210#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002211
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002212#if defined(MBEDTLS_ARIA_C)
2213 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2214 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2215 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2216#if defined(MBEDTLS_CIPHER_MODE_CBC)
2217 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2218 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2219 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2220#endif
2221#if defined(MBEDTLS_CIPHER_MODE_CFB)
2222 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2223 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2224 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2225#endif
2226#if defined(MBEDTLS_CIPHER_MODE_CTR)
2227 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2228 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2229 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2230#endif
2231#if defined(MBEDTLS_GCM_C)
2232 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2233 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2234 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2235#endif
2236#if defined(MBEDTLS_CCM_C)
2237 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2238 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2239 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2240#endif
2241#endif /* MBEDTLS_ARIA_C */
2242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002243#if defined(MBEDTLS_DES_C)
2244 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2245 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2246 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2247#if defined(MBEDTLS_CIPHER_MODE_CBC)
2248 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2249 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2250 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002251#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002252#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002253
Daniel Kingbd920622016-05-15 19:56:20 -03002254#if defined(MBEDTLS_CHACHA20_C)
2255 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2256#endif
2257
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002258#if defined(MBEDTLS_CHACHAPOLY_C)
2259 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002260#endif
2261
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002262#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2263 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2264#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002266 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002267};
2268
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002269#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2270int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002271
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002272#endif /* MBEDTLS_CIPHER_C */