blob: 09296c7f9b0c49fd86dca3b881cbe9257e53fb48 [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
Bence Szépkútif744bd72020-06-05 13:02:18 +02009 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
10 *
11 * This file is provided under the Apache License 2.0, or the
12 * GNU General Public License v2.0 or later.
13 *
14 * **********
15 * Apache License 2.0:
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020016 *
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may
18 * not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
Paul Bakker8123e9d2011-01-06 15:37:30 +000028 *
Bence Szépkútif744bd72020-06-05 13:02:18 +020029 * **********
30 *
31 * **********
32 * GNU General Public License v2.0 or later:
33 *
34 * This program is free software; you can redistribute it and/or modify
35 * it under the terms of the GNU General Public License as published by
36 * the Free Software Foundation; either version 2 of the License, or
37 * (at your option) any later version.
38 *
39 * This program is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU General Public License for more details.
43 *
44 * You should have received a copy of the GNU General Public License along
45 * with this program; if not, write to the Free Software Foundation, Inc.,
46 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
47 *
48 * **********
49 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000050 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000051 */
52
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000054#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020055#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020057#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000058
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000060
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020061#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000062
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020063#if defined(MBEDTLS_CHACHAPOLY_C)
64#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030065#endif
66
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000068#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000069#endif
70
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020071#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000072#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020073#endif
74
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000076#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000077#endif
78
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000079#if defined(MBEDTLS_ARIA_C)
80#include "mbedtls/aria.h"
81#endif
82
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000084#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000085#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000086
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000088#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000089#endif
90
Daniel Kingbd920622016-05-15 19:56:20 -030091#if defined(MBEDTLS_CHACHA20_C)
92#include "mbedtls/chacha20.h"
93#endif
94
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000096#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020097#endif
98
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000100#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200101#endif
102
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +0000104#include <string.h>
105#endif
106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000108#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +0200109#else
Rich Evans00ab4702015-02-06 13:43:58 +0000110#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200111#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +0200113#endif
114
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200115#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200116/* shared by all GCM ciphers */
117static void *gcm_ctx_alloc( void )
118{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200119 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
120
121 if( ctx != NULL )
122 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
123
124 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200125}
126
127static void gcm_ctx_free( void *ctx )
128{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129 mbedtls_gcm_free( ctx );
130 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200131}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200135/* shared by all CCM ciphers */
136static void *ccm_ctx_alloc( void )
137{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200138 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
139
140 if( ctx != NULL )
141 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
142
143 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200144}
145
146static void ccm_ctx_free( void *ctx )
147{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200148 mbedtls_ccm_free( ctx );
149 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200150}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000154
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200156 const unsigned char *input, unsigned char *output )
157{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200159}
160
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200161#if defined(MBEDTLS_CIPHER_MODE_CBC)
162static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000163 unsigned char *iv, const unsigned char *input, unsigned char *output )
164{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200165 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200166 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000167}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000169
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200170#if defined(MBEDTLS_CIPHER_MODE_CFB)
171static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200172 size_t length, size_t *iv_off, unsigned char *iv,
173 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000174{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200175 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200176 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000177}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200178#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000179
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100180#if defined(MBEDTLS_CIPHER_MODE_OFB)
181static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
182 unsigned char *iv, const unsigned char *input, unsigned char *output )
183{
184 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
185 iv, input, output );
186}
187#endif /* MBEDTLS_CIPHER_MODE_OFB */
188
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200189#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200190static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
191 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000192 const unsigned char *input, unsigned char *output )
193{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200194 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000195 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000196}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200197#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000198
Jaeden Ameroc6539902018-04-30 17:17:41 +0100199#if defined(MBEDTLS_CIPHER_MODE_XTS)
200static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
201 size_t length,
202 const unsigned char data_unit[16],
203 const unsigned char *input,
204 unsigned char *output )
205{
206 mbedtls_aes_xts_context *xts_ctx = ctx;
207 int mode;
208
209 switch( operation )
210 {
211 case MBEDTLS_ENCRYPT:
212 mode = MBEDTLS_AES_ENCRYPT;
213 break;
214 case MBEDTLS_DECRYPT:
215 mode = MBEDTLS_AES_DECRYPT;
216 break;
217 default:
218 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
219 }
220
221 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
222 data_unit, input, output );
223}
224#endif /* MBEDTLS_CIPHER_MODE_XTS */
225
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200226static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200227 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000228{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200229 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000230}
231
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200232static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200233 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000234{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200235 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000236}
237
238static void * aes_ctx_alloc( void )
239{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200240 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200241
242 if( aes == NULL )
243 return( NULL );
244
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200245 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200246
247 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000248}
249
250static void aes_ctx_free( void *ctx )
251{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200252 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
253 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000254}
255
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200256static const mbedtls_cipher_base_t aes_info = {
257 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200258 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200259#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000260 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100261#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200262#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000263 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100264#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100265#if defined(MBEDTLS_CIPHER_MODE_OFB)
266 aes_crypt_ofb_wrap,
267#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200268#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000269 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100270#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100271#if defined(MBEDTLS_CIPHER_MODE_XTS)
272 NULL,
273#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200275 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100276#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000277 aes_setkey_enc_wrap,
278 aes_setkey_dec_wrap,
279 aes_ctx_alloc,
280 aes_ctx_free
281};
282
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200283static const mbedtls_cipher_info_t aes_128_ecb_info = {
284 MBEDTLS_CIPHER_AES_128_ECB,
285 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200286 128,
287 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300288 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200289 0,
290 16,
291 &aes_info
292};
293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200294static const mbedtls_cipher_info_t aes_192_ecb_info = {
295 MBEDTLS_CIPHER_AES_192_ECB,
296 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200297 192,
298 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300299 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200300 0,
301 16,
302 &aes_info
303};
304
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200305static const mbedtls_cipher_info_t aes_256_ecb_info = {
306 MBEDTLS_CIPHER_AES_256_ECB,
307 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200308 256,
309 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300310 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200311 0,
312 16,
313 &aes_info
314};
315
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200316#if defined(MBEDTLS_CIPHER_MODE_CBC)
317static const mbedtls_cipher_info_t aes_128_cbc_info = {
318 MBEDTLS_CIPHER_AES_128_CBC,
319 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000320 128,
321 "AES-128-CBC",
322 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200323 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000324 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000325 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000326};
327
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200328static const mbedtls_cipher_info_t aes_192_cbc_info = {
329 MBEDTLS_CIPHER_AES_192_CBC,
330 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000331 192,
332 "AES-192-CBC",
333 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200334 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000335 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000336 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000337};
338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339static const mbedtls_cipher_info_t aes_256_cbc_info = {
340 MBEDTLS_CIPHER_AES_256_CBC,
341 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000342 256,
343 "AES-256-CBC",
344 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200345 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000346 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000347 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000348};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200349#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000350
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200351#if defined(MBEDTLS_CIPHER_MODE_CFB)
352static const mbedtls_cipher_info_t aes_128_cfb128_info = {
353 MBEDTLS_CIPHER_AES_128_CFB128,
354 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000355 128,
356 "AES-128-CFB128",
357 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200358 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000359 16,
360 &aes_info
361};
362
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200363static const mbedtls_cipher_info_t aes_192_cfb128_info = {
364 MBEDTLS_CIPHER_AES_192_CFB128,
365 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000366 192,
367 "AES-192-CFB128",
368 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200369 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000370 16,
371 &aes_info
372};
373
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200374static const mbedtls_cipher_info_t aes_256_cfb128_info = {
375 MBEDTLS_CIPHER_AES_256_CFB128,
376 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000377 256,
378 "AES-256-CFB128",
379 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200380 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000381 16,
382 &aes_info
383};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200384#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000385
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100386#if defined(MBEDTLS_CIPHER_MODE_OFB)
387static const mbedtls_cipher_info_t aes_128_ofb_info = {
388 MBEDTLS_CIPHER_AES_128_OFB,
389 MBEDTLS_MODE_OFB,
390 128,
391 "AES-128-OFB",
392 16,
393 0,
394 16,
395 &aes_info
396};
397
398static const mbedtls_cipher_info_t aes_192_ofb_info = {
399 MBEDTLS_CIPHER_AES_192_OFB,
400 MBEDTLS_MODE_OFB,
401 192,
402 "AES-192-OFB",
403 16,
404 0,
405 16,
406 &aes_info
407};
408
409static const mbedtls_cipher_info_t aes_256_ofb_info = {
410 MBEDTLS_CIPHER_AES_256_OFB,
411 MBEDTLS_MODE_OFB,
412 256,
413 "AES-256-OFB",
414 16,
415 0,
416 16,
417 &aes_info
418};
419#endif /* MBEDTLS_CIPHER_MODE_OFB */
420
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200421#if defined(MBEDTLS_CIPHER_MODE_CTR)
422static const mbedtls_cipher_info_t aes_128_ctr_info = {
423 MBEDTLS_CIPHER_AES_128_CTR,
424 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000425 128,
426 "AES-128-CTR",
427 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200428 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000429 16,
430 &aes_info
431};
432
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200433static const mbedtls_cipher_info_t aes_192_ctr_info = {
434 MBEDTLS_CIPHER_AES_192_CTR,
435 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000436 192,
437 "AES-192-CTR",
438 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200439 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000440 16,
441 &aes_info
442};
443
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200444static const mbedtls_cipher_info_t aes_256_ctr_info = {
445 MBEDTLS_CIPHER_AES_256_CTR,
446 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000447 256,
448 "AES-256-CTR",
449 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200450 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000451 16,
452 &aes_info
453};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200454#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000455
Jaeden Ameroc6539902018-04-30 17:17:41 +0100456#if defined(MBEDTLS_CIPHER_MODE_XTS)
457static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
458 unsigned int key_bitlen )
459{
460 mbedtls_aes_xts_context *xts_ctx = ctx;
461 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
462}
463
464static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
465 unsigned int key_bitlen )
466{
467 mbedtls_aes_xts_context *xts_ctx = ctx;
468 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
469}
470
471static void *xts_aes_ctx_alloc( void )
472{
473 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
474
475 if( xts_ctx != NULL )
476 mbedtls_aes_xts_init( xts_ctx );
477
478 return( xts_ctx );
479}
480
481static void xts_aes_ctx_free( void *ctx )
482{
483 mbedtls_aes_xts_context *xts_ctx = ctx;
484
485 if( xts_ctx == NULL )
486 return;
487
488 mbedtls_aes_xts_free( xts_ctx );
489 mbedtls_free( xts_ctx );
490}
491
492static const mbedtls_cipher_base_t xts_aes_info = {
493 MBEDTLS_CIPHER_ID_AES,
494 NULL,
495#if defined(MBEDTLS_CIPHER_MODE_CBC)
496 NULL,
497#endif
498#if defined(MBEDTLS_CIPHER_MODE_CFB)
499 NULL,
500#endif
501#if defined(MBEDTLS_CIPHER_MODE_OFB)
502 NULL,
503#endif
504#if defined(MBEDTLS_CIPHER_MODE_CTR)
505 NULL,
506#endif
507#if defined(MBEDTLS_CIPHER_MODE_XTS)
508 aes_crypt_xts_wrap,
509#endif
510#if defined(MBEDTLS_CIPHER_MODE_STREAM)
511 NULL,
512#endif
513 xts_aes_setkey_enc_wrap,
514 xts_aes_setkey_dec_wrap,
515 xts_aes_ctx_alloc,
516 xts_aes_ctx_free
517};
518
519static const mbedtls_cipher_info_t aes_128_xts_info = {
520 MBEDTLS_CIPHER_AES_128_XTS,
521 MBEDTLS_MODE_XTS,
522 256,
523 "AES-128-XTS",
524 16,
525 0,
526 16,
527 &xts_aes_info
528};
529
530static const mbedtls_cipher_info_t aes_256_xts_info = {
531 MBEDTLS_CIPHER_AES_256_XTS,
532 MBEDTLS_MODE_XTS,
533 512,
534 "AES-256-XTS",
535 16,
536 0,
537 16,
538 &xts_aes_info
539};
540#endif /* MBEDTLS_CIPHER_MODE_XTS */
541
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200542#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200543static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200544 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200545{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200546 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200547 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200548}
549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200550static const mbedtls_cipher_base_t gcm_aes_info = {
551 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200552 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200553#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200554 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100555#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200556#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200557 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100558#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100559#if defined(MBEDTLS_CIPHER_MODE_OFB)
560 NULL,
561#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200562#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200563 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100564#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100565#if defined(MBEDTLS_CIPHER_MODE_XTS)
566 NULL,
567#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200568#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200569 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100570#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200571 gcm_aes_setkey_wrap,
572 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200573 gcm_ctx_alloc,
574 gcm_ctx_free,
575};
576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200577static const mbedtls_cipher_info_t aes_128_gcm_info = {
578 MBEDTLS_CIPHER_AES_128_GCM,
579 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100580 128,
581 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200582 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100584 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200585 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100586};
587
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200588static const mbedtls_cipher_info_t aes_192_gcm_info = {
589 MBEDTLS_CIPHER_AES_192_GCM,
590 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200591 192,
592 "AES-192-GCM",
593 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200594 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200595 16,
596 &gcm_aes_info
597};
598
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200599static const mbedtls_cipher_info_t aes_256_gcm_info = {
600 MBEDTLS_CIPHER_AES_256_GCM,
601 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100602 256,
603 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200604 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200605 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100606 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200607 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100608};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200609#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100610
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200611#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200612static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200613 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200614{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200615 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200616 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200617}
618
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200619static const mbedtls_cipher_base_t ccm_aes_info = {
620 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200621 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200622#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200623 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100624#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200625#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200626 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100627#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100628#if defined(MBEDTLS_CIPHER_MODE_OFB)
629 NULL,
630#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200631#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200632 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100633#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100634#if defined(MBEDTLS_CIPHER_MODE_XTS)
635 NULL,
636#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200637#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200638 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100639#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200640 ccm_aes_setkey_wrap,
641 ccm_aes_setkey_wrap,
642 ccm_ctx_alloc,
643 ccm_ctx_free,
644};
645
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200646static const mbedtls_cipher_info_t aes_128_ccm_info = {
647 MBEDTLS_CIPHER_AES_128_CCM,
648 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200649 128,
650 "AES-128-CCM",
651 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200653 16,
654 &ccm_aes_info
655};
656
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657static const mbedtls_cipher_info_t aes_192_ccm_info = {
658 MBEDTLS_CIPHER_AES_192_CCM,
659 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200660 192,
661 "AES-192-CCM",
662 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200663 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200664 16,
665 &ccm_aes_info
666};
667
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200668static const mbedtls_cipher_info_t aes_256_ccm_info = {
669 MBEDTLS_CIPHER_AES_256_CCM,
670 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200671 256,
672 "AES-256-CCM",
673 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200674 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200675 16,
676 &ccm_aes_info
677};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200679
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000681
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000683
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200684static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200685 const unsigned char *input, unsigned char *output )
686{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200687 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200688 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200689}
690
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200691#if defined(MBEDTLS_CIPHER_MODE_CBC)
692static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200693 size_t length, unsigned char *iv,
694 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000695{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200697 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000698}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000700
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200701#if defined(MBEDTLS_CIPHER_MODE_CFB)
702static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200703 size_t length, size_t *iv_off, unsigned char *iv,
704 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000705{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200706 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200707 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000708}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200709#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000710
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200711#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200712static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
713 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000714 const unsigned char *input, unsigned char *output )
715{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200717 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000718}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200719#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000720
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200721static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200722 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000723{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200724 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000725}
726
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200727static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200728 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000729{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200730 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000731}
732
733static void * camellia_ctx_alloc( void )
734{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200735 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200736 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200737
738 if( ctx == NULL )
739 return( NULL );
740
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200741 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200742
743 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000744}
745
746static void camellia_ctx_free( void *ctx )
747{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200748 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
749 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000750}
751
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200752static const mbedtls_cipher_base_t camellia_info = {
753 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200754 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200755#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000756 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100757#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200758#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000759 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100760#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100761#if defined(MBEDTLS_CIPHER_MODE_OFB)
762 NULL,
763#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200764#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000765 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100766#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100767#if defined(MBEDTLS_CIPHER_MODE_XTS)
768 NULL,
769#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200770#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200771 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100772#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000773 camellia_setkey_enc_wrap,
774 camellia_setkey_dec_wrap,
775 camellia_ctx_alloc,
776 camellia_ctx_free
777};
778
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200779static const mbedtls_cipher_info_t camellia_128_ecb_info = {
780 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
781 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200782 128,
783 "CAMELLIA-128-ECB",
784 16,
785 0,
786 16,
787 &camellia_info
788};
789
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200790static const mbedtls_cipher_info_t camellia_192_ecb_info = {
791 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
792 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200793 192,
794 "CAMELLIA-192-ECB",
795 16,
796 0,
797 16,
798 &camellia_info
799};
800
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200801static const mbedtls_cipher_info_t camellia_256_ecb_info = {
802 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
803 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200804 256,
805 "CAMELLIA-256-ECB",
806 16,
807 0,
808 16,
809 &camellia_info
810};
811
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200812#if defined(MBEDTLS_CIPHER_MODE_CBC)
813static const mbedtls_cipher_info_t camellia_128_cbc_info = {
814 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
815 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000816 128,
817 "CAMELLIA-128-CBC",
818 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200819 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000820 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000821 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000822};
823
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200824static const mbedtls_cipher_info_t camellia_192_cbc_info = {
825 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
826 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000827 192,
828 "CAMELLIA-192-CBC",
829 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200830 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000831 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000832 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000833};
834
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200835static const mbedtls_cipher_info_t camellia_256_cbc_info = {
836 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
837 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000838 256,
839 "CAMELLIA-256-CBC",
840 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200841 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000842 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000843 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000844};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200845#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000846
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200847#if defined(MBEDTLS_CIPHER_MODE_CFB)
848static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
849 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
850 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000851 128,
852 "CAMELLIA-128-CFB128",
853 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200854 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000855 16,
856 &camellia_info
857};
858
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200859static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
860 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
861 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000862 192,
863 "CAMELLIA-192-CFB128",
864 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200865 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000866 16,
867 &camellia_info
868};
869
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200870static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
871 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
872 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000873 256,
874 "CAMELLIA-256-CFB128",
875 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200876 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000877 16,
878 &camellia_info
879};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200880#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000881
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200882#if defined(MBEDTLS_CIPHER_MODE_CTR)
883static const mbedtls_cipher_info_t camellia_128_ctr_info = {
884 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
885 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000886 128,
887 "CAMELLIA-128-CTR",
888 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200889 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000890 16,
891 &camellia_info
892};
893
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200894static const mbedtls_cipher_info_t camellia_192_ctr_info = {
895 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
896 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000897 192,
898 "CAMELLIA-192-CTR",
899 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200900 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000901 16,
902 &camellia_info
903};
904
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200905static const mbedtls_cipher_info_t camellia_256_ctr_info = {
906 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
907 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000908 256,
909 "CAMELLIA-256-CTR",
910 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200911 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000912 16,
913 &camellia_info
914};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200915#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000916
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200917#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200918static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200919 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200920{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200921 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200922 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200923}
924
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200925static const mbedtls_cipher_base_t gcm_camellia_info = {
926 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200927 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200928#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200929 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100930#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200931#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200932 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100933#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100934#if defined(MBEDTLS_CIPHER_MODE_OFB)
935 NULL,
936#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200937#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200938 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100939#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100940#if defined(MBEDTLS_CIPHER_MODE_XTS)
941 NULL,
942#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200943#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200944 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100945#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200946 gcm_camellia_setkey_wrap,
947 gcm_camellia_setkey_wrap,
948 gcm_ctx_alloc,
949 gcm_ctx_free,
950};
951
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200952static const mbedtls_cipher_info_t camellia_128_gcm_info = {
953 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
954 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200955 128,
956 "CAMELLIA-128-GCM",
957 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200958 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200959 16,
960 &gcm_camellia_info
961};
962
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200963static const mbedtls_cipher_info_t camellia_192_gcm_info = {
964 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
965 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200966 192,
967 "CAMELLIA-192-GCM",
968 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200969 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200970 16,
971 &gcm_camellia_info
972};
973
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200974static const mbedtls_cipher_info_t camellia_256_gcm_info = {
975 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
976 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200977 256,
978 "CAMELLIA-256-GCM",
979 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200980 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200981 16,
982 &gcm_camellia_info
983};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200984#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200985
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200986#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200987static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200988 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200989{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200990 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200991 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200992}
993
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200994static const mbedtls_cipher_base_t ccm_camellia_info = {
995 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200996 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200997#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200998 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100999#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001000#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001001 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001002#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001003#if defined(MBEDTLS_CIPHER_MODE_OFB)
1004 NULL,
1005#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001006#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001007 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001008#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001009#if defined(MBEDTLS_CIPHER_MODE_XTS)
1010 NULL,
1011#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001012#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001013 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001014#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001015 ccm_camellia_setkey_wrap,
1016 ccm_camellia_setkey_wrap,
1017 ccm_ctx_alloc,
1018 ccm_ctx_free,
1019};
1020
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001021static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1022 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1023 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001024 128,
1025 "CAMELLIA-128-CCM",
1026 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001027 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001028 16,
1029 &ccm_camellia_info
1030};
1031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001032static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1033 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1034 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001035 192,
1036 "CAMELLIA-192-CCM",
1037 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001038 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001039 16,
1040 &ccm_camellia_info
1041};
1042
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001043static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1044 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1045 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001046 256,
1047 "CAMELLIA-256-CCM",
1048 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001049 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001050 16,
1051 &ccm_camellia_info
1052};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001053#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001054
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001055#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001056
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001057#if defined(MBEDTLS_ARIA_C)
1058
1059static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1060 const unsigned char *input, unsigned char *output )
1061{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001062 (void) operation;
1063 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001064 output );
1065}
1066
1067#if defined(MBEDTLS_CIPHER_MODE_CBC)
1068static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1069 size_t length, unsigned char *iv,
1070 const unsigned char *input, unsigned char *output )
1071{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001072 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001073 input, output );
1074}
1075#endif /* MBEDTLS_CIPHER_MODE_CBC */
1076
1077#if defined(MBEDTLS_CIPHER_MODE_CFB)
1078static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1079 size_t length, size_t *iv_off, unsigned char *iv,
1080 const unsigned char *input, unsigned char *output )
1081{
1082 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1083 iv_off, iv, input, output );
1084}
1085#endif /* MBEDTLS_CIPHER_MODE_CFB */
1086
1087#if defined(MBEDTLS_CIPHER_MODE_CTR)
1088static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1089 unsigned char *nonce_counter, unsigned char *stream_block,
1090 const unsigned char *input, unsigned char *output )
1091{
1092 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1093 nonce_counter, stream_block, input, output );
1094}
1095#endif /* MBEDTLS_CIPHER_MODE_CTR */
1096
1097static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1098 unsigned int key_bitlen )
1099{
1100 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1101}
1102
1103static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1104 unsigned int key_bitlen )
1105{
1106 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1107}
1108
1109static void * aria_ctx_alloc( void )
1110{
1111 mbedtls_aria_context *ctx;
1112 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1113
1114 if( ctx == NULL )
1115 return( NULL );
1116
1117 mbedtls_aria_init( ctx );
1118
1119 return( ctx );
1120}
1121
1122static void aria_ctx_free( void *ctx )
1123{
1124 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1125 mbedtls_free( ctx );
1126}
1127
1128static const mbedtls_cipher_base_t aria_info = {
1129 MBEDTLS_CIPHER_ID_ARIA,
1130 aria_crypt_ecb_wrap,
1131#if defined(MBEDTLS_CIPHER_MODE_CBC)
1132 aria_crypt_cbc_wrap,
1133#endif
1134#if defined(MBEDTLS_CIPHER_MODE_CFB)
1135 aria_crypt_cfb128_wrap,
1136#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001137#if defined(MBEDTLS_CIPHER_MODE_OFB)
1138 NULL,
1139#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001140#if defined(MBEDTLS_CIPHER_MODE_CTR)
1141 aria_crypt_ctr_wrap,
1142#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001143#if defined(MBEDTLS_CIPHER_MODE_XTS)
1144 NULL,
1145#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001146#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1147 NULL,
1148#endif
1149 aria_setkey_enc_wrap,
1150 aria_setkey_dec_wrap,
1151 aria_ctx_alloc,
1152 aria_ctx_free
1153};
1154
1155static const mbedtls_cipher_info_t aria_128_ecb_info = {
1156 MBEDTLS_CIPHER_ARIA_128_ECB,
1157 MBEDTLS_MODE_ECB,
1158 128,
1159 "ARIA-128-ECB",
1160 16,
1161 0,
1162 16,
1163 &aria_info
1164};
1165
1166static const mbedtls_cipher_info_t aria_192_ecb_info = {
1167 MBEDTLS_CIPHER_ARIA_192_ECB,
1168 MBEDTLS_MODE_ECB,
1169 192,
1170 "ARIA-192-ECB",
1171 16,
1172 0,
1173 16,
1174 &aria_info
1175};
1176
1177static const mbedtls_cipher_info_t aria_256_ecb_info = {
1178 MBEDTLS_CIPHER_ARIA_256_ECB,
1179 MBEDTLS_MODE_ECB,
1180 256,
1181 "ARIA-256-ECB",
1182 16,
1183 0,
1184 16,
1185 &aria_info
1186};
1187
1188#if defined(MBEDTLS_CIPHER_MODE_CBC)
1189static const mbedtls_cipher_info_t aria_128_cbc_info = {
1190 MBEDTLS_CIPHER_ARIA_128_CBC,
1191 MBEDTLS_MODE_CBC,
1192 128,
1193 "ARIA-128-CBC",
1194 16,
1195 0,
1196 16,
1197 &aria_info
1198};
1199
1200static const mbedtls_cipher_info_t aria_192_cbc_info = {
1201 MBEDTLS_CIPHER_ARIA_192_CBC,
1202 MBEDTLS_MODE_CBC,
1203 192,
1204 "ARIA-192-CBC",
1205 16,
1206 0,
1207 16,
1208 &aria_info
1209};
1210
1211static const mbedtls_cipher_info_t aria_256_cbc_info = {
1212 MBEDTLS_CIPHER_ARIA_256_CBC,
1213 MBEDTLS_MODE_CBC,
1214 256,
1215 "ARIA-256-CBC",
1216 16,
1217 0,
1218 16,
1219 &aria_info
1220};
1221#endif /* MBEDTLS_CIPHER_MODE_CBC */
1222
1223#if defined(MBEDTLS_CIPHER_MODE_CFB)
1224static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1225 MBEDTLS_CIPHER_ARIA_128_CFB128,
1226 MBEDTLS_MODE_CFB,
1227 128,
1228 "ARIA-128-CFB128",
1229 16,
1230 0,
1231 16,
1232 &aria_info
1233};
1234
1235static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1236 MBEDTLS_CIPHER_ARIA_192_CFB128,
1237 MBEDTLS_MODE_CFB,
1238 192,
1239 "ARIA-192-CFB128",
1240 16,
1241 0,
1242 16,
1243 &aria_info
1244};
1245
1246static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1247 MBEDTLS_CIPHER_ARIA_256_CFB128,
1248 MBEDTLS_MODE_CFB,
1249 256,
1250 "ARIA-256-CFB128",
1251 16,
1252 0,
1253 16,
1254 &aria_info
1255};
1256#endif /* MBEDTLS_CIPHER_MODE_CFB */
1257
1258#if defined(MBEDTLS_CIPHER_MODE_CTR)
1259static const mbedtls_cipher_info_t aria_128_ctr_info = {
1260 MBEDTLS_CIPHER_ARIA_128_CTR,
1261 MBEDTLS_MODE_CTR,
1262 128,
1263 "ARIA-128-CTR",
1264 16,
1265 0,
1266 16,
1267 &aria_info
1268};
1269
1270static const mbedtls_cipher_info_t aria_192_ctr_info = {
1271 MBEDTLS_CIPHER_ARIA_192_CTR,
1272 MBEDTLS_MODE_CTR,
1273 192,
1274 "ARIA-192-CTR",
1275 16,
1276 0,
1277 16,
1278 &aria_info
1279};
1280
1281static const mbedtls_cipher_info_t aria_256_ctr_info = {
1282 MBEDTLS_CIPHER_ARIA_256_CTR,
1283 MBEDTLS_MODE_CTR,
1284 256,
1285 "ARIA-256-CTR",
1286 16,
1287 0,
1288 16,
1289 &aria_info
1290};
1291#endif /* MBEDTLS_CIPHER_MODE_CTR */
1292
1293#if defined(MBEDTLS_GCM_C)
1294static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1295 unsigned int key_bitlen )
1296{
1297 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1298 key, key_bitlen );
1299}
1300
1301static const mbedtls_cipher_base_t gcm_aria_info = {
1302 MBEDTLS_CIPHER_ID_ARIA,
1303 NULL,
1304#if defined(MBEDTLS_CIPHER_MODE_CBC)
1305 NULL,
1306#endif
1307#if defined(MBEDTLS_CIPHER_MODE_CFB)
1308 NULL,
1309#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001310#if defined(MBEDTLS_CIPHER_MODE_OFB)
1311 NULL,
1312#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001313#if defined(MBEDTLS_CIPHER_MODE_CTR)
1314 NULL,
1315#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001316#if defined(MBEDTLS_CIPHER_MODE_XTS)
1317 NULL,
1318#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001319#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1320 NULL,
1321#endif
1322 gcm_aria_setkey_wrap,
1323 gcm_aria_setkey_wrap,
1324 gcm_ctx_alloc,
1325 gcm_ctx_free,
1326};
1327
1328static const mbedtls_cipher_info_t aria_128_gcm_info = {
1329 MBEDTLS_CIPHER_ARIA_128_GCM,
1330 MBEDTLS_MODE_GCM,
1331 128,
1332 "ARIA-128-GCM",
1333 12,
1334 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1335 16,
1336 &gcm_aria_info
1337};
1338
1339static const mbedtls_cipher_info_t aria_192_gcm_info = {
1340 MBEDTLS_CIPHER_ARIA_192_GCM,
1341 MBEDTLS_MODE_GCM,
1342 192,
1343 "ARIA-192-GCM",
1344 12,
1345 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1346 16,
1347 &gcm_aria_info
1348};
1349
1350static const mbedtls_cipher_info_t aria_256_gcm_info = {
1351 MBEDTLS_CIPHER_ARIA_256_GCM,
1352 MBEDTLS_MODE_GCM,
1353 256,
1354 "ARIA-256-GCM",
1355 12,
1356 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1357 16,
1358 &gcm_aria_info
1359};
1360#endif /* MBEDTLS_GCM_C */
1361
1362#if defined(MBEDTLS_CCM_C)
1363static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1364 unsigned int key_bitlen )
1365{
1366 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1367 key, key_bitlen );
1368}
1369
1370static const mbedtls_cipher_base_t ccm_aria_info = {
1371 MBEDTLS_CIPHER_ID_ARIA,
1372 NULL,
1373#if defined(MBEDTLS_CIPHER_MODE_CBC)
1374 NULL,
1375#endif
1376#if defined(MBEDTLS_CIPHER_MODE_CFB)
1377 NULL,
1378#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001379#if defined(MBEDTLS_CIPHER_MODE_OFB)
1380 NULL,
1381#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001382#if defined(MBEDTLS_CIPHER_MODE_CTR)
1383 NULL,
1384#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001385#if defined(MBEDTLS_CIPHER_MODE_XTS)
1386 NULL,
1387#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001388#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1389 NULL,
1390#endif
1391 ccm_aria_setkey_wrap,
1392 ccm_aria_setkey_wrap,
1393 ccm_ctx_alloc,
1394 ccm_ctx_free,
1395};
1396
1397static const mbedtls_cipher_info_t aria_128_ccm_info = {
1398 MBEDTLS_CIPHER_ARIA_128_CCM,
1399 MBEDTLS_MODE_CCM,
1400 128,
1401 "ARIA-128-CCM",
1402 12,
1403 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1404 16,
1405 &ccm_aria_info
1406};
1407
1408static const mbedtls_cipher_info_t aria_192_ccm_info = {
1409 MBEDTLS_CIPHER_ARIA_192_CCM,
1410 MBEDTLS_MODE_CCM,
1411 192,
1412 "ARIA-192-CCM",
1413 12,
1414 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1415 16,
1416 &ccm_aria_info
1417};
1418
1419static const mbedtls_cipher_info_t aria_256_ccm_info = {
1420 MBEDTLS_CIPHER_ARIA_256_CCM,
1421 MBEDTLS_MODE_CCM,
1422 256,
1423 "ARIA-256-CCM",
1424 12,
1425 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1426 16,
1427 &ccm_aria_info
1428};
1429#endif /* MBEDTLS_CCM_C */
1430
1431#endif /* MBEDTLS_ARIA_C */
1432
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001433#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001434
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001435static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001436 const unsigned char *input, unsigned char *output )
1437{
1438 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001439 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001440}
1441
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001442static int des3_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{
1445 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001446 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, 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 des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001451 unsigned char *iv, const unsigned char *input, unsigned char *output )
1452{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001453 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001454 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001455}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001456#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001457
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001458#if defined(MBEDTLS_CIPHER_MODE_CBC)
1459static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001460 unsigned char *iv, const unsigned char *input, unsigned char *output )
1461{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001462 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001463 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001464}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001465#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001466
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001467static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001468 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001469{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001470 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001471
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001472 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001473}
1474
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001475static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001476 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001477{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001478 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001479
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001480 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001481}
1482
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001483static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001484 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001485{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001486 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001487
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001488 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001489}
1490
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001491static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001492 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001493{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001494 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001495
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001496 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001497}
1498
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001499static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001500 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001501{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001502 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001503
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001504 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001505}
1506
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001507static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001508 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001509{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001510 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001511
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001512 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001513}
1514
1515static void * des_ctx_alloc( void )
1516{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001517 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001518
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001519 if( des == NULL )
1520 return( NULL );
1521
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001522 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001523
1524 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001525}
1526
1527static void des_ctx_free( void *ctx )
1528{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001529 mbedtls_des_free( (mbedtls_des_context *) ctx );
1530 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001531}
1532
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001533static void * des3_ctx_alloc( void )
1534{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001535 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001536 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001537
1538 if( des3 == NULL )
1539 return( NULL );
1540
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001541 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001542
1543 return( des3 );
1544}
1545
Paul Bakker34617722014-06-13 17:20:13 +02001546static void des3_ctx_free( void *ctx )
1547{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001548 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1549 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001550}
1551
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001552static const mbedtls_cipher_base_t des_info = {
1553 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001554 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001555#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001556 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001557#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001558#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001559 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001560#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001561#if defined(MBEDTLS_CIPHER_MODE_OFB)
1562 NULL,
1563#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001564#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001565 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001566#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001567#if defined(MBEDTLS_CIPHER_MODE_XTS)
1568 NULL,
1569#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001570#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001571 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001572#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001573 des_setkey_enc_wrap,
1574 des_setkey_dec_wrap,
1575 des_ctx_alloc,
1576 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001577};
1578
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001579static const mbedtls_cipher_info_t des_ecb_info = {
1580 MBEDTLS_CIPHER_DES_ECB,
1581 MBEDTLS_MODE_ECB,
1582 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001583 "DES-ECB",
1584 8,
1585 0,
1586 8,
1587 &des_info
1588};
1589
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001590#if defined(MBEDTLS_CIPHER_MODE_CBC)
1591static const mbedtls_cipher_info_t des_cbc_info = {
1592 MBEDTLS_CIPHER_DES_CBC,
1593 MBEDTLS_MODE_CBC,
1594 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001595 "DES-CBC",
1596 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001597 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001598 8,
1599 &des_info
1600};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001601#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001602
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001603static const mbedtls_cipher_base_t des_ede_info = {
1604 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001605 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001606#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001607 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001608#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001609#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001610 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001611#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001612#if defined(MBEDTLS_CIPHER_MODE_OFB)
1613 NULL,
1614#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001615#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001616 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001617#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001618#if defined(MBEDTLS_CIPHER_MODE_XTS)
1619 NULL,
1620#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001621#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001622 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001623#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001624 des3_set2key_enc_wrap,
1625 des3_set2key_dec_wrap,
1626 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001627 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001628};
1629
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001630static const mbedtls_cipher_info_t des_ede_ecb_info = {
1631 MBEDTLS_CIPHER_DES_EDE_ECB,
1632 MBEDTLS_MODE_ECB,
1633 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001634 "DES-EDE-ECB",
1635 8,
1636 0,
1637 8,
1638 &des_ede_info
1639};
1640
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001641#if defined(MBEDTLS_CIPHER_MODE_CBC)
1642static const mbedtls_cipher_info_t des_ede_cbc_info = {
1643 MBEDTLS_CIPHER_DES_EDE_CBC,
1644 MBEDTLS_MODE_CBC,
1645 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001646 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001647 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001648 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001649 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001650 &des_ede_info
1651};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001652#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001653
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001654static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001655 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001656 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001657#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001658 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001659#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001660#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001661 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001662#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001663#if defined(MBEDTLS_CIPHER_MODE_OFB)
1664 NULL,
1665#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001666#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001667 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001668#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001669#if defined(MBEDTLS_CIPHER_MODE_XTS)
1670 NULL,
1671#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001672#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001673 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001674#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001675 des3_set3key_enc_wrap,
1676 des3_set3key_dec_wrap,
1677 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001678 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001679};
1680
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001681static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1682 MBEDTLS_CIPHER_DES_EDE3_ECB,
1683 MBEDTLS_MODE_ECB,
1684 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001685 "DES-EDE3-ECB",
1686 8,
1687 0,
1688 8,
1689 &des_ede3_info
1690};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001691#if defined(MBEDTLS_CIPHER_MODE_CBC)
1692static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1693 MBEDTLS_CIPHER_DES_EDE3_CBC,
1694 MBEDTLS_MODE_CBC,
1695 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001696 "DES-EDE3-CBC",
1697 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001698 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001699 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001700 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001701};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001702#endif /* MBEDTLS_CIPHER_MODE_CBC */
1703#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001704
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001705#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001706
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001707static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001708 const unsigned char *input, unsigned char *output )
1709{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001710 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001711 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001712}
1713
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001714#if defined(MBEDTLS_CIPHER_MODE_CBC)
1715static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001716 size_t length, unsigned char *iv, const unsigned char *input,
1717 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001718{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001719 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001720 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001721}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001722#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001723
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001724#if defined(MBEDTLS_CIPHER_MODE_CFB)
1725static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001726 size_t length, size_t *iv_off, unsigned char *iv,
1727 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001728{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001729 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001730 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001731}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001732#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001733
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001734#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001735static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1736 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001737 const unsigned char *input, unsigned char *output )
1738{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001739 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001740 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001741}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001742#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001743
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001744static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001745 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001746{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001747 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001748}
1749
1750static void * blowfish_ctx_alloc( void )
1751{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001752 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001753 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001754
1755 if( ctx == NULL )
1756 return( NULL );
1757
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001758 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001759
1760 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001761}
1762
1763static void blowfish_ctx_free( void *ctx )
1764{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001765 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1766 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001767}
1768
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001769static const mbedtls_cipher_base_t blowfish_info = {
1770 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001771 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001772#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001773 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001774#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001775#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001776 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001777#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001778#if defined(MBEDTLS_CIPHER_MODE_OFB)
1779 NULL,
1780#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001781#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001782 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001783#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001784#if defined(MBEDTLS_CIPHER_MODE_XTS)
1785 NULL,
1786#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001787#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001788 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001789#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001790 blowfish_setkey_wrap,
1791 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001792 blowfish_ctx_alloc,
1793 blowfish_ctx_free
1794};
1795
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001796static const mbedtls_cipher_info_t blowfish_ecb_info = {
1797 MBEDTLS_CIPHER_BLOWFISH_ECB,
1798 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001799 128,
1800 "BLOWFISH-ECB",
1801 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001802 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001803 8,
1804 &blowfish_info
1805};
1806
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001807#if defined(MBEDTLS_CIPHER_MODE_CBC)
1808static const mbedtls_cipher_info_t blowfish_cbc_info = {
1809 MBEDTLS_CIPHER_BLOWFISH_CBC,
1810 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001811 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001812 "BLOWFISH-CBC",
1813 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001814 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001815 8,
1816 &blowfish_info
1817};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001818#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001819
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001820#if defined(MBEDTLS_CIPHER_MODE_CFB)
1821static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1822 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1823 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001824 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001825 "BLOWFISH-CFB64",
1826 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001827 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001828 8,
1829 &blowfish_info
1830};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001831#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001832
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001833#if defined(MBEDTLS_CIPHER_MODE_CTR)
1834static const mbedtls_cipher_info_t blowfish_ctr_info = {
1835 MBEDTLS_CIPHER_BLOWFISH_CTR,
1836 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001837 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001838 "BLOWFISH-CTR",
1839 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001840 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001841 8,
1842 &blowfish_info
1843};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001844#endif /* MBEDTLS_CIPHER_MODE_CTR */
1845#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001846
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001847#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001848static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1849 const unsigned char *input,
1850 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001851{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001852 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001853}
1854
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001855static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001856 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001857{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001858 /* we get key_bitlen in bits, arc4 expects it in bytes */
1859 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001860 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001861
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001862 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001863 return( 0 );
1864}
1865
1866static void * arc4_ctx_alloc( void )
1867{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001868 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001869 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001870
1871 if( ctx == NULL )
1872 return( NULL );
1873
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001874 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001875
1876 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001877}
Paul Bakker68884e32013-01-07 18:20:04 +01001878
1879static void arc4_ctx_free( void *ctx )
1880{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001881 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1882 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001883}
1884
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001885static const mbedtls_cipher_base_t arc4_base_info = {
1886 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001887 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001888#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001889 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001890#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001891#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001892 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001893#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001894#if defined(MBEDTLS_CIPHER_MODE_OFB)
1895 NULL,
1896#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001897#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001898 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001899#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001900#if defined(MBEDTLS_CIPHER_MODE_XTS)
1901 NULL,
1902#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001903#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001904 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001905#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001906 arc4_setkey_wrap,
1907 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001908 arc4_ctx_alloc,
1909 arc4_ctx_free
1910};
1911
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001912static const mbedtls_cipher_info_t arc4_128_info = {
1913 MBEDTLS_CIPHER_ARC4_128,
1914 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001915 128,
1916 "ARC4-128",
1917 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001918 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001919 1,
1920 &arc4_base_info
1921};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001922#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001923
Daniel Kingbd920622016-05-15 19:56:20 -03001924#if defined(MBEDTLS_CHACHA20_C)
1925
1926static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1927 unsigned int key_bitlen )
1928{
1929 if( key_bitlen != 256U )
1930 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1931
1932 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1933 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1934
1935 return( 0 );
1936}
1937
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001938static int chacha20_stream_wrap( void *ctx, size_t length,
1939 const unsigned char *input,
1940 unsigned char *output )
1941{
1942 int ret;
1943
1944 ret = mbedtls_chacha20_update( ctx, length, input, output );
1945 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1946 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1947
1948 return( ret );
1949}
1950
Daniel Kingbd920622016-05-15 19:56:20 -03001951static void * chacha20_ctx_alloc( void )
1952{
1953 mbedtls_chacha20_context *ctx;
1954 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1955
1956 if( ctx == NULL )
1957 return( NULL );
1958
1959 mbedtls_chacha20_init( ctx );
1960
1961 return( ctx );
1962}
1963
1964static void chacha20_ctx_free( void *ctx )
1965{
1966 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1967 mbedtls_free( ctx );
1968}
1969
1970static const mbedtls_cipher_base_t chacha20_base_info = {
1971 MBEDTLS_CIPHER_ID_CHACHA20,
1972 NULL,
1973#if defined(MBEDTLS_CIPHER_MODE_CBC)
1974 NULL,
1975#endif
1976#if defined(MBEDTLS_CIPHER_MODE_CFB)
1977 NULL,
1978#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001979#if defined(MBEDTLS_CIPHER_MODE_OFB)
1980 NULL,
1981#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001982#if defined(MBEDTLS_CIPHER_MODE_CTR)
1983 NULL,
1984#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001985#if defined(MBEDTLS_CIPHER_MODE_XTS)
1986 NULL,
1987#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001988#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001989 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001990#endif
1991 chacha20_setkey_wrap,
1992 chacha20_setkey_wrap,
1993 chacha20_ctx_alloc,
1994 chacha20_ctx_free
1995};
1996static const mbedtls_cipher_info_t chacha20_info = {
1997 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001998 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001999 256,
2000 "CHACHA20",
2001 12,
2002 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002003 1,
Daniel Kingbd920622016-05-15 19:56:20 -03002004 &chacha20_base_info
2005};
2006#endif /* MBEDTLS_CHACHA20_C */
2007
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002008#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03002009
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002010static int chachapoly_setkey_wrap( void *ctx,
2011 const unsigned char *key,
2012 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03002013{
2014 if( key_bitlen != 256U )
2015 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2016
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002017 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03002018 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2019
2020 return( 0 );
2021}
2022
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002023static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03002024{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002025 mbedtls_chachapoly_context *ctx;
2026 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03002027
2028 if( ctx == NULL )
2029 return( NULL );
2030
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002031 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002032
2033 return( ctx );
2034}
2035
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002036static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002037{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002038 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002039 mbedtls_free( ctx );
2040}
2041
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002042static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002043 MBEDTLS_CIPHER_ID_CHACHA20,
2044 NULL,
2045#if defined(MBEDTLS_CIPHER_MODE_CBC)
2046 NULL,
2047#endif
2048#if defined(MBEDTLS_CIPHER_MODE_CFB)
2049 NULL,
2050#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002051#if defined(MBEDTLS_CIPHER_MODE_OFB)
2052 NULL,
2053#endif
Daniel King8fe47012016-05-17 20:33:28 -03002054#if defined(MBEDTLS_CIPHER_MODE_CTR)
2055 NULL,
2056#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002057#if defined(MBEDTLS_CIPHER_MODE_XTS)
2058 NULL,
2059#endif
Daniel King8fe47012016-05-17 20:33:28 -03002060#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2061 NULL,
2062#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002063 chachapoly_setkey_wrap,
2064 chachapoly_setkey_wrap,
2065 chachapoly_ctx_alloc,
2066 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002067};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002068static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002069 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002070 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002071 256,
2072 "CHACHA20-POLY1305",
2073 12,
2074 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002075 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002076 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002077};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002078#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002079
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002080#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002081static int null_crypt_stream( void *ctx, size_t length,
2082 const unsigned char *input,
2083 unsigned char *output )
2084{
2085 ((void) ctx);
2086 memmove( output, input, length );
2087 return( 0 );
2088}
2089
2090static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002091 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002092{
2093 ((void) ctx);
2094 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002095 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002096
2097 return( 0 );
2098}
2099
Paul Bakkerfab5c822012-02-06 16:45:10 +00002100static void * null_ctx_alloc( void )
2101{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002102 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002103}
2104
Paul Bakkerfab5c822012-02-06 16:45:10 +00002105static void null_ctx_free( void *ctx )
2106{
2107 ((void) ctx);
2108}
2109
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002110static const mbedtls_cipher_base_t null_base_info = {
2111 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002112 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002113#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002114 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002115#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002116#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002117 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002118#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002119#if defined(MBEDTLS_CIPHER_MODE_OFB)
2120 NULL,
2121#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002122#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002123 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002124#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002125#if defined(MBEDTLS_CIPHER_MODE_XTS)
2126 NULL,
2127#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002128#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002129 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002130#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002131 null_setkey,
2132 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002133 null_ctx_alloc,
2134 null_ctx_free
2135};
2136
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002137static const mbedtls_cipher_info_t null_cipher_info = {
2138 MBEDTLS_CIPHER_NULL,
2139 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002140 0,
2141 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002142 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002143 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002144 1,
2145 &null_base_info
2146};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002147#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002148
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002149const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002150{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002151#if defined(MBEDTLS_AES_C)
2152 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2153 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2154 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2155#if defined(MBEDTLS_CIPHER_MODE_CBC)
2156 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2157 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2158 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002159#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002160#if defined(MBEDTLS_CIPHER_MODE_CFB)
2161 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2162 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2163 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002164#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002165#if defined(MBEDTLS_CIPHER_MODE_OFB)
2166 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2167 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2168 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2169#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002170#if defined(MBEDTLS_CIPHER_MODE_CTR)
2171 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2172 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2173 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002174#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002175#if defined(MBEDTLS_CIPHER_MODE_XTS)
2176 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2177 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2178#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002179#if defined(MBEDTLS_GCM_C)
2180 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2181 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2182 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002183#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002184#if defined(MBEDTLS_CCM_C)
2185 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2186 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2187 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002188#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002189#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002190
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002191#if defined(MBEDTLS_ARC4_C)
2192 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002193#endif
2194
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002195#if defined(MBEDTLS_BLOWFISH_C)
2196 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2197#if defined(MBEDTLS_CIPHER_MODE_CBC)
2198 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002199#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002200#if defined(MBEDTLS_CIPHER_MODE_CFB)
2201 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002202#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002203#if defined(MBEDTLS_CIPHER_MODE_CTR)
2204 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002205#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002206#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002207
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002208#if defined(MBEDTLS_CAMELLIA_C)
2209 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2210 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2211 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2212#if defined(MBEDTLS_CIPHER_MODE_CBC)
2213 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2214 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2215 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002216#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002217#if defined(MBEDTLS_CIPHER_MODE_CFB)
2218 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2219 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2220 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002221#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002222#if defined(MBEDTLS_CIPHER_MODE_CTR)
2223 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2224 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2225 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002226#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002227#if defined(MBEDTLS_GCM_C)
2228 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2229 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2230 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002231#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002232#if defined(MBEDTLS_CCM_C)
2233 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2234 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2235 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002236#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002237#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002238
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002239#if defined(MBEDTLS_ARIA_C)
2240 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2241 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2242 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2243#if defined(MBEDTLS_CIPHER_MODE_CBC)
2244 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2245 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2246 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2247#endif
2248#if defined(MBEDTLS_CIPHER_MODE_CFB)
2249 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2250 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2251 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2252#endif
2253#if defined(MBEDTLS_CIPHER_MODE_CTR)
2254 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2255 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2256 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2257#endif
2258#if defined(MBEDTLS_GCM_C)
2259 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2260 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2261 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2262#endif
2263#if defined(MBEDTLS_CCM_C)
2264 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2265 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2266 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2267#endif
2268#endif /* MBEDTLS_ARIA_C */
2269
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002270#if defined(MBEDTLS_DES_C)
2271 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2272 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2273 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2274#if defined(MBEDTLS_CIPHER_MODE_CBC)
2275 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2276 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2277 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002278#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002279#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002280
Daniel Kingbd920622016-05-15 19:56:20 -03002281#if defined(MBEDTLS_CHACHA20_C)
2282 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2283#endif
2284
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002285#if defined(MBEDTLS_CHACHAPOLY_C)
2286 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002287#endif
2288
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002289#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2290 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2291#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002292
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002293 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002294};
2295
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002296#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2297int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002298
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002299#endif /* MBEDTLS_CIPHER_C */