blob: 5973ca6ba25fbfd4349b95d76867e5252a30a054 [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 *
Bence Szépkútia2947ac2020-08-19 16:37:36 +02008 * Copyright The Mbed TLS Contributors
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 * **********
Paul Bakker8123e9d2011-01-06 15:37:30 +000049 */
50
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000052#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020053#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020055#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000058
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020059#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000060
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +020061#if defined(MBEDTLS_CHACHAPOLY_C)
62#include "mbedtls/chachapoly.h"
Daniel King8fe47012016-05-17 20:33:28 -030063#endif
64
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020065#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000066#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000067#endif
68
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000070#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020071#endif
72
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000074#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000075#endif
76
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +000077#if defined(MBEDTLS_ARIA_C)
78#include "mbedtls/aria.h"
79#endif
80
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020081#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000082#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000083#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000084
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000086#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000087#endif
88
Daniel Kingbd920622016-05-15 19:56:20 -030089#if defined(MBEDTLS_CHACHA20_C)
90#include "mbedtls/chacha20.h"
91#endif
92
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000094#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020095#endif
96
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000098#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020099#endif
100
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +0000102#include <string.h>
103#endif
104
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200105#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000106#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +0200107#else
Rich Evans00ab4702015-02-06 13:43:58 +0000108#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200109#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +0200111#endif
112
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200113#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200114/* shared by all GCM ciphers */
115static void *gcm_ctx_alloc( void )
116{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200117 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
118
119 if( ctx != NULL )
120 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
121
122 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200123}
124
125static void gcm_ctx_free( void *ctx )
126{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200127 mbedtls_gcm_free( ctx );
128 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200129}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200131
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200133/* shared by all CCM ciphers */
134static void *ccm_ctx_alloc( void )
135{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +0200136 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
137
138 if( ctx != NULL )
139 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
140
141 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200142}
143
144static void ccm_ctx_free( void *ctx )
145{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146 mbedtls_ccm_free( ctx );
147 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200148}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200150
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000152
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200153static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200154 const unsigned char *input, unsigned char *output )
155{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200157}
158
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200159#if defined(MBEDTLS_CIPHER_MODE_CBC)
160static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000161 unsigned char *iv, const unsigned char *input, unsigned char *output )
162{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200163 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200164 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000165}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200166#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000167
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168#if defined(MBEDTLS_CIPHER_MODE_CFB)
169static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200170 size_t length, size_t *iv_off, unsigned char *iv,
171 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000172{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200173 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200174 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000175}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200176#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000177
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100178#if defined(MBEDTLS_CIPHER_MODE_OFB)
179static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
180 unsigned char *iv, const unsigned char *input, unsigned char *output )
181{
182 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
183 iv, input, output );
184}
185#endif /* MBEDTLS_CIPHER_MODE_OFB */
186
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200187#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200188static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
189 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000190 const unsigned char *input, unsigned char *output )
191{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000193 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000194}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200195#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000196
Jaeden Ameroc6539902018-04-30 17:17:41 +0100197#if defined(MBEDTLS_CIPHER_MODE_XTS)
198static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
199 size_t length,
200 const unsigned char data_unit[16],
201 const unsigned char *input,
202 unsigned char *output )
203{
204 mbedtls_aes_xts_context *xts_ctx = ctx;
205 int mode;
206
207 switch( operation )
208 {
209 case MBEDTLS_ENCRYPT:
210 mode = MBEDTLS_AES_ENCRYPT;
211 break;
212 case MBEDTLS_DECRYPT:
213 mode = MBEDTLS_AES_DECRYPT;
214 break;
215 default:
216 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
217 }
218
219 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
220 data_unit, input, output );
221}
222#endif /* MBEDTLS_CIPHER_MODE_XTS */
223
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200224static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200225 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000226{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200227 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000228}
229
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200230static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200231 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000232{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200233 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000234}
235
236static void * aes_ctx_alloc( void )
237{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200238 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200239
240 if( aes == NULL )
241 return( NULL );
242
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200244
245 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000246}
247
248static void aes_ctx_free( void *ctx )
249{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200250 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
251 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000252}
253
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200254static const mbedtls_cipher_base_t aes_info = {
255 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200256 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200257#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000258 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100259#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200260#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000261 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100262#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100263#if defined(MBEDTLS_CIPHER_MODE_OFB)
264 aes_crypt_ofb_wrap,
265#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000267 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100268#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100269#if defined(MBEDTLS_CIPHER_MODE_XTS)
270 NULL,
271#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200272#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200273 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100274#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000275 aes_setkey_enc_wrap,
276 aes_setkey_dec_wrap,
277 aes_ctx_alloc,
278 aes_ctx_free
279};
280
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200281static const mbedtls_cipher_info_t aes_128_ecb_info = {
282 MBEDTLS_CIPHER_AES_128_ECB,
283 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200284 128,
285 "AES-128-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300286 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200287 0,
288 16,
289 &aes_info
290};
291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200292static const mbedtls_cipher_info_t aes_192_ecb_info = {
293 MBEDTLS_CIPHER_AES_192_ECB,
294 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200295 192,
296 "AES-192-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300297 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200298 0,
299 16,
300 &aes_info
301};
302
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200303static const mbedtls_cipher_info_t aes_256_ecb_info = {
304 MBEDTLS_CIPHER_AES_256_ECB,
305 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200306 256,
307 "AES-256-ECB",
Ron Eldor4e64e0b2017-09-25 18:22:32 +0300308 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200309 0,
310 16,
311 &aes_info
312};
313
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200314#if defined(MBEDTLS_CIPHER_MODE_CBC)
315static const mbedtls_cipher_info_t aes_128_cbc_info = {
316 MBEDTLS_CIPHER_AES_128_CBC,
317 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000318 128,
319 "AES-128-CBC",
320 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200321 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000322 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000323 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000324};
325
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200326static const mbedtls_cipher_info_t aes_192_cbc_info = {
327 MBEDTLS_CIPHER_AES_192_CBC,
328 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000329 192,
330 "AES-192-CBC",
331 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200332 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000333 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000334 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000335};
336
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200337static const mbedtls_cipher_info_t aes_256_cbc_info = {
338 MBEDTLS_CIPHER_AES_256_CBC,
339 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000340 256,
341 "AES-256-CBC",
342 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200343 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000344 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000345 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000346};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200347#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000348
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200349#if defined(MBEDTLS_CIPHER_MODE_CFB)
350static const mbedtls_cipher_info_t aes_128_cfb128_info = {
351 MBEDTLS_CIPHER_AES_128_CFB128,
352 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000353 128,
354 "AES-128-CFB128",
355 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200356 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000357 16,
358 &aes_info
359};
360
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200361static const mbedtls_cipher_info_t aes_192_cfb128_info = {
362 MBEDTLS_CIPHER_AES_192_CFB128,
363 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000364 192,
365 "AES-192-CFB128",
366 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200367 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000368 16,
369 &aes_info
370};
371
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200372static const mbedtls_cipher_info_t aes_256_cfb128_info = {
373 MBEDTLS_CIPHER_AES_256_CFB128,
374 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000375 256,
376 "AES-256-CFB128",
377 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200378 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000379 16,
380 &aes_info
381};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200382#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000383
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100384#if defined(MBEDTLS_CIPHER_MODE_OFB)
385static const mbedtls_cipher_info_t aes_128_ofb_info = {
386 MBEDTLS_CIPHER_AES_128_OFB,
387 MBEDTLS_MODE_OFB,
388 128,
389 "AES-128-OFB",
390 16,
391 0,
392 16,
393 &aes_info
394};
395
396static const mbedtls_cipher_info_t aes_192_ofb_info = {
397 MBEDTLS_CIPHER_AES_192_OFB,
398 MBEDTLS_MODE_OFB,
399 192,
400 "AES-192-OFB",
401 16,
402 0,
403 16,
404 &aes_info
405};
406
407static const mbedtls_cipher_info_t aes_256_ofb_info = {
408 MBEDTLS_CIPHER_AES_256_OFB,
409 MBEDTLS_MODE_OFB,
410 256,
411 "AES-256-OFB",
412 16,
413 0,
414 16,
415 &aes_info
416};
417#endif /* MBEDTLS_CIPHER_MODE_OFB */
418
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200419#if defined(MBEDTLS_CIPHER_MODE_CTR)
420static const mbedtls_cipher_info_t aes_128_ctr_info = {
421 MBEDTLS_CIPHER_AES_128_CTR,
422 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000423 128,
424 "AES-128-CTR",
425 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200426 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000427 16,
428 &aes_info
429};
430
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200431static const mbedtls_cipher_info_t aes_192_ctr_info = {
432 MBEDTLS_CIPHER_AES_192_CTR,
433 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000434 192,
435 "AES-192-CTR",
436 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200437 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000438 16,
439 &aes_info
440};
441
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200442static const mbedtls_cipher_info_t aes_256_ctr_info = {
443 MBEDTLS_CIPHER_AES_256_CTR,
444 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000445 256,
446 "AES-256-CTR",
447 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200448 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000449 16,
450 &aes_info
451};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200452#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000453
Jaeden Ameroc6539902018-04-30 17:17:41 +0100454#if defined(MBEDTLS_CIPHER_MODE_XTS)
455static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
456 unsigned int key_bitlen )
457{
458 mbedtls_aes_xts_context *xts_ctx = ctx;
459 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
460}
461
462static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
463 unsigned int key_bitlen )
464{
465 mbedtls_aes_xts_context *xts_ctx = ctx;
466 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
467}
468
469static void *xts_aes_ctx_alloc( void )
470{
471 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
472
473 if( xts_ctx != NULL )
474 mbedtls_aes_xts_init( xts_ctx );
475
476 return( xts_ctx );
477}
478
479static void xts_aes_ctx_free( void *ctx )
480{
481 mbedtls_aes_xts_context *xts_ctx = ctx;
482
483 if( xts_ctx == NULL )
484 return;
485
486 mbedtls_aes_xts_free( xts_ctx );
487 mbedtls_free( xts_ctx );
488}
489
490static const mbedtls_cipher_base_t xts_aes_info = {
491 MBEDTLS_CIPHER_ID_AES,
492 NULL,
493#if defined(MBEDTLS_CIPHER_MODE_CBC)
494 NULL,
495#endif
496#if defined(MBEDTLS_CIPHER_MODE_CFB)
497 NULL,
498#endif
499#if defined(MBEDTLS_CIPHER_MODE_OFB)
500 NULL,
501#endif
502#if defined(MBEDTLS_CIPHER_MODE_CTR)
503 NULL,
504#endif
505#if defined(MBEDTLS_CIPHER_MODE_XTS)
506 aes_crypt_xts_wrap,
507#endif
508#if defined(MBEDTLS_CIPHER_MODE_STREAM)
509 NULL,
510#endif
511 xts_aes_setkey_enc_wrap,
512 xts_aes_setkey_dec_wrap,
513 xts_aes_ctx_alloc,
514 xts_aes_ctx_free
515};
516
517static const mbedtls_cipher_info_t aes_128_xts_info = {
518 MBEDTLS_CIPHER_AES_128_XTS,
519 MBEDTLS_MODE_XTS,
520 256,
521 "AES-128-XTS",
522 16,
523 0,
524 16,
525 &xts_aes_info
526};
527
528static const mbedtls_cipher_info_t aes_256_xts_info = {
529 MBEDTLS_CIPHER_AES_256_XTS,
530 MBEDTLS_MODE_XTS,
531 512,
532 "AES-256-XTS",
533 16,
534 0,
535 16,
536 &xts_aes_info
537};
538#endif /* MBEDTLS_CIPHER_MODE_XTS */
539
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200540#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200541static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200542 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200543{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200544 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200545 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200546}
547
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200548static const mbedtls_cipher_base_t gcm_aes_info = {
549 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200550 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200551#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200552 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100553#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200554#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200555 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100556#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100557#if defined(MBEDTLS_CIPHER_MODE_OFB)
558 NULL,
559#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200561 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100562#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100563#if defined(MBEDTLS_CIPHER_MODE_XTS)
564 NULL,
565#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200566#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200567 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100568#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200569 gcm_aes_setkey_wrap,
570 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200571 gcm_ctx_alloc,
572 gcm_ctx_free,
573};
574
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200575static const mbedtls_cipher_info_t aes_128_gcm_info = {
576 MBEDTLS_CIPHER_AES_128_GCM,
577 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100578 128,
579 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200580 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200581 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100582 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200583 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100584};
585
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586static const mbedtls_cipher_info_t aes_192_gcm_info = {
587 MBEDTLS_CIPHER_AES_192_GCM,
588 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200589 192,
590 "AES-192-GCM",
591 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200592 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200593 16,
594 &gcm_aes_info
595};
596
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200597static const mbedtls_cipher_info_t aes_256_gcm_info = {
598 MBEDTLS_CIPHER_AES_256_GCM,
599 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100600 256,
601 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200602 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200603 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100604 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200605 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100606};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100608
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200609#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200610static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200611 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200612{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200613 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200614 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200615}
616
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200617static const mbedtls_cipher_base_t ccm_aes_info = {
618 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200619 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200620#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200621 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100622#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200623#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200624 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100625#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100626#if defined(MBEDTLS_CIPHER_MODE_OFB)
627 NULL,
628#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200629#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200630 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100631#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100632#if defined(MBEDTLS_CIPHER_MODE_XTS)
633 NULL,
634#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200635#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200636 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100637#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200638 ccm_aes_setkey_wrap,
639 ccm_aes_setkey_wrap,
640 ccm_ctx_alloc,
641 ccm_ctx_free,
642};
643
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200644static const mbedtls_cipher_info_t aes_128_ccm_info = {
645 MBEDTLS_CIPHER_AES_128_CCM,
646 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200647 128,
648 "AES-128-CCM",
649 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200650 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200651 16,
652 &ccm_aes_info
653};
654
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200655static const mbedtls_cipher_info_t aes_192_ccm_info = {
656 MBEDTLS_CIPHER_AES_192_CCM,
657 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200658 192,
659 "AES-192-CCM",
660 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200661 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200662 16,
663 &ccm_aes_info
664};
665
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200666static const mbedtls_cipher_info_t aes_256_ccm_info = {
667 MBEDTLS_CIPHER_AES_256_CCM,
668 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200669 256,
670 "AES-256-CCM",
671 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200673 16,
674 &ccm_aes_info
675};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200676#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200677
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200678#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000679
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000681
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200682static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200683 const unsigned char *input, unsigned char *output )
684{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200685 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200686 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200687}
688
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200689#if defined(MBEDTLS_CIPHER_MODE_CBC)
690static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200691 size_t length, unsigned char *iv,
692 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000693{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200694 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200695 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000696}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200697#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000698
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200699#if defined(MBEDTLS_CIPHER_MODE_CFB)
700static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200701 size_t length, size_t *iv_off, unsigned char *iv,
702 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000703{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200704 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200705 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000706}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200707#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000708
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200709#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200710static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
711 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000712 const unsigned char *input, unsigned char *output )
713{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200714 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200715 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000716}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200717#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000718
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200719static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200720 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000721{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200722 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000723}
724
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200725static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200726 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000727{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200728 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000729}
730
731static void * camellia_ctx_alloc( void )
732{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200733 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200734 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200735
736 if( ctx == NULL )
737 return( NULL );
738
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200739 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200740
741 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000742}
743
744static void camellia_ctx_free( void *ctx )
745{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200746 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
747 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000748}
749
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200750static const mbedtls_cipher_base_t camellia_info = {
751 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200752 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200753#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000754 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100755#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200756#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000757 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100758#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100759#if defined(MBEDTLS_CIPHER_MODE_OFB)
760 NULL,
761#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200762#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000763 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100764#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100765#if defined(MBEDTLS_CIPHER_MODE_XTS)
766 NULL,
767#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200768#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200769 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100770#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000771 camellia_setkey_enc_wrap,
772 camellia_setkey_dec_wrap,
773 camellia_ctx_alloc,
774 camellia_ctx_free
775};
776
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200777static const mbedtls_cipher_info_t camellia_128_ecb_info = {
778 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
779 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200780 128,
781 "CAMELLIA-128-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +0100782 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200783 0,
784 16,
785 &camellia_info
786};
787
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200788static const mbedtls_cipher_info_t camellia_192_ecb_info = {
789 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
790 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200791 192,
792 "CAMELLIA-192-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +0100793 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200794 0,
795 16,
796 &camellia_info
797};
798
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200799static const mbedtls_cipher_info_t camellia_256_ecb_info = {
800 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
801 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200802 256,
803 "CAMELLIA-256-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +0100804 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200805 0,
806 16,
807 &camellia_info
808};
809
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200810#if defined(MBEDTLS_CIPHER_MODE_CBC)
811static const mbedtls_cipher_info_t camellia_128_cbc_info = {
812 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
813 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000814 128,
815 "CAMELLIA-128-CBC",
816 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200817 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000818 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000819 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000820};
821
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200822static const mbedtls_cipher_info_t camellia_192_cbc_info = {
823 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
824 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000825 192,
826 "CAMELLIA-192-CBC",
827 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200828 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000829 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000830 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000831};
832
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200833static const mbedtls_cipher_info_t camellia_256_cbc_info = {
834 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
835 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000836 256,
837 "CAMELLIA-256-CBC",
838 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200839 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000840 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000841 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000842};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200843#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000844
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200845#if defined(MBEDTLS_CIPHER_MODE_CFB)
846static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
847 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
848 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000849 128,
850 "CAMELLIA-128-CFB128",
851 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200852 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000853 16,
854 &camellia_info
855};
856
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200857static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
858 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
859 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000860 192,
861 "CAMELLIA-192-CFB128",
862 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200863 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000864 16,
865 &camellia_info
866};
867
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200868static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
869 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
870 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000871 256,
872 "CAMELLIA-256-CFB128",
873 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200874 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000875 16,
876 &camellia_info
877};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200878#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000879
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200880#if defined(MBEDTLS_CIPHER_MODE_CTR)
881static const mbedtls_cipher_info_t camellia_128_ctr_info = {
882 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
883 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000884 128,
885 "CAMELLIA-128-CTR",
886 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200887 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000888 16,
889 &camellia_info
890};
891
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200892static const mbedtls_cipher_info_t camellia_192_ctr_info = {
893 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
894 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000895 192,
896 "CAMELLIA-192-CTR",
897 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200898 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000899 16,
900 &camellia_info
901};
902
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200903static const mbedtls_cipher_info_t camellia_256_ctr_info = {
904 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
905 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000906 256,
907 "CAMELLIA-256-CTR",
908 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200909 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000910 16,
911 &camellia_info
912};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200913#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000914
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200915#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200916static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200917 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200918{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200919 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200920 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200921}
922
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200923static const mbedtls_cipher_base_t gcm_camellia_info = {
924 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200925 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200926#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200927 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100928#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200929#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200930 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100931#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +0100932#if defined(MBEDTLS_CIPHER_MODE_OFB)
933 NULL,
934#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200935#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200936 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100937#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +0100938#if defined(MBEDTLS_CIPHER_MODE_XTS)
939 NULL,
940#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200941#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200942 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100943#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200944 gcm_camellia_setkey_wrap,
945 gcm_camellia_setkey_wrap,
946 gcm_ctx_alloc,
947 gcm_ctx_free,
948};
949
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200950static const mbedtls_cipher_info_t camellia_128_gcm_info = {
951 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
952 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200953 128,
954 "CAMELLIA-128-GCM",
955 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200956 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200957 16,
958 &gcm_camellia_info
959};
960
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200961static const mbedtls_cipher_info_t camellia_192_gcm_info = {
962 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
963 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200964 192,
965 "CAMELLIA-192-GCM",
966 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200967 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200968 16,
969 &gcm_camellia_info
970};
971
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200972static const mbedtls_cipher_info_t camellia_256_gcm_info = {
973 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
974 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200975 256,
976 "CAMELLIA-256-GCM",
977 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200978 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200979 16,
980 &gcm_camellia_info
981};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200982#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200983
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200984#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200985static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200986 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200987{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200988 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200989 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200990}
991
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200992static const mbedtls_cipher_base_t ccm_camellia_info = {
993 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200994 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200995#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200996 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100997#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200998#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200999 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001000#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001001#if defined(MBEDTLS_CIPHER_MODE_OFB)
1002 NULL,
1003#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001004#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001005 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001006#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001007#if defined(MBEDTLS_CIPHER_MODE_XTS)
1008 NULL,
1009#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001010#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001011 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001012#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001013 ccm_camellia_setkey_wrap,
1014 ccm_camellia_setkey_wrap,
1015 ccm_ctx_alloc,
1016 ccm_ctx_free,
1017};
1018
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001019static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1020 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1021 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001022 128,
1023 "CAMELLIA-128-CCM",
1024 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001025 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001026 16,
1027 &ccm_camellia_info
1028};
1029
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001030static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1031 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1032 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001033 192,
1034 "CAMELLIA-192-CCM",
1035 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001036 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001037 16,
1038 &ccm_camellia_info
1039};
1040
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001041static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1042 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1043 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001044 256,
1045 "CAMELLIA-256-CCM",
1046 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001047 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001048 16,
1049 &ccm_camellia_info
1050};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001051#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001052
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001053#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001054
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001055#if defined(MBEDTLS_ARIA_C)
1056
1057static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1058 const unsigned char *input, unsigned char *output )
1059{
Manuel Pégourié-Gonnard08c337d2018-05-22 13:18:01 +02001060 (void) operation;
1061 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001062 output );
1063}
1064
1065#if defined(MBEDTLS_CIPHER_MODE_CBC)
1066static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1067 size_t length, unsigned char *iv,
1068 const unsigned char *input, unsigned char *output )
1069{
Manuel Pégourié-Gonnard39f25612018-05-24 14:06:02 +02001070 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001071 input, output );
1072}
1073#endif /* MBEDTLS_CIPHER_MODE_CBC */
1074
1075#if defined(MBEDTLS_CIPHER_MODE_CFB)
1076static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1077 size_t length, size_t *iv_off, unsigned char *iv,
1078 const unsigned char *input, unsigned char *output )
1079{
1080 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1081 iv_off, iv, input, output );
1082}
1083#endif /* MBEDTLS_CIPHER_MODE_CFB */
1084
1085#if defined(MBEDTLS_CIPHER_MODE_CTR)
1086static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1087 unsigned char *nonce_counter, unsigned char *stream_block,
1088 const unsigned char *input, unsigned char *output )
1089{
1090 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1091 nonce_counter, stream_block, input, output );
1092}
1093#endif /* MBEDTLS_CIPHER_MODE_CTR */
1094
1095static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1096 unsigned int key_bitlen )
1097{
1098 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1099}
1100
1101static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1102 unsigned int key_bitlen )
1103{
1104 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1105}
1106
1107static void * aria_ctx_alloc( void )
1108{
1109 mbedtls_aria_context *ctx;
1110 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1111
1112 if( ctx == NULL )
1113 return( NULL );
1114
1115 mbedtls_aria_init( ctx );
1116
1117 return( ctx );
1118}
1119
1120static void aria_ctx_free( void *ctx )
1121{
1122 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1123 mbedtls_free( ctx );
1124}
1125
1126static const mbedtls_cipher_base_t aria_info = {
1127 MBEDTLS_CIPHER_ID_ARIA,
1128 aria_crypt_ecb_wrap,
1129#if defined(MBEDTLS_CIPHER_MODE_CBC)
1130 aria_crypt_cbc_wrap,
1131#endif
1132#if defined(MBEDTLS_CIPHER_MODE_CFB)
1133 aria_crypt_cfb128_wrap,
1134#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001135#if defined(MBEDTLS_CIPHER_MODE_OFB)
1136 NULL,
1137#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001138#if defined(MBEDTLS_CIPHER_MODE_CTR)
1139 aria_crypt_ctr_wrap,
1140#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001141#if defined(MBEDTLS_CIPHER_MODE_XTS)
1142 NULL,
1143#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001144#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1145 NULL,
1146#endif
1147 aria_setkey_enc_wrap,
1148 aria_setkey_dec_wrap,
1149 aria_ctx_alloc,
1150 aria_ctx_free
1151};
1152
1153static const mbedtls_cipher_info_t aria_128_ecb_info = {
1154 MBEDTLS_CIPHER_ARIA_128_ECB,
1155 MBEDTLS_MODE_ECB,
1156 128,
1157 "ARIA-128-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001158 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001159 0,
1160 16,
1161 &aria_info
1162};
1163
1164static const mbedtls_cipher_info_t aria_192_ecb_info = {
1165 MBEDTLS_CIPHER_ARIA_192_ECB,
1166 MBEDTLS_MODE_ECB,
1167 192,
1168 "ARIA-192-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001169 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001170 0,
1171 16,
1172 &aria_info
1173};
1174
1175static const mbedtls_cipher_info_t aria_256_ecb_info = {
1176 MBEDTLS_CIPHER_ARIA_256_ECB,
1177 MBEDTLS_MODE_ECB,
1178 256,
1179 "ARIA-256-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001180 0,
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001181 0,
1182 16,
1183 &aria_info
1184};
1185
1186#if defined(MBEDTLS_CIPHER_MODE_CBC)
1187static const mbedtls_cipher_info_t aria_128_cbc_info = {
1188 MBEDTLS_CIPHER_ARIA_128_CBC,
1189 MBEDTLS_MODE_CBC,
1190 128,
1191 "ARIA-128-CBC",
1192 16,
1193 0,
1194 16,
1195 &aria_info
1196};
1197
1198static const mbedtls_cipher_info_t aria_192_cbc_info = {
1199 MBEDTLS_CIPHER_ARIA_192_CBC,
1200 MBEDTLS_MODE_CBC,
1201 192,
1202 "ARIA-192-CBC",
1203 16,
1204 0,
1205 16,
1206 &aria_info
1207};
1208
1209static const mbedtls_cipher_info_t aria_256_cbc_info = {
1210 MBEDTLS_CIPHER_ARIA_256_CBC,
1211 MBEDTLS_MODE_CBC,
1212 256,
1213 "ARIA-256-CBC",
1214 16,
1215 0,
1216 16,
1217 &aria_info
1218};
1219#endif /* MBEDTLS_CIPHER_MODE_CBC */
1220
1221#if defined(MBEDTLS_CIPHER_MODE_CFB)
1222static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1223 MBEDTLS_CIPHER_ARIA_128_CFB128,
1224 MBEDTLS_MODE_CFB,
1225 128,
1226 "ARIA-128-CFB128",
1227 16,
1228 0,
1229 16,
1230 &aria_info
1231};
1232
1233static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1234 MBEDTLS_CIPHER_ARIA_192_CFB128,
1235 MBEDTLS_MODE_CFB,
1236 192,
1237 "ARIA-192-CFB128",
1238 16,
1239 0,
1240 16,
1241 &aria_info
1242};
1243
1244static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1245 MBEDTLS_CIPHER_ARIA_256_CFB128,
1246 MBEDTLS_MODE_CFB,
1247 256,
1248 "ARIA-256-CFB128",
1249 16,
1250 0,
1251 16,
1252 &aria_info
1253};
1254#endif /* MBEDTLS_CIPHER_MODE_CFB */
1255
1256#if defined(MBEDTLS_CIPHER_MODE_CTR)
1257static const mbedtls_cipher_info_t aria_128_ctr_info = {
1258 MBEDTLS_CIPHER_ARIA_128_CTR,
1259 MBEDTLS_MODE_CTR,
1260 128,
1261 "ARIA-128-CTR",
1262 16,
1263 0,
1264 16,
1265 &aria_info
1266};
1267
1268static const mbedtls_cipher_info_t aria_192_ctr_info = {
1269 MBEDTLS_CIPHER_ARIA_192_CTR,
1270 MBEDTLS_MODE_CTR,
1271 192,
1272 "ARIA-192-CTR",
1273 16,
1274 0,
1275 16,
1276 &aria_info
1277};
1278
1279static const mbedtls_cipher_info_t aria_256_ctr_info = {
1280 MBEDTLS_CIPHER_ARIA_256_CTR,
1281 MBEDTLS_MODE_CTR,
1282 256,
1283 "ARIA-256-CTR",
1284 16,
1285 0,
1286 16,
1287 &aria_info
1288};
1289#endif /* MBEDTLS_CIPHER_MODE_CTR */
1290
1291#if defined(MBEDTLS_GCM_C)
1292static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1293 unsigned int key_bitlen )
1294{
1295 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1296 key, key_bitlen );
1297}
1298
1299static const mbedtls_cipher_base_t gcm_aria_info = {
1300 MBEDTLS_CIPHER_ID_ARIA,
1301 NULL,
1302#if defined(MBEDTLS_CIPHER_MODE_CBC)
1303 NULL,
1304#endif
1305#if defined(MBEDTLS_CIPHER_MODE_CFB)
1306 NULL,
1307#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01001308#if defined(MBEDTLS_CIPHER_MODE_OFB)
1309 NULL,
1310#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001311#if defined(MBEDTLS_CIPHER_MODE_CTR)
1312 NULL,
1313#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001314#if defined(MBEDTLS_CIPHER_MODE_XTS)
1315 NULL,
1316#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001317#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1318 NULL,
1319#endif
1320 gcm_aria_setkey_wrap,
1321 gcm_aria_setkey_wrap,
1322 gcm_ctx_alloc,
1323 gcm_ctx_free,
1324};
1325
1326static const mbedtls_cipher_info_t aria_128_gcm_info = {
1327 MBEDTLS_CIPHER_ARIA_128_GCM,
1328 MBEDTLS_MODE_GCM,
1329 128,
1330 "ARIA-128-GCM",
1331 12,
1332 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1333 16,
1334 &gcm_aria_info
1335};
1336
1337static const mbedtls_cipher_info_t aria_192_gcm_info = {
1338 MBEDTLS_CIPHER_ARIA_192_GCM,
1339 MBEDTLS_MODE_GCM,
1340 192,
1341 "ARIA-192-GCM",
1342 12,
1343 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1344 16,
1345 &gcm_aria_info
1346};
1347
1348static const mbedtls_cipher_info_t aria_256_gcm_info = {
1349 MBEDTLS_CIPHER_ARIA_256_GCM,
1350 MBEDTLS_MODE_GCM,
1351 256,
1352 "ARIA-256-GCM",
1353 12,
1354 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1355 16,
1356 &gcm_aria_info
1357};
1358#endif /* MBEDTLS_GCM_C */
1359
1360#if defined(MBEDTLS_CCM_C)
1361static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1362 unsigned int key_bitlen )
1363{
1364 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1365 key, key_bitlen );
1366}
1367
1368static const mbedtls_cipher_base_t ccm_aria_info = {
1369 MBEDTLS_CIPHER_ID_ARIA,
1370 NULL,
1371#if defined(MBEDTLS_CIPHER_MODE_CBC)
1372 NULL,
1373#endif
1374#if defined(MBEDTLS_CIPHER_MODE_CFB)
1375 NULL,
1376#endif
Simon Butcher7487c5b2018-04-29 00:24:51 +01001377#if defined(MBEDTLS_CIPHER_MODE_OFB)
1378 NULL,
1379#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001380#if defined(MBEDTLS_CIPHER_MODE_CTR)
1381 NULL,
1382#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001383#if defined(MBEDTLS_CIPHER_MODE_XTS)
1384 NULL,
1385#endif
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00001386#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1387 NULL,
1388#endif
1389 ccm_aria_setkey_wrap,
1390 ccm_aria_setkey_wrap,
1391 ccm_ctx_alloc,
1392 ccm_ctx_free,
1393};
1394
1395static const mbedtls_cipher_info_t aria_128_ccm_info = {
1396 MBEDTLS_CIPHER_ARIA_128_CCM,
1397 MBEDTLS_MODE_CCM,
1398 128,
1399 "ARIA-128-CCM",
1400 12,
1401 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1402 16,
1403 &ccm_aria_info
1404};
1405
1406static const mbedtls_cipher_info_t aria_192_ccm_info = {
1407 MBEDTLS_CIPHER_ARIA_192_CCM,
1408 MBEDTLS_MODE_CCM,
1409 192,
1410 "ARIA-192-CCM",
1411 12,
1412 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1413 16,
1414 &ccm_aria_info
1415};
1416
1417static const mbedtls_cipher_info_t aria_256_ccm_info = {
1418 MBEDTLS_CIPHER_ARIA_256_CCM,
1419 MBEDTLS_MODE_CCM,
1420 256,
1421 "ARIA-256-CCM",
1422 12,
1423 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1424 16,
1425 &ccm_aria_info
1426};
1427#endif /* MBEDTLS_CCM_C */
1428
1429#endif /* MBEDTLS_ARIA_C */
1430
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001431#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001432
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001433static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001434 const unsigned char *input, unsigned char *output )
1435{
1436 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001437 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001438}
1439
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001440static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001441 const unsigned char *input, unsigned char *output )
1442{
1443 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001444 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001445}
1446
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001447#if defined(MBEDTLS_CIPHER_MODE_CBC)
1448static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001449 unsigned char *iv, const unsigned char *input, unsigned char *output )
1450{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001451 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001452 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001453}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001454#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001455
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001456#if defined(MBEDTLS_CIPHER_MODE_CBC)
1457static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001458 unsigned char *iv, const unsigned char *input, unsigned char *output )
1459{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001460 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001461 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001462}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001463#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001464
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001465static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001466 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001467{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001468 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001469
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001470 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001471}
1472
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001473static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001474 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001475{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001476 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001477
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001478 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001479}
1480
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001481static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001482 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001483{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001484 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001485
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001486 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001487}
1488
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001489static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001490 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001491{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001492 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001493
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001494 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001495}
1496
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001497static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001498 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001499{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001500 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001501
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001502 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001503}
1504
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001505static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001506 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001507{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001508 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001509
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001510 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001511}
1512
1513static void * des_ctx_alloc( void )
1514{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001515 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001516
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001517 if( des == NULL )
1518 return( NULL );
1519
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001520 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001521
1522 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001523}
1524
1525static void des_ctx_free( void *ctx )
1526{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001527 mbedtls_des_free( (mbedtls_des_context *) ctx );
1528 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001529}
1530
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001531static void * des3_ctx_alloc( void )
1532{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001533 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001534 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001535
1536 if( des3 == NULL )
1537 return( NULL );
1538
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001539 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001540
1541 return( des3 );
1542}
1543
Paul Bakker34617722014-06-13 17:20:13 +02001544static void des3_ctx_free( void *ctx )
1545{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001546 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1547 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001548}
1549
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001550static const mbedtls_cipher_base_t des_info = {
1551 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001552 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001553#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001554 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001555#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001556#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001557 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001558#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001559#if defined(MBEDTLS_CIPHER_MODE_OFB)
1560 NULL,
1561#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001562#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001563 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001564#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001565#if defined(MBEDTLS_CIPHER_MODE_XTS)
1566 NULL,
1567#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001568#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001569 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001570#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001571 des_setkey_enc_wrap,
1572 des_setkey_dec_wrap,
1573 des_ctx_alloc,
1574 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001575};
1576
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001577static const mbedtls_cipher_info_t des_ecb_info = {
1578 MBEDTLS_CIPHER_DES_ECB,
1579 MBEDTLS_MODE_ECB,
1580 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001581 "DES-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001582 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001583 0,
1584 8,
1585 &des_info
1586};
1587
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001588#if defined(MBEDTLS_CIPHER_MODE_CBC)
1589static const mbedtls_cipher_info_t des_cbc_info = {
1590 MBEDTLS_CIPHER_DES_CBC,
1591 MBEDTLS_MODE_CBC,
1592 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001593 "DES-CBC",
1594 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001595 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001596 8,
1597 &des_info
1598};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001599#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001600
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001601static const mbedtls_cipher_base_t des_ede_info = {
1602 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001603 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001604#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001605 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001606#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001607#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001608 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001609#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001610#if defined(MBEDTLS_CIPHER_MODE_OFB)
1611 NULL,
1612#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001613#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001614 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001615#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001616#if defined(MBEDTLS_CIPHER_MODE_XTS)
1617 NULL,
1618#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001619#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001620 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001621#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001622 des3_set2key_enc_wrap,
1623 des3_set2key_dec_wrap,
1624 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001625 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001626};
1627
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001628static const mbedtls_cipher_info_t des_ede_ecb_info = {
1629 MBEDTLS_CIPHER_DES_EDE_ECB,
1630 MBEDTLS_MODE_ECB,
1631 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001632 "DES-EDE-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001633 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001634 0,
1635 8,
1636 &des_ede_info
1637};
1638
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001639#if defined(MBEDTLS_CIPHER_MODE_CBC)
1640static const mbedtls_cipher_info_t des_ede_cbc_info = {
1641 MBEDTLS_CIPHER_DES_EDE_CBC,
1642 MBEDTLS_MODE_CBC,
1643 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001644 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001645 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001646 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001647 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001648 &des_ede_info
1649};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001650#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001651
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001652static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001653 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001654 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001655#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001656 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001657#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001658#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001659 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001660#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001661#if defined(MBEDTLS_CIPHER_MODE_OFB)
1662 NULL,
1663#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001664#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001665 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001666#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001667#if defined(MBEDTLS_CIPHER_MODE_XTS)
1668 NULL,
1669#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001670#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001671 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001672#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001673 des3_set3key_enc_wrap,
1674 des3_set3key_dec_wrap,
1675 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001676 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001677};
1678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001679static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1680 MBEDTLS_CIPHER_DES_EDE3_ECB,
1681 MBEDTLS_MODE_ECB,
1682 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001683 "DES-EDE3-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001684 0,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001685 0,
1686 8,
1687 &des_ede3_info
1688};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001689#if defined(MBEDTLS_CIPHER_MODE_CBC)
1690static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1691 MBEDTLS_CIPHER_DES_EDE3_CBC,
1692 MBEDTLS_MODE_CBC,
1693 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001694 "DES-EDE3-CBC",
1695 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001696 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001697 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001698 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001699};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001700#endif /* MBEDTLS_CIPHER_MODE_CBC */
1701#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001702
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001703#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001704
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001705static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001706 const unsigned char *input, unsigned char *output )
1707{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001708 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001709 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001710}
1711
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001712#if defined(MBEDTLS_CIPHER_MODE_CBC)
1713static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001714 size_t length, unsigned char *iv, const unsigned char *input,
1715 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001716{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001717 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001718 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001719}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001720#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001721
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001722#if defined(MBEDTLS_CIPHER_MODE_CFB)
1723static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001724 size_t length, size_t *iv_off, unsigned char *iv,
1725 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001726{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001727 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001728 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001729}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001730#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001731
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001732#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001733static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1734 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001735 const unsigned char *input, unsigned char *output )
1736{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001737 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001738 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001739}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001740#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001741
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001742static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001743 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001744{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001745 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001746}
1747
1748static void * blowfish_ctx_alloc( void )
1749{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001750 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001751 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001752
1753 if( ctx == NULL )
1754 return( NULL );
1755
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001756 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001757
1758 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001759}
1760
1761static void blowfish_ctx_free( void *ctx )
1762{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001763 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1764 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001765}
1766
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001767static const mbedtls_cipher_base_t blowfish_info = {
1768 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001769 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001770#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001771 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001772#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001773#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001774 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001775#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001776#if defined(MBEDTLS_CIPHER_MODE_OFB)
1777 NULL,
1778#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001779#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001780 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001781#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001782#if defined(MBEDTLS_CIPHER_MODE_XTS)
1783 NULL,
1784#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001785#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001786 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001787#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001788 blowfish_setkey_wrap,
1789 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001790 blowfish_ctx_alloc,
1791 blowfish_ctx_free
1792};
1793
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001794static const mbedtls_cipher_info_t blowfish_ecb_info = {
1795 MBEDTLS_CIPHER_BLOWFISH_ECB,
1796 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001797 128,
1798 "BLOWFISH-ECB",
Bence Szépkúti567bd952020-10-29 10:22:35 +01001799 0,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001800 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001801 8,
1802 &blowfish_info
1803};
1804
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001805#if defined(MBEDTLS_CIPHER_MODE_CBC)
1806static const mbedtls_cipher_info_t blowfish_cbc_info = {
1807 MBEDTLS_CIPHER_BLOWFISH_CBC,
1808 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001809 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001810 "BLOWFISH-CBC",
1811 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001812 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001813 8,
1814 &blowfish_info
1815};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001816#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001817
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001818#if defined(MBEDTLS_CIPHER_MODE_CFB)
1819static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1820 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1821 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001822 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001823 "BLOWFISH-CFB64",
1824 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001825 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001826 8,
1827 &blowfish_info
1828};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001829#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001830
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001831#if defined(MBEDTLS_CIPHER_MODE_CTR)
1832static const mbedtls_cipher_info_t blowfish_ctr_info = {
1833 MBEDTLS_CIPHER_BLOWFISH_CTR,
1834 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001835 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001836 "BLOWFISH-CTR",
1837 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001838 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001839 8,
1840 &blowfish_info
1841};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001842#endif /* MBEDTLS_CIPHER_MODE_CTR */
1843#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001844
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001845#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001846static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1847 const unsigned char *input,
1848 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001849{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001850 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001851}
1852
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001853static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001854 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001855{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001856 /* we get key_bitlen in bits, arc4 expects it in bytes */
1857 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001858 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001859
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001860 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001861 return( 0 );
1862}
1863
1864static void * arc4_ctx_alloc( void )
1865{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001866 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001867 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001868
1869 if( ctx == NULL )
1870 return( NULL );
1871
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001872 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001873
1874 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001875}
Paul Bakker68884e32013-01-07 18:20:04 +01001876
1877static void arc4_ctx_free( void *ctx )
1878{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001879 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1880 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001881}
1882
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001883static const mbedtls_cipher_base_t arc4_base_info = {
1884 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001885 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001886#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001887 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001888#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001889#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001890 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001891#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01001892#if defined(MBEDTLS_CIPHER_MODE_OFB)
1893 NULL,
1894#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001895#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001896 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001897#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01001898#if defined(MBEDTLS_CIPHER_MODE_XTS)
1899 NULL,
1900#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001901#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001902 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001903#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001904 arc4_setkey_wrap,
1905 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001906 arc4_ctx_alloc,
1907 arc4_ctx_free
1908};
1909
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001910static const mbedtls_cipher_info_t arc4_128_info = {
1911 MBEDTLS_CIPHER_ARC4_128,
1912 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001913 128,
1914 "ARC4-128",
1915 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001916 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001917 1,
1918 &arc4_base_info
1919};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001920#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001921
Daniel Kingbd920622016-05-15 19:56:20 -03001922#if defined(MBEDTLS_CHACHA20_C)
1923
1924static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1925 unsigned int key_bitlen )
1926{
1927 if( key_bitlen != 256U )
1928 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1929
1930 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1931 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1932
1933 return( 0 );
1934}
1935
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001936static int chacha20_stream_wrap( void *ctx, size_t length,
1937 const unsigned char *input,
1938 unsigned char *output )
1939{
1940 int ret;
1941
1942 ret = mbedtls_chacha20_update( ctx, length, input, output );
1943 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1944 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1945
1946 return( ret );
1947}
1948
Daniel Kingbd920622016-05-15 19:56:20 -03001949static void * chacha20_ctx_alloc( void )
1950{
1951 mbedtls_chacha20_context *ctx;
1952 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1953
1954 if( ctx == NULL )
1955 return( NULL );
1956
1957 mbedtls_chacha20_init( ctx );
1958
1959 return( ctx );
1960}
1961
1962static void chacha20_ctx_free( void *ctx )
1963{
1964 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1965 mbedtls_free( ctx );
1966}
1967
1968static const mbedtls_cipher_base_t chacha20_base_info = {
1969 MBEDTLS_CIPHER_ID_CHACHA20,
1970 NULL,
1971#if defined(MBEDTLS_CIPHER_MODE_CBC)
1972 NULL,
1973#endif
1974#if defined(MBEDTLS_CIPHER_MODE_CFB)
1975 NULL,
1976#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001977#if defined(MBEDTLS_CIPHER_MODE_OFB)
1978 NULL,
1979#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001980#if defined(MBEDTLS_CIPHER_MODE_CTR)
1981 NULL,
1982#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02001983#if defined(MBEDTLS_CIPHER_MODE_XTS)
1984 NULL,
1985#endif
Daniel Kingbd920622016-05-15 19:56:20 -03001986#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001987 chacha20_stream_wrap,
Daniel Kingbd920622016-05-15 19:56:20 -03001988#endif
1989 chacha20_setkey_wrap,
1990 chacha20_setkey_wrap,
1991 chacha20_ctx_alloc,
1992 chacha20_ctx_free
1993};
1994static const mbedtls_cipher_info_t chacha20_info = {
1995 MBEDTLS_CIPHER_CHACHA20,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02001996 MBEDTLS_MODE_STREAM,
Daniel Kingbd920622016-05-15 19:56:20 -03001997 256,
1998 "CHACHA20",
1999 12,
2000 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002001 1,
Daniel Kingbd920622016-05-15 19:56:20 -03002002 &chacha20_base_info
2003};
2004#endif /* MBEDTLS_CHACHA20_C */
2005
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002006#if defined(MBEDTLS_CHACHAPOLY_C)
Daniel King8fe47012016-05-17 20:33:28 -03002007
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002008static int chachapoly_setkey_wrap( void *ctx,
2009 const unsigned char *key,
2010 unsigned int key_bitlen )
Daniel King8fe47012016-05-17 20:33:28 -03002011{
2012 if( key_bitlen != 256U )
2013 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2014
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002015 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
Daniel King8fe47012016-05-17 20:33:28 -03002016 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2017
2018 return( 0 );
2019}
2020
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002021static void * chachapoly_ctx_alloc( void )
Daniel King8fe47012016-05-17 20:33:28 -03002022{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002023 mbedtls_chachapoly_context *ctx;
2024 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
Daniel King8fe47012016-05-17 20:33:28 -03002025
2026 if( ctx == NULL )
2027 return( NULL );
2028
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002029 mbedtls_chachapoly_init( ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002030
2031 return( ctx );
2032}
2033
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002034static void chachapoly_ctx_free( void *ctx )
Daniel King8fe47012016-05-17 20:33:28 -03002035{
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002036 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
Daniel King8fe47012016-05-17 20:33:28 -03002037 mbedtls_free( ctx );
2038}
2039
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002040static const mbedtls_cipher_base_t chachapoly_base_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002041 MBEDTLS_CIPHER_ID_CHACHA20,
2042 NULL,
2043#if defined(MBEDTLS_CIPHER_MODE_CBC)
2044 NULL,
2045#endif
2046#if defined(MBEDTLS_CIPHER_MODE_CFB)
2047 NULL,
2048#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002049#if defined(MBEDTLS_CIPHER_MODE_OFB)
2050 NULL,
2051#endif
Daniel King8fe47012016-05-17 20:33:28 -03002052#if defined(MBEDTLS_CIPHER_MODE_CTR)
2053 NULL,
2054#endif
Manuel Pégourié-Gonnarda18034a2018-06-19 11:30:32 +02002055#if defined(MBEDTLS_CIPHER_MODE_XTS)
2056 NULL,
2057#endif
Daniel King8fe47012016-05-17 20:33:28 -03002058#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2059 NULL,
2060#endif
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002061 chachapoly_setkey_wrap,
2062 chachapoly_setkey_wrap,
2063 chachapoly_ctx_alloc,
2064 chachapoly_ctx_free
Daniel King8fe47012016-05-17 20:33:28 -03002065};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002066static const mbedtls_cipher_info_t chachapoly_info = {
Daniel King8fe47012016-05-17 20:33:28 -03002067 MBEDTLS_CIPHER_CHACHA20_POLY1305,
Manuel Pégourié-Gonnardf57bf8b2018-06-18 11:14:09 +02002068 MBEDTLS_MODE_CHACHAPOLY,
Daniel King8fe47012016-05-17 20:33:28 -03002069 256,
2070 "CHACHA20-POLY1305",
2071 12,
2072 0,
Manuel Pégourié-Gonnard32902e62018-05-10 12:30:19 +02002073 1,
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002074 &chachapoly_base_info
Daniel King8fe47012016-05-17 20:33:28 -03002075};
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002076#endif /* MBEDTLS_CHACHAPOLY_C */
Daniel King8fe47012016-05-17 20:33:28 -03002077
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002078#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002079static int null_crypt_stream( void *ctx, size_t length,
2080 const unsigned char *input,
2081 unsigned char *output )
2082{
2083 ((void) ctx);
2084 memmove( output, input, length );
2085 return( 0 );
2086}
2087
2088static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002089 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002090{
2091 ((void) ctx);
2092 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02002093 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002094
2095 return( 0 );
2096}
2097
Paul Bakkerfab5c822012-02-06 16:45:10 +00002098static void * null_ctx_alloc( void )
2099{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02002100 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00002101}
2102
Paul Bakkerfab5c822012-02-06 16:45:10 +00002103static void null_ctx_free( void *ctx )
2104{
2105 ((void) ctx);
2106}
2107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002108static const mbedtls_cipher_base_t null_base_info = {
2109 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002110 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002111#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002112 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002113#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002114#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00002115 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002116#endif
Simon Butcher4844bf22018-06-11 15:21:05 +01002117#if defined(MBEDTLS_CIPHER_MODE_OFB)
2118 NULL,
2119#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002120#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02002121 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002122#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002123#if defined(MBEDTLS_CIPHER_MODE_XTS)
2124 NULL,
2125#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002126#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002127 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01002128#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02002129 null_setkey,
2130 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002131 null_ctx_alloc,
2132 null_ctx_free
2133};
2134
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002135static const mbedtls_cipher_info_t null_cipher_info = {
2136 MBEDTLS_CIPHER_NULL,
2137 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002138 0,
2139 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01002140 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02002141 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00002142 1,
2143 &null_base_info
2144};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002145#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00002146
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002147const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002148{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002149#if defined(MBEDTLS_AES_C)
2150 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2151 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2152 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2153#if defined(MBEDTLS_CIPHER_MODE_CBC)
2154 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2155 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2156 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002157#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002158#if defined(MBEDTLS_CIPHER_MODE_CFB)
2159 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2160 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2161 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002162#endif
Simon Butcher8c0fd1e2018-04-22 22:58:07 +01002163#if defined(MBEDTLS_CIPHER_MODE_OFB)
2164 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2165 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2166 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2167#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002168#if defined(MBEDTLS_CIPHER_MODE_CTR)
2169 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2170 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2171 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002172#endif
Jaeden Ameroc6539902018-04-30 17:17:41 +01002173#if defined(MBEDTLS_CIPHER_MODE_XTS)
2174 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2175 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2176#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002177#if defined(MBEDTLS_GCM_C)
2178 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2179 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2180 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002181#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002182#if defined(MBEDTLS_CCM_C)
2183 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2184 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2185 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002186#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002187#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002188
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002189#if defined(MBEDTLS_ARC4_C)
2190 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002191#endif
2192
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002193#if defined(MBEDTLS_BLOWFISH_C)
2194 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2195#if defined(MBEDTLS_CIPHER_MODE_CBC)
2196 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002197#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002198#if defined(MBEDTLS_CIPHER_MODE_CFB)
2199 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002200#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002201#if defined(MBEDTLS_CIPHER_MODE_CTR)
2202 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002203#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002204#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002206#if defined(MBEDTLS_CAMELLIA_C)
2207 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2208 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2209 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2210#if defined(MBEDTLS_CIPHER_MODE_CBC)
2211 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2212 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2213 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002214#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002215#if defined(MBEDTLS_CIPHER_MODE_CFB)
2216 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2217 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2218 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002219#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002220#if defined(MBEDTLS_CIPHER_MODE_CTR)
2221 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2222 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2223 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002224#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002225#if defined(MBEDTLS_GCM_C)
2226 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2227 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2228 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02002229#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002230#if defined(MBEDTLS_CCM_C)
2231 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2232 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2233 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02002234#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002235#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002236
Markku-Juhani O. Saarinenc06e1012017-12-07 11:51:13 +00002237#if defined(MBEDTLS_ARIA_C)
2238 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2239 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2240 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2241#if defined(MBEDTLS_CIPHER_MODE_CBC)
2242 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2243 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2244 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2245#endif
2246#if defined(MBEDTLS_CIPHER_MODE_CFB)
2247 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2248 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2249 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2250#endif
2251#if defined(MBEDTLS_CIPHER_MODE_CTR)
2252 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2253 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2254 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2255#endif
2256#if defined(MBEDTLS_GCM_C)
2257 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2258 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2259 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2260#endif
2261#if defined(MBEDTLS_CCM_C)
2262 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2263 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2264 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2265#endif
2266#endif /* MBEDTLS_ARIA_C */
2267
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002268#if defined(MBEDTLS_DES_C)
2269 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2270 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2271 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2272#if defined(MBEDTLS_CIPHER_MODE_CBC)
2273 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2274 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2275 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002276#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002277#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002278
Daniel Kingbd920622016-05-15 19:56:20 -03002279#if defined(MBEDTLS_CHACHA20_C)
2280 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2281#endif
2282
Manuel Pégourié-Gonnarddca3a5d2018-05-07 10:43:27 +02002283#if defined(MBEDTLS_CHACHAPOLY_C)
2284 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
Daniel King8fe47012016-05-17 20:33:28 -03002285#endif
2286
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002287#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2288 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2289#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002290
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002291 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002292};
2293
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002294#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
2295int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02002296
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002297#endif /* MBEDTLS_CIPHER_C */