blob: a58a5c7130ffabdf4e9b72b6b78323057f67ad40 [file] [log] [blame]
Paul Bakker8123e9d2011-01-06 15:37:30 +00001/**
Paul Bakkerfae35f02013-03-13 10:33:51 +01002 * \file cipher_wrap.c
Paul Bakker9af723c2014-05-01 13:03:14 +02003 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief Generic cipher wrapper for mbed TLS
Paul Bakker8123e9d2011-01-06 15:37:30 +00005 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02008 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02009 * SPDX-License-Identifier: Apache-2.0
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
12 * not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
14 *
15 * http://www.apache.org/licenses/LICENSE-2.0
16 *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
Paul Bakker8123e9d2011-01-06 15:37:30 +000022 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000023 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker8123e9d2011-01-06 15:37:30 +000024 */
25
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000027#include "mbedtls/config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000031
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020032#if defined(MBEDTLS_CIPHER_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +000033
Manuel Pégourié-Gonnard50518f42015-05-26 11:04:15 +020034#include "mbedtls/cipher_internal.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if defined(MBEDTLS_AES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000037#include "mbedtls/aes.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000038#endif
39
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020040#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000041#include "mbedtls/arc4.h"
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +020042#endif
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if defined(MBEDTLS_CAMELLIA_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000045#include "mbedtls/camellia.h"
Paul Bakkerf6543712012-03-05 14:01:29 +000046#endif
47
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048#if defined(MBEDTLS_DES_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000049#include "mbedtls/des.h"
Paul Bakker02f61692012-03-15 10:54:25 +000050#endif
Paul Bakker8123e9d2011-01-06 15:37:30 +000051
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052#if defined(MBEDTLS_BLOWFISH_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000053#include "mbedtls/blowfish.h"
Paul Bakker6132d0a2012-07-04 17:10:40 +000054#endif
55
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000057#include "mbedtls/gcm.h"
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +020058#endif
59
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000061#include "mbedtls/ccm.h"
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020062#endif
63
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020064#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnard0c851ee2015-02-10 12:47:52 +000065#include <string.h>
66#endif
67
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000069#include "mbedtls/platform.h"
Paul Bakker6e339b52013-07-03 13:37:05 +020070#else
Rich Evans00ab4702015-02-06 13:43:58 +000071#include <stdlib.h>
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +020072#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020073#define mbedtls_free free
Paul Bakker6e339b52013-07-03 13:37:05 +020074#endif
75
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020076#if defined(MBEDTLS_GCM_C)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020077/* shared by all GCM ciphers */
78static void *gcm_ctx_alloc( void )
79{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020080 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
81
82 if( ctx != NULL )
83 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
84
85 return( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020086}
87
88static void gcm_ctx_free( void *ctx )
89{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020090 mbedtls_gcm_free( ctx );
91 mbedtls_free( ctx );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020092}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +020094
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +020096/* shared by all CCM ciphers */
97static void *ccm_ctx_alloc( void )
98{
Manuel Pégourié-Gonnard96fb6852015-06-23 11:39:01 +020099 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
100
101 if( ctx != NULL )
102 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
103
104 return( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200105}
106
107static void ccm_ctx_free( void *ctx )
108{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109 mbedtls_ccm_free( ctx );
110 mbedtls_free( ctx );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200111}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200112#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200113
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200114#if defined(MBEDTLS_AES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000115
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200116static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200117 const unsigned char *input, unsigned char *output )
118{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200119 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200120}
121
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200122#if defined(MBEDTLS_CIPHER_MODE_CBC)
123static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +0000124 unsigned char *iv, const unsigned char *input, unsigned char *output )
125{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200126 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200127 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000128}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200129#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000130
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_CIPHER_MODE_CFB)
132static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200133 size_t length, size_t *iv_off, unsigned char *iv,
134 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000135{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200137 input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000138}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000140
Simon Butcher91e254c2018-04-22 22:58:07 +0100141#if defined(MBEDTLS_CIPHER_MODE_OFB)
142static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
143 unsigned char *iv, const unsigned char *input, unsigned char *output )
144{
145 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
146 iv, input, output );
147}
148#endif /* MBEDTLS_CIPHER_MODE_OFB */
149
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200150#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200151static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
152 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000153 const unsigned char *input, unsigned char *output )
154{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200155 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
Paul Bakker343a8702011-06-09 14:27:58 +0000156 stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000157}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000159
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100160#if defined(MBEDTLS_CIPHER_MODE_XTS)
161static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
162 size_t length,
163 const unsigned char data_unit[16],
164 const unsigned char *input,
165 unsigned char *output )
166{
167 mbedtls_aes_xts_context *xts_ctx = ctx;
168 int mode;
169
170 switch (operation)
171 {
172 case MBEDTLS_ENCRYPT:
173 mode = MBEDTLS_AES_ENCRYPT;
174 break;
175 case MBEDTLS_DECRYPT:
176 mode = MBEDTLS_AES_DECRYPT;
177 break;
178 default:
179 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
180 }
181
182 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
183 data_unit, input, output );
184}
185#endif /* MBEDTLS_CIPHER_MODE_XTS */
186
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200187static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200188 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000189{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200190 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000191}
192
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200193static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200194 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000195{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200196 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000197}
198
199static void * aes_ctx_alloc( void )
200{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200201 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200202
203 if( aes == NULL )
204 return( NULL );
205
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200206 mbedtls_aes_init( aes );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200207
208 return( aes );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000209}
210
211static void aes_ctx_free( void *ctx )
212{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
214 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000215}
216
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200217static const mbedtls_cipher_base_t aes_info = {
218 MBEDTLS_CIPHER_ID_AES,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200219 aes_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000221 aes_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100222#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200223#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000224 aes_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100225#endif
Simon Butcher91e254c2018-04-22 22:58:07 +0100226#if defined(MBEDTLS_CIPHER_MODE_OFB)
227 aes_crypt_ofb_wrap,
228#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200229#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000230 aes_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100231#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100232#if defined(MBEDTLS_CIPHER_MODE_XTS)
233 NULL,
234#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200236 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100237#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000238 aes_setkey_enc_wrap,
239 aes_setkey_dec_wrap,
240 aes_ctx_alloc,
241 aes_ctx_free
242};
243
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200244static const mbedtls_cipher_info_t aes_128_ecb_info = {
245 MBEDTLS_CIPHER_AES_128_ECB,
246 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200247 128,
248 "AES-128-ECB",
249 16,
250 0,
251 16,
252 &aes_info
253};
254
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200255static const mbedtls_cipher_info_t aes_192_ecb_info = {
256 MBEDTLS_CIPHER_AES_192_ECB,
257 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200258 192,
259 "AES-192-ECB",
260 16,
261 0,
262 16,
263 &aes_info
264};
265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200266static const mbedtls_cipher_info_t aes_256_ecb_info = {
267 MBEDTLS_CIPHER_AES_256_ECB,
268 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200269 256,
270 "AES-256-ECB",
271 16,
272 0,
273 16,
274 &aes_info
275};
276
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277#if defined(MBEDTLS_CIPHER_MODE_CBC)
278static const mbedtls_cipher_info_t aes_128_cbc_info = {
279 MBEDTLS_CIPHER_AES_128_CBC,
280 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000281 128,
282 "AES-128-CBC",
283 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200284 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000285 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000286 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000287};
288
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200289static const mbedtls_cipher_info_t aes_192_cbc_info = {
290 MBEDTLS_CIPHER_AES_192_CBC,
291 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000292 192,
293 "AES-192-CBC",
294 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200295 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000296 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000297 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000298};
299
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200300static const mbedtls_cipher_info_t aes_256_cbc_info = {
301 MBEDTLS_CIPHER_AES_256_CBC,
302 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000303 256,
304 "AES-256-CBC",
305 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200306 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000307 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000308 &aes_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000309};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200310#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000311
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200312#if defined(MBEDTLS_CIPHER_MODE_CFB)
313static const mbedtls_cipher_info_t aes_128_cfb128_info = {
314 MBEDTLS_CIPHER_AES_128_CFB128,
315 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000316 128,
317 "AES-128-CFB128",
318 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200319 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000320 16,
321 &aes_info
322};
323
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200324static const mbedtls_cipher_info_t aes_192_cfb128_info = {
325 MBEDTLS_CIPHER_AES_192_CFB128,
326 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000327 192,
328 "AES-192-CFB128",
329 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200330 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000331 16,
332 &aes_info
333};
334
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200335static const mbedtls_cipher_info_t aes_256_cfb128_info = {
336 MBEDTLS_CIPHER_AES_256_CFB128,
337 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000338 256,
339 "AES-256-CFB128",
340 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200341 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000342 16,
343 &aes_info
344};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200345#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000346
Simon Butcher91e254c2018-04-22 22:58:07 +0100347#if defined(MBEDTLS_CIPHER_MODE_OFB)
348static const mbedtls_cipher_info_t aes_128_ofb_info = {
349 MBEDTLS_CIPHER_AES_128_OFB,
350 MBEDTLS_MODE_OFB,
351 128,
352 "AES-128-OFB",
353 16,
354 0,
355 16,
356 &aes_info
357};
358
359static const mbedtls_cipher_info_t aes_192_ofb_info = {
360 MBEDTLS_CIPHER_AES_192_OFB,
361 MBEDTLS_MODE_OFB,
362 192,
363 "AES-192-OFB",
364 16,
365 0,
366 16,
367 &aes_info
368};
369
370static const mbedtls_cipher_info_t aes_256_ofb_info = {
371 MBEDTLS_CIPHER_AES_256_OFB,
372 MBEDTLS_MODE_OFB,
373 256,
374 "AES-256-OFB",
375 16,
376 0,
377 16,
378 &aes_info
379};
380#endif /* MBEDTLS_CIPHER_MODE_OFB */
381
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200382#if defined(MBEDTLS_CIPHER_MODE_CTR)
383static const mbedtls_cipher_info_t aes_128_ctr_info = {
384 MBEDTLS_CIPHER_AES_128_CTR,
385 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000386 128,
387 "AES-128-CTR",
388 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200389 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000390 16,
391 &aes_info
392};
393
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200394static const mbedtls_cipher_info_t aes_192_ctr_info = {
395 MBEDTLS_CIPHER_AES_192_CTR,
396 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000397 192,
398 "AES-192-CTR",
399 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200400 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000401 16,
402 &aes_info
403};
404
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200405static const mbedtls_cipher_info_t aes_256_ctr_info = {
406 MBEDTLS_CIPHER_AES_256_CTR,
407 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000408 256,
409 "AES-256-CTR",
410 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200411 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000412 16,
413 &aes_info
414};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200415#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000416
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100417#if defined(MBEDTLS_CIPHER_MODE_XTS)
418static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
419 unsigned int key_bitlen )
420{
421 mbedtls_aes_xts_context *xts_ctx = ctx;
422 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
423}
424
425static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
426 unsigned int key_bitlen )
427{
428 mbedtls_aes_xts_context *xts_ctx = ctx;
429 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
430}
431
432static void *xts_aes_ctx_alloc( void )
433{
434 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
435
436 if( xts_ctx )
437 mbedtls_aes_xts_init( xts_ctx );
438
439 return( xts_ctx );
440}
441
442static void xts_aes_ctx_free( void *ctx )
443{
444 mbedtls_aes_xts_context *xts_ctx = ctx;
445
446 if ( !xts_ctx )
447 return;
448
449 mbedtls_aes_xts_free( xts_ctx );
450 mbedtls_free( xts_ctx );
451}
452
453static const mbedtls_cipher_base_t xts_aes_info = {
454 MBEDTLS_CIPHER_ID_AES,
455 NULL,
456#if defined(MBEDTLS_CIPHER_MODE_CBC)
457 NULL,
458#endif
459#if defined(MBEDTLS_CIPHER_MODE_CFB)
460 NULL,
461#endif
Jaeden Amero7d8f00e2018-05-11 10:56:21 +0100462#if defined(MBEDTLS_CIPHER_MODE_OFB)
463 NULL,
464#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100465#if defined(MBEDTLS_CIPHER_MODE_CTR)
466 NULL,
467#endif
468#if defined(MBEDTLS_CIPHER_MODE_XTS)
469 aes_crypt_xts_wrap,
470#endif
471#if defined(MBEDTLS_CIPHER_MODE_STREAM)
472 NULL,
473#endif
474 xts_aes_setkey_enc_wrap,
475 xts_aes_setkey_dec_wrap,
476 xts_aes_ctx_alloc,
477 xts_aes_ctx_free
478};
479
480static const mbedtls_cipher_info_t aes_128_xts_info = {
481 MBEDTLS_CIPHER_AES_128_XTS,
482 MBEDTLS_MODE_XTS,
483 256,
484 "AES-128-XTS",
485 16,
486 0,
487 16,
488 &xts_aes_info
489};
490
491static const mbedtls_cipher_info_t aes_256_xts_info = {
492 MBEDTLS_CIPHER_AES_256_XTS,
493 MBEDTLS_MODE_XTS,
494 512,
495 "AES-256-XTS",
496 16,
497 0,
498 16,
499 &xts_aes_info
500};
501#endif /* MBEDTLS_CIPHER_MODE_XTS */
502
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200503#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200504static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200505 unsigned int key_bitlen )
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200506{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200507 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200508 key, key_bitlen );
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200509}
510
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200511static const mbedtls_cipher_base_t gcm_aes_info = {
512 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200513 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200514#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200515 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100516#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200517#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200518 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100519#endif
Simon Butcher91e254c2018-04-22 22:58:07 +0100520#if defined(MBEDTLS_CIPHER_MODE_OFB)
521 NULL,
522#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200523#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200524 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100525#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100526#if defined(MBEDTLS_CIPHER_MODE_XTS)
527 NULL,
528#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200529#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Paul Bakker5e0efa72013-09-08 23:04:04 +0200530 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100531#endif
Paul Bakker43aff2a2013-09-09 00:10:27 +0200532 gcm_aes_setkey_wrap,
533 gcm_aes_setkey_wrap,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200534 gcm_ctx_alloc,
535 gcm_ctx_free,
536};
537
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200538static const mbedtls_cipher_info_t aes_128_gcm_info = {
539 MBEDTLS_CIPHER_AES_128_GCM,
540 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100541 128,
542 "AES-128-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200543 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200544 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100545 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200546 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100547};
548
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200549static const mbedtls_cipher_info_t aes_192_gcm_info = {
550 MBEDTLS_CIPHER_AES_192_GCM,
551 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200552 192,
553 "AES-192-GCM",
554 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200555 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard83f3fc02013-09-04 12:07:24 +0200556 16,
557 &gcm_aes_info
558};
559
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200560static const mbedtls_cipher_info_t aes_256_gcm_info = {
561 MBEDTLS_CIPHER_AES_256_GCM,
562 MBEDTLS_MODE_GCM,
Paul Bakker68884e32013-01-07 18:20:04 +0100563 256,
564 "AES-256-GCM",
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200565 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200566 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Paul Bakker68884e32013-01-07 18:20:04 +0100567 16,
Manuel Pégourié-Gonnard07f8fa52013-08-30 18:34:08 +0200568 &gcm_aes_info
Paul Bakker68884e32013-01-07 18:20:04 +0100569};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200570#endif /* MBEDTLS_GCM_C */
Paul Bakker68884e32013-01-07 18:20:04 +0100571
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200572#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200573static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200574 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200575{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200576 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200577 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200578}
579
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200580static const mbedtls_cipher_base_t ccm_aes_info = {
581 MBEDTLS_CIPHER_ID_AES,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200582 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200583#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200584 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100585#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200586#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200587 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100588#endif
Simon Butcher91e254c2018-04-22 22:58:07 +0100589#if defined(MBEDTLS_CIPHER_MODE_OFB)
590 NULL,
591#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200592#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200593 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100594#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100595#if defined(MBEDTLS_CIPHER_MODE_XTS)
596 NULL,
597#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200598#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200599 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100600#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200601 ccm_aes_setkey_wrap,
602 ccm_aes_setkey_wrap,
603 ccm_ctx_alloc,
604 ccm_ctx_free,
605};
606
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200607static const mbedtls_cipher_info_t aes_128_ccm_info = {
608 MBEDTLS_CIPHER_AES_128_CCM,
609 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200610 128,
611 "AES-128-CCM",
612 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200613 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200614 16,
615 &ccm_aes_info
616};
617
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200618static const mbedtls_cipher_info_t aes_192_ccm_info = {
619 MBEDTLS_CIPHER_AES_192_CCM,
620 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200621 192,
622 "AES-192-CCM",
623 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200624 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200625 16,
626 &ccm_aes_info
627};
628
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200629static const mbedtls_cipher_info_t aes_256_ccm_info = {
630 MBEDTLS_CIPHER_AES_256_CCM,
631 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200632 256,
633 "AES-256-CCM",
634 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200635 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200636 16,
637 &ccm_aes_info
638};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200639#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200640
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200641#endif /* MBEDTLS_AES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000642
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200643#if defined(MBEDTLS_CAMELLIA_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +0000644
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200645static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200646 const unsigned char *input, unsigned char *output )
647{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200649 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +0200650}
651
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200652#if defined(MBEDTLS_CIPHER_MODE_CBC)
653static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200654 size_t length, unsigned char *iv,
655 const unsigned char *input, unsigned char *output )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000656{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200657 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200658 input, output );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000659}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200660#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +0000661
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200662#if defined(MBEDTLS_CIPHER_MODE_CFB)
663static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200664 size_t length, size_t *iv_off, unsigned char *iv,
665 const unsigned char *input, unsigned char *output )
Paul Bakker343a8702011-06-09 14:27:58 +0000666{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200667 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200668 iv_off, iv, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000669}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200670#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000671
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200672#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200673static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
674 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker343a8702011-06-09 14:27:58 +0000675 const unsigned char *input, unsigned char *output )
676{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200677 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200678 nonce_counter, stream_block, input, output );
Paul Bakker343a8702011-06-09 14:27:58 +0000679}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200680#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000681
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200682static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200683 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000684{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200685 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000686}
687
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200688static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200689 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +0000690{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200691 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000692}
693
694static void * camellia_ctx_alloc( void )
695{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200696 mbedtls_camellia_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200697 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200698
699 if( ctx == NULL )
700 return( NULL );
701
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200702 mbedtls_camellia_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +0200703
704 return( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000705}
706
707static void camellia_ctx_free( void *ctx )
708{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200709 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
710 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +0000711}
712
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200713static const mbedtls_cipher_base_t camellia_info = {
714 MBEDTLS_CIPHER_ID_CAMELLIA,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200715 camellia_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200716#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +0000717 camellia_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100718#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200719#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker343a8702011-06-09 14:27:58 +0000720 camellia_crypt_cfb128_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100721#endif
Simon Butcher91e254c2018-04-22 22:58:07 +0100722#if defined(MBEDTLS_CIPHER_MODE_OFB)
723 NULL,
724#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200725#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker343a8702011-06-09 14:27:58 +0000726 camellia_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100727#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100728#if defined(MBEDTLS_CIPHER_MODE_XTS)
729 NULL,
730#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200731#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +0200732 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100733#endif
Paul Bakker343a8702011-06-09 14:27:58 +0000734 camellia_setkey_enc_wrap,
735 camellia_setkey_dec_wrap,
736 camellia_ctx_alloc,
737 camellia_ctx_free
738};
739
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200740static const mbedtls_cipher_info_t camellia_128_ecb_info = {
741 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
742 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200743 128,
744 "CAMELLIA-128-ECB",
745 16,
746 0,
747 16,
748 &camellia_info
749};
750
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200751static const mbedtls_cipher_info_t camellia_192_ecb_info = {
752 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
753 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200754 192,
755 "CAMELLIA-192-ECB",
756 16,
757 0,
758 16,
759 &camellia_info
760};
761
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200762static const mbedtls_cipher_info_t camellia_256_ecb_info = {
763 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
764 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +0200765 256,
766 "CAMELLIA-256-ECB",
767 16,
768 0,
769 16,
770 &camellia_info
771};
772
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200773#if defined(MBEDTLS_CIPHER_MODE_CBC)
774static const mbedtls_cipher_info_t camellia_128_cbc_info = {
775 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
776 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000777 128,
778 "CAMELLIA-128-CBC",
779 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200780 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000781 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000782 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000783};
784
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200785static const mbedtls_cipher_info_t camellia_192_cbc_info = {
786 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
787 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000788 192,
789 "CAMELLIA-192-CBC",
790 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200791 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000792 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000793 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000794};
795
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200796static const mbedtls_cipher_info_t camellia_256_cbc_info = {
797 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
798 MBEDTLS_MODE_CBC,
Paul Bakker23986e52011-04-24 08:57:21 +0000799 256,
800 "CAMELLIA-256-CBC",
801 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200802 0,
Paul Bakker23986e52011-04-24 08:57:21 +0000803 16,
Paul Bakker343a8702011-06-09 14:27:58 +0000804 &camellia_info
Paul Bakker8123e9d2011-01-06 15:37:30 +0000805};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200806#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +0000807
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200808#if defined(MBEDTLS_CIPHER_MODE_CFB)
809static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
810 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
811 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000812 128,
813 "CAMELLIA-128-CFB128",
814 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200815 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000816 16,
817 &camellia_info
818};
819
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200820static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
821 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
822 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000823 192,
824 "CAMELLIA-192-CFB128",
825 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200826 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000827 16,
828 &camellia_info
829};
830
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200831static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
832 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
833 MBEDTLS_MODE_CFB,
Paul Bakker343a8702011-06-09 14:27:58 +0000834 256,
835 "CAMELLIA-256-CFB128",
836 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200837 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000838 16,
839 &camellia_info
840};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200841#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker343a8702011-06-09 14:27:58 +0000842
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200843#if defined(MBEDTLS_CIPHER_MODE_CTR)
844static const mbedtls_cipher_info_t camellia_128_ctr_info = {
845 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
846 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000847 128,
848 "CAMELLIA-128-CTR",
849 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200850 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000851 16,
852 &camellia_info
853};
854
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200855static const mbedtls_cipher_info_t camellia_192_ctr_info = {
856 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
857 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000858 192,
859 "CAMELLIA-192-CTR",
860 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200861 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000862 16,
863 &camellia_info
864};
865
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200866static const mbedtls_cipher_info_t camellia_256_ctr_info = {
867 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
868 MBEDTLS_MODE_CTR,
Paul Bakker343a8702011-06-09 14:27:58 +0000869 256,
870 "CAMELLIA-256-CTR",
871 16,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +0200872 0,
Paul Bakker343a8702011-06-09 14:27:58 +0000873 16,
874 &camellia_info
875};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200876#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker343a8702011-06-09 14:27:58 +0000877
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200878#if defined(MBEDTLS_GCM_C)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +0200879static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200880 unsigned int key_bitlen )
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200881{
Manuel Pégourié-Gonnardc34e8dd2015-04-28 21:42:17 +0200882 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200883 key, key_bitlen );
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200884}
885
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200886static const mbedtls_cipher_base_t gcm_camellia_info = {
887 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200888 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200889#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200890 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100891#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200892#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200893 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100894#endif
Simon Butcher91e254c2018-04-22 22:58:07 +0100895#if defined(MBEDTLS_CIPHER_MODE_OFB)
896 NULL,
897#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200898#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200899 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100900#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100901#if defined(MBEDTLS_CIPHER_MODE_XTS)
902 NULL,
903#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200904#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200905 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100906#endif
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200907 gcm_camellia_setkey_wrap,
908 gcm_camellia_setkey_wrap,
909 gcm_ctx_alloc,
910 gcm_ctx_free,
911};
912
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200913static const mbedtls_cipher_info_t camellia_128_gcm_info = {
914 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
915 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200916 128,
917 "CAMELLIA-128-GCM",
918 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200919 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200920 16,
921 &gcm_camellia_info
922};
923
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200924static const mbedtls_cipher_info_t camellia_192_gcm_info = {
925 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
926 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200927 192,
928 "CAMELLIA-192-GCM",
929 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200930 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200931 16,
932 &gcm_camellia_info
933};
934
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200935static const mbedtls_cipher_info_t camellia_256_gcm_info = {
936 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
937 MBEDTLS_MODE_GCM,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200938 256,
939 "CAMELLIA-256-GCM",
940 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200941 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200942 16,
943 &gcm_camellia_info
944};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200945#endif /* MBEDTLS_GCM_C */
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +0200946
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947#if defined(MBEDTLS_CCM_C)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200948static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200949 unsigned int key_bitlen )
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200950{
Manuel Pégourié-Gonnard6963ff02015-04-28 18:02:54 +0200951 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +0200952 key, key_bitlen );
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200953}
954
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200955static const mbedtls_cipher_base_t ccm_camellia_info = {
956 MBEDTLS_CIPHER_ID_CAMELLIA,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200957 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200958#if defined(MBEDTLS_CIPHER_MODE_CBC)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200959 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100960#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200961#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200962 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100963#endif
Simon Butcher91e254c2018-04-22 22:58:07 +0100964#if defined(MBEDTLS_CIPHER_MODE_OFB)
965 NULL,
966#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200967#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200968 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100969#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +0100970#if defined(MBEDTLS_CIPHER_MODE_XTS)
971 NULL,
972#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200973#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200974 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +0100975#endif
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200976 ccm_camellia_setkey_wrap,
977 ccm_camellia_setkey_wrap,
978 ccm_ctx_alloc,
979 ccm_ctx_free,
980};
981
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200982static const mbedtls_cipher_info_t camellia_128_ccm_info = {
983 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
984 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200985 128,
986 "CAMELLIA-128-CCM",
987 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200988 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200989 16,
990 &ccm_camellia_info
991};
992
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200993static const mbedtls_cipher_info_t camellia_192_ccm_info = {
994 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
995 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +0200996 192,
997 "CAMELLIA-192-CCM",
998 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200999 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001000 16,
1001 &ccm_camellia_info
1002};
1003
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001004static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1005 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1006 MBEDTLS_MODE_CCM,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001007 256,
1008 "CAMELLIA-256-CCM",
1009 12,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001010 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001011 16,
1012 &ccm_camellia_info
1013};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001014#endif /* MBEDTLS_CCM_C */
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001015
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001016#endif /* MBEDTLS_CAMELLIA_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001017
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001018#if defined(MBEDTLS_DES_C)
Paul Bakker8123e9d2011-01-06 15:37:30 +00001019
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001020static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001021 const unsigned char *input, unsigned char *output )
1022{
1023 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001024 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001025}
1026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001027static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001028 const unsigned char *input, unsigned char *output )
1029{
1030 ((void) operation);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001031 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001032}
1033
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001034#if defined(MBEDTLS_CIPHER_MODE_CBC)
1035static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001036 unsigned char *iv, const unsigned char *input, unsigned char *output )
1037{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001038 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001039 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001040}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001041#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001042
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001043#if defined(MBEDTLS_CIPHER_MODE_CBC)
1044static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
Paul Bakker8123e9d2011-01-06 15:37:30 +00001045 unsigned char *iv, const unsigned char *input, unsigned char *output )
1046{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001047 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001048 output );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001049}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001050#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001051
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001052static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001053 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001054{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001055 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001056
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001057 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001058}
1059
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001060static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001061 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001062{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001063 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001064
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001065 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001066}
1067
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001068static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001069 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001070{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001071 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001072
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001073 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001074}
1075
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001076static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001077 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001078{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001079 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001080
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001081 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001082}
1083
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001084static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001085 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001086{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001087 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001088
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001089 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001090}
1091
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001092static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001093 unsigned int key_bitlen )
Paul Bakker8123e9d2011-01-06 15:37:30 +00001094{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001095 ((void) key_bitlen);
Paul Bakkerd61e7d92011-01-18 16:17:47 +00001096
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001097 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001098}
1099
1100static void * des_ctx_alloc( void )
1101{
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001102 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001103
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001104 if( des == NULL )
1105 return( NULL );
1106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001107 mbedtls_des_init( des );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001108
1109 return( des );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001110}
1111
1112static void des_ctx_free( void *ctx )
1113{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001114 mbedtls_des_free( (mbedtls_des_context *) ctx );
1115 mbedtls_free( ctx );
Paul Bakker34617722014-06-13 17:20:13 +02001116}
1117
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001118static void * des3_ctx_alloc( void )
1119{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001120 mbedtls_des3_context *des3;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001121 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001122
1123 if( des3 == NULL )
1124 return( NULL );
1125
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001126 mbedtls_des3_init( des3 );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001127
1128 return( des3 );
1129}
1130
Paul Bakker34617722014-06-13 17:20:13 +02001131static void des3_ctx_free( void *ctx )
1132{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001133 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1134 mbedtls_free( ctx );
Paul Bakker8123e9d2011-01-06 15:37:30 +00001135}
1136
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001137static const mbedtls_cipher_base_t des_info = {
1138 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001139 des_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001140#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001141 des_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001142#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001143#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001144 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001145#endif
Simon Butcher91e254c2018-04-22 22:58:07 +01001146#if defined(MBEDTLS_CIPHER_MODE_OFB)
1147 NULL,
1148#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001149#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001150 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001151#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001152#if defined(MBEDTLS_CIPHER_MODE_XTS)
1153 NULL,
1154#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001155#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001156 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001157#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001158 des_setkey_enc_wrap,
1159 des_setkey_dec_wrap,
1160 des_ctx_alloc,
1161 des_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001162};
1163
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001164static const mbedtls_cipher_info_t des_ecb_info = {
1165 MBEDTLS_CIPHER_DES_ECB,
1166 MBEDTLS_MODE_ECB,
1167 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001168 "DES-ECB",
1169 8,
1170 0,
1171 8,
1172 &des_info
1173};
1174
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001175#if defined(MBEDTLS_CIPHER_MODE_CBC)
1176static const mbedtls_cipher_info_t des_cbc_info = {
1177 MBEDTLS_CIPHER_DES_CBC,
1178 MBEDTLS_MODE_CBC,
1179 MBEDTLS_KEY_LENGTH_DES,
Paul Bakker343a8702011-06-09 14:27:58 +00001180 "DES-CBC",
1181 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001182 0,
Paul Bakker343a8702011-06-09 14:27:58 +00001183 8,
1184 &des_info
1185};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001186#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001187
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001188static const mbedtls_cipher_base_t des_ede_info = {
1189 MBEDTLS_CIPHER_ID_DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001190 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001191#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker23986e52011-04-24 08:57:21 +00001192 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001193#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001194#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001195 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001196#endif
Simon Butcher91e254c2018-04-22 22:58:07 +01001197#if defined(MBEDTLS_CIPHER_MODE_OFB)
1198 NULL,
1199#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001200#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001201 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001202#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001203#if defined(MBEDTLS_CIPHER_MODE_XTS)
1204 NULL,
1205#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001206#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001207 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001208#endif
Paul Bakker23986e52011-04-24 08:57:21 +00001209 des3_set2key_enc_wrap,
1210 des3_set2key_dec_wrap,
1211 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001212 des3_ctx_free
Paul Bakker8123e9d2011-01-06 15:37:30 +00001213};
1214
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001215static const mbedtls_cipher_info_t des_ede_ecb_info = {
1216 MBEDTLS_CIPHER_DES_EDE_ECB,
1217 MBEDTLS_MODE_ECB,
1218 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001219 "DES-EDE-ECB",
1220 8,
1221 0,
1222 8,
1223 &des_ede_info
1224};
1225
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001226#if defined(MBEDTLS_CIPHER_MODE_CBC)
1227static const mbedtls_cipher_info_t des_ede_cbc_info = {
1228 MBEDTLS_CIPHER_DES_EDE_CBC,
1229 MBEDTLS_MODE_CBC,
1230 MBEDTLS_KEY_LENGTH_DES_EDE,
Paul Bakker343a8702011-06-09 14:27:58 +00001231 "DES-EDE-CBC",
Paul Bakker0e342352013-06-24 19:33:02 +02001232 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001233 0,
Paul Bakker0e342352013-06-24 19:33:02 +02001234 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001235 &des_ede_info
1236};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001237#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker343a8702011-06-09 14:27:58 +00001238
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001239static const mbedtls_cipher_base_t des_ede3_info = {
Manuel Pégourié-Gonnard9d515832015-06-02 10:00:04 +01001240 MBEDTLS_CIPHER_ID_3DES,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001241 des3_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001242#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker343a8702011-06-09 14:27:58 +00001243 des3_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001244#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001245#if defined(MBEDTLS_CIPHER_MODE_CFB)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001246 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001247#endif
Simon Butcher91e254c2018-04-22 22:58:07 +01001248#if defined(MBEDTLS_CIPHER_MODE_OFB)
1249 NULL,
1250#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001251#if defined(MBEDTLS_CIPHER_MODE_CTR)
Manuel Pégourié-Gonnardb9126162014-06-13 15:06:59 +02001252 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001253#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001254#if defined(MBEDTLS_CIPHER_MODE_XTS)
1255 NULL,
1256#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001257#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001258 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001259#endif
Paul Bakker343a8702011-06-09 14:27:58 +00001260 des3_set3key_enc_wrap,
1261 des3_set3key_dec_wrap,
1262 des3_ctx_alloc,
Paul Bakker34617722014-06-13 17:20:13 +02001263 des3_ctx_free
Paul Bakker343a8702011-06-09 14:27:58 +00001264};
1265
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001266static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1267 MBEDTLS_CIPHER_DES_EDE3_ECB,
1268 MBEDTLS_MODE_ECB,
1269 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001270 "DES-EDE3-ECB",
1271 8,
1272 0,
1273 8,
1274 &des_ede3_info
1275};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001276#if defined(MBEDTLS_CIPHER_MODE_CBC)
1277static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1278 MBEDTLS_CIPHER_DES_EDE3_CBC,
1279 MBEDTLS_MODE_CBC,
1280 MBEDTLS_KEY_LENGTH_DES_EDE3,
Paul Bakker23986e52011-04-24 08:57:21 +00001281 "DES-EDE3-CBC",
1282 8,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001283 0,
Paul Bakker23986e52011-04-24 08:57:21 +00001284 8,
Paul Bakker343a8702011-06-09 14:27:58 +00001285 &des_ede3_info
Paul Bakker8123e9d2011-01-06 15:37:30 +00001286};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001287#endif /* MBEDTLS_CIPHER_MODE_CBC */
1288#endif /* MBEDTLS_DES_C */
Paul Bakker8123e9d2011-01-06 15:37:30 +00001289
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001290#if defined(MBEDTLS_BLOWFISH_C)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001291
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001292static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001293 const unsigned char *input, unsigned char *output )
1294{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001295 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001296 output );
Paul Bakker5e0efa72013-09-08 23:04:04 +02001297}
1298
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001299#if defined(MBEDTLS_CIPHER_MODE_CBC)
1300static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001301 size_t length, unsigned char *iv, const unsigned char *input,
1302 unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001303{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001304 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001305 input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001306}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001307#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001308
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001309#if defined(MBEDTLS_CIPHER_MODE_CFB)
1310static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001311 size_t length, size_t *iv_off, unsigned char *iv,
1312 const unsigned char *input, unsigned char *output )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001313{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001314 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001315 iv_off, iv, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001316}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001317#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001318
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001319#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001320static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1321 unsigned char *nonce_counter, unsigned char *stream_block,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001322 const unsigned char *input, unsigned char *output )
1323{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001324 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001325 nonce_counter, stream_block, input, output );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001326}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001327#endif /* MBEDTLS_CIPHER_MODE_CTR */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001328
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +02001329static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001330 unsigned int key_bitlen )
Paul Bakker6132d0a2012-07-04 17:10:40 +00001331{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001332 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001333}
1334
1335static void * blowfish_ctx_alloc( void )
1336{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001337 mbedtls_blowfish_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001338 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001339
1340 if( ctx == NULL )
1341 return( NULL );
1342
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001343 mbedtls_blowfish_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001344
1345 return( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001346}
1347
1348static void blowfish_ctx_free( void *ctx )
1349{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001350 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1351 mbedtls_free( ctx );
Paul Bakker6132d0a2012-07-04 17:10:40 +00001352}
1353
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001354static const mbedtls_cipher_base_t blowfish_info = {
1355 MBEDTLS_CIPHER_ID_BLOWFISH,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001356 blowfish_crypt_ecb_wrap,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001357#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001358 blowfish_crypt_cbc_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001359#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001360#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001361 blowfish_crypt_cfb64_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001362#endif
Simon Butcher91e254c2018-04-22 22:58:07 +01001363#if defined(MBEDTLS_CIPHER_MODE_OFB)
1364 NULL,
1365#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001366#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker6132d0a2012-07-04 17:10:40 +00001367 blowfish_crypt_ctr_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001368#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001369#if defined(MBEDTLS_CIPHER_MODE_XTS)
1370 NULL,
1371#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001372#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001373 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001374#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001375 blowfish_setkey_wrap,
1376 blowfish_setkey_wrap,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001377 blowfish_ctx_alloc,
1378 blowfish_ctx_free
1379};
1380
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001381static const mbedtls_cipher_info_t blowfish_ecb_info = {
1382 MBEDTLS_CIPHER_BLOWFISH_ECB,
1383 MBEDTLS_MODE_ECB,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001384 128,
1385 "BLOWFISH-ECB",
1386 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001387 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker5e0efa72013-09-08 23:04:04 +02001388 8,
1389 &blowfish_info
1390};
1391
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001392#if defined(MBEDTLS_CIPHER_MODE_CBC)
1393static const mbedtls_cipher_info_t blowfish_cbc_info = {
1394 MBEDTLS_CIPHER_BLOWFISH_CBC,
1395 MBEDTLS_MODE_CBC,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001396 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001397 "BLOWFISH-CBC",
1398 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001399 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001400 8,
1401 &blowfish_info
1402};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001403#endif /* MBEDTLS_CIPHER_MODE_CBC */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001404
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001405#if defined(MBEDTLS_CIPHER_MODE_CFB)
1406static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1407 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1408 MBEDTLS_MODE_CFB,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001409 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001410 "BLOWFISH-CFB64",
1411 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001412 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001413 8,
1414 &blowfish_info
1415};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001416#endif /* MBEDTLS_CIPHER_MODE_CFB */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001417
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001418#if defined(MBEDTLS_CIPHER_MODE_CTR)
1419static const mbedtls_cipher_info_t blowfish_ctr_info = {
1420 MBEDTLS_CIPHER_BLOWFISH_CTR,
1421 MBEDTLS_MODE_CTR,
Paul Bakkerbfe671f2013-04-07 22:35:44 +02001422 128,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001423 "BLOWFISH-CTR",
1424 8,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001425 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
Paul Bakker6132d0a2012-07-04 17:10:40 +00001426 8,
1427 &blowfish_info
1428};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001429#endif /* MBEDTLS_CIPHER_MODE_CTR */
1430#endif /* MBEDTLS_BLOWFISH_C */
Paul Bakker6132d0a2012-07-04 17:10:40 +00001431
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001432#if defined(MBEDTLS_ARC4_C)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001433static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1434 const unsigned char *input,
1435 unsigned char *output )
Paul Bakker68884e32013-01-07 18:20:04 +01001436{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001437 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
Paul Bakker68884e32013-01-07 18:20:04 +01001438}
1439
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001440static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001441 unsigned int key_bitlen )
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001442{
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001443 /* we get key_bitlen in bits, arc4 expects it in bytes */
1444 if( key_bitlen % 8 != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001445 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
Manuel Pégourié-Gonnardce411252013-09-04 12:28:37 +02001446
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001447 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001448 return( 0 );
1449}
1450
1451static void * arc4_ctx_alloc( void )
1452{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001453 mbedtls_arc4_context *ctx;
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +02001454 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001455
1456 if( ctx == NULL )
1457 return( NULL );
1458
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001459 mbedtls_arc4_init( ctx );
Paul Bakkerc7ea99a2014-06-18 11:12:03 +02001460
1461 return( ctx );
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001462}
Paul Bakker68884e32013-01-07 18:20:04 +01001463
1464static void arc4_ctx_free( void *ctx )
1465{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001466 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1467 mbedtls_free( ctx );
Paul Bakker68884e32013-01-07 18:20:04 +01001468}
1469
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001470static const mbedtls_cipher_base_t arc4_base_info = {
1471 MBEDTLS_CIPHER_ID_ARC4,
Paul Bakker68884e32013-01-07 18:20:04 +01001472 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001473#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakker68884e32013-01-07 18:20:04 +01001474 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001475#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001476#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakker68884e32013-01-07 18:20:04 +01001477 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001478#endif
Simon Butcher91e254c2018-04-22 22:58:07 +01001479#if defined(MBEDTLS_CIPHER_MODE_OFB)
1480 NULL,
1481#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001482#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001483 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001484#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001485#if defined(MBEDTLS_CIPHER_MODE_XTS)
1486 NULL,
1487#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001488#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001489 arc4_crypt_stream_wrap,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001490#endif
Manuel Pégourié-Gonnard37e230c2013-08-28 13:50:42 +02001491 arc4_setkey_wrap,
1492 arc4_setkey_wrap,
Paul Bakker68884e32013-01-07 18:20:04 +01001493 arc4_ctx_alloc,
1494 arc4_ctx_free
1495};
1496
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001497static const mbedtls_cipher_info_t arc4_128_info = {
1498 MBEDTLS_CIPHER_ARC4_128,
1499 MBEDTLS_MODE_STREAM,
Paul Bakker68884e32013-01-07 18:20:04 +01001500 128,
1501 "ARC4-128",
1502 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001503 0,
Paul Bakker68884e32013-01-07 18:20:04 +01001504 1,
1505 &arc4_base_info
1506};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001507#endif /* MBEDTLS_ARC4_C */
Paul Bakker68884e32013-01-07 18:20:04 +01001508
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001509#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001510static int null_crypt_stream( void *ctx, size_t length,
1511 const unsigned char *input,
1512 unsigned char *output )
1513{
1514 ((void) ctx);
1515 memmove( output, input, length );
1516 return( 0 );
1517}
1518
1519static int null_setkey( void *ctx, const unsigned char *key,
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001520 unsigned int key_bitlen )
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001521{
1522 ((void) ctx);
1523 ((void) key);
Manuel Pégourié-Gonnard898e0aa2015-06-18 15:28:12 +02001524 ((void) key_bitlen);
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001525
1526 return( 0 );
1527}
1528
Paul Bakkerfab5c822012-02-06 16:45:10 +00001529static void * null_ctx_alloc( void )
1530{
Manuel Pégourié-Gonnard86bbc7f2014-07-12 02:14:41 +02001531 return( (void *) 1 );
Paul Bakkerfab5c822012-02-06 16:45:10 +00001532}
1533
Paul Bakkerfab5c822012-02-06 16:45:10 +00001534static void null_ctx_free( void *ctx )
1535{
1536 ((void) ctx);
1537}
1538
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001539static const mbedtls_cipher_base_t null_base_info = {
1540 MBEDTLS_CIPHER_ID_NULL,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001541 NULL,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001542#if defined(MBEDTLS_CIPHER_MODE_CBC)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001543 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001544#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001545#if defined(MBEDTLS_CIPHER_MODE_CFB)
Paul Bakkerfab5c822012-02-06 16:45:10 +00001546 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001547#endif
Simon Butchera3f3f162018-04-29 00:24:51 +01001548#if defined(MBEDTLS_CIPHER_MODE_OFB)
1549 NULL,
1550#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001551#if defined(MBEDTLS_CIPHER_MODE_CTR)
Paul Bakker5e0efa72013-09-08 23:04:04 +02001552 NULL,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001553#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001554#if defined(MBEDTLS_CIPHER_MODE_XTS)
1555 NULL,
1556#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001557#if defined(MBEDTLS_CIPHER_MODE_STREAM)
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001558 null_crypt_stream,
Manuel Pégourié-Gonnardb8ca7232014-12-02 10:09:10 +01001559#endif
Manuel Pégourié-Gonnardb5e85882013-08-28 16:36:14 +02001560 null_setkey,
1561 null_setkey,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001562 null_ctx_alloc,
1563 null_ctx_free
1564};
1565
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001566static const mbedtls_cipher_info_t null_cipher_info = {
1567 MBEDTLS_CIPHER_NULL,
1568 MBEDTLS_MODE_STREAM,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001569 0,
1570 "NULL",
Paul Bakker68884e32013-01-07 18:20:04 +01001571 0,
Manuel Pégourié-Gonnarda235b5b2013-09-03 13:25:52 +02001572 0,
Paul Bakkerfab5c822012-02-06 16:45:10 +00001573 1,
1574 &null_base_info
1575};
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001576#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
Paul Bakkerfab5c822012-02-06 16:45:10 +00001577
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001578const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001579{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001580#if defined(MBEDTLS_AES_C)
1581 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
1582 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
1583 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
1584#if defined(MBEDTLS_CIPHER_MODE_CBC)
1585 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
1586 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
1587 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001588#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001589#if defined(MBEDTLS_CIPHER_MODE_CFB)
1590 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
1591 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
1592 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001593#endif
Simon Butcher91e254c2018-04-22 22:58:07 +01001594#if defined(MBEDTLS_CIPHER_MODE_OFB)
1595 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
1596 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
1597 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
1598#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001599#if defined(MBEDTLS_CIPHER_MODE_CTR)
1600 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
1601 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
1602 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001603#endif
Jaeden Ameroe4daf772018-04-30 17:17:41 +01001604#if defined(MBEDTLS_CIPHER_MODE_XTS)
1605 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
1606 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
1607#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001608#if defined(MBEDTLS_GCM_C)
1609 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
1610 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
1611 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001612#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001613#if defined(MBEDTLS_CCM_C)
1614 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
1615 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
1616 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001617#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001618#endif /* MBEDTLS_AES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001619
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001620#if defined(MBEDTLS_ARC4_C)
1621 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001622#endif
1623
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001624#if defined(MBEDTLS_BLOWFISH_C)
1625 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
1626#if defined(MBEDTLS_CIPHER_MODE_CBC)
1627 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001628#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001629#if defined(MBEDTLS_CIPHER_MODE_CFB)
1630 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001631#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001632#if defined(MBEDTLS_CIPHER_MODE_CTR)
1633 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001634#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001635#endif /* MBEDTLS_BLOWFISH_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001636
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001637#if defined(MBEDTLS_CAMELLIA_C)
1638 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
1639 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
1640 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
1641#if defined(MBEDTLS_CIPHER_MODE_CBC)
1642 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
1643 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
1644 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001645#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001646#if defined(MBEDTLS_CIPHER_MODE_CFB)
1647 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
1648 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
1649 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001650#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001651#if defined(MBEDTLS_CIPHER_MODE_CTR)
1652 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
1653 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
1654 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001655#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001656#if defined(MBEDTLS_GCM_C)
1657 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
1658 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
1659 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
Manuel Pégourié-Gonnard87181d12013-10-24 14:02:40 +02001660#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001661#if defined(MBEDTLS_CCM_C)
1662 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
1663 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
1664 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
Manuel Pégourié-Gonnard41936952014-05-13 13:18:17 +02001665#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001666#endif /* MBEDTLS_CAMELLIA_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001667
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001668#if defined(MBEDTLS_DES_C)
1669 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
1670 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
1671 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
1672#if defined(MBEDTLS_CIPHER_MODE_CBC)
1673 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
1674 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
1675 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001676#endif
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001677#endif /* MBEDTLS_DES_C */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001678
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001679#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
1680 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
1681#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001682
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001683 { MBEDTLS_CIPHER_NONE, NULL }
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001684};
1685
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001686#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
1687int mbedtls_cipher_supported[NUM_CIPHERS];
Manuel Pégourié-Gonnarddace82f2013-09-18 15:12:07 +02001688
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001689#endif /* MBEDTLS_CIPHER_C */