blob: 790adb37343e1886cc818ccaf818d5bd7df71d1d [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief Generic cipher wrapper for mbed TLS
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker8123e9d2011-01-06 15:37:30 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000024 */
25
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000033
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020034#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020036#if defined(MBEDTLS_CHACHAPOLY_C)
37#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020046#endif
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000050#endif
51
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000052#if defined(MBEDTLS_ARIA_C)
53#include "mbedtls/aria.h"
54#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000058#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000059
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000062#endif
63
Daniel Kingbd920622016-05-15 19:56:20 -030064#if defined(MBEDTLS_CHACHA20_C)
65#include "mbedtls/chacha20.h"
66#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020070#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020074#endif
75
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000077#include <string.h>
78#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000081#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020082#else
Rich Evans00ab4702015-02-06 13:43:58 +000083#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020084#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020086#endif
87
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020089/* shared by all GCM ciphers */
90static void *gcm_ctx_alloc( void )
91{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020092 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
93
94 if( ctx != NULL )
95 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
96
97 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020098}
99
100static void gcm_ctx_free( void *ctx )
101{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102 mbedtls_gcm_free( ctx );
103 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200104}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200108/* shared by all CCM ciphers */
109static void *ccm_ctx_alloc( void )
110{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200111 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
112
113 if( ctx != NULL )
114 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
115
116 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200117}
118
119static void ccm_ctx_free( void *ctx )
120{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121 mbedtls_ccm_free( ctx );
122 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200123}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000127
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200129 const unsigned char *input, unsigned char *output )
130{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200132}
133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#if defined(MBEDTLS_CIPHER_MODE_CBC)
135static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000136 unsigned char *iv, const unsigned char *input, unsigned char *output )
137{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200138 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200139 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000140}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000142
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#if defined(MBEDTLS_CIPHER_MODE_CFB)
144static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200145 size_t length, size_t *iv_off, unsigned char *iv,
146 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000147{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200149 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000150}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200154static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
155 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000156 const unsigned char *input, unsigned char *output )
157{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000159 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000160}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000162
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200163static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200164 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000165{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200166 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000167}
168
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200169static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200170 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000171{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200172 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000173}
174
175static void * aes_ctx_alloc( void )
176{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200177 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200178
179 if( aes == NULL )
180 return( NULL );
181
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200182 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200183
184 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000185}
186
187static void aes_ctx_free( void *ctx )
188{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
190 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000191}
192
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200193static const mbedtls_cipher_base_t aes_info = {
194 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200195 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200196#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000197 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100198#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200199#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000200 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100201#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200202#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000203 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100204#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200206 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100207#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000208 aes_setkey_enc_wrap,
209 aes_setkey_dec_wrap,
210 aes_ctx_alloc,
211 aes_ctx_free
212};
213
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200214static const mbedtls_cipher_info_t aes_128_ecb_info = {
215 MBEDTLS_CIPHER_AES_128_ECB,
216 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200217 128,
218 "AES-128-ECB",
219 16,
220 0,
221 16,
222 &aes_info
223};
224
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200225static const mbedtls_cipher_info_t aes_192_ecb_info = {
226 MBEDTLS_CIPHER_AES_192_ECB,
227 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200228 192,
229 "AES-192-ECB",
230 16,
231 0,
232 16,
233 &aes_info
234};
235
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200236static const mbedtls_cipher_info_t aes_256_ecb_info = {
237 MBEDTLS_CIPHER_AES_256_ECB,
238 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200239 256,
240 "AES-256-ECB",
241 16,
242 0,
243 16,
244 &aes_info
245};
246
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200247#if defined(MBEDTLS_CIPHER_MODE_CBC)
248static const mbedtls_cipher_info_t aes_128_cbc_info = {
249 MBEDTLS_CIPHER_AES_128_CBC,
250 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000251 128,
252 "AES-128-CBC",
253 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200254 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000255 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000256 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000257};
258
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259static const mbedtls_cipher_info_t aes_192_cbc_info = {
260 MBEDTLS_CIPHER_AES_192_CBC,
261 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000262 192,
263 "AES-192-CBC",
264 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200265 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000266 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000267 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000268};
269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200270static const mbedtls_cipher_info_t aes_256_cbc_info = {
271 MBEDTLS_CIPHER_AES_256_CBC,
272 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000273 256,
274 "AES-256-CBC",
275 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200276 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000277 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000278 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000279};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200280#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282#if defined(MBEDTLS_CIPHER_MODE_CFB)
283static const mbedtls_cipher_info_t aes_128_cfb128_info = {
284 MBEDTLS_CIPHER_AES_128_CFB128,
285 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000286 128,
287 "AES-128-CFB128",
288 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200289 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000290 16,
291 &aes_info
292};
293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294static const mbedtls_cipher_info_t aes_192_cfb128_info = {
295 MBEDTLS_CIPHER_AES_192_CFB128,
296 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000297 192,
298 "AES-192-CFB128",
299 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200300 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000301 16,
302 &aes_info
303};
304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305static const mbedtls_cipher_info_t aes_256_cfb128_info = {
306 MBEDTLS_CIPHER_AES_256_CFB128,
307 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000308 256,
309 "AES-256-CFB128",
310 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200311 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000312 16,
313 &aes_info
314};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200315#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000316
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200317#if defined(MBEDTLS_CIPHER_MODE_CTR)
318static const mbedtls_cipher_info_t aes_128_ctr_info = {
319 MBEDTLS_CIPHER_AES_128_CTR,
320 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000321 128,
322 "AES-128-CTR",
323 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200324 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000325 16,
326 &aes_info
327};
328
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200329static const mbedtls_cipher_info_t aes_192_ctr_info = {
330 MBEDTLS_CIPHER_AES_192_CTR,
331 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000332 192,
333 "AES-192-CTR",
334 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200335 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000336 16,
337 &aes_info
338};
339
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200340static const mbedtls_cipher_info_t aes_256_ctr_info = {
341 MBEDTLS_CIPHER_AES_256_CTR,
342 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000343 256,
344 "AES-256-CTR",
345 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200346 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000347 16,
348 &aes_info
349};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200350#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000351
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200353static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200354 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200355{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200356 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200357 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200358}
359
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200360static const mbedtls_cipher_base_t gcm_aes_info = {
361 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200362 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200363#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200364 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100365#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200366#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200367 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100368#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200369#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200370 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100371#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200372#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200373 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100374#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200375 gcm_aes_setkey_wrap,
376 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200377 gcm_ctx_alloc,
378 gcm_ctx_free,
379};
380
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200381static const mbedtls_cipher_info_t aes_128_gcm_info = {
382 MBEDTLS_CIPHER_AES_128_GCM,
383 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100384 128,
385 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200386 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200387 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100388 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200389 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100390};
391
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200392static const mbedtls_cipher_info_t aes_192_gcm_info = {
393 MBEDTLS_CIPHER_AES_192_GCM,
394 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200395 192,
396 "AES-192-GCM",
397 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200398 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200399 16,
400 &gcm_aes_info
401};
402
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200403static const mbedtls_cipher_info_t aes_256_gcm_info = {
404 MBEDTLS_CIPHER_AES_256_GCM,
405 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100406 256,
407 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200408 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200409 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100410 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200411 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100412};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200413#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200416static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200417 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200418{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200419 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200420 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200421}
422
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200423static const mbedtls_cipher_base_t ccm_aes_info = {
424 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200425 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200426#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200427 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100428#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200429#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200430 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100431#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200432#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200433 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100434#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200435#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200436 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100437#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200438 ccm_aes_setkey_wrap,
439 ccm_aes_setkey_wrap,
440 ccm_ctx_alloc,
441 ccm_ctx_free,
442};
443
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200444static const mbedtls_cipher_info_t aes_128_ccm_info = {
445 MBEDTLS_CIPHER_AES_128_CCM,
446 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200447 128,
448 "AES-128-CCM",
449 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200450 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200451 16,
452 &ccm_aes_info
453};
454
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200455static const mbedtls_cipher_info_t aes_192_ccm_info = {
456 MBEDTLS_CIPHER_AES_192_CCM,
457 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200458 192,
459 "AES-192-CCM",
460 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200461 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200462 16,
463 &ccm_aes_info
464};
465
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200466static const mbedtls_cipher_info_t aes_256_ccm_info = {
467 MBEDTLS_CIPHER_AES_256_CCM,
468 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200469 256,
470 "AES-256-CCM",
471 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200472 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200473 16,
474 &ccm_aes_info
475};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200476#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200477
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200478#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000479
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200480#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000481
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200482static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200483 const unsigned char *input, unsigned char *output )
484{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200485 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200486 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200487}
488
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200489#if defined(MBEDTLS_CIPHER_MODE_CBC)
490static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200491 size_t length, unsigned char *iv,
492 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000493{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200494 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200495 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000496}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200497#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000498
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200499#if defined(MBEDTLS_CIPHER_MODE_CFB)
500static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200501 size_t length, size_t *iv_off, unsigned char *iv,
502 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000503{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200504 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200505 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000506}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200507#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000508
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200509#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200510static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
511 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000512 const unsigned char *input, unsigned char *output )
513{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200515 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000516}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200517#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000518
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200519static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200520 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000521{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200522 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000523}
524
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200525static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200526 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000527{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200528 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000529}
530
531static void * camellia_ctx_alloc( void )
532{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200533 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200534 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200535
536 if( ctx == NULL )
537 return( NULL );
538
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200539 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200540
541 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000542}
543
544static void camellia_ctx_free( void *ctx )
545{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200546 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
547 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000548}
549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200550static const mbedtls_cipher_base_t camellia_info = {
551 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200552 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200553#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000554 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100555#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000557 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100558#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200559#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000560 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100561#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200563 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100564#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000565 camellia_setkey_enc_wrap,
566 camellia_setkey_dec_wrap,
567 camellia_ctx_alloc,
568 camellia_ctx_free
569};
570
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200571static const mbedtls_cipher_info_t camellia_128_ecb_info = {
572 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
573 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200574 128,
575 "CAMELLIA-128-ECB",
576 16,
577 0,
578 16,
579 &camellia_info
580};
581
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200582static const mbedtls_cipher_info_t camellia_192_ecb_info = {
583 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
584 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200585 192,
586 "CAMELLIA-192-ECB",
587 16,
588 0,
589 16,
590 &camellia_info
591};
592
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200593static const mbedtls_cipher_info_t camellia_256_ecb_info = {
594 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
595 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200596 256,
597 "CAMELLIA-256-ECB",
598 16,
599 0,
600 16,
601 &camellia_info
602};
603
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200604#if defined(MBEDTLS_CIPHER_MODE_CBC)
605static const mbedtls_cipher_info_t camellia_128_cbc_info = {
606 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
607 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000608 128,
609 "CAMELLIA-128-CBC",
610 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200611 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000612 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000613 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000614};
615
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200616static const mbedtls_cipher_info_t camellia_192_cbc_info = {
617 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
618 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000619 192,
620 "CAMELLIA-192-CBC",
621 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200622 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000623 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000624 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000625};
626
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200627static const mbedtls_cipher_info_t camellia_256_cbc_info = {
628 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
629 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000630 256,
631 "CAMELLIA-256-CBC",
632 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200633 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000634 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000635 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000636};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200637#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000638
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200639#if defined(MBEDTLS_CIPHER_MODE_CFB)
640static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
641 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
642 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000643 128,
644 "CAMELLIA-128-CFB128",
645 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200646 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000647 16,
648 &camellia_info
649};
650
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200651static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
652 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
653 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000654 192,
655 "CAMELLIA-192-CFB128",
656 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200657 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000658 16,
659 &camellia_info
660};
661
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200662static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
663 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
664 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000665 256,
666 "CAMELLIA-256-CFB128",
667 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200668 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000669 16,
670 &camellia_info
671};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000673
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674#if defined(MBEDTLS_CIPHER_MODE_CTR)
675static const mbedtls_cipher_info_t camellia_128_ctr_info = {
676 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
677 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000678 128,
679 "CAMELLIA-128-CTR",
680 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200681 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000682 16,
683 &camellia_info
684};
685
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200686static const mbedtls_cipher_info_t camellia_192_ctr_info = {
687 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
688 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000689 192,
690 "CAMELLIA-192-CTR",
691 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200692 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000693 16,
694 &camellia_info
695};
696
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200697static const mbedtls_cipher_info_t camellia_256_ctr_info = {
698 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
699 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000700 256,
701 "CAMELLIA-256-CTR",
702 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200703 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000704 16,
705 &camellia_info
706};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000708
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200709#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200710static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200711 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200712{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200713 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200714 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200715}
716
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200717static const mbedtls_cipher_base_t gcm_camellia_info = {
718 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200719 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200720#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200721 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100722#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200723#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200724 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100725#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200726#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200727 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100728#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200729#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200730 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100731#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200732 gcm_camellia_setkey_wrap,
733 gcm_camellia_setkey_wrap,
734 gcm_ctx_alloc,
735 gcm_ctx_free,
736};
737
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200738static const mbedtls_cipher_info_t camellia_128_gcm_info = {
739 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
740 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200741 128,
742 "CAMELLIA-128-GCM",
743 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200744 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200745 16,
746 &gcm_camellia_info
747};
748
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200749static const mbedtls_cipher_info_t camellia_192_gcm_info = {
750 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
751 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200752 192,
753 "CAMELLIA-192-GCM",
754 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200756 16,
757 &gcm_camellia_info
758};
759
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200760static const mbedtls_cipher_info_t camellia_256_gcm_info = {
761 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
762 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200763 256,
764 "CAMELLIA-256-GCM",
765 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200766 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200767 16,
768 &gcm_camellia_info
769};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200770#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200771
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200772#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200773static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200774 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200775{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200776 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200777 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200778}
779
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200780static const mbedtls_cipher_base_t ccm_camellia_info = {
781 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200782 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200783#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200784 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100785#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200786#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200787 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100788#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200789#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200790 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100791#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200792#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200793 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100794#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200795 ccm_camellia_setkey_wrap,
796 ccm_camellia_setkey_wrap,
797 ccm_ctx_alloc,
798 ccm_ctx_free,
799};
800
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200801static const mbedtls_cipher_info_t camellia_128_ccm_info = {
802 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
803 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200804 128,
805 "CAMELLIA-128-CCM",
806 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200807 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200808 16,
809 &ccm_camellia_info
810};
811
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200812static const mbedtls_cipher_info_t camellia_192_ccm_info = {
813 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
814 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200815 192,
816 "CAMELLIA-192-CCM",
817 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200818 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200819 16,
820 &ccm_camellia_info
821};
822
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200823static const mbedtls_cipher_info_t camellia_256_ccm_info = {
824 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
825 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200826 256,
827 "CAMELLIA-256-CCM",
828 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200829 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200830 16,
831 &ccm_camellia_info
832};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200833#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200834
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200835#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000836
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000837#if defined(MBEDTLS_ARIA_C)
838
839static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
840 const unsigned char *input, unsigned char *output )
841{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200842 (void) operation;
843 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000844 output );
845}
846
847#if defined(MBEDTLS_CIPHER_MODE_CBC)
848static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
849 size_t length, unsigned char *iv,
850 const unsigned char *input, unsigned char *output )
851{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +0200852 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000853 input, output );
854}
855#endif /* MBEDTLS_CIPHER_MODE_CBC */
856
857#if defined(MBEDTLS_CIPHER_MODE_CFB)
858static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
859 size_t length, size_t *iv_off, unsigned char *iv,
860 const unsigned char *input, unsigned char *output )
861{
862 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
863 iv_off, iv, input, output );
864}
865#endif /* MBEDTLS_CIPHER_MODE_CFB */
866
867#if defined(MBEDTLS_CIPHER_MODE_CTR)
868static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
869 unsigned char *nonce_counter, unsigned char *stream_block,
870 const unsigned char *input, unsigned char *output )
871{
872 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
873 nonce_counter, stream_block, input, output );
874}
875#endif /* MBEDTLS_CIPHER_MODE_CTR */
876
877static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
878 unsigned int key_bitlen )
879{
880 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
881}
882
883static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
884 unsigned int key_bitlen )
885{
886 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
887}
888
889static void * aria_ctx_alloc( void )
890{
891 mbedtls_aria_context *ctx;
892 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
893
894 if( ctx == NULL )
895 return( NULL );
896
897 mbedtls_aria_init( ctx );
898
899 return( ctx );
900}
901
902static void aria_ctx_free( void *ctx )
903{
904 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
905 mbedtls_free( ctx );
906}
907
908static const mbedtls_cipher_base_t aria_info = {
909 MBEDTLS_CIPHER_ID_ARIA,
910 aria_crypt_ecb_wrap,
911#if defined(MBEDTLS_CIPHER_MODE_CBC)
912 aria_crypt_cbc_wrap,
913#endif
914#if defined(MBEDTLS_CIPHER_MODE_CFB)
915 aria_crypt_cfb128_wrap,
916#endif
917#if defined(MBEDTLS_CIPHER_MODE_CTR)
918 aria_crypt_ctr_wrap,
919#endif
920#if defined(MBEDTLS_CIPHER_MODE_STREAM)
921 NULL,
922#endif
923 aria_setkey_enc_wrap,
924 aria_setkey_dec_wrap,
925 aria_ctx_alloc,
926 aria_ctx_free
927};
928
929static const mbedtls_cipher_info_t aria_128_ecb_info = {
930 MBEDTLS_CIPHER_ARIA_128_ECB,
931 MBEDTLS_MODE_ECB,
932 128,
933 "ARIA-128-ECB",
934 16,
935 0,
936 16,
937 &aria_info
938};
939
940static const mbedtls_cipher_info_t aria_192_ecb_info = {
941 MBEDTLS_CIPHER_ARIA_192_ECB,
942 MBEDTLS_MODE_ECB,
943 192,
944 "ARIA-192-ECB",
945 16,
946 0,
947 16,
948 &aria_info
949};
950
951static const mbedtls_cipher_info_t aria_256_ecb_info = {
952 MBEDTLS_CIPHER_ARIA_256_ECB,
953 MBEDTLS_MODE_ECB,
954 256,
955 "ARIA-256-ECB",
956 16,
957 0,
958 16,
959 &aria_info
960};
961
962#if defined(MBEDTLS_CIPHER_MODE_CBC)
963static const mbedtls_cipher_info_t aria_128_cbc_info = {
964 MBEDTLS_CIPHER_ARIA_128_CBC,
965 MBEDTLS_MODE_CBC,
966 128,
967 "ARIA-128-CBC",
968 16,
969 0,
970 16,
971 &aria_info
972};
973
974static const mbedtls_cipher_info_t aria_192_cbc_info = {
975 MBEDTLS_CIPHER_ARIA_192_CBC,
976 MBEDTLS_MODE_CBC,
977 192,
978 "ARIA-192-CBC",
979 16,
980 0,
981 16,
982 &aria_info
983};
984
985static const mbedtls_cipher_info_t aria_256_cbc_info = {
986 MBEDTLS_CIPHER_ARIA_256_CBC,
987 MBEDTLS_MODE_CBC,
988 256,
989 "ARIA-256-CBC",
990 16,
991 0,
992 16,
993 &aria_info
994};
995#endif /* MBEDTLS_CIPHER_MODE_CBC */
996
997#if defined(MBEDTLS_CIPHER_MODE_CFB)
998static const mbedtls_cipher_info_t aria_128_cfb128_info = {
999 MBEDTLS_CIPHER_ARIA_128_CFB128,
1000 MBEDTLS_MODE_CFB,
1001 128,
1002 "ARIA-128-CFB128",
1003 16,
1004 0,
1005 16,
1006 &aria_info
1007};
1008
1009static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1010 MBEDTLS_CIPHER_ARIA_192_CFB128,
1011 MBEDTLS_MODE_CFB,
1012 192,
1013 "ARIA-192-CFB128",
1014 16,
1015 0,
1016 16,
1017 &aria_info
1018};
1019
1020static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1021 MBEDTLS_CIPHER_ARIA_256_CFB128,
1022 MBEDTLS_MODE_CFB,
1023 256,
1024 "ARIA-256-CFB128",
1025 16,
1026 0,
1027 16,
1028 &aria_info
1029};
1030#endif /* MBEDTLS_CIPHER_MODE_CFB */
1031
1032#if defined(MBEDTLS_CIPHER_MODE_CTR)
1033static const mbedtls_cipher_info_t aria_128_ctr_info = {
1034 MBEDTLS_CIPHER_ARIA_128_CTR,
1035 MBEDTLS_MODE_CTR,
1036 128,
1037 "ARIA-128-CTR",
1038 16,
1039 0,
1040 16,
1041 &aria_info
1042};
1043
1044static const mbedtls_cipher_info_t aria_192_ctr_info = {
1045 MBEDTLS_CIPHER_ARIA_192_CTR,
1046 MBEDTLS_MODE_CTR,
1047 192,
1048 "ARIA-192-CTR",
1049 16,
1050 0,
1051 16,
1052 &aria_info
1053};
1054
1055static const mbedtls_cipher_info_t aria_256_ctr_info = {
1056 MBEDTLS_CIPHER_ARIA_256_CTR,
1057 MBEDTLS_MODE_CTR,
1058 256,
1059 "ARIA-256-CTR",
1060 16,
1061 0,
1062 16,
1063 &aria_info
1064};
1065#endif /* MBEDTLS_CIPHER_MODE_CTR */
1066
1067#if defined(MBEDTLS_GCM_C)
1068static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1069 unsigned int key_bitlen )
1070{
1071 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1072 key, key_bitlen );
1073}
1074
1075static const mbedtls_cipher_base_t gcm_aria_info = {
1076 MBEDTLS_CIPHER_ID_ARIA,
1077 NULL,
1078#if defined(MBEDTLS_CIPHER_MODE_CBC)
1079 NULL,
1080#endif
1081#if defined(MBEDTLS_CIPHER_MODE_CFB)
1082 NULL,
1083#endif
1084#if defined(MBEDTLS_CIPHER_MODE_CTR)
1085 NULL,
1086#endif
1087#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1088 NULL,
1089#endif
1090 gcm_aria_setkey_wrap,
1091 gcm_aria_setkey_wrap,
1092 gcm_ctx_alloc,
1093 gcm_ctx_free,
1094};
1095
1096static const mbedtls_cipher_info_t aria_128_gcm_info = {
1097 MBEDTLS_CIPHER_ARIA_128_GCM,
1098 MBEDTLS_MODE_GCM,
1099 128,
1100 "ARIA-128-GCM",
1101 12,
1102 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1103 16,
1104 &gcm_aria_info
1105};
1106
1107static const mbedtls_cipher_info_t aria_192_gcm_info = {
1108 MBEDTLS_CIPHER_ARIA_192_GCM,
1109 MBEDTLS_MODE_GCM,
1110 192,
1111 "ARIA-192-GCM",
1112 12,
1113 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1114 16,
1115 &gcm_aria_info
1116};
1117
1118static const mbedtls_cipher_info_t aria_256_gcm_info = {
1119 MBEDTLS_CIPHER_ARIA_256_GCM,
1120 MBEDTLS_MODE_GCM,
1121 256,
1122 "ARIA-256-GCM",
1123 12,
1124 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1125 16,
1126 &gcm_aria_info
1127};
1128#endif /* MBEDTLS_GCM_C */
1129
1130#if defined(MBEDTLS_CCM_C)
1131static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1132 unsigned int key_bitlen )
1133{
1134 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1135 key, key_bitlen );
1136}
1137
1138static const mbedtls_cipher_base_t ccm_aria_info = {
1139 MBEDTLS_CIPHER_ID_ARIA,
1140 NULL,
1141#if defined(MBEDTLS_CIPHER_MODE_CBC)
1142 NULL,
1143#endif
1144#if defined(MBEDTLS_CIPHER_MODE_CFB)
1145 NULL,
1146#endif
1147#if defined(MBEDTLS_CIPHER_MODE_CTR)
1148 NULL,
1149#endif
1150#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1151 NULL,
1152#endif
1153 ccm_aria_setkey_wrap,
1154 ccm_aria_setkey_wrap,
1155 ccm_ctx_alloc,
1156 ccm_ctx_free,
1157};
1158
1159static const mbedtls_cipher_info_t aria_128_ccm_info = {
1160 MBEDTLS_CIPHER_ARIA_128_CCM,
1161 MBEDTLS_MODE_CCM,
1162 128,
1163 "ARIA-128-CCM",
1164 12,
1165 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1166 16,
1167 &ccm_aria_info
1168};
1169
1170static const mbedtls_cipher_info_t aria_192_ccm_info = {
1171 MBEDTLS_CIPHER_ARIA_192_CCM,
1172 MBEDTLS_MODE_CCM,
1173 192,
1174 "ARIA-192-CCM",
1175 12,
1176 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1177 16,
1178 &ccm_aria_info
1179};
1180
1181static const mbedtls_cipher_info_t aria_256_ccm_info = {
1182 MBEDTLS_CIPHER_ARIA_256_CCM,
1183 MBEDTLS_MODE_CCM,
1184 256,
1185 "ARIA-256-CCM",
1186 12,
1187 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1188 16,
1189 &ccm_aria_info
1190};
1191#endif /* MBEDTLS_CCM_C */
1192
1193#endif /* MBEDTLS_ARIA_C */
1194
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001195#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001196
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001197static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001198 const unsigned char *input, unsigned char *output )
1199{
1200 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001201 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001202}
1203
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001204static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001205 const unsigned char *input, unsigned char *output )
1206{
1207 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001208 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001209}
1210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001211#if defined(MBEDTLS_CIPHER_MODE_CBC)
1212static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001213 unsigned char *iv, const unsigned char *input, unsigned char *output )
1214{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001215 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001216 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001217}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001218#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001219
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001220#if defined(MBEDTLS_CIPHER_MODE_CBC)
1221static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001222 unsigned char *iv, const unsigned char *input, unsigned char *output )
1223{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001224 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001225 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001226}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001227#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001228
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001229static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001230 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001231{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001232 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001233
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001234 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001235}
1236
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001237static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001238 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001239{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001240 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001241
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001242 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001243}
1244
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001245static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001246 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001247{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001248 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001249
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001250 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001251}
1252
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001253static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001254 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001255{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001256 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001257
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001258 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001259}
1260
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001261static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001262 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001263{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001264 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001266 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001267}
1268
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001269static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001270 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001271{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001272 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001274 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001275}
1276
1277static void * des_ctx_alloc( void )
1278{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001279 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001280
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001281 if( des == NULL )
1282 return( NULL );
1283
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001284 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001285
1286 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001287}
1288
1289static void des_ctx_free( void *ctx )
1290{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001291 mbedtls_des_free( (mbedtls_des_context *) ctx );
1292 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001293}
1294
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001295static void * des3_ctx_alloc( void )
1296{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001297 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001298 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001299
1300 if( des3 == NULL )
1301 return( NULL );
1302
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001303 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001304
1305 return( des3 );
1306}
1307
Paul Bakker34617722014-06-13 17:20:13 +02001308static void des3_ctx_free( void *ctx )
1309{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001310 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1311 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001312}
1313
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001314static const mbedtls_cipher_base_t des_info = {
1315 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001316 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001317#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001318 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001319#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001320#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001321 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001322#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001323#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001324 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001325#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001326#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001327 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001328#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001329 des_setkey_enc_wrap,
1330 des_setkey_dec_wrap,
1331 des_ctx_alloc,
1332 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001333};
1334
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001335static const mbedtls_cipher_info_t des_ecb_info = {
1336 MBEDTLS_CIPHER_DES_ECB,
1337 MBEDTLS_MODE_ECB,
1338 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001339 "DES-ECB",
1340 8,
1341 0,
1342 8,
1343 &des_info
1344};
1345
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001346#if defined(MBEDTLS_CIPHER_MODE_CBC)
1347static const mbedtls_cipher_info_t des_cbc_info = {
1348 MBEDTLS_CIPHER_DES_CBC,
1349 MBEDTLS_MODE_CBC,
1350 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001351 "DES-CBC",
1352 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001353 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001354 8,
1355 &des_info
1356};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001357#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001358
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001359static const mbedtls_cipher_base_t des_ede_info = {
1360 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001361 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001362#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001363 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001364#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001365#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001366 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001367#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001368#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001369 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001370#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001371#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001372 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001373#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001374 des3_set2key_enc_wrap,
1375 des3_set2key_dec_wrap,
1376 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001377 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001378};
1379
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001380static const mbedtls_cipher_info_t des_ede_ecb_info = {
1381 MBEDTLS_CIPHER_DES_EDE_ECB,
1382 MBEDTLS_MODE_ECB,
1383 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001384 "DES-EDE-ECB",
1385 8,
1386 0,
1387 8,
1388 &des_ede_info
1389};
1390
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001391#if defined(MBEDTLS_CIPHER_MODE_CBC)
1392static const mbedtls_cipher_info_t des_ede_cbc_info = {
1393 MBEDTLS_CIPHER_DES_EDE_CBC,
1394 MBEDTLS_MODE_CBC,
1395 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001396 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001397 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001398 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001399 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001400 &des_ede_info
1401};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001402#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001403
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001404static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001405 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001406 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001407#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001408 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001409#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001410#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001411 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001412#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001413#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001414 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001415#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001416#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001417 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001418#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001419 des3_set3key_enc_wrap,
1420 des3_set3key_dec_wrap,
1421 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001422 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001423};
1424
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001425static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1426 MBEDTLS_CIPHER_DES_EDE3_ECB,
1427 MBEDTLS_MODE_ECB,
1428 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001429 "DES-EDE3-ECB",
1430 8,
1431 0,
1432 8,
1433 &des_ede3_info
1434};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001435#if defined(MBEDTLS_CIPHER_MODE_CBC)
1436static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1437 MBEDTLS_CIPHER_DES_EDE3_CBC,
1438 MBEDTLS_MODE_CBC,
1439 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001440 "DES-EDE3-CBC",
1441 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001442 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001443 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001444 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001445};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001446#endif /* MBEDTLS_CIPHER_MODE_CBC */
1447#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001448
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001449#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001450
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001451static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001452 const unsigned char *input, unsigned char *output )
1453{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001454 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001455 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001456}
1457
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001458#if defined(MBEDTLS_CIPHER_MODE_CBC)
1459static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001460 size_t length, unsigned char *iv, const unsigned char *input,
1461 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001462{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001463 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001464 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001465}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001466#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001467
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001468#if defined(MBEDTLS_CIPHER_MODE_CFB)
1469static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001470 size_t length, size_t *iv_off, unsigned char *iv,
1471 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001472{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001473 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001474 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001475}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001476#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001477
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001478#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001479static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1480 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001481 const unsigned char *input, unsigned char *output )
1482{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001483 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001484 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001485}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001486#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001487
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001488static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001489 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001490{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001491 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001492}
1493
1494static void * blowfish_ctx_alloc( void )
1495{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001496 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001497 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001498
1499 if( ctx == NULL )
1500 return( NULL );
1501
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001502 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001503
1504 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001505}
1506
1507static void blowfish_ctx_free( void *ctx )
1508{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1510 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001511}
1512
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001513static const mbedtls_cipher_base_t blowfish_info = {
1514 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001515 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001516#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001517 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001518#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001519#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001520 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001521#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001522#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001523 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001524#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001525#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001526 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001527#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001528 blowfish_setkey_wrap,
1529 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001530 blowfish_ctx_alloc,
1531 blowfish_ctx_free
1532};
1533
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001534static const mbedtls_cipher_info_t blowfish_ecb_info = {
1535 MBEDTLS_CIPHER_BLOWFISH_ECB,
1536 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001537 128,
1538 "BLOWFISH-ECB",
1539 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001540 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001541 8,
1542 &blowfish_info
1543};
1544
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001545#if defined(MBEDTLS_CIPHER_MODE_CBC)
1546static const mbedtls_cipher_info_t blowfish_cbc_info = {
1547 MBEDTLS_CIPHER_BLOWFISH_CBC,
1548 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001549 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001550 "BLOWFISH-CBC",
1551 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001552 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001553 8,
1554 &blowfish_info
1555};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001556#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001557
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001558#if defined(MBEDTLS_CIPHER_MODE_CFB)
1559static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1560 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1561 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001562 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001563 "BLOWFISH-CFB64",
1564 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001565 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001566 8,
1567 &blowfish_info
1568};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001569#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001570
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001571#if defined(MBEDTLS_CIPHER_MODE_CTR)
1572static const mbedtls_cipher_info_t blowfish_ctr_info = {
1573 MBEDTLS_CIPHER_BLOWFISH_CTR,
1574 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001575 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001576 "BLOWFISH-CTR",
1577 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001578 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001579 8,
1580 &blowfish_info
1581};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001582#endif /* MBEDTLS_CIPHER_MODE_CTR */
1583#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001585#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001586static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1587 const unsigned char *input,
1588 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001589{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001590 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001591}
1592
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001593static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001594 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001595{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001596 /* we get key_bitlen in bits, arc4 expects it in bytes */
1597 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001599
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001600 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001601 return( 0 );
1602}
1603
1604static void * arc4_ctx_alloc( void )
1605{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001606 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001607 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001608
1609 if( ctx == NULL )
1610 return( NULL );
1611
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001612 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001613
1614 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001615}
Paul Bakker68884e32013-01-07 18:20:04 +01001616
1617static void arc4_ctx_free( void *ctx )
1618{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001619 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1620 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001621}
1622
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001623static const mbedtls_cipher_base_t arc4_base_info = {
1624 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001625 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001626#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001627 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001628#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001629#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001630 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001631#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001632#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001633 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001634#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001635#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001636 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001637#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001638 arc4_setkey_wrap,
1639 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001640 arc4_ctx_alloc,
1641 arc4_ctx_free
1642};
1643
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001644static const mbedtls_cipher_info_t arc4_128_info = {
1645 MBEDTLS_CIPHER_ARC4_128,
1646 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001647 128,
1648 "ARC4-128",
1649 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001650 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001651 1,
1652 &arc4_base_info
1653};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001654#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001655
Daniel Kingbd920622016-05-15 19:56:20 -03001656#if defined(MBEDTLS_CHACHA20_C)
1657
1658static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1659 unsigned int key_bitlen )
1660{
1661 if( key_bitlen != 256U )
1662 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1663
1664 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1665 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1666
1667 return( 0 );
1668}
1669
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001670static int chacha20_stream_wrap( void *ctx, size_t length,
1671 const unsigned char *input,
1672 unsigned char *output )
1673{
1674 int ret;
1675
1676 ret = mbedtls_chacha20_update( ctx, length, input, output );
1677 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1678 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1679
1680 return( ret );
1681}
1682
Daniel Kingbd920622016-05-15 19:56:20 -03001683static void * chacha20_ctx_alloc( void )
1684{
1685 mbedtls_chacha20_context *ctx;
1686 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1687
1688 if( ctx == NULL )
1689 return( NULL );
1690
1691 mbedtls_chacha20_init( ctx );
1692
1693 return( ctx );
1694}
1695
1696static void chacha20_ctx_free( void *ctx )
1697{
1698 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1699 mbedtls_free( ctx );
1700}
1701
1702static const mbedtls_cipher_base_t chacha20_base_info = {
1703 MBEDTLS_CIPHER_ID_CHACHA20,
1704 NULL,
1705#if defined(MBEDTLS_CIPHER_MODE_CBC)
1706 NULL,
1707#endif
1708#if defined(MBEDTLS_CIPHER_MODE_CFB)
1709 NULL,
1710#endif
1711#if defined(MBEDTLS_CIPHER_MODE_CTR)
1712 NULL,
1713#endif
1714#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001715 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001716#endif
1717 chacha20_setkey_wrap,
1718 chacha20_setkey_wrap,
1719 chacha20_ctx_alloc,
1720 chacha20_ctx_free
1721};
1722static const mbedtls_cipher_info_t chacha20_info = {
1723 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001724 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001725 256,
1726 "CHACHA20",
1727 12,
1728 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001729 1,
Daniel Kingbd920622016-05-15 19:56:20 -03001730 &chacha20_base_info
1731};
1732#endif /* MBEDTLS_CHACHA20_C */
1733
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001734#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03001735
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001736static int chachapoly_setkey_wrap( void *ctx,
1737 const unsigned char *key,
1738 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03001739{
1740 if( key_bitlen != 256U )
1741 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1742
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001743 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03001744 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1745
1746 return( 0 );
1747}
1748
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001749static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03001750{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001751 mbedtls_chachapoly_context *ctx;
1752 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03001753
1754 if( ctx == NULL )
1755 return( NULL );
1756
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001757 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001758
1759 return( ctx );
1760}
1761
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001762static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03001763{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001764 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03001765 mbedtls_free( ctx );
1766}
1767
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001768static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03001769 MBEDTLS_CIPHER_ID_CHACHA20,
1770 NULL,
1771#if defined(MBEDTLS_CIPHER_MODE_CBC)
1772 NULL,
1773#endif
1774#if defined(MBEDTLS_CIPHER_MODE_CFB)
1775 NULL,
1776#endif
1777#if defined(MBEDTLS_CIPHER_MODE_CTR)
1778 NULL,
1779#endif
1780#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1781 NULL,
1782#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001783 chachapoly_setkey_wrap,
1784 chachapoly_setkey_wrap,
1785 chachapoly_ctx_alloc,
1786 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03001787};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001788static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03001789 MBEDTLS_CIPHER_CHACHA20_POLY1305,
1790 MBEDTLS_MODE_NONE,
1791 256,
1792 "CHACHA20-POLY1305",
1793 12,
1794 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001795 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001796 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03001797};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001798#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03001799
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001800#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001801static int null_crypt_stream( void *ctx, size_t length,
1802 const unsigned char *input,
1803 unsigned char *output )
1804{
1805 ((void) ctx);
1806 memmove( output, input, length );
1807 return( 0 );
1808}
1809
1810static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001811 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001812{
1813 ((void) ctx);
1814 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001815 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001816
1817 return( 0 );
1818}
1819
Paul Bakkerfab5c822012-02-06 16:45:10 +00001820static void * null_ctx_alloc( void )
1821{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001822 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001823}
1824
Paul Bakkerfab5c822012-02-06 16:45:10 +00001825static void null_ctx_free( void *ctx )
1826{
1827 ((void) ctx);
1828}
1829
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001830static const mbedtls_cipher_base_t null_base_info = {
1831 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001832 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001834 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001835#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001836#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001837 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001838#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001839#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001840 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001841#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001842#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001843 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001844#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001845 null_setkey,
1846 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001847 null_ctx_alloc,
1848 null_ctx_free
1849};
1850
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001851static const mbedtls_cipher_info_t null_cipher_info = {
1852 MBEDTLS_CIPHER_NULL,
1853 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001854 0,
1855 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001856 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001857 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001858 1,
1859 &null_base_info
1860};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001861#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001862
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001863const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001864{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001865#if defined(MBEDTLS_AES_C)
1866 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1867 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1868 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1869#if defined(MBEDTLS_CIPHER_MODE_CBC)
1870 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1871 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1872 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001873#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001874#if defined(MBEDTLS_CIPHER_MODE_CFB)
1875 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1876 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1877 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001878#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001879#if defined(MBEDTLS_CIPHER_MODE_CTR)
1880 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1881 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1882 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001883#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001884#if defined(MBEDTLS_GCM_C)
1885 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1886 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1887 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001888#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001889#if defined(MBEDTLS_CCM_C)
1890 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1891 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1892 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001893#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001894#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001895
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001896#if defined(MBEDTLS_ARC4_C)
1897 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001898#endif
1899
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001900#if defined(MBEDTLS_BLOWFISH_C)
1901 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1902#if defined(MBEDTLS_CIPHER_MODE_CBC)
1903 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001904#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001905#if defined(MBEDTLS_CIPHER_MODE_CFB)
1906 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001907#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001908#if defined(MBEDTLS_CIPHER_MODE_CTR)
1909 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001910#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001911#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001912
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001913#if defined(MBEDTLS_CAMELLIA_C)
1914 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1915 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1916 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1917#if defined(MBEDTLS_CIPHER_MODE_CBC)
1918 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1919 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1920 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001921#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001922#if defined(MBEDTLS_CIPHER_MODE_CFB)
1923 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1924 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1925 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001926#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001927#if defined(MBEDTLS_CIPHER_MODE_CTR)
1928 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1929 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1930 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001931#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001932#if defined(MBEDTLS_GCM_C)
1933 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1934 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1935 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001936#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001937#if defined(MBEDTLS_CCM_C)
1938 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1939 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1940 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001941#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001942#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001943
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001944#if defined(MBEDTLS_ARIA_C)
1945 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1946 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1947 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1948#if defined(MBEDTLS_CIPHER_MODE_CBC)
1949 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1950 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1951 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1952#endif
1953#if defined(MBEDTLS_CIPHER_MODE_CFB)
1954 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1955 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1956 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1957#endif
1958#if defined(MBEDTLS_CIPHER_MODE_CTR)
1959 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1960 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1961 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1962#endif
1963#if defined(MBEDTLS_GCM_C)
1964 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1965 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1966 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1967#endif
1968#if defined(MBEDTLS_CCM_C)
1969 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1970 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1971 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1972#endif
1973#endif /* MBEDTLS_ARIA_C */
1974
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001975#if defined(MBEDTLS_DES_C)
1976 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1977 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1978 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1979#if defined(MBEDTLS_CIPHER_MODE_CBC)
1980 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1981 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1982 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001983#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001984#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001985
Daniel Kingbd920622016-05-15 19:56:20 -03001986#if defined(MBEDTLS_CHACHA20_C)
1987 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
1988#endif
1989
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02001990#if defined(MBEDTLS_CHACHAPOLY_C)
1991 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03001992#endif
1993
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001994#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1995 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1996#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001997
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001998 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001999};
2000
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002001#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2002int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002003
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002004#endif /* MBEDTLS_CIPHER_C */