blob: b1ab8f164b30e4245dc846d5807dbd831209339a [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é-Gonnard08c337d2018-05-22 13:18:01 +0200844 (void) operation;
845 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +0000846 input, output );
847}
848#endif /* MBEDTLS_CIPHER_MODE_CBC */
849
850#if defined(MBEDTLS_CIPHER_MODE_CFB)
851static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
852 size_t length, size_t *iv_off, unsigned char *iv,
853 const unsigned char *input, unsigned char *output )
854{
855 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
856 iv_off, iv, input, output );
857}
858#endif /* MBEDTLS_CIPHER_MODE_CFB */
859
860#if defined(MBEDTLS_CIPHER_MODE_CTR)
861static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
862 unsigned char *nonce_counter, unsigned char *stream_block,
863 const unsigned char *input, unsigned char *output )
864{
865 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
866 nonce_counter, stream_block, input, output );
867}
868#endif /* MBEDTLS_CIPHER_MODE_CTR */
869
870static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
871 unsigned int key_bitlen )
872{
873 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
874}
875
876static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
877 unsigned int key_bitlen )
878{
879 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
880}
881
882static void * aria_ctx_alloc( void )
883{
884 mbedtls_aria_context *ctx;
885 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
886
887 if( ctx == NULL )
888 return( NULL );
889
890 mbedtls_aria_init( ctx );
891
892 return( ctx );
893}
894
895static void aria_ctx_free( void *ctx )
896{
897 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
898 mbedtls_free( ctx );
899}
900
901static const mbedtls_cipher_base_t aria_info = {
902 MBEDTLS_CIPHER_ID_ARIA,
903 aria_crypt_ecb_wrap,
904#if defined(MBEDTLS_CIPHER_MODE_CBC)
905 aria_crypt_cbc_wrap,
906#endif
907#if defined(MBEDTLS_CIPHER_MODE_CFB)
908 aria_crypt_cfb128_wrap,
909#endif
910#if defined(MBEDTLS_CIPHER_MODE_CTR)
911 aria_crypt_ctr_wrap,
912#endif
913#if defined(MBEDTLS_CIPHER_MODE_STREAM)
914 NULL,
915#endif
916 aria_setkey_enc_wrap,
917 aria_setkey_dec_wrap,
918 aria_ctx_alloc,
919 aria_ctx_free
920};
921
922static const mbedtls_cipher_info_t aria_128_ecb_info = {
923 MBEDTLS_CIPHER_ARIA_128_ECB,
924 MBEDTLS_MODE_ECB,
925 128,
926 "ARIA-128-ECB",
927 16,
928 0,
929 16,
930 &aria_info
931};
932
933static const mbedtls_cipher_info_t aria_192_ecb_info = {
934 MBEDTLS_CIPHER_ARIA_192_ECB,
935 MBEDTLS_MODE_ECB,
936 192,
937 "ARIA-192-ECB",
938 16,
939 0,
940 16,
941 &aria_info
942};
943
944static const mbedtls_cipher_info_t aria_256_ecb_info = {
945 MBEDTLS_CIPHER_ARIA_256_ECB,
946 MBEDTLS_MODE_ECB,
947 256,
948 "ARIA-256-ECB",
949 16,
950 0,
951 16,
952 &aria_info
953};
954
955#if defined(MBEDTLS_CIPHER_MODE_CBC)
956static const mbedtls_cipher_info_t aria_128_cbc_info = {
957 MBEDTLS_CIPHER_ARIA_128_CBC,
958 MBEDTLS_MODE_CBC,
959 128,
960 "ARIA-128-CBC",
961 16,
962 0,
963 16,
964 &aria_info
965};
966
967static const mbedtls_cipher_info_t aria_192_cbc_info = {
968 MBEDTLS_CIPHER_ARIA_192_CBC,
969 MBEDTLS_MODE_CBC,
970 192,
971 "ARIA-192-CBC",
972 16,
973 0,
974 16,
975 &aria_info
976};
977
978static const mbedtls_cipher_info_t aria_256_cbc_info = {
979 MBEDTLS_CIPHER_ARIA_256_CBC,
980 MBEDTLS_MODE_CBC,
981 256,
982 "ARIA-256-CBC",
983 16,
984 0,
985 16,
986 &aria_info
987};
988#endif /* MBEDTLS_CIPHER_MODE_CBC */
989
990#if defined(MBEDTLS_CIPHER_MODE_CFB)
991static const mbedtls_cipher_info_t aria_128_cfb128_info = {
992 MBEDTLS_CIPHER_ARIA_128_CFB128,
993 MBEDTLS_MODE_CFB,
994 128,
995 "ARIA-128-CFB128",
996 16,
997 0,
998 16,
999 &aria_info
1000};
1001
1002static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1003 MBEDTLS_CIPHER_ARIA_192_CFB128,
1004 MBEDTLS_MODE_CFB,
1005 192,
1006 "ARIA-192-CFB128",
1007 16,
1008 0,
1009 16,
1010 &aria_info
1011};
1012
1013static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1014 MBEDTLS_CIPHER_ARIA_256_CFB128,
1015 MBEDTLS_MODE_CFB,
1016 256,
1017 "ARIA-256-CFB128",
1018 16,
1019 0,
1020 16,
1021 &aria_info
1022};
1023#endif /* MBEDTLS_CIPHER_MODE_CFB */
1024
1025#if defined(MBEDTLS_CIPHER_MODE_CTR)
1026static const mbedtls_cipher_info_t aria_128_ctr_info = {
1027 MBEDTLS_CIPHER_ARIA_128_CTR,
1028 MBEDTLS_MODE_CTR,
1029 128,
1030 "ARIA-128-CTR",
1031 16,
1032 0,
1033 16,
1034 &aria_info
1035};
1036
1037static const mbedtls_cipher_info_t aria_192_ctr_info = {
1038 MBEDTLS_CIPHER_ARIA_192_CTR,
1039 MBEDTLS_MODE_CTR,
1040 192,
1041 "ARIA-192-CTR",
1042 16,
1043 0,
1044 16,
1045 &aria_info
1046};
1047
1048static const mbedtls_cipher_info_t aria_256_ctr_info = {
1049 MBEDTLS_CIPHER_ARIA_256_CTR,
1050 MBEDTLS_MODE_CTR,
1051 256,
1052 "ARIA-256-CTR",
1053 16,
1054 0,
1055 16,
1056 &aria_info
1057};
1058#endif /* MBEDTLS_CIPHER_MODE_CTR */
1059
1060#if defined(MBEDTLS_GCM_C)
1061static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1062 unsigned int key_bitlen )
1063{
1064 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1065 key, key_bitlen );
1066}
1067
1068static const mbedtls_cipher_base_t gcm_aria_info = {
1069 MBEDTLS_CIPHER_ID_ARIA,
1070 NULL,
1071#if defined(MBEDTLS_CIPHER_MODE_CBC)
1072 NULL,
1073#endif
1074#if defined(MBEDTLS_CIPHER_MODE_CFB)
1075 NULL,
1076#endif
1077#if defined(MBEDTLS_CIPHER_MODE_CTR)
1078 NULL,
1079#endif
1080#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1081 NULL,
1082#endif
1083 gcm_aria_setkey_wrap,
1084 gcm_aria_setkey_wrap,
1085 gcm_ctx_alloc,
1086 gcm_ctx_free,
1087};
1088
1089static const mbedtls_cipher_info_t aria_128_gcm_info = {
1090 MBEDTLS_CIPHER_ARIA_128_GCM,
1091 MBEDTLS_MODE_GCM,
1092 128,
1093 "ARIA-128-GCM",
1094 12,
1095 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1096 16,
1097 &gcm_aria_info
1098};
1099
1100static const mbedtls_cipher_info_t aria_192_gcm_info = {
1101 MBEDTLS_CIPHER_ARIA_192_GCM,
1102 MBEDTLS_MODE_GCM,
1103 192,
1104 "ARIA-192-GCM",
1105 12,
1106 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1107 16,
1108 &gcm_aria_info
1109};
1110
1111static const mbedtls_cipher_info_t aria_256_gcm_info = {
1112 MBEDTLS_CIPHER_ARIA_256_GCM,
1113 MBEDTLS_MODE_GCM,
1114 256,
1115 "ARIA-256-GCM",
1116 12,
1117 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1118 16,
1119 &gcm_aria_info
1120};
1121#endif /* MBEDTLS_GCM_C */
1122
1123#if defined(MBEDTLS_CCM_C)
1124static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1125 unsigned int key_bitlen )
1126{
1127 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1128 key, key_bitlen );
1129}
1130
1131static const mbedtls_cipher_base_t ccm_aria_info = {
1132 MBEDTLS_CIPHER_ID_ARIA,
1133 NULL,
1134#if defined(MBEDTLS_CIPHER_MODE_CBC)
1135 NULL,
1136#endif
1137#if defined(MBEDTLS_CIPHER_MODE_CFB)
1138 NULL,
1139#endif
1140#if defined(MBEDTLS_CIPHER_MODE_CTR)
1141 NULL,
1142#endif
1143#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1144 NULL,
1145#endif
1146 ccm_aria_setkey_wrap,
1147 ccm_aria_setkey_wrap,
1148 ccm_ctx_alloc,
1149 ccm_ctx_free,
1150};
1151
1152static const mbedtls_cipher_info_t aria_128_ccm_info = {
1153 MBEDTLS_CIPHER_ARIA_128_CCM,
1154 MBEDTLS_MODE_CCM,
1155 128,
1156 "ARIA-128-CCM",
1157 12,
1158 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1159 16,
1160 &ccm_aria_info
1161};
1162
1163static const mbedtls_cipher_info_t aria_192_ccm_info = {
1164 MBEDTLS_CIPHER_ARIA_192_CCM,
1165 MBEDTLS_MODE_CCM,
1166 192,
1167 "ARIA-192-CCM",
1168 12,
1169 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1170 16,
1171 &ccm_aria_info
1172};
1173
1174static const mbedtls_cipher_info_t aria_256_ccm_info = {
1175 MBEDTLS_CIPHER_ARIA_256_CCM,
1176 MBEDTLS_MODE_CCM,
1177 256,
1178 "ARIA-256-CCM",
1179 12,
1180 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1181 16,
1182 &ccm_aria_info
1183};
1184#endif /* MBEDTLS_CCM_C */
1185
1186#endif /* MBEDTLS_ARIA_C */
1187
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001188#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001189
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001190static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001191 const unsigned char *input, unsigned char *output )
1192{
1193 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001194 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001195}
1196
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001197static int des3_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_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001202}
1203
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001204#if defined(MBEDTLS_CIPHER_MODE_CBC)
1205static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001206 unsigned char *iv, const unsigned char *input, unsigned char *output )
1207{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001208 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001209 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001210}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001211#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001212
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001213#if defined(MBEDTLS_CIPHER_MODE_CBC)
1214static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001215 unsigned char *iv, const unsigned char *input, unsigned char *output )
1216{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001217 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001218 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001219}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001220#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001221
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001222static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001223 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001224{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001225 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001226
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001227 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001228}
1229
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001230static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001231 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001232{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001233 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001234
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001235 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001236}
1237
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001238static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001239 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001240{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001241 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001243 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001244}
1245
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001246static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001247 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001248{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001249 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001250
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001251 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001252}
1253
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001254static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001255 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001256{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001257 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001258
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001259 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001260}
1261
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001262static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001263 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001264{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001265 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001266
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001267 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001268}
1269
1270static void * des_ctx_alloc( void )
1271{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001272 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001273
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001274 if( des == NULL )
1275 return( NULL );
1276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001277 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001278
1279 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001280}
1281
1282static void des_ctx_free( void *ctx )
1283{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001284 mbedtls_des_free( (mbedtls_des_context *) ctx );
1285 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001286}
1287
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001288static void * des3_ctx_alloc( void )
1289{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001290 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001291 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001292
1293 if( des3 == NULL )
1294 return( NULL );
1295
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001296 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001297
1298 return( des3 );
1299}
1300
Paul Bakker34617722014-06-13 17:20:13 +02001301static void des3_ctx_free( void *ctx )
1302{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001303 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1304 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001305}
1306
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001307static const mbedtls_cipher_base_t des_info = {
1308 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001309 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001310#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001311 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001312#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001313#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001314 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001315#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001316#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001317 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001318#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001319#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001320 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001321#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001322 des_setkey_enc_wrap,
1323 des_setkey_dec_wrap,
1324 des_ctx_alloc,
1325 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001326};
1327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001328static const mbedtls_cipher_info_t des_ecb_info = {
1329 MBEDTLS_CIPHER_DES_ECB,
1330 MBEDTLS_MODE_ECB,
1331 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001332 "DES-ECB",
1333 8,
1334 0,
1335 8,
1336 &des_info
1337};
1338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001339#if defined(MBEDTLS_CIPHER_MODE_CBC)
1340static const mbedtls_cipher_info_t des_cbc_info = {
1341 MBEDTLS_CIPHER_DES_CBC,
1342 MBEDTLS_MODE_CBC,
1343 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001344 "DES-CBC",
1345 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001346 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001347 8,
1348 &des_info
1349};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001350#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001351
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001352static const mbedtls_cipher_base_t des_ede_info = {
1353 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001354 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001355#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001356 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001357#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001358#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001359 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001360#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001361#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001362 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001363#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001364#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001365 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001366#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001367 des3_set2key_enc_wrap,
1368 des3_set2key_dec_wrap,
1369 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001370 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001371};
1372
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001373static const mbedtls_cipher_info_t des_ede_ecb_info = {
1374 MBEDTLS_CIPHER_DES_EDE_ECB,
1375 MBEDTLS_MODE_ECB,
1376 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001377 "DES-EDE-ECB",
1378 8,
1379 0,
1380 8,
1381 &des_ede_info
1382};
1383
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001384#if defined(MBEDTLS_CIPHER_MODE_CBC)
1385static const mbedtls_cipher_info_t des_ede_cbc_info = {
1386 MBEDTLS_CIPHER_DES_EDE_CBC,
1387 MBEDTLS_MODE_CBC,
1388 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001389 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001390 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001391 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001392 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001393 &des_ede_info
1394};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001395#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001396
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001397static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001398 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001399 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001400#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001401 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001402#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001403#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001404 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001405#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001406#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001407 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001408#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001409#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001410 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001411#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001412 des3_set3key_enc_wrap,
1413 des3_set3key_dec_wrap,
1414 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001415 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001416};
1417
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001418static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1419 MBEDTLS_CIPHER_DES_EDE3_ECB,
1420 MBEDTLS_MODE_ECB,
1421 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001422 "DES-EDE3-ECB",
1423 8,
1424 0,
1425 8,
1426 &des_ede3_info
1427};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001428#if defined(MBEDTLS_CIPHER_MODE_CBC)
1429static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1430 MBEDTLS_CIPHER_DES_EDE3_CBC,
1431 MBEDTLS_MODE_CBC,
1432 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001433 "DES-EDE3-CBC",
1434 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001435 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001436 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001437 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001438};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001439#endif /* MBEDTLS_CIPHER_MODE_CBC */
1440#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001441
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001442#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001443
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001444static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001445 const unsigned char *input, unsigned char *output )
1446{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001447 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001448 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001449}
1450
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001451#if defined(MBEDTLS_CIPHER_MODE_CBC)
1452static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001453 size_t length, unsigned char *iv, const unsigned char *input,
1454 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001455{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001456 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001457 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001458}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001459#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001460
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001461#if defined(MBEDTLS_CIPHER_MODE_CFB)
1462static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001463 size_t length, size_t *iv_off, unsigned char *iv,
1464 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001465{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001466 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001467 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001468}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001469#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001470
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001471#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001472static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1473 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001474 const unsigned char *input, unsigned char *output )
1475{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001476 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001477 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001478}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001479#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001480
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001481static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001482 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001483{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001484 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001485}
1486
1487static void * blowfish_ctx_alloc( void )
1488{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001489 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001490 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001491
1492 if( ctx == NULL )
1493 return( NULL );
1494
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001495 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001496
1497 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001498}
1499
1500static void blowfish_ctx_free( void *ctx )
1501{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001502 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1503 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001504}
1505
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001506static const mbedtls_cipher_base_t blowfish_info = {
1507 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001508 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001510 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001511#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001512#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001513 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001514#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001515#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001516 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001517#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001518#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001519 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001520#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001521 blowfish_setkey_wrap,
1522 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001523 blowfish_ctx_alloc,
1524 blowfish_ctx_free
1525};
1526
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001527static const mbedtls_cipher_info_t blowfish_ecb_info = {
1528 MBEDTLS_CIPHER_BLOWFISH_ECB,
1529 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001530 128,
1531 "BLOWFISH-ECB",
1532 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001533 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001534 8,
1535 &blowfish_info
1536};
1537
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001538#if defined(MBEDTLS_CIPHER_MODE_CBC)
1539static const mbedtls_cipher_info_t blowfish_cbc_info = {
1540 MBEDTLS_CIPHER_BLOWFISH_CBC,
1541 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001542 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001543 "BLOWFISH-CBC",
1544 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001545 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001546 8,
1547 &blowfish_info
1548};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001549#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001550
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001551#if defined(MBEDTLS_CIPHER_MODE_CFB)
1552static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1553 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1554 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001555 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001556 "BLOWFISH-CFB64",
1557 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001558 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001559 8,
1560 &blowfish_info
1561};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001562#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001563
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001564#if defined(MBEDTLS_CIPHER_MODE_CTR)
1565static const mbedtls_cipher_info_t blowfish_ctr_info = {
1566 MBEDTLS_CIPHER_BLOWFISH_CTR,
1567 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001568 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001569 "BLOWFISH-CTR",
1570 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001571 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001572 8,
1573 &blowfish_info
1574};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001575#endif /* MBEDTLS_CIPHER_MODE_CTR */
1576#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001577
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001578#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001579static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1580 const unsigned char *input,
1581 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001582{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001583 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001584}
1585
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001586static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001587 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001588{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001589 /* we get key_bitlen in bits, arc4 expects it in bytes */
1590 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001591 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001592
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001593 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001594 return( 0 );
1595}
1596
1597static void * arc4_ctx_alloc( void )
1598{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001599 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001600 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001601
1602 if( ctx == NULL )
1603 return( NULL );
1604
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001605 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001606
1607 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001608}
Paul Bakker68884e32013-01-07 18:20:04 +01001609
1610static void arc4_ctx_free( void *ctx )
1611{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001612 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1613 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001614}
1615
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001616static const mbedtls_cipher_base_t arc4_base_info = {
1617 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001618 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001619#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001620 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001621#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001622#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001623 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001624#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001625#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001626 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001627#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001628#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001629 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001630#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001631 arc4_setkey_wrap,
1632 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001633 arc4_ctx_alloc,
1634 arc4_ctx_free
1635};
1636
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001637static const mbedtls_cipher_info_t arc4_128_info = {
1638 MBEDTLS_CIPHER_ARC4_128,
1639 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001640 128,
1641 "ARC4-128",
1642 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001643 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001644 1,
1645 &arc4_base_info
1646};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001647#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001648
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001649#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001650static int null_crypt_stream( void *ctx, size_t length,
1651 const unsigned char *input,
1652 unsigned char *output )
1653{
1654 ((void) ctx);
1655 memmove( output, input, length );
1656 return( 0 );
1657}
1658
1659static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001660 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001661{
1662 ((void) ctx);
1663 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001664 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001665
1666 return( 0 );
1667}
1668
Paul Bakkerfab5c822012-02-06 16:45:10 +00001669static void * null_ctx_alloc( void )
1670{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001671 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001672}
1673
Paul Bakkerfab5c822012-02-06 16:45:10 +00001674static void null_ctx_free( void *ctx )
1675{
1676 ((void) ctx);
1677}
1678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001679static const mbedtls_cipher_base_t null_base_info = {
1680 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001681 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001682#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001683 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001684#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001685#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001686 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001687#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001688#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001689 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001690#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001691#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001692 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001693#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001694 null_setkey,
1695 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001696 null_ctx_alloc,
1697 null_ctx_free
1698};
1699
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001700static const mbedtls_cipher_info_t null_cipher_info = {
1701 MBEDTLS_CIPHER_NULL,
1702 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001703 0,
1704 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001705 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001706 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001707 1,
1708 &null_base_info
1709};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001710#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001711
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001712const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001713{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001714#if defined(MBEDTLS_AES_C)
1715 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1716 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1717 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1718#if defined(MBEDTLS_CIPHER_MODE_CBC)
1719 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1720 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1721 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001722#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001723#if defined(MBEDTLS_CIPHER_MODE_CFB)
1724 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1725 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1726 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001727#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001728#if defined(MBEDTLS_CIPHER_MODE_CTR)
1729 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1730 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1731 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001732#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001733#if defined(MBEDTLS_GCM_C)
1734 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1735 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1736 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001737#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001738#if defined(MBEDTLS_CCM_C)
1739 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1740 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1741 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001742#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001743#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001744
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001745#if defined(MBEDTLS_ARC4_C)
1746 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001747#endif
1748
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001749#if defined(MBEDTLS_BLOWFISH_C)
1750 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1751#if defined(MBEDTLS_CIPHER_MODE_CBC)
1752 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001753#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001754#if defined(MBEDTLS_CIPHER_MODE_CFB)
1755 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001756#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001757#if defined(MBEDTLS_CIPHER_MODE_CTR)
1758 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001759#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001760#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001761
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001762#if defined(MBEDTLS_CAMELLIA_C)
1763 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1764 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1765 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1766#if defined(MBEDTLS_CIPHER_MODE_CBC)
1767 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1768 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1769 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001770#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001771#if defined(MBEDTLS_CIPHER_MODE_CFB)
1772 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1773 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1774 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001775#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001776#if defined(MBEDTLS_CIPHER_MODE_CTR)
1777 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1778 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1779 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001780#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001781#if defined(MBEDTLS_GCM_C)
1782 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1783 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1784 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001785#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001786#if defined(MBEDTLS_CCM_C)
1787 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1788 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1789 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001790#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001791#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001792
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001793#if defined(MBEDTLS_ARIA_C)
1794 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1795 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1796 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1797#if defined(MBEDTLS_CIPHER_MODE_CBC)
1798 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1799 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1800 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1801#endif
1802#if defined(MBEDTLS_CIPHER_MODE_CFB)
1803 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1804 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1805 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1806#endif
1807#if defined(MBEDTLS_CIPHER_MODE_CTR)
1808 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1809 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1810 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1811#endif
1812#if defined(MBEDTLS_GCM_C)
1813 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1814 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1815 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1816#endif
1817#if defined(MBEDTLS_CCM_C)
1818 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1819 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1820 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1821#endif
1822#endif /* MBEDTLS_ARIA_C */
1823
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001824#if defined(MBEDTLS_DES_C)
1825 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1826 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1827 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1828#if defined(MBEDTLS_CIPHER_MODE_CBC)
1829 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1830 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1831 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001832#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001834
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001835#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1836 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1837#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001838
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001839 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001840};
1841
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001842#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1843int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001844
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001845#endif /* MBEDTLS_CIPHER_C */