blob: 47851e9c02d4f3a76807879fe9349e2234d3b3a6 [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{
834 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, operation, input,
835 output );
836}
837
838#if defined(MBEDTLS_CIPHER_MODE_CBC)
839static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
840 size_t length, unsigned char *iv,
841 const unsigned char *input, unsigned char *output )
842{
843 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
844 input, output );
845}
846#endif /* MBEDTLS_CIPHER_MODE_CBC */
847
848#if defined(MBEDTLS_CIPHER_MODE_CFB)
849static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
850 size_t length, size_t *iv_off, unsigned char *iv,
851 const unsigned char *input, unsigned char *output )
852{
853 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
854 iv_off, iv, input, output );
855}
856#endif /* MBEDTLS_CIPHER_MODE_CFB */
857
858#if defined(MBEDTLS_CIPHER_MODE_CTR)
859static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
860 unsigned char *nonce_counter, unsigned char *stream_block,
861 const unsigned char *input, unsigned char *output )
862{
863 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
864 nonce_counter, stream_block, input, output );
865}
866#endif /* MBEDTLS_CIPHER_MODE_CTR */
867
868static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
869 unsigned int key_bitlen )
870{
871 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
872}
873
874static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
875 unsigned int key_bitlen )
876{
877 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
878}
879
880static void * aria_ctx_alloc( void )
881{
882 mbedtls_aria_context *ctx;
883 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
884
885 if( ctx == NULL )
886 return( NULL );
887
888 mbedtls_aria_init( ctx );
889
890 return( ctx );
891}
892
893static void aria_ctx_free( void *ctx )
894{
895 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
896 mbedtls_free( ctx );
897}
898
899static const mbedtls_cipher_base_t aria_info = {
900 MBEDTLS_CIPHER_ID_ARIA,
901 aria_crypt_ecb_wrap,
902#if defined(MBEDTLS_CIPHER_MODE_CBC)
903 aria_crypt_cbc_wrap,
904#endif
905#if defined(MBEDTLS_CIPHER_MODE_CFB)
906 aria_crypt_cfb128_wrap,
907#endif
908#if defined(MBEDTLS_CIPHER_MODE_CTR)
909 aria_crypt_ctr_wrap,
910#endif
911#if defined(MBEDTLS_CIPHER_MODE_STREAM)
912 NULL,
913#endif
914 aria_setkey_enc_wrap,
915 aria_setkey_dec_wrap,
916 aria_ctx_alloc,
917 aria_ctx_free
918};
919
920static const mbedtls_cipher_info_t aria_128_ecb_info = {
921 MBEDTLS_CIPHER_ARIA_128_ECB,
922 MBEDTLS_MODE_ECB,
923 128,
924 "ARIA-128-ECB",
925 16,
926 0,
927 16,
928 &aria_info
929};
930
931static const mbedtls_cipher_info_t aria_192_ecb_info = {
932 MBEDTLS_CIPHER_ARIA_192_ECB,
933 MBEDTLS_MODE_ECB,
934 192,
935 "ARIA-192-ECB",
936 16,
937 0,
938 16,
939 &aria_info
940};
941
942static const mbedtls_cipher_info_t aria_256_ecb_info = {
943 MBEDTLS_CIPHER_ARIA_256_ECB,
944 MBEDTLS_MODE_ECB,
945 256,
946 "ARIA-256-ECB",
947 16,
948 0,
949 16,
950 &aria_info
951};
952
953#if defined(MBEDTLS_CIPHER_MODE_CBC)
954static const mbedtls_cipher_info_t aria_128_cbc_info = {
955 MBEDTLS_CIPHER_ARIA_128_CBC,
956 MBEDTLS_MODE_CBC,
957 128,
958 "ARIA-128-CBC",
959 16,
960 0,
961 16,
962 &aria_info
963};
964
965static const mbedtls_cipher_info_t aria_192_cbc_info = {
966 MBEDTLS_CIPHER_ARIA_192_CBC,
967 MBEDTLS_MODE_CBC,
968 192,
969 "ARIA-192-CBC",
970 16,
971 0,
972 16,
973 &aria_info
974};
975
976static const mbedtls_cipher_info_t aria_256_cbc_info = {
977 MBEDTLS_CIPHER_ARIA_256_CBC,
978 MBEDTLS_MODE_CBC,
979 256,
980 "ARIA-256-CBC",
981 16,
982 0,
983 16,
984 &aria_info
985};
986#endif /* MBEDTLS_CIPHER_MODE_CBC */
987
988#if defined(MBEDTLS_CIPHER_MODE_CFB)
989static const mbedtls_cipher_info_t aria_128_cfb128_info = {
990 MBEDTLS_CIPHER_ARIA_128_CFB128,
991 MBEDTLS_MODE_CFB,
992 128,
993 "ARIA-128-CFB128",
994 16,
995 0,
996 16,
997 &aria_info
998};
999
1000static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1001 MBEDTLS_CIPHER_ARIA_192_CFB128,
1002 MBEDTLS_MODE_CFB,
1003 192,
1004 "ARIA-192-CFB128",
1005 16,
1006 0,
1007 16,
1008 &aria_info
1009};
1010
1011static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1012 MBEDTLS_CIPHER_ARIA_256_CFB128,
1013 MBEDTLS_MODE_CFB,
1014 256,
1015 "ARIA-256-CFB128",
1016 16,
1017 0,
1018 16,
1019 &aria_info
1020};
1021#endif /* MBEDTLS_CIPHER_MODE_CFB */
1022
1023#if defined(MBEDTLS_CIPHER_MODE_CTR)
1024static const mbedtls_cipher_info_t aria_128_ctr_info = {
1025 MBEDTLS_CIPHER_ARIA_128_CTR,
1026 MBEDTLS_MODE_CTR,
1027 128,
1028 "ARIA-128-CTR",
1029 16,
1030 0,
1031 16,
1032 &aria_info
1033};
1034
1035static const mbedtls_cipher_info_t aria_192_ctr_info = {
1036 MBEDTLS_CIPHER_ARIA_192_CTR,
1037 MBEDTLS_MODE_CTR,
1038 192,
1039 "ARIA-192-CTR",
1040 16,
1041 0,
1042 16,
1043 &aria_info
1044};
1045
1046static const mbedtls_cipher_info_t aria_256_ctr_info = {
1047 MBEDTLS_CIPHER_ARIA_256_CTR,
1048 MBEDTLS_MODE_CTR,
1049 256,
1050 "ARIA-256-CTR",
1051 16,
1052 0,
1053 16,
1054 &aria_info
1055};
1056#endif /* MBEDTLS_CIPHER_MODE_CTR */
1057
1058#if defined(MBEDTLS_GCM_C)
1059static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1060 unsigned int key_bitlen )
1061{
1062 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1063 key, key_bitlen );
1064}
1065
1066static const mbedtls_cipher_base_t gcm_aria_info = {
1067 MBEDTLS_CIPHER_ID_ARIA,
1068 NULL,
1069#if defined(MBEDTLS_CIPHER_MODE_CBC)
1070 NULL,
1071#endif
1072#if defined(MBEDTLS_CIPHER_MODE_CFB)
1073 NULL,
1074#endif
1075#if defined(MBEDTLS_CIPHER_MODE_CTR)
1076 NULL,
1077#endif
1078#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1079 NULL,
1080#endif
1081 gcm_aria_setkey_wrap,
1082 gcm_aria_setkey_wrap,
1083 gcm_ctx_alloc,
1084 gcm_ctx_free,
1085};
1086
1087static const mbedtls_cipher_info_t aria_128_gcm_info = {
1088 MBEDTLS_CIPHER_ARIA_128_GCM,
1089 MBEDTLS_MODE_GCM,
1090 128,
1091 "ARIA-128-GCM",
1092 12,
1093 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1094 16,
1095 &gcm_aria_info
1096};
1097
1098static const mbedtls_cipher_info_t aria_192_gcm_info = {
1099 MBEDTLS_CIPHER_ARIA_192_GCM,
1100 MBEDTLS_MODE_GCM,
1101 192,
1102 "ARIA-192-GCM",
1103 12,
1104 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1105 16,
1106 &gcm_aria_info
1107};
1108
1109static const mbedtls_cipher_info_t aria_256_gcm_info = {
1110 MBEDTLS_CIPHER_ARIA_256_GCM,
1111 MBEDTLS_MODE_GCM,
1112 256,
1113 "ARIA-256-GCM",
1114 12,
1115 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1116 16,
1117 &gcm_aria_info
1118};
1119#endif /* MBEDTLS_GCM_C */
1120
1121#if defined(MBEDTLS_CCM_C)
1122static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1123 unsigned int key_bitlen )
1124{
1125 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1126 key, key_bitlen );
1127}
1128
1129static const mbedtls_cipher_base_t ccm_aria_info = {
1130 MBEDTLS_CIPHER_ID_ARIA,
1131 NULL,
1132#if defined(MBEDTLS_CIPHER_MODE_CBC)
1133 NULL,
1134#endif
1135#if defined(MBEDTLS_CIPHER_MODE_CFB)
1136 NULL,
1137#endif
1138#if defined(MBEDTLS_CIPHER_MODE_CTR)
1139 NULL,
1140#endif
1141#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1142 NULL,
1143#endif
1144 ccm_aria_setkey_wrap,
1145 ccm_aria_setkey_wrap,
1146 ccm_ctx_alloc,
1147 ccm_ctx_free,
1148};
1149
1150static const mbedtls_cipher_info_t aria_128_ccm_info = {
1151 MBEDTLS_CIPHER_ARIA_128_CCM,
1152 MBEDTLS_MODE_CCM,
1153 128,
1154 "ARIA-128-CCM",
1155 12,
1156 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1157 16,
1158 &ccm_aria_info
1159};
1160
1161static const mbedtls_cipher_info_t aria_192_ccm_info = {
1162 MBEDTLS_CIPHER_ARIA_192_CCM,
1163 MBEDTLS_MODE_CCM,
1164 192,
1165 "ARIA-192-CCM",
1166 12,
1167 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1168 16,
1169 &ccm_aria_info
1170};
1171
1172static const mbedtls_cipher_info_t aria_256_ccm_info = {
1173 MBEDTLS_CIPHER_ARIA_256_CCM,
1174 MBEDTLS_MODE_CCM,
1175 256,
1176 "ARIA-256-CCM",
1177 12,
1178 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1179 16,
1180 &ccm_aria_info
1181};
1182#endif /* MBEDTLS_CCM_C */
1183
1184#endif /* MBEDTLS_ARIA_C */
1185
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001186#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001187
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001188static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001189 const unsigned char *input, unsigned char *output )
1190{
1191 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001192 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001193}
1194
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001195static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001196 const unsigned char *input, unsigned char *output )
1197{
1198 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001199 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001200}
1201
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001202#if defined(MBEDTLS_CIPHER_MODE_CBC)
1203static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001204 unsigned char *iv, const unsigned char *input, unsigned char *output )
1205{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001206 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001207 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001208}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001209#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001210
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001211#if defined(MBEDTLS_CIPHER_MODE_CBC)
1212static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001213 unsigned char *iv, const unsigned char *input, unsigned char *output )
1214{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001215 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001216 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001217}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001218#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001219
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001220static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001221 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001222{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001223 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001224
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001225 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001226}
1227
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001228static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001229 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001230{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001231 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001232
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001233 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001234}
1235
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001236static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001237 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001238{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001239 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001240
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001241 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001242}
1243
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001244static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001245 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001246{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001247 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001248
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001249 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001250}
1251
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001252static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001253 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001254{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001255 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001256
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001257 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001258}
1259
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001260static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001261 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001262{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001263 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001264
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001265 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001266}
1267
1268static void * des_ctx_alloc( void )
1269{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001270 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001271
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001272 if( des == NULL )
1273 return( NULL );
1274
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001275 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001276
1277 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001278}
1279
1280static void des_ctx_free( void *ctx )
1281{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001282 mbedtls_des_free( (mbedtls_des_context *) ctx );
1283 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001284}
1285
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001286static void * des3_ctx_alloc( void )
1287{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001288 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001289 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001290
1291 if( des3 == NULL )
1292 return( NULL );
1293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001294 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001295
1296 return( des3 );
1297}
1298
Paul Bakker34617722014-06-13 17:20:13 +02001299static void des3_ctx_free( void *ctx )
1300{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001301 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1302 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001303}
1304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001305static const mbedtls_cipher_base_t des_info = {
1306 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001307 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001308#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001309 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001310#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001311#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001312 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001313#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001314#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001315 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001316#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001317#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001318 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001319#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001320 des_setkey_enc_wrap,
1321 des_setkey_dec_wrap,
1322 des_ctx_alloc,
1323 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001324};
1325
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001326static const mbedtls_cipher_info_t des_ecb_info = {
1327 MBEDTLS_CIPHER_DES_ECB,
1328 MBEDTLS_MODE_ECB,
1329 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001330 "DES-ECB",
1331 8,
1332 0,
1333 8,
1334 &des_info
1335};
1336
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001337#if defined(MBEDTLS_CIPHER_MODE_CBC)
1338static const mbedtls_cipher_info_t des_cbc_info = {
1339 MBEDTLS_CIPHER_DES_CBC,
1340 MBEDTLS_MODE_CBC,
1341 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001342 "DES-CBC",
1343 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001344 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001345 8,
1346 &des_info
1347};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001348#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001349
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001350static const mbedtls_cipher_base_t des_ede_info = {
1351 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001352 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001353#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001354 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001355#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001356#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001357 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001358#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001359#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001360 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001361#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001362#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001363 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001364#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001365 des3_set2key_enc_wrap,
1366 des3_set2key_dec_wrap,
1367 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001368 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001369};
1370
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001371static const mbedtls_cipher_info_t des_ede_ecb_info = {
1372 MBEDTLS_CIPHER_DES_EDE_ECB,
1373 MBEDTLS_MODE_ECB,
1374 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001375 "DES-EDE-ECB",
1376 8,
1377 0,
1378 8,
1379 &des_ede_info
1380};
1381
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001382#if defined(MBEDTLS_CIPHER_MODE_CBC)
1383static const mbedtls_cipher_info_t des_ede_cbc_info = {
1384 MBEDTLS_CIPHER_DES_EDE_CBC,
1385 MBEDTLS_MODE_CBC,
1386 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001387 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001388 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001389 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001390 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001391 &des_ede_info
1392};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001393#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001394
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001395static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001396 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001397 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001398#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001399 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001400#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001401#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001402 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001403#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001404#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001405 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001406#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001407#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001408 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001409#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001410 des3_set3key_enc_wrap,
1411 des3_set3key_dec_wrap,
1412 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001413 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001414};
1415
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001416static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1417 MBEDTLS_CIPHER_DES_EDE3_ECB,
1418 MBEDTLS_MODE_ECB,
1419 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001420 "DES-EDE3-ECB",
1421 8,
1422 0,
1423 8,
1424 &des_ede3_info
1425};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001426#if defined(MBEDTLS_CIPHER_MODE_CBC)
1427static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1428 MBEDTLS_CIPHER_DES_EDE3_CBC,
1429 MBEDTLS_MODE_CBC,
1430 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001431 "DES-EDE3-CBC",
1432 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001433 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001434 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001435 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001436};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001437#endif /* MBEDTLS_CIPHER_MODE_CBC */
1438#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001439
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001440#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001441
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001442static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001443 const unsigned char *input, unsigned char *output )
1444{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001445 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001446 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001447}
1448
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001449#if defined(MBEDTLS_CIPHER_MODE_CBC)
1450static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001451 size_t length, unsigned char *iv, const unsigned char *input,
1452 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001453{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001454 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001455 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001456}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001457#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001458
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001459#if defined(MBEDTLS_CIPHER_MODE_CFB)
1460static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001461 size_t length, size_t *iv_off, unsigned char *iv,
1462 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001463{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001464 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001465 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001466}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001467#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001468
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001469#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001470static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1471 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001472 const unsigned char *input, unsigned char *output )
1473{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001474 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001475 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001476}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001477#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001478
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001479static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001480 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001481{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001482 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001483}
1484
1485static void * blowfish_ctx_alloc( void )
1486{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001487 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001488 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001489
1490 if( ctx == NULL )
1491 return( NULL );
1492
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001493 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001494
1495 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001496}
1497
1498static void blowfish_ctx_free( void *ctx )
1499{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001500 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1501 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001502}
1503
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001504static const mbedtls_cipher_base_t blowfish_info = {
1505 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001506 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001507#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001508 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001509#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001510#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001511 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001512#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001513#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001514 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001515#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001516#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001517 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001518#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001519 blowfish_setkey_wrap,
1520 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001521 blowfish_ctx_alloc,
1522 blowfish_ctx_free
1523};
1524
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001525static const mbedtls_cipher_info_t blowfish_ecb_info = {
1526 MBEDTLS_CIPHER_BLOWFISH_ECB,
1527 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001528 128,
1529 "BLOWFISH-ECB",
1530 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001531 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001532 8,
1533 &blowfish_info
1534};
1535
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001536#if defined(MBEDTLS_CIPHER_MODE_CBC)
1537static const mbedtls_cipher_info_t blowfish_cbc_info = {
1538 MBEDTLS_CIPHER_BLOWFISH_CBC,
1539 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001540 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001541 "BLOWFISH-CBC",
1542 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001543 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001544 8,
1545 &blowfish_info
1546};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001547#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001548
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001549#if defined(MBEDTLS_CIPHER_MODE_CFB)
1550static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1551 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1552 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001553 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001554 "BLOWFISH-CFB64",
1555 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001556 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001557 8,
1558 &blowfish_info
1559};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001560#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001561
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001562#if defined(MBEDTLS_CIPHER_MODE_CTR)
1563static const mbedtls_cipher_info_t blowfish_ctr_info = {
1564 MBEDTLS_CIPHER_BLOWFISH_CTR,
1565 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001566 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001567 "BLOWFISH-CTR",
1568 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001569 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001570 8,
1571 &blowfish_info
1572};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001573#endif /* MBEDTLS_CIPHER_MODE_CTR */
1574#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001575
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001576#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001577static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1578 const unsigned char *input,
1579 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001580{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001581 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001582}
1583
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001584static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001585 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001586{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001587 /* we get key_bitlen in bits, arc4 expects it in bytes */
1588 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001589 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001590
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001591 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001592 return( 0 );
1593}
1594
1595static void * arc4_ctx_alloc( void )
1596{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001597 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001598 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001599
1600 if( ctx == NULL )
1601 return( NULL );
1602
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001603 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001604
1605 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001606}
Paul Bakker68884e32013-01-07 18:20:04 +01001607
1608static void arc4_ctx_free( void *ctx )
1609{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001610 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1611 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001612}
1613
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001614static const mbedtls_cipher_base_t arc4_base_info = {
1615 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001616 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001617#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001618 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001619#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001620#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001621 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001622#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001623#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001624 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001625#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001626#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001627 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001628#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001629 arc4_setkey_wrap,
1630 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001631 arc4_ctx_alloc,
1632 arc4_ctx_free
1633};
1634
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001635static const mbedtls_cipher_info_t arc4_128_info = {
1636 MBEDTLS_CIPHER_ARC4_128,
1637 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001638 128,
1639 "ARC4-128",
1640 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001641 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001642 1,
1643 &arc4_base_info
1644};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001645#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001646
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001647#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001648static int null_crypt_stream( void *ctx, size_t length,
1649 const unsigned char *input,
1650 unsigned char *output )
1651{
1652 ((void) ctx);
1653 memmove( output, input, length );
1654 return( 0 );
1655}
1656
1657static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001658 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001659{
1660 ((void) ctx);
1661 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001662 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001663
1664 return( 0 );
1665}
1666
Paul Bakkerfab5c822012-02-06 16:45:10 +00001667static void * null_ctx_alloc( void )
1668{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001669 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001670}
1671
Paul Bakkerfab5c822012-02-06 16:45:10 +00001672static void null_ctx_free( void *ctx )
1673{
1674 ((void) ctx);
1675}
1676
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001677static const mbedtls_cipher_base_t null_base_info = {
1678 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001679 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001680#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001681 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001682#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001683#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001684 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001685#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001686#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001687 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001688#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001689#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001690 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001691#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001692 null_setkey,
1693 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001694 null_ctx_alloc,
1695 null_ctx_free
1696};
1697
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001698static const mbedtls_cipher_info_t null_cipher_info = {
1699 MBEDTLS_CIPHER_NULL,
1700 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001701 0,
1702 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001703 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001704 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001705 1,
1706 &null_base_info
1707};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001708#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001709
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001710const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001711{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001712#if defined(MBEDTLS_AES_C)
1713 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1714 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1715 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1716#if defined(MBEDTLS_CIPHER_MODE_CBC)
1717 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1718 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1719 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001720#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001721#if defined(MBEDTLS_CIPHER_MODE_CFB)
1722 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1723 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1724 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001725#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001726#if defined(MBEDTLS_CIPHER_MODE_CTR)
1727 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1728 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1729 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001730#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001731#if defined(MBEDTLS_GCM_C)
1732 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1733 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1734 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001735#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001736#if defined(MBEDTLS_CCM_C)
1737 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1738 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1739 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001740#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001741#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001742
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001743#if defined(MBEDTLS_ARC4_C)
1744 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001745#endif
1746
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001747#if defined(MBEDTLS_BLOWFISH_C)
1748 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1749#if defined(MBEDTLS_CIPHER_MODE_CBC)
1750 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001751#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001752#if defined(MBEDTLS_CIPHER_MODE_CFB)
1753 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001754#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001755#if defined(MBEDTLS_CIPHER_MODE_CTR)
1756 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001757#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001758#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001759
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001760#if defined(MBEDTLS_CAMELLIA_C)
1761 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1762 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1763 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1764#if defined(MBEDTLS_CIPHER_MODE_CBC)
1765 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1766 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1767 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001768#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001769#if defined(MBEDTLS_CIPHER_MODE_CFB)
1770 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1771 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1772 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001773#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001774#if defined(MBEDTLS_CIPHER_MODE_CTR)
1775 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1776 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1777 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001778#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001779#if defined(MBEDTLS_GCM_C)
1780 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1781 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1782 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001783#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001784#if defined(MBEDTLS_CCM_C)
1785 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1786 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1787 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001788#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001789#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001790
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001791#if defined(MBEDTLS_ARIA_C)
1792 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
1793 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
1794 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
1795#if defined(MBEDTLS_CIPHER_MODE_CBC)
1796 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
1797 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
1798 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
1799#endif
1800#if defined(MBEDTLS_CIPHER_MODE_CFB)
1801 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
1802 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
1803 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
1804#endif
1805#if defined(MBEDTLS_CIPHER_MODE_CTR)
1806 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
1807 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
1808 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
1809#endif
1810#if defined(MBEDTLS_GCM_C)
1811 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
1812 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
1813 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
1814#endif
1815#if defined(MBEDTLS_CCM_C)
1816 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
1817 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
1818 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
1819#endif
1820#endif /* MBEDTLS_ARIA_C */
1821
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001822#if defined(MBEDTLS_DES_C)
1823 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1824 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1825 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1826#if defined(MBEDTLS_CIPHER_MODE_CBC)
1827 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1828 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1829 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001830#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001831#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001832
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1834 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1835#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001836
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001837 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001838};
1839
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001840#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1841int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001842
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001843#endif /* MBEDTLS_CIPHER_C */