blob: ef47037ee5af2f24e8e856259e30bc9cfdd32df0 [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
971#if defined(MBEDTLS_CIPHER_MODE_CTR)
972 aria_crypt_ctr_wrap,
973#endif
974#if defined(MBEDTLS_CIPHER_MODE_STREAM)
975 NULL,
976#endif
977 aria_setkey_enc_wrap,
978 aria_setkey_dec_wrap,
979 aria_ctx_alloc,
980 aria_ctx_free
981};
982
983static const mbedtls_cipher_info_t aria_128_ecb_info = {
984 MBEDTLS_CIPHER_ARIA_128_ECB,
985 MBEDTLS_MODE_ECB,
986 128,
987 "ARIA-128-ECB",
988 16,
989 0,
990 16,
991 &aria_info
992};
993
994static const mbedtls_cipher_info_t aria_192_ecb_info = {
995 MBEDTLS_CIPHER_ARIA_192_ECB,
996 MBEDTLS_MODE_ECB,
997 192,
998 "ARIA-192-ECB",
999 16,
1000 0,
1001 16,
1002 &aria_info
1003};
1004
1005static const mbedtls_cipher_info_t aria_256_ecb_info = {
1006 MBEDTLS_CIPHER_ARIA_256_ECB,
1007 MBEDTLS_MODE_ECB,
1008 256,
1009 "ARIA-256-ECB",
1010 16,
1011 0,
1012 16,
1013 &aria_info
1014};
1015
1016#if defined(MBEDTLS_CIPHER_MODE_CBC)
1017static const mbedtls_cipher_info_t aria_128_cbc_info = {
1018 MBEDTLS_CIPHER_ARIA_128_CBC,
1019 MBEDTLS_MODE_CBC,
1020 128,
1021 "ARIA-128-CBC",
1022 16,
1023 0,
1024 16,
1025 &aria_info
1026};
1027
1028static const mbedtls_cipher_info_t aria_192_cbc_info = {
1029 MBEDTLS_CIPHER_ARIA_192_CBC,
1030 MBEDTLS_MODE_CBC,
1031 192,
1032 "ARIA-192-CBC",
1033 16,
1034 0,
1035 16,
1036 &aria_info
1037};
1038
1039static const mbedtls_cipher_info_t aria_256_cbc_info = {
1040 MBEDTLS_CIPHER_ARIA_256_CBC,
1041 MBEDTLS_MODE_CBC,
1042 256,
1043 "ARIA-256-CBC",
1044 16,
1045 0,
1046 16,
1047 &aria_info
1048};
1049#endif /* MBEDTLS_CIPHER_MODE_CBC */
1050
1051#if defined(MBEDTLS_CIPHER_MODE_CFB)
1052static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1053 MBEDTLS_CIPHER_ARIA_128_CFB128,
1054 MBEDTLS_MODE_CFB,
1055 128,
1056 "ARIA-128-CFB128",
1057 16,
1058 0,
1059 16,
1060 &aria_info
1061};
1062
1063static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1064 MBEDTLS_CIPHER_ARIA_192_CFB128,
1065 MBEDTLS_MODE_CFB,
1066 192,
1067 "ARIA-192-CFB128",
1068 16,
1069 0,
1070 16,
1071 &aria_info
1072};
1073
1074static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1075 MBEDTLS_CIPHER_ARIA_256_CFB128,
1076 MBEDTLS_MODE_CFB,
1077 256,
1078 "ARIA-256-CFB128",
1079 16,
1080 0,
1081 16,
1082 &aria_info
1083};
1084#endif /* MBEDTLS_CIPHER_MODE_CFB */
1085
1086#if defined(MBEDTLS_CIPHER_MODE_CTR)
1087static const mbedtls_cipher_info_t aria_128_ctr_info = {
1088 MBEDTLS_CIPHER_ARIA_128_CTR,
1089 MBEDTLS_MODE_CTR,
1090 128,
1091 "ARIA-128-CTR",
1092 16,
1093 0,
1094 16,
1095 &aria_info
1096};
1097
1098static const mbedtls_cipher_info_t aria_192_ctr_info = {
1099 MBEDTLS_CIPHER_ARIA_192_CTR,
1100 MBEDTLS_MODE_CTR,
1101 192,
1102 "ARIA-192-CTR",
1103 16,
1104 0,
1105 16,
1106 &aria_info
1107};
1108
1109static const mbedtls_cipher_info_t aria_256_ctr_info = {
1110 MBEDTLS_CIPHER_ARIA_256_CTR,
1111 MBEDTLS_MODE_CTR,
1112 256,
1113 "ARIA-256-CTR",
1114 16,
1115 0,
1116 16,
1117 &aria_info
1118};
1119#endif /* MBEDTLS_CIPHER_MODE_CTR */
1120
1121#if defined(MBEDTLS_GCM_C)
1122static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1123 unsigned int key_bitlen )
1124{
1125 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1126 key, key_bitlen );
1127}
1128
1129static const mbedtls_cipher_base_t gcm_aria_info = {
1130 MBEDTLS_CIPHER_ID_ARIA,
1131 NULL,
1132#if defined(MBEDTLS_CIPHER_MODE_CBC)
1133 NULL,
1134#endif
1135#if defined(MBEDTLS_CIPHER_MODE_CFB)
1136 NULL,
1137#endif
1138#if defined(MBEDTLS_CIPHER_MODE_CTR)
1139 NULL,
1140#endif
1141#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1142 NULL,
1143#endif
1144 gcm_aria_setkey_wrap,
1145 gcm_aria_setkey_wrap,
1146 gcm_ctx_alloc,
1147 gcm_ctx_free,
1148};
1149
1150static const mbedtls_cipher_info_t aria_128_gcm_info = {
1151 MBEDTLS_CIPHER_ARIA_128_GCM,
1152 MBEDTLS_MODE_GCM,
1153 128,
1154 "ARIA-128-GCM",
1155 12,
1156 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1157 16,
1158 &gcm_aria_info
1159};
1160
1161static const mbedtls_cipher_info_t aria_192_gcm_info = {
1162 MBEDTLS_CIPHER_ARIA_192_GCM,
1163 MBEDTLS_MODE_GCM,
1164 192,
1165 "ARIA-192-GCM",
1166 12,
1167 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1168 16,
1169 &gcm_aria_info
1170};
1171
1172static const mbedtls_cipher_info_t aria_256_gcm_info = {
1173 MBEDTLS_CIPHER_ARIA_256_GCM,
1174 MBEDTLS_MODE_GCM,
1175 256,
1176 "ARIA-256-GCM",
1177 12,
1178 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1179 16,
1180 &gcm_aria_info
1181};
1182#endif /* MBEDTLS_GCM_C */
1183
1184#if defined(MBEDTLS_CCM_C)
1185static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1186 unsigned int key_bitlen )
1187{
1188 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1189 key, key_bitlen );
1190}
1191
1192static const mbedtls_cipher_base_t ccm_aria_info = {
1193 MBEDTLS_CIPHER_ID_ARIA,
1194 NULL,
1195#if defined(MBEDTLS_CIPHER_MODE_CBC)
1196 NULL,
1197#endif
1198#if defined(MBEDTLS_CIPHER_MODE_CFB)
1199 NULL,
1200#endif
1201#if defined(MBEDTLS_CIPHER_MODE_CTR)
1202 NULL,
1203#endif
1204#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1205 NULL,
1206#endif
1207 ccm_aria_setkey_wrap,
1208 ccm_aria_setkey_wrap,
1209 ccm_ctx_alloc,
1210 ccm_ctx_free,
1211};
1212
1213static const mbedtls_cipher_info_t aria_128_ccm_info = {
1214 MBEDTLS_CIPHER_ARIA_128_CCM,
1215 MBEDTLS_MODE_CCM,
1216 128,
1217 "ARIA-128-CCM",
1218 12,
1219 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1220 16,
1221 &ccm_aria_info
1222};
1223
1224static const mbedtls_cipher_info_t aria_192_ccm_info = {
1225 MBEDTLS_CIPHER_ARIA_192_CCM,
1226 MBEDTLS_MODE_CCM,
1227 192,
1228 "ARIA-192-CCM",
1229 12,
1230 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1231 16,
1232 &ccm_aria_info
1233};
1234
1235static const mbedtls_cipher_info_t aria_256_ccm_info = {
1236 MBEDTLS_CIPHER_ARIA_256_CCM,
1237 MBEDTLS_MODE_CCM,
1238 256,
1239 "ARIA-256-CCM",
1240 12,
1241 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1242 16,
1243 &ccm_aria_info
1244};
1245#endif /* MBEDTLS_CCM_C */
1246
1247#endif /* MBEDTLS_ARIA_C */
1248
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001249#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001251static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001252 const unsigned char *input, unsigned char *output )
1253{
1254 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001255 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001256}
1257
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001258static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001259 const unsigned char *input, unsigned char *output )
1260{
1261 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001262 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001263}
1264
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001265#if defined(MBEDTLS_CIPHER_MODE_CBC)
1266static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001267 unsigned char *iv, const unsigned char *input, unsigned char *output )
1268{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001269 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001270 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001271}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001272#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001274#if defined(MBEDTLS_CIPHER_MODE_CBC)
1275static int des3_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_des3_crypt_cbc( (mbedtls_des3_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
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001283static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001284 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001285{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001286 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001287
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001288 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001289}
1290
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001291static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001292 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001293{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001294 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001295
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001296 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001297}
1298
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001299static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001300 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001301{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001302 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001303
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001304 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001305}
1306
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001307static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001308 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001309{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001310 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001311
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001312 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001313}
1314
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001315static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001316 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001317{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001318 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001319
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001320 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001321}
1322
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001323static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001324 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001325{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001326 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001328 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001329}
1330
1331static void * des_ctx_alloc( void )
1332{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001333 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001334
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001335 if( des == NULL )
1336 return( NULL );
1337
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001338 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001339
1340 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001341}
1342
1343static void des_ctx_free( void *ctx )
1344{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001345 mbedtls_des_free( (mbedtls_des_context *) ctx );
1346 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001347}
1348
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001349static void * des3_ctx_alloc( void )
1350{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001351 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001352 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001353
1354 if( des3 == NULL )
1355 return( NULL );
1356
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001357 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001358
1359 return( des3 );
1360}
1361
Paul Bakker34617722014-06-13 17:20:13 +02001362static void des3_ctx_free( void *ctx )
1363{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001364 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1365 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001366}
1367
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001368static const mbedtls_cipher_base_t des_info = {
1369 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001370 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001371#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001372 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001373#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001374#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001375 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001376#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001377#if defined(MBEDTLS_CIPHER_MODE_OFB)
1378 NULL,
1379#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001380#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001381 NULL,
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_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001384 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001385#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001386 des_setkey_enc_wrap,
1387 des_setkey_dec_wrap,
1388 des_ctx_alloc,
1389 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001390};
1391
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001392static const mbedtls_cipher_info_t des_ecb_info = {
1393 MBEDTLS_CIPHER_DES_ECB,
1394 MBEDTLS_MODE_ECB,
1395 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001396 "DES-ECB",
1397 8,
1398 0,
1399 8,
1400 &des_info
1401};
1402
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001403#if defined(MBEDTLS_CIPHER_MODE_CBC)
1404static const mbedtls_cipher_info_t des_cbc_info = {
1405 MBEDTLS_CIPHER_DES_CBC,
1406 MBEDTLS_MODE_CBC,
1407 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001408 "DES-CBC",
1409 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001410 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001411 8,
1412 &des_info
1413};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001414#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001415
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001416static const mbedtls_cipher_base_t des_ede_info = {
1417 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001418 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001419#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001420 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001421#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001422#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001423 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001424#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001425#if defined(MBEDTLS_CIPHER_MODE_OFB)
1426 NULL,
1427#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001428#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001429 NULL,
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_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001432 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001433#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001434 des3_set2key_enc_wrap,
1435 des3_set2key_dec_wrap,
1436 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001437 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001438};
1439
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001440static const mbedtls_cipher_info_t des_ede_ecb_info = {
1441 MBEDTLS_CIPHER_DES_EDE_ECB,
1442 MBEDTLS_MODE_ECB,
1443 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001444 "DES-EDE-ECB",
1445 8,
1446 0,
1447 8,
1448 &des_ede_info
1449};
1450
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001451#if defined(MBEDTLS_CIPHER_MODE_CBC)
1452static const mbedtls_cipher_info_t des_ede_cbc_info = {
1453 MBEDTLS_CIPHER_DES_EDE_CBC,
1454 MBEDTLS_MODE_CBC,
1455 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001456 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001457 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001458 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001459 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001460 &des_ede_info
1461};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001462#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001463
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001464static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001465 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001466 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001467#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001468 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001469#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001470#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001471 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001472#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001473#if defined(MBEDTLS_CIPHER_MODE_OFB)
1474 NULL,
1475#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001476#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001477 NULL,
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_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001480 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001481#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001482 des3_set3key_enc_wrap,
1483 des3_set3key_dec_wrap,
1484 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001485 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001486};
1487
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001488static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1489 MBEDTLS_CIPHER_DES_EDE3_ECB,
1490 MBEDTLS_MODE_ECB,
1491 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001492 "DES-EDE3-ECB",
1493 8,
1494 0,
1495 8,
1496 &des_ede3_info
1497};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001498#if defined(MBEDTLS_CIPHER_MODE_CBC)
1499static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1500 MBEDTLS_CIPHER_DES_EDE3_CBC,
1501 MBEDTLS_MODE_CBC,
1502 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001503 "DES-EDE3-CBC",
1504 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001505 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001506 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001507 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001508};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509#endif /* MBEDTLS_CIPHER_MODE_CBC */
1510#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001511
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001512#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001513
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001514static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001515 const unsigned char *input, unsigned char *output )
1516{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001517 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001518 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001519}
1520
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001521#if defined(MBEDTLS_CIPHER_MODE_CBC)
1522static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001523 size_t length, unsigned char *iv, const unsigned char *input,
1524 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001525{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001526 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001527 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001528}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001530
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001531#if defined(MBEDTLS_CIPHER_MODE_CFB)
1532static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001533 size_t length, size_t *iv_off, unsigned char *iv,
1534 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001535{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001536 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001537 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001538}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001539#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001540
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001541#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001542static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1543 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001544 const unsigned char *input, unsigned char *output )
1545{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001546 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001547 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001548}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001549#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001550
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001551static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001552 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001553{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001554 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001555}
1556
1557static void * blowfish_ctx_alloc( void )
1558{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001559 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001560 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001561
1562 if( ctx == NULL )
1563 return( NULL );
1564
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001565 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001566
1567 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001568}
1569
1570static void blowfish_ctx_free( void *ctx )
1571{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001572 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1573 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001574}
1575
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001576static const mbedtls_cipher_base_t blowfish_info = {
1577 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001578 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001579#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001580 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001581#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001582#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001583 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001584#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001585#if defined(MBEDTLS_CIPHER_MODE_OFB)
1586 NULL,
1587#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001588#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001589 blowfish_crypt_ctr_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_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001592 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001593#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001594 blowfish_setkey_wrap,
1595 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001596 blowfish_ctx_alloc,
1597 blowfish_ctx_free
1598};
1599
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001600static const mbedtls_cipher_info_t blowfish_ecb_info = {
1601 MBEDTLS_CIPHER_BLOWFISH_ECB,
1602 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001603 128,
1604 "BLOWFISH-ECB",
1605 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001606 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001607 8,
1608 &blowfish_info
1609};
1610
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001611#if defined(MBEDTLS_CIPHER_MODE_CBC)
1612static const mbedtls_cipher_info_t blowfish_cbc_info = {
1613 MBEDTLS_CIPHER_BLOWFISH_CBC,
1614 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001615 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001616 "BLOWFISH-CBC",
1617 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001619 8,
1620 &blowfish_info
1621};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001622#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001623
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001624#if defined(MBEDTLS_CIPHER_MODE_CFB)
1625static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1626 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1627 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001628 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001629 "BLOWFISH-CFB64",
1630 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001631 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001632 8,
1633 &blowfish_info
1634};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001635#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001636
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001637#if defined(MBEDTLS_CIPHER_MODE_CTR)
1638static const mbedtls_cipher_info_t blowfish_ctr_info = {
1639 MBEDTLS_CIPHER_BLOWFISH_CTR,
1640 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001641 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001642 "BLOWFISH-CTR",
1643 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001644 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001645 8,
1646 &blowfish_info
1647};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001648#endif /* MBEDTLS_CIPHER_MODE_CTR */
1649#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001650
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001651#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001652static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1653 const unsigned char *input,
1654 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001655{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001656 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001657}
1658
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001659static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001660 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001661{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001662 /* we get key_bitlen in bits, arc4 expects it in bytes */
1663 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001664 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001665
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001666 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001667 return( 0 );
1668}
1669
1670static void * arc4_ctx_alloc( void )
1671{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001672 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001673 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001674
1675 if( ctx == NULL )
1676 return( NULL );
1677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001678 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001679
1680 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001681}
Paul Bakker68884e32013-01-07 18:20:04 +01001682
1683static void arc4_ctx_free( void *ctx )
1684{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001685 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1686 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001687}
1688
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001689static const mbedtls_cipher_base_t arc4_base_info = {
1690 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001691 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001692#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001693 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001694#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001695#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001696 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001697#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001698#if defined(MBEDTLS_CIPHER_MODE_OFB)
1699 NULL,
1700#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001701#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001702 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_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001705 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001706#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001707 arc4_setkey_wrap,
1708 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001709 arc4_ctx_alloc,
1710 arc4_ctx_free
1711};
1712
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001713static const mbedtls_cipher_info_t arc4_128_info = {
1714 MBEDTLS_CIPHER_ARC4_128,
1715 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001716 128,
1717 "ARC4-128",
1718 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001719 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001720 1,
1721 &arc4_base_info
1722};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001723#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001724
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001725#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001726static int null_crypt_stream( void *ctx, size_t length,
1727 const unsigned char *input,
1728 unsigned char *output )
1729{
1730 ((void) ctx);
1731 memmove( output, input, length );
1732 return( 0 );
1733}
1734
1735static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001736 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001737{
1738 ((void) ctx);
1739 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001740 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001741
1742 return( 0 );
1743}
1744
Paul Bakkerfab5c822012-02-06 16:45:10 +00001745static void * null_ctx_alloc( void )
1746{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001747 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001748}
1749
Paul Bakkerfab5c822012-02-06 16:45:10 +00001750static void null_ctx_free( void *ctx )
1751{
1752 ((void) ctx);
1753}
1754
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001755static const mbedtls_cipher_base_t null_base_info = {
1756 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001757 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001758#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001759 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001760#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001761#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001762 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001763#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001764#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001765 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001766#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001767#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001768 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001769#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001770 null_setkey,
1771 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001772 null_ctx_alloc,
1773 null_ctx_free
1774};
1775
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001776static const mbedtls_cipher_info_t null_cipher_info = {
1777 MBEDTLS_CIPHER_NULL,
1778 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001779 0,
1780 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001781 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001782 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001783 1,
1784 &null_base_info
1785};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001786#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001787
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001788const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001789{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001790#if defined(MBEDTLS_AES_C)
1791 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1792 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1793 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1794#if defined(MBEDTLS_CIPHER_MODE_CBC)
1795 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1796 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1797 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001798#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001799#if defined(MBEDTLS_CIPHER_MODE_CFB)
1800 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1801 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1802 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001803#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001804#if defined(MBEDTLS_CIPHER_MODE_OFB)
1805 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
1806 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
1807 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
1808#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001809#if defined(MBEDTLS_CIPHER_MODE_CTR)
1810 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1811 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1812 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001813#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001814#if defined(MBEDTLS_GCM_C)
1815 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1816 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1817 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001818#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001819#if defined(MBEDTLS_CCM_C)
1820 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1821 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1822 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001823#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001824#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001825
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001826#if defined(MBEDTLS_ARC4_C)
1827 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001828#endif
1829
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001830#if defined(MBEDTLS_BLOWFISH_C)
1831 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1832#if defined(MBEDTLS_CIPHER_MODE_CBC)
1833 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001834#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001835#if defined(MBEDTLS_CIPHER_MODE_CFB)
1836 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001837#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001838#if defined(MBEDTLS_CIPHER_MODE_CTR)
1839 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001840#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001841#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001842
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001843#if defined(MBEDTLS_CAMELLIA_C)
1844 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1845 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1846 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1847#if defined(MBEDTLS_CIPHER_MODE_CBC)
1848 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1849 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1850 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001851#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001852#if defined(MBEDTLS_CIPHER_MODE_CFB)
1853 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1854 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1855 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001856#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001857#if defined(MBEDTLS_CIPHER_MODE_CTR)
1858 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1859 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1860 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001861#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001862#if defined(MBEDTLS_GCM_C)
1863 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1864 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1865 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001866#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001867#if defined(MBEDTLS_CCM_C)
1868 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1869 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1870 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001871#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001872#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001873
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001874#if defined(MBEDTLS_ARIA_C)
1875 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1876 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1877 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1878#if defined(MBEDTLS_CIPHER_MODE_CBC)
1879 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1880 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1881 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1882#endif
1883#if defined(MBEDTLS_CIPHER_MODE_CFB)
1884 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1885 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1886 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1887#endif
1888#if defined(MBEDTLS_CIPHER_MODE_CTR)
1889 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1890 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1891 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1892#endif
1893#if defined(MBEDTLS_GCM_C)
1894 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1895 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1896 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1897#endif
1898#if defined(MBEDTLS_CCM_C)
1899 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1900 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1901 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1902#endif
1903#endif /* MBEDTLS_ARIA_C */
1904
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001905#if defined(MBEDTLS_DES_C)
1906 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1907 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1908 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1909#if defined(MBEDTLS_CIPHER_MODE_CBC)
1910 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1911 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1912 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001913#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001914#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001915
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001916#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1917 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1918#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001919
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001920 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001921};
1922
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001923#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1924int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001925
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001926#endif /* MBEDTLS_CIPHER_C */