blob: fd6e69cb316f80ec352fa666c857bfc6dfc57648 [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é-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000037#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000048#if defined(MBEDTLS_ARIA_C)
49#include "mbedtls/aria.h"
50#endif
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000054#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000069#include <string.h>
70#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020074#else
Rich Evans00ab4702015-02-06 13:43:58 +000075#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020076#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020078#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020081/* shared by all GCM ciphers */
82static void *gcm_ctx_alloc( void )
83{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020084 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
85
86 if( ctx != NULL )
87 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
88
89 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020090}
91
92static void gcm_ctx_free( void *ctx )
93{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094 mbedtls_gcm_free( ctx );
95 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020096}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020098
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200100/* shared by all CCM ciphers */
101static void *ccm_ctx_alloc( void )
102{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200103 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
104
105 if( ctx != NULL )
106 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
107
108 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200109}
110
111static void ccm_ctx_free( void *ctx )
112{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113 mbedtls_ccm_free( ctx );
114 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200115}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200117
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200121 const unsigned char *input, unsigned char *output )
122{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200124}
125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_CIPHER_MODE_CBC)
127static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000128 unsigned char *iv, const unsigned char *input, unsigned char *output )
129{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200131 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000132}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if defined(MBEDTLS_CIPHER_MODE_CFB)
136static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200137 size_t length, size_t *iv_off, unsigned char *iv,
138 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000139{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200141 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000142}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000144
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100145#if defined(MBEDTLS_CIPHER_MODE_OFB)
146static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
147 unsigned char *iv, const unsigned char *input, unsigned char *output )
148{
149 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
150 iv, input, output );
151}
152#endif /* MBEDTLS_CIPHER_MODE_OFB */
153
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200154#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200155static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
156 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000157 const unsigned char *input, unsigned char *output )
158{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000160 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000161}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000163
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200164static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200165 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000166{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200167 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000168}
169
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200170static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200171 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000172{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200173 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000174}
175
176static void * aes_ctx_alloc( void )
177{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200178 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200179
180 if( aes == NULL )
181 return( NULL );
182
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200183 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200184
185 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000186}
187
188static void aes_ctx_free( void *ctx )
189{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200190 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
191 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000192}
193
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194static const mbedtls_cipher_base_t aes_info = {
195 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200196 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000198 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100199#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200200#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000201 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100202#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100203#if defined(MBEDTLS_CIPHER_MODE_OFB)
204 aes_crypt_ofb_wrap,
205#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000207 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100208#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200209#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200210 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100211#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000212 aes_setkey_enc_wrap,
213 aes_setkey_dec_wrap,
214 aes_ctx_alloc,
215 aes_ctx_free
216};
217
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200218static const mbedtls_cipher_info_t aes_128_ecb_info = {
219 MBEDTLS_CIPHER_AES_128_ECB,
220 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200221 128,
222 "AES-128-ECB",
223 16,
224 0,
225 16,
226 &aes_info
227};
228
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229static const mbedtls_cipher_info_t aes_192_ecb_info = {
230 MBEDTLS_CIPHER_AES_192_ECB,
231 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200232 192,
233 "AES-192-ECB",
234 16,
235 0,
236 16,
237 &aes_info
238};
239
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200240static const mbedtls_cipher_info_t aes_256_ecb_info = {
241 MBEDTLS_CIPHER_AES_256_ECB,
242 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200243 256,
244 "AES-256-ECB",
245 16,
246 0,
247 16,
248 &aes_info
249};
250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251#if defined(MBEDTLS_CIPHER_MODE_CBC)
252static const mbedtls_cipher_info_t aes_128_cbc_info = {
253 MBEDTLS_CIPHER_AES_128_CBC,
254 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000255 128,
256 "AES-128-CBC",
257 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200258 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000259 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000260 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000261};
262
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200263static const mbedtls_cipher_info_t aes_192_cbc_info = {
264 MBEDTLS_CIPHER_AES_192_CBC,
265 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000266 192,
267 "AES-192-CBC",
268 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200269 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000270 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000271 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000272};
273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274static const mbedtls_cipher_info_t aes_256_cbc_info = {
275 MBEDTLS_CIPHER_AES_256_CBC,
276 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000277 256,
278 "AES-256-CBC",
279 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200280 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000281 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000282 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000283};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200284#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000285
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286#if defined(MBEDTLS_CIPHER_MODE_CFB)
287static const mbedtls_cipher_info_t aes_128_cfb128_info = {
288 MBEDTLS_CIPHER_AES_128_CFB128,
289 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000290 128,
291 "AES-128-CFB128",
292 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200293 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000294 16,
295 &aes_info
296};
297
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200298static const mbedtls_cipher_info_t aes_192_cfb128_info = {
299 MBEDTLS_CIPHER_AES_192_CFB128,
300 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000301 192,
302 "AES-192-CFB128",
303 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200304 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000305 16,
306 &aes_info
307};
308
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309static const mbedtls_cipher_info_t aes_256_cfb128_info = {
310 MBEDTLS_CIPHER_AES_256_CFB128,
311 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000312 256,
313 "AES-256-CFB128",
314 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200315 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000316 16,
317 &aes_info
318};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200319#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000320
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100321#if defined(MBEDTLS_CIPHER_MODE_OFB)
322static const mbedtls_cipher_info_t aes_128_ofb_info = {
323 MBEDTLS_CIPHER_AES_128_OFB,
324 MBEDTLS_MODE_OFB,
325 128,
326 "AES-128-OFB",
327 16,
328 0,
329 16,
330 &aes_info
331};
332
333static const mbedtls_cipher_info_t aes_192_ofb_info = {
334 MBEDTLS_CIPHER_AES_192_OFB,
335 MBEDTLS_MODE_OFB,
336 192,
337 "AES-192-OFB",
338 16,
339 0,
340 16,
341 &aes_info
342};
343
344static const mbedtls_cipher_info_t aes_256_ofb_info = {
345 MBEDTLS_CIPHER_AES_256_OFB,
346 MBEDTLS_MODE_OFB,
347 256,
348 "AES-256-OFB",
349 16,
350 0,
351 16,
352 &aes_info
353};
354#endif /* MBEDTLS_CIPHER_MODE_OFB */
355
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200356#if defined(MBEDTLS_CIPHER_MODE_CTR)
357static const mbedtls_cipher_info_t aes_128_ctr_info = {
358 MBEDTLS_CIPHER_AES_128_CTR,
359 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000360 128,
361 "AES-128-CTR",
362 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200363 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000364 16,
365 &aes_info
366};
367
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200368static const mbedtls_cipher_info_t aes_192_ctr_info = {
369 MBEDTLS_CIPHER_AES_192_CTR,
370 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000371 192,
372 "AES-192-CTR",
373 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200374 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000375 16,
376 &aes_info
377};
378
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379static const mbedtls_cipher_info_t aes_256_ctr_info = {
380 MBEDTLS_CIPHER_AES_256_CTR,
381 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000382 256,
383 "AES-256-CTR",
384 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200385 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000386 16,
387 &aes_info
388};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200389#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000390
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200391#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200392static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200393 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200394{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200395 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200396 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200397}
398
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200399static const mbedtls_cipher_base_t gcm_aes_info = {
400 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200401 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200403 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100404#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200406 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100407#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100408#if defined(MBEDTLS_CIPHER_MODE_OFB)
409 NULL,
410#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200411#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200412 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100413#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200414#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200415 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100416#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200417 gcm_aes_setkey_wrap,
418 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200419 gcm_ctx_alloc,
420 gcm_ctx_free,
421};
422
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200423static const mbedtls_cipher_info_t aes_128_gcm_info = {
424 MBEDTLS_CIPHER_AES_128_GCM,
425 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100426 128,
427 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200428 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200429 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100430 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200431 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100432};
433
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200434static const mbedtls_cipher_info_t aes_192_gcm_info = {
435 MBEDTLS_CIPHER_AES_192_GCM,
436 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200437 192,
438 "AES-192-GCM",
439 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200440 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200441 16,
442 &gcm_aes_info
443};
444
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200445static const mbedtls_cipher_info_t aes_256_gcm_info = {
446 MBEDTLS_CIPHER_AES_256_GCM,
447 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100448 256,
449 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200450 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200451 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100452 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200453 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100454};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200455#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100456
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200457#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200458static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200459 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200460{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200461 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200462 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200463}
464
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200465static const mbedtls_cipher_base_t ccm_aes_info = {
466 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200467 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200469 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100470#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200471#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200472 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100473#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100474#if defined(MBEDTLS_CIPHER_MODE_OFB)
475 NULL,
476#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200477#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200478 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100479#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200480#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200481 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100482#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200483 ccm_aes_setkey_wrap,
484 ccm_aes_setkey_wrap,
485 ccm_ctx_alloc,
486 ccm_ctx_free,
487};
488
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200489static const mbedtls_cipher_info_t aes_128_ccm_info = {
490 MBEDTLS_CIPHER_AES_128_CCM,
491 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200492 128,
493 "AES-128-CCM",
494 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200495 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200496 16,
497 &ccm_aes_info
498};
499
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200500static const mbedtls_cipher_info_t aes_192_ccm_info = {
501 MBEDTLS_CIPHER_AES_192_CCM,
502 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200503 192,
504 "AES-192-CCM",
505 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200506 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200507 16,
508 &ccm_aes_info
509};
510
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200511static const mbedtls_cipher_info_t aes_256_ccm_info = {
512 MBEDTLS_CIPHER_AES_256_CCM,
513 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200514 256,
515 "AES-256-CCM",
516 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200517 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200518 16,
519 &ccm_aes_info
520};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200521#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200522
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200523#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000524
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200525#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200527static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200528 const unsigned char *input, unsigned char *output )
529{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200530 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200531 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200532}
533
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200534#if defined(MBEDTLS_CIPHER_MODE_CBC)
535static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200536 size_t length, unsigned char *iv,
537 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000538{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200540 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000541}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200542#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000543
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200544#if defined(MBEDTLS_CIPHER_MODE_CFB)
545static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200546 size_t length, size_t *iv_off, unsigned char *iv,
547 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000548{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200549 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200550 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000551}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200552#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000553
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200555static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
556 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000557 const unsigned char *input, unsigned char *output )
558{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200559 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200560 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000561}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000563
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200564static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200565 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000566{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200567 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000568}
569
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200570static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200571 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000572{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200573 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000574}
575
576static void * camellia_ctx_alloc( void )
577{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200578 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200579 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200580
581 if( ctx == NULL )
582 return( NULL );
583
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200584 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200585
586 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000587}
588
589static void camellia_ctx_free( void *ctx )
590{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200591 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
592 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000593}
594
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200595static const mbedtls_cipher_base_t camellia_info = {
596 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200597 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000599 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100600#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200601#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000602 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100603#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100604#if defined(MBEDTLS_CIPHER_MODE_OFB)
605 NULL,
606#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000608 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100609#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200610#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200611 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100612#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000613 camellia_setkey_enc_wrap,
614 camellia_setkey_dec_wrap,
615 camellia_ctx_alloc,
616 camellia_ctx_free
617};
618
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200619static const mbedtls_cipher_info_t camellia_128_ecb_info = {
620 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
621 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200622 128,
623 "CAMELLIA-128-ECB",
624 16,
625 0,
626 16,
627 &camellia_info
628};
629
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200630static const mbedtls_cipher_info_t camellia_192_ecb_info = {
631 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
632 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200633 192,
634 "CAMELLIA-192-ECB",
635 16,
636 0,
637 16,
638 &camellia_info
639};
640
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200641static const mbedtls_cipher_info_t camellia_256_ecb_info = {
642 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
643 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200644 256,
645 "CAMELLIA-256-ECB",
646 16,
647 0,
648 16,
649 &camellia_info
650};
651
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652#if defined(MBEDTLS_CIPHER_MODE_CBC)
653static const mbedtls_cipher_info_t camellia_128_cbc_info = {
654 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
655 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000656 128,
657 "CAMELLIA-128-CBC",
658 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200659 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000660 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000661 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000662};
663
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200664static const mbedtls_cipher_info_t camellia_192_cbc_info = {
665 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
666 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000667 192,
668 "CAMELLIA-192-CBC",
669 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200670 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000671 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000672 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000673};
674
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200675static const mbedtls_cipher_info_t camellia_256_cbc_info = {
676 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
677 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000678 256,
679 "CAMELLIA-256-CBC",
680 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200681 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000682 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000683 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000684};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000686
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200687#if defined(MBEDTLS_CIPHER_MODE_CFB)
688static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
689 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
690 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000691 128,
692 "CAMELLIA-128-CFB128",
693 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200694 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000695 16,
696 &camellia_info
697};
698
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
700 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
701 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000702 192,
703 "CAMELLIA-192-CFB128",
704 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200705 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000706 16,
707 &camellia_info
708};
709
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200710static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
711 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
712 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000713 256,
714 "CAMELLIA-256-CFB128",
715 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200716 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000717 16,
718 &camellia_info
719};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200720#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000721
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200722#if defined(MBEDTLS_CIPHER_MODE_CTR)
723static const mbedtls_cipher_info_t camellia_128_ctr_info = {
724 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
725 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000726 128,
727 "CAMELLIA-128-CTR",
728 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200729 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000730 16,
731 &camellia_info
732};
733
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200734static const mbedtls_cipher_info_t camellia_192_ctr_info = {
735 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
736 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000737 192,
738 "CAMELLIA-192-CTR",
739 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200740 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000741 16,
742 &camellia_info
743};
744
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200745static const mbedtls_cipher_info_t camellia_256_ctr_info = {
746 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
747 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000748 256,
749 "CAMELLIA-256-CTR",
750 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200751 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000752 16,
753 &camellia_info
754};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000756
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200757#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200758static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200759 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200760{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200761 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200762 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200763}
764
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200765static const mbedtls_cipher_base_t gcm_camellia_info = {
766 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200767 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200769 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100770#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200771#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200772 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100773#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100774#if defined(MBEDTLS_CIPHER_MODE_OFB)
775 NULL,
776#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200777#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200778 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100779#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200780#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200781 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100782#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200783 gcm_camellia_setkey_wrap,
784 gcm_camellia_setkey_wrap,
785 gcm_ctx_alloc,
786 gcm_ctx_free,
787};
788
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200789static const mbedtls_cipher_info_t camellia_128_gcm_info = {
790 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
791 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200792 128,
793 "CAMELLIA-128-GCM",
794 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200795 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200796 16,
797 &gcm_camellia_info
798};
799
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200800static const mbedtls_cipher_info_t camellia_192_gcm_info = {
801 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
802 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200803 192,
804 "CAMELLIA-192-GCM",
805 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200806 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200807 16,
808 &gcm_camellia_info
809};
810
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200811static const mbedtls_cipher_info_t camellia_256_gcm_info = {
812 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
813 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200814 256,
815 "CAMELLIA-256-GCM",
816 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200817 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200818 16,
819 &gcm_camellia_info
820};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200821#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200822
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200823#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200824static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200825 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200826{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200827 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200828 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200829}
830
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200831static const mbedtls_cipher_base_t ccm_camellia_info = {
832 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200833 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200834#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200835 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100836#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200837#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200838 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100839#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100840#if defined(MBEDTLS_CIPHER_MODE_OFB)
841 NULL,
842#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200843#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200844 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100845#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200846#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200847 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100848#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200849 ccm_camellia_setkey_wrap,
850 ccm_camellia_setkey_wrap,
851 ccm_ctx_alloc,
852 ccm_ctx_free,
853};
854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855static const mbedtls_cipher_info_t camellia_128_ccm_info = {
856 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
857 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200858 128,
859 "CAMELLIA-128-CCM",
860 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200861 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200862 16,
863 &ccm_camellia_info
864};
865
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200866static const mbedtls_cipher_info_t camellia_192_ccm_info = {
867 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
868 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200869 192,
870 "CAMELLIA-192-CCM",
871 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200872 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200873 16,
874 &ccm_camellia_info
875};
876
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200877static const mbedtls_cipher_info_t camellia_256_ccm_info = {
878 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
879 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200880 256,
881 "CAMELLIA-256-CCM",
882 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200883 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200884 16,
885 &ccm_camellia_info
886};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200887#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200888
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200889#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000890
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000891#if defined(MBEDTLS_ARIA_C)
892
893static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
894 const unsigned char *input, unsigned char *output )
895{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200896 (void) operation;
897 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000898 output );
899}
900
901#if defined(MBEDTLS_CIPHER_MODE_CBC)
902static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
903 size_t length, unsigned char *iv,
904 const unsigned char *input, unsigned char *output )
905{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +0200906 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000907 input, output );
908}
909#endif /* MBEDTLS_CIPHER_MODE_CBC */
910
911#if defined(MBEDTLS_CIPHER_MODE_CFB)
912static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
913 size_t length, size_t *iv_off, unsigned char *iv,
914 const unsigned char *input, unsigned char *output )
915{
916 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
917 iv_off, iv, input, output );
918}
919#endif /* MBEDTLS_CIPHER_MODE_CFB */
920
921#if defined(MBEDTLS_CIPHER_MODE_CTR)
922static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
923 unsigned char *nonce_counter, unsigned char *stream_block,
924 const unsigned char *input, unsigned char *output )
925{
926 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
927 nonce_counter, stream_block, input, output );
928}
929#endif /* MBEDTLS_CIPHER_MODE_CTR */
930
931static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
932 unsigned int key_bitlen )
933{
934 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
935}
936
937static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
938 unsigned int key_bitlen )
939{
940 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
941}
942
943static void * aria_ctx_alloc( void )
944{
945 mbedtls_aria_context *ctx;
946 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
947
948 if( ctx == NULL )
949 return( NULL );
950
951 mbedtls_aria_init( ctx );
952
953 return( ctx );
954}
955
956static void aria_ctx_free( void *ctx )
957{
958 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
959 mbedtls_free( ctx );
960}
961
962static const mbedtls_cipher_base_t aria_info = {
963 MBEDTLS_CIPHER_ID_ARIA,
964 aria_crypt_ecb_wrap,
965#if defined(MBEDTLS_CIPHER_MODE_CBC)
966 aria_crypt_cbc_wrap,
967#endif
968#if defined(MBEDTLS_CIPHER_MODE_CFB)
969 aria_crypt_cfb128_wrap,
970#endif
Simon Butcher4844bf22018-06-11 15:21:05 +0100971#if defined(MBEDTLS_CIPHER_MODE_OFB)
972 NULL,
973#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000974#if defined(MBEDTLS_CIPHER_MODE_CTR)
975 aria_crypt_ctr_wrap,
976#endif
977#if defined(MBEDTLS_CIPHER_MODE_STREAM)
978 NULL,
979#endif
980 aria_setkey_enc_wrap,
981 aria_setkey_dec_wrap,
982 aria_ctx_alloc,
983 aria_ctx_free
984};
985
986static const mbedtls_cipher_info_t aria_128_ecb_info = {
987 MBEDTLS_CIPHER_ARIA_128_ECB,
988 MBEDTLS_MODE_ECB,
989 128,
990 "ARIA-128-ECB",
991 16,
992 0,
993 16,
994 &aria_info
995};
996
997static const mbedtls_cipher_info_t aria_192_ecb_info = {
998 MBEDTLS_CIPHER_ARIA_192_ECB,
999 MBEDTLS_MODE_ECB,
1000 192,
1001 "ARIA-192-ECB",
1002 16,
1003 0,
1004 16,
1005 &aria_info
1006};
1007
1008static const mbedtls_cipher_info_t aria_256_ecb_info = {
1009 MBEDTLS_CIPHER_ARIA_256_ECB,
1010 MBEDTLS_MODE_ECB,
1011 256,
1012 "ARIA-256-ECB",
1013 16,
1014 0,
1015 16,
1016 &aria_info
1017};
1018
1019#if defined(MBEDTLS_CIPHER_MODE_CBC)
1020static const mbedtls_cipher_info_t aria_128_cbc_info = {
1021 MBEDTLS_CIPHER_ARIA_128_CBC,
1022 MBEDTLS_MODE_CBC,
1023 128,
1024 "ARIA-128-CBC",
1025 16,
1026 0,
1027 16,
1028 &aria_info
1029};
1030
1031static const mbedtls_cipher_info_t aria_192_cbc_info = {
1032 MBEDTLS_CIPHER_ARIA_192_CBC,
1033 MBEDTLS_MODE_CBC,
1034 192,
1035 "ARIA-192-CBC",
1036 16,
1037 0,
1038 16,
1039 &aria_info
1040};
1041
1042static const mbedtls_cipher_info_t aria_256_cbc_info = {
1043 MBEDTLS_CIPHER_ARIA_256_CBC,
1044 MBEDTLS_MODE_CBC,
1045 256,
1046 "ARIA-256-CBC",
1047 16,
1048 0,
1049 16,
1050 &aria_info
1051};
1052#endif /* MBEDTLS_CIPHER_MODE_CBC */
1053
1054#if defined(MBEDTLS_CIPHER_MODE_CFB)
1055static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1056 MBEDTLS_CIPHER_ARIA_128_CFB128,
1057 MBEDTLS_MODE_CFB,
1058 128,
1059 "ARIA-128-CFB128",
1060 16,
1061 0,
1062 16,
1063 &aria_info
1064};
1065
1066static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1067 MBEDTLS_CIPHER_ARIA_192_CFB128,
1068 MBEDTLS_MODE_CFB,
1069 192,
1070 "ARIA-192-CFB128",
1071 16,
1072 0,
1073 16,
1074 &aria_info
1075};
1076
1077static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1078 MBEDTLS_CIPHER_ARIA_256_CFB128,
1079 MBEDTLS_MODE_CFB,
1080 256,
1081 "ARIA-256-CFB128",
1082 16,
1083 0,
1084 16,
1085 &aria_info
1086};
1087#endif /* MBEDTLS_CIPHER_MODE_CFB */
1088
1089#if defined(MBEDTLS_CIPHER_MODE_CTR)
1090static const mbedtls_cipher_info_t aria_128_ctr_info = {
1091 MBEDTLS_CIPHER_ARIA_128_CTR,
1092 MBEDTLS_MODE_CTR,
1093 128,
1094 "ARIA-128-CTR",
1095 16,
1096 0,
1097 16,
1098 &aria_info
1099};
1100
1101static const mbedtls_cipher_info_t aria_192_ctr_info = {
1102 MBEDTLS_CIPHER_ARIA_192_CTR,
1103 MBEDTLS_MODE_CTR,
1104 192,
1105 "ARIA-192-CTR",
1106 16,
1107 0,
1108 16,
1109 &aria_info
1110};
1111
1112static const mbedtls_cipher_info_t aria_256_ctr_info = {
1113 MBEDTLS_CIPHER_ARIA_256_CTR,
1114 MBEDTLS_MODE_CTR,
1115 256,
1116 "ARIA-256-CTR",
1117 16,
1118 0,
1119 16,
1120 &aria_info
1121};
1122#endif /* MBEDTLS_CIPHER_MODE_CTR */
1123
1124#if defined(MBEDTLS_GCM_C)
1125static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1126 unsigned int key_bitlen )
1127{
1128 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1129 key, key_bitlen );
1130}
1131
1132static const mbedtls_cipher_base_t gcm_aria_info = {
1133 MBEDTLS_CIPHER_ID_ARIA,
1134 NULL,
1135#if defined(MBEDTLS_CIPHER_MODE_CBC)
1136 NULL,
1137#endif
1138#if defined(MBEDTLS_CIPHER_MODE_CFB)
1139 NULL,
1140#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001141#if defined(MBEDTLS_CIPHER_MODE_OFB)
1142 NULL,
1143#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001144#if defined(MBEDTLS_CIPHER_MODE_CTR)
1145 NULL,
1146#endif
1147#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1148 NULL,
1149#endif
1150 gcm_aria_setkey_wrap,
1151 gcm_aria_setkey_wrap,
1152 gcm_ctx_alloc,
1153 gcm_ctx_free,
1154};
1155
1156static const mbedtls_cipher_info_t aria_128_gcm_info = {
1157 MBEDTLS_CIPHER_ARIA_128_GCM,
1158 MBEDTLS_MODE_GCM,
1159 128,
1160 "ARIA-128-GCM",
1161 12,
1162 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1163 16,
1164 &gcm_aria_info
1165};
1166
1167static const mbedtls_cipher_info_t aria_192_gcm_info = {
1168 MBEDTLS_CIPHER_ARIA_192_GCM,
1169 MBEDTLS_MODE_GCM,
1170 192,
1171 "ARIA-192-GCM",
1172 12,
1173 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1174 16,
1175 &gcm_aria_info
1176};
1177
1178static const mbedtls_cipher_info_t aria_256_gcm_info = {
1179 MBEDTLS_CIPHER_ARIA_256_GCM,
1180 MBEDTLS_MODE_GCM,
1181 256,
1182 "ARIA-256-GCM",
1183 12,
1184 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1185 16,
1186 &gcm_aria_info
1187};
1188#endif /* MBEDTLS_GCM_C */
1189
1190#if defined(MBEDTLS_CCM_C)
1191static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1192 unsigned int key_bitlen )
1193{
1194 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1195 key, key_bitlen );
1196}
1197
1198static const mbedtls_cipher_base_t ccm_aria_info = {
1199 MBEDTLS_CIPHER_ID_ARIA,
1200 NULL,
1201#if defined(MBEDTLS_CIPHER_MODE_CBC)
1202 NULL,
1203#endif
1204#if defined(MBEDTLS_CIPHER_MODE_CFB)
1205 NULL,
1206#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001207#if defined(MBEDTLS_CIPHER_MODE_OFB)
1208 NULL,
1209#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001210#if defined(MBEDTLS_CIPHER_MODE_CTR)
1211 NULL,
1212#endif
1213#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1214 NULL,
1215#endif
1216 ccm_aria_setkey_wrap,
1217 ccm_aria_setkey_wrap,
1218 ccm_ctx_alloc,
1219 ccm_ctx_free,
1220};
1221
1222static const mbedtls_cipher_info_t aria_128_ccm_info = {
1223 MBEDTLS_CIPHER_ARIA_128_CCM,
1224 MBEDTLS_MODE_CCM,
1225 128,
1226 "ARIA-128-CCM",
1227 12,
1228 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1229 16,
1230 &ccm_aria_info
1231};
1232
1233static const mbedtls_cipher_info_t aria_192_ccm_info = {
1234 MBEDTLS_CIPHER_ARIA_192_CCM,
1235 MBEDTLS_MODE_CCM,
1236 192,
1237 "ARIA-192-CCM",
1238 12,
1239 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1240 16,
1241 &ccm_aria_info
1242};
1243
1244static const mbedtls_cipher_info_t aria_256_ccm_info = {
1245 MBEDTLS_CIPHER_ARIA_256_CCM,
1246 MBEDTLS_MODE_CCM,
1247 256,
1248 "ARIA-256-CCM",
1249 12,
1250 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1251 16,
1252 &ccm_aria_info
1253};
1254#endif /* MBEDTLS_CCM_C */
1255
1256#endif /* MBEDTLS_ARIA_C */
1257
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001258#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001259
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001260static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001261 const unsigned char *input, unsigned char *output )
1262{
1263 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001264 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001265}
1266
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001267static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001268 const unsigned char *input, unsigned char *output )
1269{
1270 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001271 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001272}
1273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001274#if defined(MBEDTLS_CIPHER_MODE_CBC)
1275static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001276 unsigned char *iv, const unsigned char *input, unsigned char *output )
1277{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001278 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001279 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001280}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001281#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001282
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001283#if defined(MBEDTLS_CIPHER_MODE_CBC)
1284static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001285 unsigned char *iv, const unsigned char *input, unsigned char *output )
1286{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001287 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001288 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001289}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001290#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001291
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001292static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001293 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001294{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001295 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001297 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001298}
1299
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001300static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001301 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001302{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001303 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001305 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001306}
1307
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001308static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001309 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001310{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001311 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001312
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001313 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001314}
1315
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001316static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001317 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001318{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001319 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001320
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001321 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001322}
1323
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001324static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001325 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001326{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001327 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001328
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001329 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001330}
1331
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001332static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001333 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001334{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001335 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001336
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001337 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001338}
1339
1340static void * des_ctx_alloc( void )
1341{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001342 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001343
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001344 if( des == NULL )
1345 return( NULL );
1346
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001347 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001348
1349 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001350}
1351
1352static void des_ctx_free( void *ctx )
1353{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001354 mbedtls_des_free( (mbedtls_des_context *) ctx );
1355 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001356}
1357
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001358static void * des3_ctx_alloc( void )
1359{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001360 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001361 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001362
1363 if( des3 == NULL )
1364 return( NULL );
1365
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001366 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001367
1368 return( des3 );
1369}
1370
Paul Bakker34617722014-06-13 17:20:13 +02001371static void des3_ctx_free( void *ctx )
1372{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001373 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1374 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001375}
1376
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001377static const mbedtls_cipher_base_t des_info = {
1378 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001379 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001380#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001381 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001382#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001383#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001384 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001385#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001386#if defined(MBEDTLS_CIPHER_MODE_OFB)
1387 NULL,
1388#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001389#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001390 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001391#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001392#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001393 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001394#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001395 des_setkey_enc_wrap,
1396 des_setkey_dec_wrap,
1397 des_ctx_alloc,
1398 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001399};
1400
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001401static const mbedtls_cipher_info_t des_ecb_info = {
1402 MBEDTLS_CIPHER_DES_ECB,
1403 MBEDTLS_MODE_ECB,
1404 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001405 "DES-ECB",
1406 8,
1407 0,
1408 8,
1409 &des_info
1410};
1411
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001412#if defined(MBEDTLS_CIPHER_MODE_CBC)
1413static const mbedtls_cipher_info_t des_cbc_info = {
1414 MBEDTLS_CIPHER_DES_CBC,
1415 MBEDTLS_MODE_CBC,
1416 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001417 "DES-CBC",
1418 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001419 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001420 8,
1421 &des_info
1422};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001423#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001424
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001425static const mbedtls_cipher_base_t des_ede_info = {
1426 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001427 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001428#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001429 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001430#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001431#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001432 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001433#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001434#if defined(MBEDTLS_CIPHER_MODE_OFB)
1435 NULL,
1436#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001437#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001438 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001439#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001440#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001441 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001442#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001443 des3_set2key_enc_wrap,
1444 des3_set2key_dec_wrap,
1445 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001446 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001447};
1448
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001449static const mbedtls_cipher_info_t des_ede_ecb_info = {
1450 MBEDTLS_CIPHER_DES_EDE_ECB,
1451 MBEDTLS_MODE_ECB,
1452 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001453 "DES-EDE-ECB",
1454 8,
1455 0,
1456 8,
1457 &des_ede_info
1458};
1459
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001460#if defined(MBEDTLS_CIPHER_MODE_CBC)
1461static const mbedtls_cipher_info_t des_ede_cbc_info = {
1462 MBEDTLS_CIPHER_DES_EDE_CBC,
1463 MBEDTLS_MODE_CBC,
1464 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001465 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001466 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001467 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001468 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001469 &des_ede_info
1470};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001471#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001472
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001473static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001474 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001475 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001476#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001477 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001478#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001479#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001480 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001481#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001482#if defined(MBEDTLS_CIPHER_MODE_OFB)
1483 NULL,
1484#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001485#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001486 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001487#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001488#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001489 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001490#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001491 des3_set3key_enc_wrap,
1492 des3_set3key_dec_wrap,
1493 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001494 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001495};
1496
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001497static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1498 MBEDTLS_CIPHER_DES_EDE3_ECB,
1499 MBEDTLS_MODE_ECB,
1500 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001501 "DES-EDE3-ECB",
1502 8,
1503 0,
1504 8,
1505 &des_ede3_info
1506};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001507#if defined(MBEDTLS_CIPHER_MODE_CBC)
1508static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1509 MBEDTLS_CIPHER_DES_EDE3_CBC,
1510 MBEDTLS_MODE_CBC,
1511 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001512 "DES-EDE3-CBC",
1513 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001514 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001515 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001516 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001517};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001518#endif /* MBEDTLS_CIPHER_MODE_CBC */
1519#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001520
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001521#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001522
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001523static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001524 const unsigned char *input, unsigned char *output )
1525{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001526 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001527 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001528}
1529
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001530#if defined(MBEDTLS_CIPHER_MODE_CBC)
1531static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001532 size_t length, unsigned char *iv, const unsigned char *input,
1533 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001534{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001535 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001536 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001537}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001538#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001539
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001540#if defined(MBEDTLS_CIPHER_MODE_CFB)
1541static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001542 size_t length, size_t *iv_off, unsigned char *iv,
1543 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001544{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001545 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001546 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001547}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001548#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001550#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001551static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1552 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001553 const unsigned char *input, unsigned char *output )
1554{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001555 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001556 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001557}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001558#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001559
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001560static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001561 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001562{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001563 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001564}
1565
1566static void * blowfish_ctx_alloc( void )
1567{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001568 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001569 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001570
1571 if( ctx == NULL )
1572 return( NULL );
1573
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001574 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001575
1576 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001577}
1578
1579static void blowfish_ctx_free( void *ctx )
1580{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001581 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1582 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001583}
1584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001585static const mbedtls_cipher_base_t blowfish_info = {
1586 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001587 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001588#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001589 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001590#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001591#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001592 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001593#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001594#if defined(MBEDTLS_CIPHER_MODE_OFB)
1595 NULL,
1596#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001597#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001598 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001599#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001600#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001601 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001602#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001603 blowfish_setkey_wrap,
1604 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001605 blowfish_ctx_alloc,
1606 blowfish_ctx_free
1607};
1608
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001609static const mbedtls_cipher_info_t blowfish_ecb_info = {
1610 MBEDTLS_CIPHER_BLOWFISH_ECB,
1611 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001612 128,
1613 "BLOWFISH-ECB",
1614 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001615 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001616 8,
1617 &blowfish_info
1618};
1619
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001620#if defined(MBEDTLS_CIPHER_MODE_CBC)
1621static const mbedtls_cipher_info_t blowfish_cbc_info = {
1622 MBEDTLS_CIPHER_BLOWFISH_CBC,
1623 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001624 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001625 "BLOWFISH-CBC",
1626 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001627 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001628 8,
1629 &blowfish_info
1630};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001631#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001632
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001633#if defined(MBEDTLS_CIPHER_MODE_CFB)
1634static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1635 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1636 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001637 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001638 "BLOWFISH-CFB64",
1639 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001640 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001641 8,
1642 &blowfish_info
1643};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001644#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001645
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001646#if defined(MBEDTLS_CIPHER_MODE_CTR)
1647static const mbedtls_cipher_info_t blowfish_ctr_info = {
1648 MBEDTLS_CIPHER_BLOWFISH_CTR,
1649 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001650 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001651 "BLOWFISH-CTR",
1652 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001653 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001654 8,
1655 &blowfish_info
1656};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001657#endif /* MBEDTLS_CIPHER_MODE_CTR */
1658#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001659
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001660#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001661static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1662 const unsigned char *input,
1663 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001664{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001665 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001666}
1667
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001668static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001669 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001670{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001671 /* we get key_bitlen in bits, arc4 expects it in bytes */
1672 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001673 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001674
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001675 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001676 return( 0 );
1677}
1678
1679static void * arc4_ctx_alloc( void )
1680{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001681 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001682 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001683
1684 if( ctx == NULL )
1685 return( NULL );
1686
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001687 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001688
1689 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001690}
Paul Bakker68884e32013-01-07 18:20:04 +01001691
1692static void arc4_ctx_free( void *ctx )
1693{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001694 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1695 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001696}
1697
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001698static const mbedtls_cipher_base_t arc4_base_info = {
1699 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001700 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001701#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001702 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001703#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001704#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001705 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001706#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001707#if defined(MBEDTLS_CIPHER_MODE_OFB)
1708 NULL,
1709#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001710#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001711 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001712#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001713#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001714 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001715#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001716 arc4_setkey_wrap,
1717 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001718 arc4_ctx_alloc,
1719 arc4_ctx_free
1720};
1721
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001722static const mbedtls_cipher_info_t arc4_128_info = {
1723 MBEDTLS_CIPHER_ARC4_128,
1724 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001725 128,
1726 "ARC4-128",
1727 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001728 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001729 1,
1730 &arc4_base_info
1731};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001732#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001733
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001734#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001735static int null_crypt_stream( void *ctx, size_t length,
1736 const unsigned char *input,
1737 unsigned char *output )
1738{
1739 ((void) ctx);
1740 memmove( output, input, length );
1741 return( 0 );
1742}
1743
1744static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001745 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001746{
1747 ((void) ctx);
1748 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001749 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001750
1751 return( 0 );
1752}
1753
Paul Bakkerfab5c822012-02-06 16:45:10 +00001754static void * null_ctx_alloc( void )
1755{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001756 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001757}
1758
Paul Bakkerfab5c822012-02-06 16:45:10 +00001759static void null_ctx_free( void *ctx )
1760{
1761 ((void) ctx);
1762}
1763
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001764static const mbedtls_cipher_base_t null_base_info = {
1765 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001766 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001767#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001768 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001769#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001770#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001771 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001772#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001773#if defined(MBEDTLS_CIPHER_MODE_OFB)
1774 NULL,
1775#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001776#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001777 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001778#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001779#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001780 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001781#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001782 null_setkey,
1783 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001784 null_ctx_alloc,
1785 null_ctx_free
1786};
1787
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001788static const mbedtls_cipher_info_t null_cipher_info = {
1789 MBEDTLS_CIPHER_NULL,
1790 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001791 0,
1792 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001793 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001794 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001795 1,
1796 &null_base_info
1797};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001798#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001799
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001800const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001801{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001802#if defined(MBEDTLS_AES_C)
1803 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1804 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1805 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1806#if defined(MBEDTLS_CIPHER_MODE_CBC)
1807 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1808 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1809 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001810#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001811#if defined(MBEDTLS_CIPHER_MODE_CFB)
1812 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1813 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1814 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001815#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001816#if defined(MBEDTLS_CIPHER_MODE_OFB)
1817 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
1818 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
1819 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
1820#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001821#if defined(MBEDTLS_CIPHER_MODE_CTR)
1822 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1823 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1824 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001825#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001826#if defined(MBEDTLS_GCM_C)
1827 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1828 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1829 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001830#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001831#if defined(MBEDTLS_CCM_C)
1832 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1833 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1834 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001835#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001836#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001837
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001838#if defined(MBEDTLS_ARC4_C)
1839 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001840#endif
1841
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001842#if defined(MBEDTLS_BLOWFISH_C)
1843 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1844#if defined(MBEDTLS_CIPHER_MODE_CBC)
1845 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001846#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001847#if defined(MBEDTLS_CIPHER_MODE_CFB)
1848 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001849#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001850#if defined(MBEDTLS_CIPHER_MODE_CTR)
1851 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001852#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001853#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001855#if defined(MBEDTLS_CAMELLIA_C)
1856 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1857 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1858 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1859#if defined(MBEDTLS_CIPHER_MODE_CBC)
1860 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1861 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1862 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001863#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001864#if defined(MBEDTLS_CIPHER_MODE_CFB)
1865 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1866 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1867 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001868#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001869#if defined(MBEDTLS_CIPHER_MODE_CTR)
1870 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1871 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1872 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001873#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001874#if defined(MBEDTLS_GCM_C)
1875 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1876 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1877 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001878#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001879#if defined(MBEDTLS_CCM_C)
1880 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1881 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1882 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001883#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001884#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001885
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001886#if defined(MBEDTLS_ARIA_C)
1887 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1888 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1889 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1890#if defined(MBEDTLS_CIPHER_MODE_CBC)
1891 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1892 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1893 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1894#endif
1895#if defined(MBEDTLS_CIPHER_MODE_CFB)
1896 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1897 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1898 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1899#endif
1900#if defined(MBEDTLS_CIPHER_MODE_CTR)
1901 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1902 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1903 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1904#endif
1905#if defined(MBEDTLS_GCM_C)
1906 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1907 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1908 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1909#endif
1910#if defined(MBEDTLS_CCM_C)
1911 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1912 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1913 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1914#endif
1915#endif /* MBEDTLS_ARIA_C */
1916
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001917#if defined(MBEDTLS_DES_C)
1918 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1919 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1920 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1921#if defined(MBEDTLS_CIPHER_MODE_CBC)
1922 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1923 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1924 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001925#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001926#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001927
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001928#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1929 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1930#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001931
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001932 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001933};
1934
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001935#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1936int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001937
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001938#endif /* MBEDTLS_CIPHER_C */