blob: a9ef8195cad77447af9e86c8befa6837e1759306 [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief Generic cipher wrapper for mbed TLS
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker8123e9d2011-01-06 15:37:30 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000024 */
25
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000033
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020034#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000037#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000048#if defined(MBEDTLS_ARIA_C)
49#include "mbedtls/aria.h"
50#endif
51
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000054#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000055
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000065#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020066#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000069#include <string.h>
70#endif
71
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000073#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020074#else
Rich Evans00ab4702015-02-06 13:43:58 +000075#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020076#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020077#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020078#endif
79
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020080#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020081/* shared by all GCM ciphers */
82static void *gcm_ctx_alloc( void )
83{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020084 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
85
86 if( ctx != NULL )
87 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
88
89 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020090}
91
92static void gcm_ctx_free( void *ctx )
93{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094 mbedtls_gcm_free( ctx );
95 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020096}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020098
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200100/* shared by all CCM ciphers */
101static void *ccm_ctx_alloc( void )
102{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200103 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
104
105 if( ctx != NULL )
106 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
107
108 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200109}
110
111static void ccm_ctx_free( void *ctx )
112{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113 mbedtls_ccm_free( ctx );
114 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200115}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200117
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000119
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200120static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200121 const unsigned char *input, unsigned char *output )
122{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200124}
125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126#if defined(MBEDTLS_CIPHER_MODE_CBC)
127static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000128 unsigned char *iv, const unsigned char *input, unsigned char *output )
129{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200131 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000132}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135#if defined(MBEDTLS_CIPHER_MODE_CFB)
136static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200137 size_t length, size_t *iv_off, unsigned char *iv,
138 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000139{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200141 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000142}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200143#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000144
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200146static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
147 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000148 const unsigned char *input, unsigned char *output )
149{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000151 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000152}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000154
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200155static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200156 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000157{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200158 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000159}
160
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200161static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200162 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000163{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200164 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000165}
166
167static void * aes_ctx_alloc( void )
168{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200169 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200170
171 if( aes == NULL )
172 return( NULL );
173
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200174 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200175
176 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000177}
178
179static void aes_ctx_free( void *ctx )
180{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200181 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
182 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000183}
184
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200185static const mbedtls_cipher_base_t aes_info = {
186 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200187 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000189 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100190#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200191#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000192 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100193#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000195 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100196#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200198 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100199#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000200 aes_setkey_enc_wrap,
201 aes_setkey_dec_wrap,
202 aes_ctx_alloc,
203 aes_ctx_free
204};
205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206static const mbedtls_cipher_info_t aes_128_ecb_info = {
207 MBEDTLS_CIPHER_AES_128_ECB,
208 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200209 128,
210 "AES-128-ECB",
211 16,
212 0,
213 16,
214 &aes_info
215};
216
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217static const mbedtls_cipher_info_t aes_192_ecb_info = {
218 MBEDTLS_CIPHER_AES_192_ECB,
219 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200220 192,
221 "AES-192-ECB",
222 16,
223 0,
224 16,
225 &aes_info
226};
227
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200228static const mbedtls_cipher_info_t aes_256_ecb_info = {
229 MBEDTLS_CIPHER_AES_256_ECB,
230 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200231 256,
232 "AES-256-ECB",
233 16,
234 0,
235 16,
236 &aes_info
237};
238
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200239#if defined(MBEDTLS_CIPHER_MODE_CBC)
240static const mbedtls_cipher_info_t aes_128_cbc_info = {
241 MBEDTLS_CIPHER_AES_128_CBC,
242 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000243 128,
244 "AES-128-CBC",
245 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200246 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000247 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000248 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000249};
250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200251static const mbedtls_cipher_info_t aes_192_cbc_info = {
252 MBEDTLS_CIPHER_AES_192_CBC,
253 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000254 192,
255 "AES-192-CBC",
256 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200257 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000258 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000259 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000260};
261
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262static const mbedtls_cipher_info_t aes_256_cbc_info = {
263 MBEDTLS_CIPHER_AES_256_CBC,
264 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000265 256,
266 "AES-256-CBC",
267 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200268 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000269 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000270 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000271};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000273
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274#if defined(MBEDTLS_CIPHER_MODE_CFB)
275static const mbedtls_cipher_info_t aes_128_cfb128_info = {
276 MBEDTLS_CIPHER_AES_128_CFB128,
277 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000278 128,
279 "AES-128-CFB128",
280 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200281 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000282 16,
283 &aes_info
284};
285
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200286static const mbedtls_cipher_info_t aes_192_cfb128_info = {
287 MBEDTLS_CIPHER_AES_192_CFB128,
288 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000289 192,
290 "AES-192-CFB128",
291 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200292 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000293 16,
294 &aes_info
295};
296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200297static const mbedtls_cipher_info_t aes_256_cfb128_info = {
298 MBEDTLS_CIPHER_AES_256_CFB128,
299 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000300 256,
301 "AES-256-CFB128",
302 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200303 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000304 16,
305 &aes_info
306};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000308
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200309#if defined(MBEDTLS_CIPHER_MODE_CTR)
310static const mbedtls_cipher_info_t aes_128_ctr_info = {
311 MBEDTLS_CIPHER_AES_128_CTR,
312 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000313 128,
314 "AES-128-CTR",
315 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200316 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000317 16,
318 &aes_info
319};
320
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200321static const mbedtls_cipher_info_t aes_192_ctr_info = {
322 MBEDTLS_CIPHER_AES_192_CTR,
323 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000324 192,
325 "AES-192-CTR",
326 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200327 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000328 16,
329 &aes_info
330};
331
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200332static const mbedtls_cipher_info_t aes_256_ctr_info = {
333 MBEDTLS_CIPHER_AES_256_CTR,
334 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000335 256,
336 "AES-256-CTR",
337 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200338 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000339 16,
340 &aes_info
341};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200342#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000343
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200344#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200345static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200346 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200347{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200348 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200349 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200350}
351
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200352static const mbedtls_cipher_base_t gcm_aes_info = {
353 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200354 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200355#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200356 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100357#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200358#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200359 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100360#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200362 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100363#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200364#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200365 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100366#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200367 gcm_aes_setkey_wrap,
368 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200369 gcm_ctx_alloc,
370 gcm_ctx_free,
371};
372
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200373static const mbedtls_cipher_info_t aes_128_gcm_info = {
374 MBEDTLS_CIPHER_AES_128_GCM,
375 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100376 128,
377 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200378 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200379 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100380 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200381 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100382};
383
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200384static const mbedtls_cipher_info_t aes_192_gcm_info = {
385 MBEDTLS_CIPHER_AES_192_GCM,
386 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200387 192,
388 "AES-192-GCM",
389 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200390 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200391 16,
392 &gcm_aes_info
393};
394
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395static const mbedtls_cipher_info_t aes_256_gcm_info = {
396 MBEDTLS_CIPHER_AES_256_GCM,
397 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100398 256,
399 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200400 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200401 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100402 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200403 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100404};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100406
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200407#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200408static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200409 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200410{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200411 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200412 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200413}
414
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415static const mbedtls_cipher_base_t ccm_aes_info = {
416 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200417 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200418#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200419 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100420#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200421#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200422 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100423#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200424#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200425 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100426#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200427#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200428 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100429#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200430 ccm_aes_setkey_wrap,
431 ccm_aes_setkey_wrap,
432 ccm_ctx_alloc,
433 ccm_ctx_free,
434};
435
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200436static const mbedtls_cipher_info_t aes_128_ccm_info = {
437 MBEDTLS_CIPHER_AES_128_CCM,
438 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200439 128,
440 "AES-128-CCM",
441 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200442 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200443 16,
444 &ccm_aes_info
445};
446
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200447static const mbedtls_cipher_info_t aes_192_ccm_info = {
448 MBEDTLS_CIPHER_AES_192_CCM,
449 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200450 192,
451 "AES-192-CCM",
452 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200453 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200454 16,
455 &ccm_aes_info
456};
457
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200458static const mbedtls_cipher_info_t aes_256_ccm_info = {
459 MBEDTLS_CIPHER_AES_256_CCM,
460 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200461 256,
462 "AES-256-CCM",
463 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200464 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200465 16,
466 &ccm_aes_info
467};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200468#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200469
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200470#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000471
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200472#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000473
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200474static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200475 const unsigned char *input, unsigned char *output )
476{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200477 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200478 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200479}
480
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200481#if defined(MBEDTLS_CIPHER_MODE_CBC)
482static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200483 size_t length, unsigned char *iv,
484 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000485{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200486 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200487 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000488}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200489#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000490
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200491#if defined(MBEDTLS_CIPHER_MODE_CFB)
492static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200493 size_t length, size_t *iv_off, unsigned char *iv,
494 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000495{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200496 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200497 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000498}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200499#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000500
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200501#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200502static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
503 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000504 const unsigned char *input, unsigned char *output )
505{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200506 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200507 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000508}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200509#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000510
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200511static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200512 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000513{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200514 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000515}
516
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200517static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200518 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000519{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200520 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000521}
522
523static void * camellia_ctx_alloc( void )
524{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200525 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200526 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200527
528 if( ctx == NULL )
529 return( NULL );
530
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200531 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200532
533 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000534}
535
536static void camellia_ctx_free( void *ctx )
537{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200538 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
539 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000540}
541
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200542static const mbedtls_cipher_base_t camellia_info = {
543 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200544 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200545#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000546 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100547#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200548#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000549 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100550#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000552 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100553#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200555 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100556#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000557 camellia_setkey_enc_wrap,
558 camellia_setkey_dec_wrap,
559 camellia_ctx_alloc,
560 camellia_ctx_free
561};
562
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200563static const mbedtls_cipher_info_t camellia_128_ecb_info = {
564 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
565 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200566 128,
567 "CAMELLIA-128-ECB",
568 16,
569 0,
570 16,
571 &camellia_info
572};
573
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200574static const mbedtls_cipher_info_t camellia_192_ecb_info = {
575 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
576 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200577 192,
578 "CAMELLIA-192-ECB",
579 16,
580 0,
581 16,
582 &camellia_info
583};
584
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200585static const mbedtls_cipher_info_t camellia_256_ecb_info = {
586 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
587 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200588 256,
589 "CAMELLIA-256-ECB",
590 16,
591 0,
592 16,
593 &camellia_info
594};
595
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200596#if defined(MBEDTLS_CIPHER_MODE_CBC)
597static const mbedtls_cipher_info_t camellia_128_cbc_info = {
598 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
599 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000600 128,
601 "CAMELLIA-128-CBC",
602 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200603 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000604 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000605 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000606};
607
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200608static const mbedtls_cipher_info_t camellia_192_cbc_info = {
609 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
610 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000611 192,
612 "CAMELLIA-192-CBC",
613 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200614 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000615 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000616 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000617};
618
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200619static const mbedtls_cipher_info_t camellia_256_cbc_info = {
620 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
621 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000622 256,
623 "CAMELLIA-256-CBC",
624 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200625 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000626 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000627 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000628};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200629#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000630
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200631#if defined(MBEDTLS_CIPHER_MODE_CFB)
632static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
633 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
634 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000635 128,
636 "CAMELLIA-128-CFB128",
637 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200638 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000639 16,
640 &camellia_info
641};
642
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200643static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
644 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
645 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000646 192,
647 "CAMELLIA-192-CFB128",
648 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200649 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000650 16,
651 &camellia_info
652};
653
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200654static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
655 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
656 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000657 256,
658 "CAMELLIA-256-CFB128",
659 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200660 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000661 16,
662 &camellia_info
663};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200664#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000665
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200666#if defined(MBEDTLS_CIPHER_MODE_CTR)
667static const mbedtls_cipher_info_t camellia_128_ctr_info = {
668 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
669 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000670 128,
671 "CAMELLIA-128-CTR",
672 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200673 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000674 16,
675 &camellia_info
676};
677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678static const mbedtls_cipher_info_t camellia_192_ctr_info = {
679 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
680 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000681 192,
682 "CAMELLIA-192-CTR",
683 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200684 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000685 16,
686 &camellia_info
687};
688
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200689static const mbedtls_cipher_info_t camellia_256_ctr_info = {
690 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
691 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000692 256,
693 "CAMELLIA-256-CTR",
694 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200695 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000696 16,
697 &camellia_info
698};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000700
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200702static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200703 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200704{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200705 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200706 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200707}
708
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200709static const mbedtls_cipher_base_t gcm_camellia_info = {
710 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200711 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200712#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200713 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100714#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200715#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200716 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100717#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200718#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200719 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100720#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200721#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200722 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100723#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200724 gcm_camellia_setkey_wrap,
725 gcm_camellia_setkey_wrap,
726 gcm_ctx_alloc,
727 gcm_ctx_free,
728};
729
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200730static const mbedtls_cipher_info_t camellia_128_gcm_info = {
731 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
732 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200733 128,
734 "CAMELLIA-128-GCM",
735 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200736 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200737 16,
738 &gcm_camellia_info
739};
740
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741static const mbedtls_cipher_info_t camellia_192_gcm_info = {
742 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
743 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200744 192,
745 "CAMELLIA-192-GCM",
746 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200747 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200748 16,
749 &gcm_camellia_info
750};
751
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200752static const mbedtls_cipher_info_t camellia_256_gcm_info = {
753 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
754 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200755 256,
756 "CAMELLIA-256-GCM",
757 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200758 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200759 16,
760 &gcm_camellia_info
761};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200762#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200763
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200764#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200765static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200766 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200767{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200768 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200769 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200770}
771
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200772static const mbedtls_cipher_base_t ccm_camellia_info = {
773 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200774 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200775#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200776 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100777#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200778#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200779 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100780#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200781#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200782 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100783#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200784#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200785 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100786#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200787 ccm_camellia_setkey_wrap,
788 ccm_camellia_setkey_wrap,
789 ccm_ctx_alloc,
790 ccm_ctx_free,
791};
792
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200793static const mbedtls_cipher_info_t camellia_128_ccm_info = {
794 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
795 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200796 128,
797 "CAMELLIA-128-CCM",
798 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200799 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200800 16,
801 &ccm_camellia_info
802};
803
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200804static const mbedtls_cipher_info_t camellia_192_ccm_info = {
805 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
806 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200807 192,
808 "CAMELLIA-192-CCM",
809 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200810 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200811 16,
812 &ccm_camellia_info
813};
814
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200815static const mbedtls_cipher_info_t camellia_256_ccm_info = {
816 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
817 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200818 256,
819 "CAMELLIA-256-CCM",
820 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200821 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200822 16,
823 &ccm_camellia_info
824};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200825#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200826
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200827#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000828
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000829#if defined(MBEDTLS_ARIA_C)
830
831static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
832 const unsigned char *input, unsigned char *output )
833{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +0200834 (void) operation;
835 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000836 output );
837}
838
839#if defined(MBEDTLS_CIPHER_MODE_CBC)
840static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
841 size_t length, unsigned char *iv,
842 const unsigned char *input, unsigned char *output )
843{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +0200844 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000845 input, output );
846}
847#endif /* MBEDTLS_CIPHER_MODE_CBC */
848
849#if defined(MBEDTLS_CIPHER_MODE_CFB)
850static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
851 size_t length, size_t *iv_off, unsigned char *iv,
852 const unsigned char *input, unsigned char *output )
853{
854 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
855 iv_off, iv, input, output );
856}
857#endif /* MBEDTLS_CIPHER_MODE_CFB */
858
859#if defined(MBEDTLS_CIPHER_MODE_CTR)
860static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
861 unsigned char *nonce_counter, unsigned char *stream_block,
862 const unsigned char *input, unsigned char *output )
863{
864 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
865 nonce_counter, stream_block, input, output );
866}
867#endif /* MBEDTLS_CIPHER_MODE_CTR */
868
869static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
870 unsigned int key_bitlen )
871{
872 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
873}
874
875static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
876 unsigned int key_bitlen )
877{
878 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
879}
880
881static void * aria_ctx_alloc( void )
882{
883 mbedtls_aria_context *ctx;
884 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
885
886 if( ctx == NULL )
887 return( NULL );
888
889 mbedtls_aria_init( ctx );
890
891 return( ctx );
892}
893
894static void aria_ctx_free( void *ctx )
895{
896 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
897 mbedtls_free( ctx );
898}
899
900static const mbedtls_cipher_base_t aria_info = {
901 MBEDTLS_CIPHER_ID_ARIA,
902 aria_crypt_ecb_wrap,
903#if defined(MBEDTLS_CIPHER_MODE_CBC)
904 aria_crypt_cbc_wrap,
905#endif
906#if defined(MBEDTLS_CIPHER_MODE_CFB)
907 aria_crypt_cfb128_wrap,
908#endif
909#if defined(MBEDTLS_CIPHER_MODE_CTR)
910 aria_crypt_ctr_wrap,
911#endif
912#if defined(MBEDTLS_CIPHER_MODE_STREAM)
913 NULL,
914#endif
915 aria_setkey_enc_wrap,
916 aria_setkey_dec_wrap,
917 aria_ctx_alloc,
918 aria_ctx_free
919};
920
921static const mbedtls_cipher_info_t aria_128_ecb_info = {
922 MBEDTLS_CIPHER_ARIA_128_ECB,
923 MBEDTLS_MODE_ECB,
924 128,
925 "ARIA-128-ECB",
926 16,
927 0,
928 16,
929 &aria_info
930};
931
932static const mbedtls_cipher_info_t aria_192_ecb_info = {
933 MBEDTLS_CIPHER_ARIA_192_ECB,
934 MBEDTLS_MODE_ECB,
935 192,
936 "ARIA-192-ECB",
937 16,
938 0,
939 16,
940 &aria_info
941};
942
943static const mbedtls_cipher_info_t aria_256_ecb_info = {
944 MBEDTLS_CIPHER_ARIA_256_ECB,
945 MBEDTLS_MODE_ECB,
946 256,
947 "ARIA-256-ECB",
948 16,
949 0,
950 16,
951 &aria_info
952};
953
954#if defined(MBEDTLS_CIPHER_MODE_CBC)
955static const mbedtls_cipher_info_t aria_128_cbc_info = {
956 MBEDTLS_CIPHER_ARIA_128_CBC,
957 MBEDTLS_MODE_CBC,
958 128,
959 "ARIA-128-CBC",
960 16,
961 0,
962 16,
963 &aria_info
964};
965
966static const mbedtls_cipher_info_t aria_192_cbc_info = {
967 MBEDTLS_CIPHER_ARIA_192_CBC,
968 MBEDTLS_MODE_CBC,
969 192,
970 "ARIA-192-CBC",
971 16,
972 0,
973 16,
974 &aria_info
975};
976
977static const mbedtls_cipher_info_t aria_256_cbc_info = {
978 MBEDTLS_CIPHER_ARIA_256_CBC,
979 MBEDTLS_MODE_CBC,
980 256,
981 "ARIA-256-CBC",
982 16,
983 0,
984 16,
985 &aria_info
986};
987#endif /* MBEDTLS_CIPHER_MODE_CBC */
988
989#if defined(MBEDTLS_CIPHER_MODE_CFB)
990static const mbedtls_cipher_info_t aria_128_cfb128_info = {
991 MBEDTLS_CIPHER_ARIA_128_CFB128,
992 MBEDTLS_MODE_CFB,
993 128,
994 "ARIA-128-CFB128",
995 16,
996 0,
997 16,
998 &aria_info
999};
1000
1001static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1002 MBEDTLS_CIPHER_ARIA_192_CFB128,
1003 MBEDTLS_MODE_CFB,
1004 192,
1005 "ARIA-192-CFB128",
1006 16,
1007 0,
1008 16,
1009 &aria_info
1010};
1011
1012static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1013 MBEDTLS_CIPHER_ARIA_256_CFB128,
1014 MBEDTLS_MODE_CFB,
1015 256,
1016 "ARIA-256-CFB128",
1017 16,
1018 0,
1019 16,
1020 &aria_info
1021};
1022#endif /* MBEDTLS_CIPHER_MODE_CFB */
1023
1024#if defined(MBEDTLS_CIPHER_MODE_CTR)
1025static const mbedtls_cipher_info_t aria_128_ctr_info = {
1026 MBEDTLS_CIPHER_ARIA_128_CTR,
1027 MBEDTLS_MODE_CTR,
1028 128,
1029 "ARIA-128-CTR",
1030 16,
1031 0,
1032 16,
1033 &aria_info
1034};
1035
1036static const mbedtls_cipher_info_t aria_192_ctr_info = {
1037 MBEDTLS_CIPHER_ARIA_192_CTR,
1038 MBEDTLS_MODE_CTR,
1039 192,
1040 "ARIA-192-CTR",
1041 16,
1042 0,
1043 16,
1044 &aria_info
1045};
1046
1047static const mbedtls_cipher_info_t aria_256_ctr_info = {
1048 MBEDTLS_CIPHER_ARIA_256_CTR,
1049 MBEDTLS_MODE_CTR,
1050 256,
1051 "ARIA-256-CTR",
1052 16,
1053 0,
1054 16,
1055 &aria_info
1056};
1057#endif /* MBEDTLS_CIPHER_MODE_CTR */
1058
1059#if defined(MBEDTLS_GCM_C)
1060static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1061 unsigned int key_bitlen )
1062{
1063 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1064 key, key_bitlen );
1065}
1066
1067static const mbedtls_cipher_base_t gcm_aria_info = {
1068 MBEDTLS_CIPHER_ID_ARIA,
1069 NULL,
1070#if defined(MBEDTLS_CIPHER_MODE_CBC)
1071 NULL,
1072#endif
1073#if defined(MBEDTLS_CIPHER_MODE_CFB)
1074 NULL,
1075#endif
1076#if defined(MBEDTLS_CIPHER_MODE_CTR)
1077 NULL,
1078#endif
1079#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1080 NULL,
1081#endif
1082 gcm_aria_setkey_wrap,
1083 gcm_aria_setkey_wrap,
1084 gcm_ctx_alloc,
1085 gcm_ctx_free,
1086};
1087
1088static const mbedtls_cipher_info_t aria_128_gcm_info = {
1089 MBEDTLS_CIPHER_ARIA_128_GCM,
1090 MBEDTLS_MODE_GCM,
1091 128,
1092 "ARIA-128-GCM",
1093 12,
1094 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1095 16,
1096 &gcm_aria_info
1097};
1098
1099static const mbedtls_cipher_info_t aria_192_gcm_info = {
1100 MBEDTLS_CIPHER_ARIA_192_GCM,
1101 MBEDTLS_MODE_GCM,
1102 192,
1103 "ARIA-192-GCM",
1104 12,
1105 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1106 16,
1107 &gcm_aria_info
1108};
1109
1110static const mbedtls_cipher_info_t aria_256_gcm_info = {
1111 MBEDTLS_CIPHER_ARIA_256_GCM,
1112 MBEDTLS_MODE_GCM,
1113 256,
1114 "ARIA-256-GCM",
1115 12,
1116 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1117 16,
1118 &gcm_aria_info
1119};
1120#endif /* MBEDTLS_GCM_C */
1121
1122#if defined(MBEDTLS_CCM_C)
1123static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1124 unsigned int key_bitlen )
1125{
1126 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1127 key, key_bitlen );
1128}
1129
1130static const mbedtls_cipher_base_t ccm_aria_info = {
1131 MBEDTLS_CIPHER_ID_ARIA,
1132 NULL,
1133#if defined(MBEDTLS_CIPHER_MODE_CBC)
1134 NULL,
1135#endif
1136#if defined(MBEDTLS_CIPHER_MODE_CFB)
1137 NULL,
1138#endif
1139#if defined(MBEDTLS_CIPHER_MODE_CTR)
1140 NULL,
1141#endif
1142#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1143 NULL,
1144#endif
1145 ccm_aria_setkey_wrap,
1146 ccm_aria_setkey_wrap,
1147 ccm_ctx_alloc,
1148 ccm_ctx_free,
1149};
1150
1151static const mbedtls_cipher_info_t aria_128_ccm_info = {
1152 MBEDTLS_CIPHER_ARIA_128_CCM,
1153 MBEDTLS_MODE_CCM,
1154 128,
1155 "ARIA-128-CCM",
1156 12,
1157 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1158 16,
1159 &ccm_aria_info
1160};
1161
1162static const mbedtls_cipher_info_t aria_192_ccm_info = {
1163 MBEDTLS_CIPHER_ARIA_192_CCM,
1164 MBEDTLS_MODE_CCM,
1165 192,
1166 "ARIA-192-CCM",
1167 12,
1168 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1169 16,
1170 &ccm_aria_info
1171};
1172
1173static const mbedtls_cipher_info_t aria_256_ccm_info = {
1174 MBEDTLS_CIPHER_ARIA_256_CCM,
1175 MBEDTLS_MODE_CCM,
1176 256,
1177 "ARIA-256-CCM",
1178 12,
1179 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1180 16,
1181 &ccm_aria_info
1182};
1183#endif /* MBEDTLS_CCM_C */
1184
1185#endif /* MBEDTLS_ARIA_C */
1186
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001187#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001188
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001189static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001190 const unsigned char *input, unsigned char *output )
1191{
1192 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001193 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001194}
1195
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001196static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001197 const unsigned char *input, unsigned char *output )
1198{
1199 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001200 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001201}
1202
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001203#if defined(MBEDTLS_CIPHER_MODE_CBC)
1204static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001205 unsigned char *iv, const unsigned char *input, unsigned char *output )
1206{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001207 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001208 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001209}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001210#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001211
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001212#if defined(MBEDTLS_CIPHER_MODE_CBC)
1213static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001214 unsigned char *iv, const unsigned char *input, unsigned char *output )
1215{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001216 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001217 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001218}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001219#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001220
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001221static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001222 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001223{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001224 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001225
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001226 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001227}
1228
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001229static int des_setkey_enc_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_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001235}
1236
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001237static int des3_set2key_dec_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_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001243}
1244
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001245static int des3_set2key_enc_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_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001251}
1252
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001253static int des3_set3key_dec_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_set3key_dec( (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_enc_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_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001267}
1268
1269static void * des_ctx_alloc( void )
1270{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001271 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001272
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001273 if( des == NULL )
1274 return( NULL );
1275
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001276 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001277
1278 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001279}
1280
1281static void des_ctx_free( void *ctx )
1282{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001283 mbedtls_des_free( (mbedtls_des_context *) ctx );
1284 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001285}
1286
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001287static void * des3_ctx_alloc( void )
1288{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001289 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001290 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001291
1292 if( des3 == NULL )
1293 return( NULL );
1294
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001295 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001296
1297 return( des3 );
1298}
1299
Paul Bakker34617722014-06-13 17:20:13 +02001300static void des3_ctx_free( void *ctx )
1301{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001302 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1303 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001304}
1305
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001306static const mbedtls_cipher_base_t des_info = {
1307 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001308 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001309#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001310 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001311#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001312#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001313 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001314#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001315#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001316 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001317#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001318#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001319 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001320#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001321 des_setkey_enc_wrap,
1322 des_setkey_dec_wrap,
1323 des_ctx_alloc,
1324 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001325};
1326
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001327static const mbedtls_cipher_info_t des_ecb_info = {
1328 MBEDTLS_CIPHER_DES_ECB,
1329 MBEDTLS_MODE_ECB,
1330 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001331 "DES-ECB",
1332 8,
1333 0,
1334 8,
1335 &des_info
1336};
1337
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001338#if defined(MBEDTLS_CIPHER_MODE_CBC)
1339static const mbedtls_cipher_info_t des_cbc_info = {
1340 MBEDTLS_CIPHER_DES_CBC,
1341 MBEDTLS_MODE_CBC,
1342 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001343 "DES-CBC",
1344 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001345 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001346 8,
1347 &des_info
1348};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001349#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001350
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001351static const mbedtls_cipher_base_t des_ede_info = {
1352 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001353 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001354#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001355 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001356#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001357#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001358 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001359#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001360#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001361 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001362#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001363#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001364 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001365#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001366 des3_set2key_enc_wrap,
1367 des3_set2key_dec_wrap,
1368 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001369 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001370};
1371
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001372static const mbedtls_cipher_info_t des_ede_ecb_info = {
1373 MBEDTLS_CIPHER_DES_EDE_ECB,
1374 MBEDTLS_MODE_ECB,
1375 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001376 "DES-EDE-ECB",
1377 8,
1378 0,
1379 8,
1380 &des_ede_info
1381};
1382
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001383#if defined(MBEDTLS_CIPHER_MODE_CBC)
1384static const mbedtls_cipher_info_t des_ede_cbc_info = {
1385 MBEDTLS_CIPHER_DES_EDE_CBC,
1386 MBEDTLS_MODE_CBC,
1387 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001388 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001389 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001390 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001391 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001392 &des_ede_info
1393};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001394#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001395
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001396static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001397 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001398 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001399#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001400 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001401#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001402#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001403 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001404#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001405#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001406 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001407#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001408#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001409 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001410#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001411 des3_set3key_enc_wrap,
1412 des3_set3key_dec_wrap,
1413 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001414 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001415};
1416
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001417static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1418 MBEDTLS_CIPHER_DES_EDE3_ECB,
1419 MBEDTLS_MODE_ECB,
1420 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001421 "DES-EDE3-ECB",
1422 8,
1423 0,
1424 8,
1425 &des_ede3_info
1426};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001427#if defined(MBEDTLS_CIPHER_MODE_CBC)
1428static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1429 MBEDTLS_CIPHER_DES_EDE3_CBC,
1430 MBEDTLS_MODE_CBC,
1431 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001432 "DES-EDE3-CBC",
1433 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001434 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001435 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001436 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001437};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001438#endif /* MBEDTLS_CIPHER_MODE_CBC */
1439#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001440
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001441#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001442
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001443static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001444 const unsigned char *input, unsigned char *output )
1445{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001446 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001447 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001448}
1449
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001450#if defined(MBEDTLS_CIPHER_MODE_CBC)
1451static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001452 size_t length, unsigned char *iv, const unsigned char *input,
1453 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001454{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001455 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001456 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001457}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001458#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001459
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001460#if defined(MBEDTLS_CIPHER_MODE_CFB)
1461static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001462 size_t length, size_t *iv_off, unsigned char *iv,
1463 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001464{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001465 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001466 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001467}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001468#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001469
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001470#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001471static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1472 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001473 const unsigned char *input, unsigned char *output )
1474{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001475 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001476 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001477}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001478#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001479
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001480static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001481 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001482{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001483 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001484}
1485
1486static void * blowfish_ctx_alloc( void )
1487{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001488 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001489 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001490
1491 if( ctx == NULL )
1492 return( NULL );
1493
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001494 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001495
1496 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001497}
1498
1499static void blowfish_ctx_free( void *ctx )
1500{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001501 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1502 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001503}
1504
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001505static const mbedtls_cipher_base_t blowfish_info = {
1506 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001507 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001508#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001509 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001510#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001511#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001512 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001513#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001514#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001515 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001516#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001517#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001518 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001519#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001520 blowfish_setkey_wrap,
1521 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001522 blowfish_ctx_alloc,
1523 blowfish_ctx_free
1524};
1525
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001526static const mbedtls_cipher_info_t blowfish_ecb_info = {
1527 MBEDTLS_CIPHER_BLOWFISH_ECB,
1528 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001529 128,
1530 "BLOWFISH-ECB",
1531 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001532 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001533 8,
1534 &blowfish_info
1535};
1536
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001537#if defined(MBEDTLS_CIPHER_MODE_CBC)
1538static const mbedtls_cipher_info_t blowfish_cbc_info = {
1539 MBEDTLS_CIPHER_BLOWFISH_CBC,
1540 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001541 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001542 "BLOWFISH-CBC",
1543 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001544 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001545 8,
1546 &blowfish_info
1547};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001548#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001550#if defined(MBEDTLS_CIPHER_MODE_CFB)
1551static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1552 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1553 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001554 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001555 "BLOWFISH-CFB64",
1556 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001557 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001558 8,
1559 &blowfish_info
1560};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001561#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001562
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001563#if defined(MBEDTLS_CIPHER_MODE_CTR)
1564static const mbedtls_cipher_info_t blowfish_ctr_info = {
1565 MBEDTLS_CIPHER_BLOWFISH_CTR,
1566 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001567 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001568 "BLOWFISH-CTR",
1569 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001570 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001571 8,
1572 &blowfish_info
1573};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001574#endif /* MBEDTLS_CIPHER_MODE_CTR */
1575#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001577#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001578static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1579 const unsigned char *input,
1580 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001581{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001582 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001583}
1584
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001585static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001586 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001587{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001588 /* we get key_bitlen in bits, arc4 expects it in bytes */
1589 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001590 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001591
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001592 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001593 return( 0 );
1594}
1595
1596static void * arc4_ctx_alloc( void )
1597{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001598 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001599 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001600
1601 if( ctx == NULL )
1602 return( NULL );
1603
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001604 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001605
1606 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001607}
Paul Bakker68884e32013-01-07 18:20:04 +01001608
1609static void arc4_ctx_free( void *ctx )
1610{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001611 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1612 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001613}
1614
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001615static const mbedtls_cipher_base_t arc4_base_info = {
1616 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001617 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001619 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001620#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001621#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001622 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001623#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001624#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001625 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001626#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001627#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001628 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001629#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001630 arc4_setkey_wrap,
1631 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001632 arc4_ctx_alloc,
1633 arc4_ctx_free
1634};
1635
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001636static const mbedtls_cipher_info_t arc4_128_info = {
1637 MBEDTLS_CIPHER_ARC4_128,
1638 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001639 128,
1640 "ARC4-128",
1641 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001642 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001643 1,
1644 &arc4_base_info
1645};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001646#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001647
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001648#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001649static int null_crypt_stream( void *ctx, size_t length,
1650 const unsigned char *input,
1651 unsigned char *output )
1652{
1653 ((void) ctx);
1654 memmove( output, input, length );
1655 return( 0 );
1656}
1657
1658static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001659 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001660{
1661 ((void) ctx);
1662 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001663 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001664
1665 return( 0 );
1666}
1667
Paul Bakkerfab5c822012-02-06 16:45:10 +00001668static void * null_ctx_alloc( void )
1669{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001670 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001671}
1672
Paul Bakkerfab5c822012-02-06 16:45:10 +00001673static void null_ctx_free( void *ctx )
1674{
1675 ((void) ctx);
1676}
1677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001678static const mbedtls_cipher_base_t null_base_info = {
1679 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001680 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001681#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001682 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001683#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001684#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001685 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001686#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001687#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001688 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001689#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001690#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001691 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001692#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001693 null_setkey,
1694 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001695 null_ctx_alloc,
1696 null_ctx_free
1697};
1698
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001699static const mbedtls_cipher_info_t null_cipher_info = {
1700 MBEDTLS_CIPHER_NULL,
1701 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001702 0,
1703 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001704 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001705 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001706 1,
1707 &null_base_info
1708};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001709#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001710
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001711const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001712{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001713#if defined(MBEDTLS_AES_C)
1714 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1715 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1716 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1717#if defined(MBEDTLS_CIPHER_MODE_CBC)
1718 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1719 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1720 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001721#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001722#if defined(MBEDTLS_CIPHER_MODE_CFB)
1723 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1724 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1725 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001726#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001727#if defined(MBEDTLS_CIPHER_MODE_CTR)
1728 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1729 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1730 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001731#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001732#if defined(MBEDTLS_GCM_C)
1733 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1734 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1735 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001736#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001737#if defined(MBEDTLS_CCM_C)
1738 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1739 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1740 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001741#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001742#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001743
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001744#if defined(MBEDTLS_ARC4_C)
1745 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001746#endif
1747
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001748#if defined(MBEDTLS_BLOWFISH_C)
1749 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1750#if defined(MBEDTLS_CIPHER_MODE_CBC)
1751 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001752#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001753#if defined(MBEDTLS_CIPHER_MODE_CFB)
1754 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001755#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001756#if defined(MBEDTLS_CIPHER_MODE_CTR)
1757 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001758#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001759#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001760
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001761#if defined(MBEDTLS_CAMELLIA_C)
1762 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1763 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1764 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1765#if defined(MBEDTLS_CIPHER_MODE_CBC)
1766 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1767 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1768 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001769#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001770#if defined(MBEDTLS_CIPHER_MODE_CFB)
1771 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1772 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1773 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001774#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001775#if defined(MBEDTLS_CIPHER_MODE_CTR)
1776 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1777 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1778 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001779#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001780#if defined(MBEDTLS_GCM_C)
1781 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1782 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1783 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001784#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001785#if defined(MBEDTLS_CCM_C)
1786 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1787 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1788 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001789#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001790#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001791
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001792#if defined(MBEDTLS_ARIA_C)
1793 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1794 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1795 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1796#if defined(MBEDTLS_CIPHER_MODE_CBC)
1797 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1798 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1799 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1800#endif
1801#if defined(MBEDTLS_CIPHER_MODE_CFB)
1802 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1803 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1804 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1805#endif
1806#if defined(MBEDTLS_CIPHER_MODE_CTR)
1807 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1808 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1809 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1810#endif
1811#if defined(MBEDTLS_GCM_C)
1812 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1813 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1814 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1815#endif
1816#if defined(MBEDTLS_CCM_C)
1817 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1818 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1819 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1820#endif
1821#endif /* MBEDTLS_ARIA_C */
1822
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001823#if defined(MBEDTLS_DES_C)
1824 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1825 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1826 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1827#if defined(MBEDTLS_CIPHER_MODE_CBC)
1828 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1829 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1830 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001831#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001832#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001833
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001834#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1835 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1836#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001837
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001838 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001839};
1840
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001841#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1842int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001843
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001844#endif /* MBEDTLS_CIPHER_C */