blob: 33c71f1073b54853edbc5343af483ce6e7b7b619 [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
Simon Butcher7487c5b2018-04-29 00:24:51 +01001201#if defined(MBEDTLS_CIPHER_MODE_OFB)
1202 NULL,
1203#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001204#if defined(MBEDTLS_CIPHER_MODE_CTR)
1205 NULL,
1206#endif
1207#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1208 NULL,
1209#endif
1210 ccm_aria_setkey_wrap,
1211 ccm_aria_setkey_wrap,
1212 ccm_ctx_alloc,
1213 ccm_ctx_free,
1214};
1215
1216static const mbedtls_cipher_info_t aria_128_ccm_info = {
1217 MBEDTLS_CIPHER_ARIA_128_CCM,
1218 MBEDTLS_MODE_CCM,
1219 128,
1220 "ARIA-128-CCM",
1221 12,
1222 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1223 16,
1224 &ccm_aria_info
1225};
1226
1227static const mbedtls_cipher_info_t aria_192_ccm_info = {
1228 MBEDTLS_CIPHER_ARIA_192_CCM,
1229 MBEDTLS_MODE_CCM,
1230 192,
1231 "ARIA-192-CCM",
1232 12,
1233 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1234 16,
1235 &ccm_aria_info
1236};
1237
1238static const mbedtls_cipher_info_t aria_256_ccm_info = {
1239 MBEDTLS_CIPHER_ARIA_256_CCM,
1240 MBEDTLS_MODE_CCM,
1241 256,
1242 "ARIA-256-CCM",
1243 12,
1244 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1245 16,
1246 &ccm_aria_info
1247};
1248#endif /* MBEDTLS_CCM_C */
1249
1250#endif /* MBEDTLS_ARIA_C */
1251
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001252#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001253
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001254static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001255 const unsigned char *input, unsigned char *output )
1256{
1257 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001258 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001259}
1260
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001261static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001262 const unsigned char *input, unsigned char *output )
1263{
1264 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001265 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001266}
1267
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001268#if defined(MBEDTLS_CIPHER_MODE_CBC)
1269static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001270 unsigned char *iv, const unsigned char *input, unsigned char *output )
1271{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001272 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001273 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001274}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001275#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001277#if defined(MBEDTLS_CIPHER_MODE_CBC)
1278static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001279 unsigned char *iv, const unsigned char *input, unsigned char *output )
1280{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001281 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001282 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001283}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001284#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001285
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001286static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001287 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001288{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001289 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001290
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001291 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001292}
1293
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001294static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001295 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001296{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001297 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001298
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001299 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001300}
1301
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001302static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001303 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001304{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001305 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001306
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001307 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001308}
1309
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001310static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001311 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001312{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001313 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001314
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001315 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001316}
1317
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001318static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001319 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001320{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001321 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001322
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001323 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001324}
1325
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001326static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001327 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001328{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001329 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001330
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001331 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001332}
1333
1334static void * des_ctx_alloc( void )
1335{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001336 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001337
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001338 if( des == NULL )
1339 return( NULL );
1340
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001341 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001342
1343 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001344}
1345
1346static void des_ctx_free( void *ctx )
1347{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001348 mbedtls_des_free( (mbedtls_des_context *) ctx );
1349 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001350}
1351
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001352static void * des3_ctx_alloc( void )
1353{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001354 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001355 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001356
1357 if( des3 == NULL )
1358 return( NULL );
1359
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001360 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001361
1362 return( des3 );
1363}
1364
Paul Bakker34617722014-06-13 17:20:13 +02001365static void des3_ctx_free( void *ctx )
1366{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001367 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1368 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001369}
1370
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001371static const mbedtls_cipher_base_t des_info = {
1372 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001373 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001374#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001375 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001376#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001377#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001378 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001379#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001380#if defined(MBEDTLS_CIPHER_MODE_OFB)
1381 NULL,
1382#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001383#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001384 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001385#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001386#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001387 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001388#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001389 des_setkey_enc_wrap,
1390 des_setkey_dec_wrap,
1391 des_ctx_alloc,
1392 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001393};
1394
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001395static const mbedtls_cipher_info_t des_ecb_info = {
1396 MBEDTLS_CIPHER_DES_ECB,
1397 MBEDTLS_MODE_ECB,
1398 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001399 "DES-ECB",
1400 8,
1401 0,
1402 8,
1403 &des_info
1404};
1405
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001406#if defined(MBEDTLS_CIPHER_MODE_CBC)
1407static const mbedtls_cipher_info_t des_cbc_info = {
1408 MBEDTLS_CIPHER_DES_CBC,
1409 MBEDTLS_MODE_CBC,
1410 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001411 "DES-CBC",
1412 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001413 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001414 8,
1415 &des_info
1416};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001417#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001418
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001419static const mbedtls_cipher_base_t des_ede_info = {
1420 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001421 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001422#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001423 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001424#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001425#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001426 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001427#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001428#if defined(MBEDTLS_CIPHER_MODE_OFB)
1429 NULL,
1430#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001431#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001432 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001433#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001434#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001435 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001436#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001437 des3_set2key_enc_wrap,
1438 des3_set2key_dec_wrap,
1439 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001440 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001441};
1442
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001443static const mbedtls_cipher_info_t des_ede_ecb_info = {
1444 MBEDTLS_CIPHER_DES_EDE_ECB,
1445 MBEDTLS_MODE_ECB,
1446 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001447 "DES-EDE-ECB",
1448 8,
1449 0,
1450 8,
1451 &des_ede_info
1452};
1453
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001454#if defined(MBEDTLS_CIPHER_MODE_CBC)
1455static const mbedtls_cipher_info_t des_ede_cbc_info = {
1456 MBEDTLS_CIPHER_DES_EDE_CBC,
1457 MBEDTLS_MODE_CBC,
1458 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001459 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001460 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001461 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001462 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001463 &des_ede_info
1464};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001465#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001466
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001467static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001468 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001469 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001470#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001471 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001472#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001473#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001474 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001475#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001476#if defined(MBEDTLS_CIPHER_MODE_OFB)
1477 NULL,
1478#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001479#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001480 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001481#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001482#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001483 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001484#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001485 des3_set3key_enc_wrap,
1486 des3_set3key_dec_wrap,
1487 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001488 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001489};
1490
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001491static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1492 MBEDTLS_CIPHER_DES_EDE3_ECB,
1493 MBEDTLS_MODE_ECB,
1494 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001495 "DES-EDE3-ECB",
1496 8,
1497 0,
1498 8,
1499 &des_ede3_info
1500};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001501#if defined(MBEDTLS_CIPHER_MODE_CBC)
1502static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1503 MBEDTLS_CIPHER_DES_EDE3_CBC,
1504 MBEDTLS_MODE_CBC,
1505 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001506 "DES-EDE3-CBC",
1507 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001508 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001509 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001510 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001511};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001512#endif /* MBEDTLS_CIPHER_MODE_CBC */
1513#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001514
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001515#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001516
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001517static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001518 const unsigned char *input, unsigned char *output )
1519{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001520 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001521 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001522}
1523
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001524#if defined(MBEDTLS_CIPHER_MODE_CBC)
1525static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001526 size_t length, unsigned char *iv, const unsigned char *input,
1527 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001528{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001530 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001531}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001532#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001533
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001534#if defined(MBEDTLS_CIPHER_MODE_CFB)
1535static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001536 size_t length, size_t *iv_off, unsigned char *iv,
1537 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001538{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001539 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001540 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001541}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001542#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001543
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001544#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001545static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1546 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001547 const unsigned char *input, unsigned char *output )
1548{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001549 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001550 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001551}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001552#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001553
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001554static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001555 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001556{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001557 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001558}
1559
1560static void * blowfish_ctx_alloc( void )
1561{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001562 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001563 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001564
1565 if( ctx == NULL )
1566 return( NULL );
1567
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001568 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001569
1570 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001571}
1572
1573static void blowfish_ctx_free( void *ctx )
1574{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001575 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1576 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001577}
1578
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001579static const mbedtls_cipher_base_t blowfish_info = {
1580 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001581 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001582#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001583 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001584#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001585#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001586 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001587#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001588#if defined(MBEDTLS_CIPHER_MODE_OFB)
1589 NULL,
1590#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001591#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001592 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001593#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001594#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001595 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001596#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001597 blowfish_setkey_wrap,
1598 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001599 blowfish_ctx_alloc,
1600 blowfish_ctx_free
1601};
1602
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001603static const mbedtls_cipher_info_t blowfish_ecb_info = {
1604 MBEDTLS_CIPHER_BLOWFISH_ECB,
1605 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001606 128,
1607 "BLOWFISH-ECB",
1608 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001609 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001610 8,
1611 &blowfish_info
1612};
1613
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001614#if defined(MBEDTLS_CIPHER_MODE_CBC)
1615static const mbedtls_cipher_info_t blowfish_cbc_info = {
1616 MBEDTLS_CIPHER_BLOWFISH_CBC,
1617 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001618 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001619 "BLOWFISH-CBC",
1620 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001621 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001622 8,
1623 &blowfish_info
1624};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001625#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001626
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001627#if defined(MBEDTLS_CIPHER_MODE_CFB)
1628static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1629 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1630 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001631 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001632 "BLOWFISH-CFB64",
1633 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001634 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001635 8,
1636 &blowfish_info
1637};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001638#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001639
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001640#if defined(MBEDTLS_CIPHER_MODE_CTR)
1641static const mbedtls_cipher_info_t blowfish_ctr_info = {
1642 MBEDTLS_CIPHER_BLOWFISH_CTR,
1643 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001644 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001645 "BLOWFISH-CTR",
1646 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001647 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001648 8,
1649 &blowfish_info
1650};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001651#endif /* MBEDTLS_CIPHER_MODE_CTR */
1652#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001653
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001654#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001655static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1656 const unsigned char *input,
1657 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001658{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001659 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001660}
1661
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001662static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001663 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001664{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001665 /* we get key_bitlen in bits, arc4 expects it in bytes */
1666 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001667 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001668
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001669 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001670 return( 0 );
1671}
1672
1673static void * arc4_ctx_alloc( void )
1674{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001675 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001676 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001677
1678 if( ctx == NULL )
1679 return( NULL );
1680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001681 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001682
1683 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001684}
Paul Bakker68884e32013-01-07 18:20:04 +01001685
1686static void arc4_ctx_free( void *ctx )
1687{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001688 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1689 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001690}
1691
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001692static const mbedtls_cipher_base_t arc4_base_info = {
1693 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001694 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001695#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001696 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001697#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001698#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001699 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001700#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001701#if defined(MBEDTLS_CIPHER_MODE_OFB)
1702 NULL,
1703#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001704#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001705 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001706#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001707#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001708 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001709#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001710 arc4_setkey_wrap,
1711 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001712 arc4_ctx_alloc,
1713 arc4_ctx_free
1714};
1715
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001716static const mbedtls_cipher_info_t arc4_128_info = {
1717 MBEDTLS_CIPHER_ARC4_128,
1718 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001719 128,
1720 "ARC4-128",
1721 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001722 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001723 1,
1724 &arc4_base_info
1725};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001726#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001727
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001728#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001729static int null_crypt_stream( void *ctx, size_t length,
1730 const unsigned char *input,
1731 unsigned char *output )
1732{
1733 ((void) ctx);
1734 memmove( output, input, length );
1735 return( 0 );
1736}
1737
1738static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001739 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001740{
1741 ((void) ctx);
1742 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001743 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001744
1745 return( 0 );
1746}
1747
Paul Bakkerfab5c822012-02-06 16:45:10 +00001748static void * null_ctx_alloc( void )
1749{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001750 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001751}
1752
Paul Bakkerfab5c822012-02-06 16:45:10 +00001753static void null_ctx_free( void *ctx )
1754{
1755 ((void) ctx);
1756}
1757
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001758static const mbedtls_cipher_base_t null_base_info = {
1759 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001760 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001761#if defined(MBEDTLS_CIPHER_MODE_CBC)
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_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001765 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_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001768 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_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001771 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001772#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001773 null_setkey,
1774 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001775 null_ctx_alloc,
1776 null_ctx_free
1777};
1778
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001779static const mbedtls_cipher_info_t null_cipher_info = {
1780 MBEDTLS_CIPHER_NULL,
1781 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001782 0,
1783 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001784 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001785 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001786 1,
1787 &null_base_info
1788};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001789#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001790
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001791const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001792{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001793#if defined(MBEDTLS_AES_C)
1794 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1795 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1796 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1797#if defined(MBEDTLS_CIPHER_MODE_CBC)
1798 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1799 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1800 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001801#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001802#if defined(MBEDTLS_CIPHER_MODE_CFB)
1803 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1804 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1805 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001806#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001807#if defined(MBEDTLS_CIPHER_MODE_OFB)
1808 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
1809 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
1810 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
1811#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001812#if defined(MBEDTLS_CIPHER_MODE_CTR)
1813 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1814 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1815 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001816#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001817#if defined(MBEDTLS_GCM_C)
1818 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1819 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1820 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001821#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001822#if defined(MBEDTLS_CCM_C)
1823 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1824 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1825 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001826#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001827#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001828
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001829#if defined(MBEDTLS_ARC4_C)
1830 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001831#endif
1832
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833#if defined(MBEDTLS_BLOWFISH_C)
1834 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1835#if defined(MBEDTLS_CIPHER_MODE_CBC)
1836 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_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_CFB)
1839 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001840#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001841#if defined(MBEDTLS_CIPHER_MODE_CTR)
1842 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001843#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001844#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001845
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001846#if defined(MBEDTLS_CAMELLIA_C)
1847 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1848 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1849 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1850#if defined(MBEDTLS_CIPHER_MODE_CBC)
1851 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1852 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1853 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001854#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001855#if defined(MBEDTLS_CIPHER_MODE_CFB)
1856 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1857 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1858 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001859#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001860#if defined(MBEDTLS_CIPHER_MODE_CTR)
1861 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1862 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1863 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001864#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001865#if defined(MBEDTLS_GCM_C)
1866 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1867 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1868 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001869#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001870#if defined(MBEDTLS_CCM_C)
1871 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1872 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1873 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001874#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001875#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001876
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001877#if defined(MBEDTLS_ARIA_C)
1878 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1879 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1880 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1881#if defined(MBEDTLS_CIPHER_MODE_CBC)
1882 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1883 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1884 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1885#endif
1886#if defined(MBEDTLS_CIPHER_MODE_CFB)
1887 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1888 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1889 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1890#endif
1891#if defined(MBEDTLS_CIPHER_MODE_CTR)
1892 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1893 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1894 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1895#endif
1896#if defined(MBEDTLS_GCM_C)
1897 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1898 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1899 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1900#endif
1901#if defined(MBEDTLS_CCM_C)
1902 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1903 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1904 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1905#endif
1906#endif /* MBEDTLS_ARIA_C */
1907
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001908#if defined(MBEDTLS_DES_C)
1909 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1910 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1911 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1912#if defined(MBEDTLS_CIPHER_MODE_CBC)
1913 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1914 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1915 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001916#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001917#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001918
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001919#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1920 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1921#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001922
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001923 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001924};
1925
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001926#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1927int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001928
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001929#endif /* MBEDTLS_CIPHER_C */