blob: 4b9d35680d1ad8322dc8d4332de025653a4755b6 [file] [log] [blame]
Jens Wiklander817466c2018-05-22 13:49:31 +02001/**
2 * \file cipher_wrap.c
3 *
4 * \brief Generic cipher wrapper for mbed TLS
5 *
6 * \author Adriaan de Jong <dejong@fox-it.com>
7 *
Jerome Forissier79013242021-07-28 10:24:04 +02008 * Copyright The Mbed TLS Contributors
9 * SPDX-License-Identifier: Apache-2.0
Jens Wiklander817466c2018-05-22 13:49:31 +020010 *
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.
Jens Wiklander817466c2018-05-22 13:49:31 +020022 */
23
Jerome Forissier79013242021-07-28 10:24:04 +020024#include "common.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020025
Edison Ai12484fc2018-12-19 15:36:28 +080026#include <string.h>
27
Jens Wiklander817466c2018-05-22 13:49:31 +020028#if defined(MBEDTLS_CIPHER_C)
29
30#include "mbedtls/cipher_internal.h"
Jerome Forissier11fa71b2020-04-20 17:17:56 +020031#include "mbedtls/error.h"
Jens Wiklander817466c2018-05-22 13:49:31 +020032
Jens Wiklander3d3b0592019-03-20 15:30:29 +010033#if defined(MBEDTLS_CHACHAPOLY_C)
34#include "mbedtls/chachapoly.h"
35#endif
36
Jens Wiklander817466c2018-05-22 13:49:31 +020037#if defined(MBEDTLS_AES_C)
38#include "mbedtls/aes.h"
39#endif
40
41#if defined(MBEDTLS_ARC4_C)
42#include "mbedtls/arc4.h"
43#endif
44
45#if defined(MBEDTLS_CAMELLIA_C)
46#include "mbedtls/camellia.h"
47#endif
48
Jens Wiklander3d3b0592019-03-20 15:30:29 +010049#if defined(MBEDTLS_ARIA_C)
50#include "mbedtls/aria.h"
51#endif
52
Jens Wiklander817466c2018-05-22 13:49:31 +020053#if defined(MBEDTLS_DES_C)
54#include "mbedtls/des.h"
55#endif
56
57#if defined(MBEDTLS_BLOWFISH_C)
58#include "mbedtls/blowfish.h"
59#endif
60
Jens Wiklander3d3b0592019-03-20 15:30:29 +010061#if defined(MBEDTLS_CHACHA20_C)
62#include "mbedtls/chacha20.h"
63#endif
64
Jens Wiklander817466c2018-05-22 13:49:31 +020065#if defined(MBEDTLS_GCM_C)
66#include "mbedtls/gcm.h"
67#endif
68
69#if defined(MBEDTLS_CCM_C)
70#include "mbedtls/ccm.h"
71#endif
72
Jerome Forissier11fa71b2020-04-20 17:17:56 +020073#if defined(MBEDTLS_NIST_KW_C)
74#include "mbedtls/nist_kw.h"
75#endif
76
Jens Wiklander817466c2018-05-22 13:49:31 +020077#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
78#include <string.h>
79#endif
80
81#if defined(MBEDTLS_PLATFORM_C)
82#include "mbedtls/platform.h"
83#else
84#include <stdlib.h>
85#define mbedtls_calloc calloc
86#define mbedtls_free free
87#endif
88
89#if defined(MBEDTLS_GCM_C)
90/* shared by all GCM ciphers */
91static void *gcm_ctx_alloc( void )
92{
93 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
94
95 if( ctx != NULL )
96 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
97
98 return( ctx );
99}
100
Edison Ai12484fc2018-12-19 15:36:28 +0800101static void gcm_ctx_clone( void *dst, const void *src )
102{
103 memcpy( dst, src, sizeof( mbedtls_gcm_context ) );
104}
105
Jens Wiklander817466c2018-05-22 13:49:31 +0200106static void gcm_ctx_free( void *ctx )
107{
108 mbedtls_gcm_free( ctx );
109 mbedtls_free( ctx );
110}
111#endif /* MBEDTLS_GCM_C */
112
113#if defined(MBEDTLS_CCM_C)
114/* shared by all CCM ciphers */
115static void *ccm_ctx_alloc( void )
116{
117 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
118
119 if( ctx != NULL )
120 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
121
122 return( ctx );
123}
124
Edison Ai12484fc2018-12-19 15:36:28 +0800125static void ccm_ctx_clone( void *dst, const void *src )
126{
127 memcpy( dst, src, sizeof( mbedtls_ccm_context ) );
128}
129
Jens Wiklander817466c2018-05-22 13:49:31 +0200130static void ccm_ctx_free( void *ctx )
131{
132 mbedtls_ccm_free( ctx );
133 mbedtls_free( ctx );
134}
135#endif /* MBEDTLS_CCM_C */
136
137#if defined(MBEDTLS_AES_C)
138
139static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
140 const unsigned char *input, unsigned char *output )
141{
142 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
143}
144
145#if defined(MBEDTLS_CIPHER_MODE_CBC)
146static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
147 unsigned char *iv, const unsigned char *input, unsigned char *output )
148{
149 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
150 output );
151}
152#endif /* MBEDTLS_CIPHER_MODE_CBC */
153
154#if defined(MBEDTLS_CIPHER_MODE_CFB)
155static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
156 size_t length, size_t *iv_off, unsigned char *iv,
157 const unsigned char *input, unsigned char *output )
158{
159 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
160 input, output );
161}
162#endif /* MBEDTLS_CIPHER_MODE_CFB */
163
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100164#if defined(MBEDTLS_CIPHER_MODE_OFB)
165static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
166 unsigned char *iv, const unsigned char *input, unsigned char *output )
167{
168 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
169 iv, input, output );
170}
171#endif /* MBEDTLS_CIPHER_MODE_OFB */
172
Jens Wiklander817466c2018-05-22 13:49:31 +0200173#if defined(MBEDTLS_CIPHER_MODE_CTR)
174static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
175 unsigned char *nonce_counter, unsigned char *stream_block,
176 const unsigned char *input, unsigned char *output )
177{
178 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
179 stream_block, input, output );
180}
181#endif /* MBEDTLS_CIPHER_MODE_CTR */
182
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100183#if defined(MBEDTLS_CIPHER_MODE_XTS)
184static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
185 size_t length,
186 const unsigned char data_unit[16],
187 const unsigned char *input,
188 unsigned char *output )
189{
190 mbedtls_aes_xts_context *xts_ctx = ctx;
191 int mode;
192
193 switch( operation )
194 {
195 case MBEDTLS_ENCRYPT:
196 mode = MBEDTLS_AES_ENCRYPT;
197 break;
198 case MBEDTLS_DECRYPT:
199 mode = MBEDTLS_AES_DECRYPT;
200 break;
201 default:
202 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
203 }
204
205 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
206 data_unit, input, output );
207}
208#endif /* MBEDTLS_CIPHER_MODE_XTS */
209
Jens Wiklander817466c2018-05-22 13:49:31 +0200210static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
211 unsigned int key_bitlen )
212{
213 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
214}
215
216static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
217 unsigned int key_bitlen )
218{
219 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
220}
221
222static void * aes_ctx_alloc( void )
223{
224 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
225
226 if( aes == NULL )
227 return( NULL );
228
229 mbedtls_aes_init( aes );
230
231 return( aes );
232}
233
Edison Ai12484fc2018-12-19 15:36:28 +0800234static void aes_ctx_clone( void *dst, const void *src )
235{
236 memcpy( dst, src, sizeof( mbedtls_aes_context ) );
237}
238
Jens Wiklander817466c2018-05-22 13:49:31 +0200239static void aes_ctx_free( void *ctx )
240{
241 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
242 mbedtls_free( ctx );
243}
244
245static const mbedtls_cipher_base_t aes_info = {
246 MBEDTLS_CIPHER_ID_AES,
247 aes_crypt_ecb_wrap,
248#if defined(MBEDTLS_CIPHER_MODE_CBC)
249 aes_crypt_cbc_wrap,
250#endif
251#if defined(MBEDTLS_CIPHER_MODE_CFB)
252 aes_crypt_cfb128_wrap,
253#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100254#if defined(MBEDTLS_CIPHER_MODE_OFB)
255 aes_crypt_ofb_wrap,
256#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200257#if defined(MBEDTLS_CIPHER_MODE_CTR)
258 aes_crypt_ctr_wrap,
259#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100260#if defined(MBEDTLS_CIPHER_MODE_XTS)
261 NULL,
262#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200263#if defined(MBEDTLS_CIPHER_MODE_STREAM)
264 NULL,
265#endif
266 aes_setkey_enc_wrap,
267 aes_setkey_dec_wrap,
268 aes_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +0800269 aes_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +0200270 aes_ctx_free
271};
272
273static const mbedtls_cipher_info_t aes_128_ecb_info = {
274 MBEDTLS_CIPHER_AES_128_ECB,
275 MBEDTLS_MODE_ECB,
276 128,
277 "AES-128-ECB",
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100278 0,
Jens Wiklander817466c2018-05-22 13:49:31 +0200279 0,
280 16,
281 &aes_info
282};
283
284static const mbedtls_cipher_info_t aes_192_ecb_info = {
285 MBEDTLS_CIPHER_AES_192_ECB,
286 MBEDTLS_MODE_ECB,
287 192,
288 "AES-192-ECB",
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100289 0,
Jens Wiklander817466c2018-05-22 13:49:31 +0200290 0,
291 16,
292 &aes_info
293};
294
295static const mbedtls_cipher_info_t aes_256_ecb_info = {
296 MBEDTLS_CIPHER_AES_256_ECB,
297 MBEDTLS_MODE_ECB,
298 256,
299 "AES-256-ECB",
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100300 0,
Jens Wiklander817466c2018-05-22 13:49:31 +0200301 0,
302 16,
303 &aes_info
304};
305
306#if defined(MBEDTLS_CIPHER_MODE_CBC)
307static const mbedtls_cipher_info_t aes_128_cbc_info = {
308 MBEDTLS_CIPHER_AES_128_CBC,
309 MBEDTLS_MODE_CBC,
310 128,
311 "AES-128-CBC",
312 16,
313 0,
314 16,
315 &aes_info
316};
317
318static const mbedtls_cipher_info_t aes_192_cbc_info = {
319 MBEDTLS_CIPHER_AES_192_CBC,
320 MBEDTLS_MODE_CBC,
321 192,
322 "AES-192-CBC",
323 16,
324 0,
325 16,
326 &aes_info
327};
328
329static const mbedtls_cipher_info_t aes_256_cbc_info = {
330 MBEDTLS_CIPHER_AES_256_CBC,
331 MBEDTLS_MODE_CBC,
332 256,
333 "AES-256-CBC",
334 16,
335 0,
336 16,
337 &aes_info
338};
339#endif /* MBEDTLS_CIPHER_MODE_CBC */
340
341#if defined(MBEDTLS_CIPHER_MODE_CFB)
342static const mbedtls_cipher_info_t aes_128_cfb128_info = {
343 MBEDTLS_CIPHER_AES_128_CFB128,
344 MBEDTLS_MODE_CFB,
345 128,
346 "AES-128-CFB128",
347 16,
348 0,
349 16,
350 &aes_info
351};
352
353static const mbedtls_cipher_info_t aes_192_cfb128_info = {
354 MBEDTLS_CIPHER_AES_192_CFB128,
355 MBEDTLS_MODE_CFB,
356 192,
357 "AES-192-CFB128",
358 16,
359 0,
360 16,
361 &aes_info
362};
363
364static const mbedtls_cipher_info_t aes_256_cfb128_info = {
365 MBEDTLS_CIPHER_AES_256_CFB128,
366 MBEDTLS_MODE_CFB,
367 256,
368 "AES-256-CFB128",
369 16,
370 0,
371 16,
372 &aes_info
373};
374#endif /* MBEDTLS_CIPHER_MODE_CFB */
375
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100376#if defined(MBEDTLS_CIPHER_MODE_OFB)
377static const mbedtls_cipher_info_t aes_128_ofb_info = {
378 MBEDTLS_CIPHER_AES_128_OFB,
379 MBEDTLS_MODE_OFB,
380 128,
381 "AES-128-OFB",
382 16,
383 0,
384 16,
385 &aes_info
386};
387
388static const mbedtls_cipher_info_t aes_192_ofb_info = {
389 MBEDTLS_CIPHER_AES_192_OFB,
390 MBEDTLS_MODE_OFB,
391 192,
392 "AES-192-OFB",
393 16,
394 0,
395 16,
396 &aes_info
397};
398
399static const mbedtls_cipher_info_t aes_256_ofb_info = {
400 MBEDTLS_CIPHER_AES_256_OFB,
401 MBEDTLS_MODE_OFB,
402 256,
403 "AES-256-OFB",
404 16,
405 0,
406 16,
407 &aes_info
408};
409#endif /* MBEDTLS_CIPHER_MODE_OFB */
410
Jens Wiklander817466c2018-05-22 13:49:31 +0200411#if defined(MBEDTLS_CIPHER_MODE_CTR)
412static const mbedtls_cipher_info_t aes_128_ctr_info = {
413 MBEDTLS_CIPHER_AES_128_CTR,
414 MBEDTLS_MODE_CTR,
415 128,
416 "AES-128-CTR",
417 16,
418 0,
419 16,
420 &aes_info
421};
422
423static const mbedtls_cipher_info_t aes_192_ctr_info = {
424 MBEDTLS_CIPHER_AES_192_CTR,
425 MBEDTLS_MODE_CTR,
426 192,
427 "AES-192-CTR",
428 16,
429 0,
430 16,
431 &aes_info
432};
433
434static const mbedtls_cipher_info_t aes_256_ctr_info = {
435 MBEDTLS_CIPHER_AES_256_CTR,
436 MBEDTLS_MODE_CTR,
437 256,
438 "AES-256-CTR",
439 16,
440 0,
441 16,
442 &aes_info
443};
444#endif /* MBEDTLS_CIPHER_MODE_CTR */
445
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100446#if defined(MBEDTLS_CIPHER_MODE_XTS)
447static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
448 unsigned int key_bitlen )
449{
450 mbedtls_aes_xts_context *xts_ctx = ctx;
451 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
452}
453
454static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
455 unsigned int key_bitlen )
456{
457 mbedtls_aes_xts_context *xts_ctx = ctx;
458 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
459}
460
461static void *xts_aes_ctx_alloc( void )
462{
463 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
464
465 if( xts_ctx != NULL )
466 mbedtls_aes_xts_init( xts_ctx );
467
468 return( xts_ctx );
469}
470
471static void xts_aes_ctx_free( void *ctx )
472{
473 mbedtls_aes_xts_context *xts_ctx = ctx;
474
475 if( xts_ctx == NULL )
476 return;
477
478 mbedtls_aes_xts_free( xts_ctx );
479 mbedtls_free( xts_ctx );
480}
481
482static const mbedtls_cipher_base_t xts_aes_info = {
483 MBEDTLS_CIPHER_ID_AES,
484 NULL,
485#if defined(MBEDTLS_CIPHER_MODE_CBC)
486 NULL,
487#endif
488#if defined(MBEDTLS_CIPHER_MODE_CFB)
489 NULL,
490#endif
491#if defined(MBEDTLS_CIPHER_MODE_OFB)
492 NULL,
493#endif
494#if defined(MBEDTLS_CIPHER_MODE_CTR)
495 NULL,
496#endif
497#if defined(MBEDTLS_CIPHER_MODE_XTS)
498 aes_crypt_xts_wrap,
499#endif
500#if defined(MBEDTLS_CIPHER_MODE_STREAM)
501 NULL,
502#endif
503 xts_aes_setkey_enc_wrap,
504 xts_aes_setkey_dec_wrap,
505 xts_aes_ctx_alloc,
506 xts_aes_ctx_free
507};
508
509static const mbedtls_cipher_info_t aes_128_xts_info = {
510 MBEDTLS_CIPHER_AES_128_XTS,
511 MBEDTLS_MODE_XTS,
512 256,
513 "AES-128-XTS",
514 16,
515 0,
516 16,
517 &xts_aes_info
518};
519
520static const mbedtls_cipher_info_t aes_256_xts_info = {
521 MBEDTLS_CIPHER_AES_256_XTS,
522 MBEDTLS_MODE_XTS,
523 512,
524 "AES-256-XTS",
525 16,
526 0,
527 16,
528 &xts_aes_info
529};
530#endif /* MBEDTLS_CIPHER_MODE_XTS */
531
Jens Wiklander817466c2018-05-22 13:49:31 +0200532#if defined(MBEDTLS_GCM_C)
533static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
534 unsigned int key_bitlen )
535{
536 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
537 key, key_bitlen );
538}
539
540static const mbedtls_cipher_base_t gcm_aes_info = {
541 MBEDTLS_CIPHER_ID_AES,
542 NULL,
543#if defined(MBEDTLS_CIPHER_MODE_CBC)
544 NULL,
545#endif
546#if defined(MBEDTLS_CIPHER_MODE_CFB)
547 NULL,
548#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100549#if defined(MBEDTLS_CIPHER_MODE_OFB)
550 NULL,
551#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200552#if defined(MBEDTLS_CIPHER_MODE_CTR)
553 NULL,
554#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100555#if defined(MBEDTLS_CIPHER_MODE_XTS)
556 NULL,
557#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200558#if defined(MBEDTLS_CIPHER_MODE_STREAM)
559 NULL,
560#endif
561 gcm_aes_setkey_wrap,
562 gcm_aes_setkey_wrap,
563 gcm_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +0800564 gcm_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +0200565 gcm_ctx_free,
566};
567
568static const mbedtls_cipher_info_t aes_128_gcm_info = {
569 MBEDTLS_CIPHER_AES_128_GCM,
570 MBEDTLS_MODE_GCM,
571 128,
572 "AES-128-GCM",
573 12,
574 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
575 16,
576 &gcm_aes_info
577};
578
579static const mbedtls_cipher_info_t aes_192_gcm_info = {
580 MBEDTLS_CIPHER_AES_192_GCM,
581 MBEDTLS_MODE_GCM,
582 192,
583 "AES-192-GCM",
584 12,
585 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
586 16,
587 &gcm_aes_info
588};
589
590static const mbedtls_cipher_info_t aes_256_gcm_info = {
591 MBEDTLS_CIPHER_AES_256_GCM,
592 MBEDTLS_MODE_GCM,
593 256,
594 "AES-256-GCM",
595 12,
596 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
597 16,
598 &gcm_aes_info
599};
600#endif /* MBEDTLS_GCM_C */
601
602#if defined(MBEDTLS_CCM_C)
603static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
604 unsigned int key_bitlen )
605{
606 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
607 key, key_bitlen );
608}
609
610static const mbedtls_cipher_base_t ccm_aes_info = {
611 MBEDTLS_CIPHER_ID_AES,
612 NULL,
613#if defined(MBEDTLS_CIPHER_MODE_CBC)
614 NULL,
615#endif
616#if defined(MBEDTLS_CIPHER_MODE_CFB)
617 NULL,
618#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100619#if defined(MBEDTLS_CIPHER_MODE_OFB)
620 NULL,
621#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200622#if defined(MBEDTLS_CIPHER_MODE_CTR)
623 NULL,
624#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100625#if defined(MBEDTLS_CIPHER_MODE_XTS)
626 NULL,
627#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200628#if defined(MBEDTLS_CIPHER_MODE_STREAM)
629 NULL,
630#endif
631 ccm_aes_setkey_wrap,
632 ccm_aes_setkey_wrap,
633 ccm_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +0800634 ccm_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +0200635 ccm_ctx_free,
636};
637
638static const mbedtls_cipher_info_t aes_128_ccm_info = {
639 MBEDTLS_CIPHER_AES_128_CCM,
640 MBEDTLS_MODE_CCM,
641 128,
642 "AES-128-CCM",
643 12,
644 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
645 16,
646 &ccm_aes_info
647};
648
649static const mbedtls_cipher_info_t aes_192_ccm_info = {
650 MBEDTLS_CIPHER_AES_192_CCM,
651 MBEDTLS_MODE_CCM,
652 192,
653 "AES-192-CCM",
654 12,
655 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
656 16,
657 &ccm_aes_info
658};
659
660static const mbedtls_cipher_info_t aes_256_ccm_info = {
661 MBEDTLS_CIPHER_AES_256_CCM,
662 MBEDTLS_MODE_CCM,
663 256,
664 "AES-256-CCM",
665 12,
666 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
667 16,
668 &ccm_aes_info
669};
670#endif /* MBEDTLS_CCM_C */
671
672#endif /* MBEDTLS_AES_C */
673
674#if defined(MBEDTLS_CAMELLIA_C)
675
676static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
677 const unsigned char *input, unsigned char *output )
678{
679 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
680 output );
681}
682
683#if defined(MBEDTLS_CIPHER_MODE_CBC)
684static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
685 size_t length, unsigned char *iv,
686 const unsigned char *input, unsigned char *output )
687{
688 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
689 input, output );
690}
691#endif /* MBEDTLS_CIPHER_MODE_CBC */
692
693#if defined(MBEDTLS_CIPHER_MODE_CFB)
694static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
695 size_t length, size_t *iv_off, unsigned char *iv,
696 const unsigned char *input, unsigned char *output )
697{
698 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
699 iv_off, iv, input, output );
700}
701#endif /* MBEDTLS_CIPHER_MODE_CFB */
702
703#if defined(MBEDTLS_CIPHER_MODE_CTR)
704static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
705 unsigned char *nonce_counter, unsigned char *stream_block,
706 const unsigned char *input, unsigned char *output )
707{
708 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
709 nonce_counter, stream_block, input, output );
710}
711#endif /* MBEDTLS_CIPHER_MODE_CTR */
712
713static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
714 unsigned int key_bitlen )
715{
716 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
717}
718
719static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
720 unsigned int key_bitlen )
721{
722 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
723}
724
725static void * camellia_ctx_alloc( void )
726{
727 mbedtls_camellia_context *ctx;
728 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
729
730 if( ctx == NULL )
731 return( NULL );
732
733 mbedtls_camellia_init( ctx );
734
735 return( ctx );
736}
737
Edison Ai12484fc2018-12-19 15:36:28 +0800738static void camellia_ctx_clone( void *dst, const void *src )
739{
740 memcpy( dst, src, sizeof( mbedtls_camellia_context ) );
741}
742
Jens Wiklander817466c2018-05-22 13:49:31 +0200743static void camellia_ctx_free( void *ctx )
744{
745 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
746 mbedtls_free( ctx );
747}
748
749static const mbedtls_cipher_base_t camellia_info = {
750 MBEDTLS_CIPHER_ID_CAMELLIA,
751 camellia_crypt_ecb_wrap,
752#if defined(MBEDTLS_CIPHER_MODE_CBC)
753 camellia_crypt_cbc_wrap,
754#endif
755#if defined(MBEDTLS_CIPHER_MODE_CFB)
756 camellia_crypt_cfb128_wrap,
757#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100758#if defined(MBEDTLS_CIPHER_MODE_OFB)
759 NULL,
760#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200761#if defined(MBEDTLS_CIPHER_MODE_CTR)
762 camellia_crypt_ctr_wrap,
763#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100764#if defined(MBEDTLS_CIPHER_MODE_XTS)
765 NULL,
766#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200767#if defined(MBEDTLS_CIPHER_MODE_STREAM)
768 NULL,
769#endif
770 camellia_setkey_enc_wrap,
771 camellia_setkey_dec_wrap,
772 camellia_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +0800773 camellia_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +0200774 camellia_ctx_free
775};
776
777static const mbedtls_cipher_info_t camellia_128_ecb_info = {
778 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
779 MBEDTLS_MODE_ECB,
780 128,
781 "CAMELLIA-128-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +0200782 0,
Jens Wiklander817466c2018-05-22 13:49:31 +0200783 0,
784 16,
785 &camellia_info
786};
787
788static const mbedtls_cipher_info_t camellia_192_ecb_info = {
789 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
790 MBEDTLS_MODE_ECB,
791 192,
792 "CAMELLIA-192-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +0200793 0,
Jens Wiklander817466c2018-05-22 13:49:31 +0200794 0,
795 16,
796 &camellia_info
797};
798
799static const mbedtls_cipher_info_t camellia_256_ecb_info = {
800 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
801 MBEDTLS_MODE_ECB,
802 256,
803 "CAMELLIA-256-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +0200804 0,
Jens Wiklander817466c2018-05-22 13:49:31 +0200805 0,
806 16,
807 &camellia_info
808};
809
810#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,
814 128,
815 "CAMELLIA-128-CBC",
816 16,
817 0,
818 16,
819 &camellia_info
820};
821
822static const mbedtls_cipher_info_t camellia_192_cbc_info = {
823 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
824 MBEDTLS_MODE_CBC,
825 192,
826 "CAMELLIA-192-CBC",
827 16,
828 0,
829 16,
830 &camellia_info
831};
832
833static const mbedtls_cipher_info_t camellia_256_cbc_info = {
834 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
835 MBEDTLS_MODE_CBC,
836 256,
837 "CAMELLIA-256-CBC",
838 16,
839 0,
840 16,
841 &camellia_info
842};
843#endif /* MBEDTLS_CIPHER_MODE_CBC */
844
845#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,
849 128,
850 "CAMELLIA-128-CFB128",
851 16,
852 0,
853 16,
854 &camellia_info
855};
856
857static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
858 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
859 MBEDTLS_MODE_CFB,
860 192,
861 "CAMELLIA-192-CFB128",
862 16,
863 0,
864 16,
865 &camellia_info
866};
867
868static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
869 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
870 MBEDTLS_MODE_CFB,
871 256,
872 "CAMELLIA-256-CFB128",
873 16,
874 0,
875 16,
876 &camellia_info
877};
878#endif /* MBEDTLS_CIPHER_MODE_CFB */
879
880#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,
884 128,
885 "CAMELLIA-128-CTR",
886 16,
887 0,
888 16,
889 &camellia_info
890};
891
892static const mbedtls_cipher_info_t camellia_192_ctr_info = {
893 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
894 MBEDTLS_MODE_CTR,
895 192,
896 "CAMELLIA-192-CTR",
897 16,
898 0,
899 16,
900 &camellia_info
901};
902
903static const mbedtls_cipher_info_t camellia_256_ctr_info = {
904 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
905 MBEDTLS_MODE_CTR,
906 256,
907 "CAMELLIA-256-CTR",
908 16,
909 0,
910 16,
911 &camellia_info
912};
913#endif /* MBEDTLS_CIPHER_MODE_CTR */
914
915#if defined(MBEDTLS_GCM_C)
916static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
917 unsigned int key_bitlen )
918{
919 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
920 key, key_bitlen );
921}
922
923static const mbedtls_cipher_base_t gcm_camellia_info = {
924 MBEDTLS_CIPHER_ID_CAMELLIA,
925 NULL,
926#if defined(MBEDTLS_CIPHER_MODE_CBC)
927 NULL,
928#endif
929#if defined(MBEDTLS_CIPHER_MODE_CFB)
930 NULL,
931#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100932#if defined(MBEDTLS_CIPHER_MODE_OFB)
933 NULL,
934#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200935#if defined(MBEDTLS_CIPHER_MODE_CTR)
936 NULL,
937#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +0100938#if defined(MBEDTLS_CIPHER_MODE_XTS)
939 NULL,
940#endif
Jens Wiklander817466c2018-05-22 13:49:31 +0200941#if defined(MBEDTLS_CIPHER_MODE_STREAM)
942 NULL,
943#endif
944 gcm_camellia_setkey_wrap,
945 gcm_camellia_setkey_wrap,
946 gcm_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +0800947 gcm_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +0200948 gcm_ctx_free,
949};
950
951static const mbedtls_cipher_info_t camellia_128_gcm_info = {
952 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
953 MBEDTLS_MODE_GCM,
954 128,
955 "CAMELLIA-128-GCM",
956 12,
957 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
958 16,
959 &gcm_camellia_info
960};
961
962static const mbedtls_cipher_info_t camellia_192_gcm_info = {
963 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
964 MBEDTLS_MODE_GCM,
965 192,
966 "CAMELLIA-192-GCM",
967 12,
968 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
969 16,
970 &gcm_camellia_info
971};
972
973static const mbedtls_cipher_info_t camellia_256_gcm_info = {
974 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
975 MBEDTLS_MODE_GCM,
976 256,
977 "CAMELLIA-256-GCM",
978 12,
979 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
980 16,
981 &gcm_camellia_info
982};
983#endif /* MBEDTLS_GCM_C */
984
985#if defined(MBEDTLS_CCM_C)
986static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
987 unsigned int key_bitlen )
988{
989 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
990 key, key_bitlen );
991}
992
993static const mbedtls_cipher_base_t ccm_camellia_info = {
994 MBEDTLS_CIPHER_ID_CAMELLIA,
995 NULL,
996#if defined(MBEDTLS_CIPHER_MODE_CBC)
997 NULL,
998#endif
999#if defined(MBEDTLS_CIPHER_MODE_CFB)
1000 NULL,
1001#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001002#if defined(MBEDTLS_CIPHER_MODE_OFB)
1003 NULL,
1004#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001005#if defined(MBEDTLS_CIPHER_MODE_CTR)
1006 NULL,
1007#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001008#if defined(MBEDTLS_CIPHER_MODE_XTS)
1009 NULL,
1010#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001011#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1012 NULL,
1013#endif
1014 ccm_camellia_setkey_wrap,
1015 ccm_camellia_setkey_wrap,
1016 ccm_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08001017 ccm_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02001018 ccm_ctx_free,
1019};
1020
1021static const mbedtls_cipher_info_t camellia_128_ccm_info = {
1022 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
1023 MBEDTLS_MODE_CCM,
1024 128,
1025 "CAMELLIA-128-CCM",
1026 12,
1027 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1028 16,
1029 &ccm_camellia_info
1030};
1031
1032static const mbedtls_cipher_info_t camellia_192_ccm_info = {
1033 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
1034 MBEDTLS_MODE_CCM,
1035 192,
1036 "CAMELLIA-192-CCM",
1037 12,
1038 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1039 16,
1040 &ccm_camellia_info
1041};
1042
1043static const mbedtls_cipher_info_t camellia_256_ccm_info = {
1044 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
1045 MBEDTLS_MODE_CCM,
1046 256,
1047 "CAMELLIA-256-CCM",
1048 12,
1049 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1050 16,
1051 &ccm_camellia_info
1052};
1053#endif /* MBEDTLS_CCM_C */
1054
1055#endif /* MBEDTLS_CAMELLIA_C */
1056
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001057#if defined(MBEDTLS_ARIA_C)
1058
1059static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1060 const unsigned char *input, unsigned char *output )
1061{
1062 (void) operation;
1063 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
1064 output );
1065}
1066
1067#if defined(MBEDTLS_CIPHER_MODE_CBC)
1068static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1069 size_t length, unsigned char *iv,
1070 const unsigned char *input, unsigned char *output )
1071{
1072 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
1073 input, output );
1074}
1075#endif /* MBEDTLS_CIPHER_MODE_CBC */
1076
1077#if defined(MBEDTLS_CIPHER_MODE_CFB)
1078static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
1079 size_t length, size_t *iv_off, unsigned char *iv,
1080 const unsigned char *input, unsigned char *output )
1081{
1082 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
1083 iv_off, iv, input, output );
1084}
1085#endif /* MBEDTLS_CIPHER_MODE_CFB */
1086
1087#if defined(MBEDTLS_CIPHER_MODE_CTR)
1088static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1089 unsigned char *nonce_counter, unsigned char *stream_block,
1090 const unsigned char *input, unsigned char *output )
1091{
1092 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
1093 nonce_counter, stream_block, input, output );
1094}
1095#endif /* MBEDTLS_CIPHER_MODE_CTR */
1096
1097static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
1098 unsigned int key_bitlen )
1099{
1100 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
1101}
1102
1103static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
1104 unsigned int key_bitlen )
1105{
1106 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
1107}
1108
1109static void * aria_ctx_alloc( void )
1110{
1111 mbedtls_aria_context *ctx;
1112 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
1113
1114 if( ctx == NULL )
1115 return( NULL );
1116
1117 mbedtls_aria_init( ctx );
1118
1119 return( ctx );
1120}
1121
1122static void aria_ctx_free( void *ctx )
1123{
1124 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
1125 mbedtls_free( ctx );
1126}
1127
1128static const mbedtls_cipher_base_t aria_info = {
1129 MBEDTLS_CIPHER_ID_ARIA,
1130 aria_crypt_ecb_wrap,
1131#if defined(MBEDTLS_CIPHER_MODE_CBC)
1132 aria_crypt_cbc_wrap,
1133#endif
1134#if defined(MBEDTLS_CIPHER_MODE_CFB)
1135 aria_crypt_cfb128_wrap,
1136#endif
1137#if defined(MBEDTLS_CIPHER_MODE_OFB)
1138 NULL,
1139#endif
1140#if defined(MBEDTLS_CIPHER_MODE_CTR)
1141 aria_crypt_ctr_wrap,
1142#endif
1143#if defined(MBEDTLS_CIPHER_MODE_XTS)
1144 NULL,
1145#endif
1146#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1147 NULL,
1148#endif
1149 aria_setkey_enc_wrap,
1150 aria_setkey_dec_wrap,
1151 aria_ctx_alloc,
1152 aria_ctx_free
1153};
1154
1155static const mbedtls_cipher_info_t aria_128_ecb_info = {
1156 MBEDTLS_CIPHER_ARIA_128_ECB,
1157 MBEDTLS_MODE_ECB,
1158 128,
1159 "ARIA-128-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001160 0,
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001161 0,
1162 16,
1163 &aria_info
1164};
1165
1166static const mbedtls_cipher_info_t aria_192_ecb_info = {
1167 MBEDTLS_CIPHER_ARIA_192_ECB,
1168 MBEDTLS_MODE_ECB,
1169 192,
1170 "ARIA-192-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001171 0,
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001172 0,
1173 16,
1174 &aria_info
1175};
1176
1177static const mbedtls_cipher_info_t aria_256_ecb_info = {
1178 MBEDTLS_CIPHER_ARIA_256_ECB,
1179 MBEDTLS_MODE_ECB,
1180 256,
1181 "ARIA-256-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001182 0,
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001183 0,
1184 16,
1185 &aria_info
1186};
1187
1188#if defined(MBEDTLS_CIPHER_MODE_CBC)
1189static const mbedtls_cipher_info_t aria_128_cbc_info = {
1190 MBEDTLS_CIPHER_ARIA_128_CBC,
1191 MBEDTLS_MODE_CBC,
1192 128,
1193 "ARIA-128-CBC",
1194 16,
1195 0,
1196 16,
1197 &aria_info
1198};
1199
1200static const mbedtls_cipher_info_t aria_192_cbc_info = {
1201 MBEDTLS_CIPHER_ARIA_192_CBC,
1202 MBEDTLS_MODE_CBC,
1203 192,
1204 "ARIA-192-CBC",
1205 16,
1206 0,
1207 16,
1208 &aria_info
1209};
1210
1211static const mbedtls_cipher_info_t aria_256_cbc_info = {
1212 MBEDTLS_CIPHER_ARIA_256_CBC,
1213 MBEDTLS_MODE_CBC,
1214 256,
1215 "ARIA-256-CBC",
1216 16,
1217 0,
1218 16,
1219 &aria_info
1220};
1221#endif /* MBEDTLS_CIPHER_MODE_CBC */
1222
1223#if defined(MBEDTLS_CIPHER_MODE_CFB)
1224static const mbedtls_cipher_info_t aria_128_cfb128_info = {
1225 MBEDTLS_CIPHER_ARIA_128_CFB128,
1226 MBEDTLS_MODE_CFB,
1227 128,
1228 "ARIA-128-CFB128",
1229 16,
1230 0,
1231 16,
1232 &aria_info
1233};
1234
1235static const mbedtls_cipher_info_t aria_192_cfb128_info = {
1236 MBEDTLS_CIPHER_ARIA_192_CFB128,
1237 MBEDTLS_MODE_CFB,
1238 192,
1239 "ARIA-192-CFB128",
1240 16,
1241 0,
1242 16,
1243 &aria_info
1244};
1245
1246static const mbedtls_cipher_info_t aria_256_cfb128_info = {
1247 MBEDTLS_CIPHER_ARIA_256_CFB128,
1248 MBEDTLS_MODE_CFB,
1249 256,
1250 "ARIA-256-CFB128",
1251 16,
1252 0,
1253 16,
1254 &aria_info
1255};
1256#endif /* MBEDTLS_CIPHER_MODE_CFB */
1257
1258#if defined(MBEDTLS_CIPHER_MODE_CTR)
1259static const mbedtls_cipher_info_t aria_128_ctr_info = {
1260 MBEDTLS_CIPHER_ARIA_128_CTR,
1261 MBEDTLS_MODE_CTR,
1262 128,
1263 "ARIA-128-CTR",
1264 16,
1265 0,
1266 16,
1267 &aria_info
1268};
1269
1270static const mbedtls_cipher_info_t aria_192_ctr_info = {
1271 MBEDTLS_CIPHER_ARIA_192_CTR,
1272 MBEDTLS_MODE_CTR,
1273 192,
1274 "ARIA-192-CTR",
1275 16,
1276 0,
1277 16,
1278 &aria_info
1279};
1280
1281static const mbedtls_cipher_info_t aria_256_ctr_info = {
1282 MBEDTLS_CIPHER_ARIA_256_CTR,
1283 MBEDTLS_MODE_CTR,
1284 256,
1285 "ARIA-256-CTR",
1286 16,
1287 0,
1288 16,
1289 &aria_info
1290};
1291#endif /* MBEDTLS_CIPHER_MODE_CTR */
1292
1293#if defined(MBEDTLS_GCM_C)
1294static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1295 unsigned int key_bitlen )
1296{
1297 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1298 key, key_bitlen );
1299}
1300
1301static const mbedtls_cipher_base_t gcm_aria_info = {
1302 MBEDTLS_CIPHER_ID_ARIA,
1303 NULL,
1304#if defined(MBEDTLS_CIPHER_MODE_CBC)
1305 NULL,
1306#endif
1307#if defined(MBEDTLS_CIPHER_MODE_CFB)
1308 NULL,
1309#endif
1310#if defined(MBEDTLS_CIPHER_MODE_OFB)
1311 NULL,
1312#endif
1313#if defined(MBEDTLS_CIPHER_MODE_CTR)
1314 NULL,
1315#endif
1316#if defined(MBEDTLS_CIPHER_MODE_XTS)
1317 NULL,
1318#endif
1319#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1320 NULL,
1321#endif
1322 gcm_aria_setkey_wrap,
1323 gcm_aria_setkey_wrap,
1324 gcm_ctx_alloc,
1325 gcm_ctx_free,
1326};
1327
1328static const mbedtls_cipher_info_t aria_128_gcm_info = {
1329 MBEDTLS_CIPHER_ARIA_128_GCM,
1330 MBEDTLS_MODE_GCM,
1331 128,
1332 "ARIA-128-GCM",
1333 12,
1334 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1335 16,
1336 &gcm_aria_info
1337};
1338
1339static const mbedtls_cipher_info_t aria_192_gcm_info = {
1340 MBEDTLS_CIPHER_ARIA_192_GCM,
1341 MBEDTLS_MODE_GCM,
1342 192,
1343 "ARIA-192-GCM",
1344 12,
1345 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1346 16,
1347 &gcm_aria_info
1348};
1349
1350static const mbedtls_cipher_info_t aria_256_gcm_info = {
1351 MBEDTLS_CIPHER_ARIA_256_GCM,
1352 MBEDTLS_MODE_GCM,
1353 256,
1354 "ARIA-256-GCM",
1355 12,
1356 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1357 16,
1358 &gcm_aria_info
1359};
1360#endif /* MBEDTLS_GCM_C */
1361
1362#if defined(MBEDTLS_CCM_C)
1363static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
1364 unsigned int key_bitlen )
1365{
1366 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
1367 key, key_bitlen );
1368}
1369
1370static const mbedtls_cipher_base_t ccm_aria_info = {
1371 MBEDTLS_CIPHER_ID_ARIA,
1372 NULL,
1373#if defined(MBEDTLS_CIPHER_MODE_CBC)
1374 NULL,
1375#endif
1376#if defined(MBEDTLS_CIPHER_MODE_CFB)
1377 NULL,
1378#endif
1379#if defined(MBEDTLS_CIPHER_MODE_OFB)
1380 NULL,
1381#endif
1382#if defined(MBEDTLS_CIPHER_MODE_CTR)
1383 NULL,
1384#endif
1385#if defined(MBEDTLS_CIPHER_MODE_XTS)
1386 NULL,
1387#endif
1388#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1389 NULL,
1390#endif
1391 ccm_aria_setkey_wrap,
1392 ccm_aria_setkey_wrap,
1393 ccm_ctx_alloc,
1394 ccm_ctx_free,
1395};
1396
1397static const mbedtls_cipher_info_t aria_128_ccm_info = {
1398 MBEDTLS_CIPHER_ARIA_128_CCM,
1399 MBEDTLS_MODE_CCM,
1400 128,
1401 "ARIA-128-CCM",
1402 12,
1403 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1404 16,
1405 &ccm_aria_info
1406};
1407
1408static const mbedtls_cipher_info_t aria_192_ccm_info = {
1409 MBEDTLS_CIPHER_ARIA_192_CCM,
1410 MBEDTLS_MODE_CCM,
1411 192,
1412 "ARIA-192-CCM",
1413 12,
1414 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1415 16,
1416 &ccm_aria_info
1417};
1418
1419static const mbedtls_cipher_info_t aria_256_ccm_info = {
1420 MBEDTLS_CIPHER_ARIA_256_CCM,
1421 MBEDTLS_MODE_CCM,
1422 256,
1423 "ARIA-256-CCM",
1424 12,
1425 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
1426 16,
1427 &ccm_aria_info
1428};
1429#endif /* MBEDTLS_CCM_C */
1430
1431#endif /* MBEDTLS_ARIA_C */
1432
Jens Wiklander817466c2018-05-22 13:49:31 +02001433#if defined(MBEDTLS_DES_C)
1434
1435static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1436 const unsigned char *input, unsigned char *output )
1437{
1438 ((void) operation);
1439 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
1440}
1441
1442static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1443 const unsigned char *input, unsigned char *output )
1444{
1445 ((void) operation);
1446 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
1447}
1448
1449#if defined(MBEDTLS_CIPHER_MODE_CBC)
1450static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
1451 unsigned char *iv, const unsigned char *input, unsigned char *output )
1452{
1453 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
1454 output );
1455}
1456#endif /* MBEDTLS_CIPHER_MODE_CBC */
1457
1458#if defined(MBEDTLS_CIPHER_MODE_CBC)
1459static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
1460 unsigned char *iv, const unsigned char *input, unsigned char *output )
1461{
1462 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
1463 output );
1464}
1465#endif /* MBEDTLS_CIPHER_MODE_CBC */
1466
1467static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
1468 unsigned int key_bitlen )
1469{
1470 ((void) key_bitlen);
1471
1472 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
1473}
1474
1475static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
1476 unsigned int key_bitlen )
1477{
1478 ((void) key_bitlen);
1479
1480 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
1481}
1482
1483static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
1484 unsigned int key_bitlen )
1485{
1486 ((void) key_bitlen);
1487
1488 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
1489}
1490
1491static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
1492 unsigned int key_bitlen )
1493{
1494 ((void) key_bitlen);
1495
1496 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
1497}
1498
1499static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
1500 unsigned int key_bitlen )
1501{
1502 ((void) key_bitlen);
1503
1504 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
1505}
1506
1507static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
1508 unsigned int key_bitlen )
1509{
1510 ((void) key_bitlen);
1511
1512 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
1513}
1514
1515static void * des_ctx_alloc( void )
1516{
1517 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
1518
1519 if( des == NULL )
1520 return( NULL );
1521
1522 mbedtls_des_init( des );
1523
1524 return( des );
1525}
1526
Edison Ai12484fc2018-12-19 15:36:28 +08001527static void des_ctx_clone( void *dst, const void *src )
1528{
1529 memcpy( dst, src, sizeof( mbedtls_des_context ) );
1530}
1531
Jens Wiklander817466c2018-05-22 13:49:31 +02001532static void des_ctx_free( void *ctx )
1533{
1534 mbedtls_des_free( (mbedtls_des_context *) ctx );
1535 mbedtls_free( ctx );
1536}
1537
1538static void * des3_ctx_alloc( void )
1539{
1540 mbedtls_des3_context *des3;
1541 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
1542
1543 if( des3 == NULL )
1544 return( NULL );
1545
1546 mbedtls_des3_init( des3 );
1547
1548 return( des3 );
1549}
1550
Edison Ai12484fc2018-12-19 15:36:28 +08001551static void des3_ctx_clone( void *dst, const void *src )
1552{
1553 memcpy( dst, src, sizeof( mbedtls_des3_context ) );
1554}
1555
Jens Wiklander817466c2018-05-22 13:49:31 +02001556static void des3_ctx_free( void *ctx )
1557{
1558 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
1559 mbedtls_free( ctx );
1560}
1561
1562static const mbedtls_cipher_base_t des_info = {
1563 MBEDTLS_CIPHER_ID_DES,
1564 des_crypt_ecb_wrap,
1565#if defined(MBEDTLS_CIPHER_MODE_CBC)
1566 des_crypt_cbc_wrap,
1567#endif
1568#if defined(MBEDTLS_CIPHER_MODE_CFB)
1569 NULL,
1570#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001571#if defined(MBEDTLS_CIPHER_MODE_OFB)
1572 NULL,
1573#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001574#if defined(MBEDTLS_CIPHER_MODE_CTR)
1575 NULL,
1576#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001577#if defined(MBEDTLS_CIPHER_MODE_XTS)
1578 NULL,
1579#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001580#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1581 NULL,
1582#endif
1583 des_setkey_enc_wrap,
1584 des_setkey_dec_wrap,
1585 des_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08001586 des_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02001587 des_ctx_free
1588};
1589
1590static const mbedtls_cipher_info_t des_ecb_info = {
1591 MBEDTLS_CIPHER_DES_ECB,
1592 MBEDTLS_MODE_ECB,
1593 MBEDTLS_KEY_LENGTH_DES,
1594 "DES-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001595 0,
Jens Wiklander817466c2018-05-22 13:49:31 +02001596 0,
1597 8,
1598 &des_info
1599};
1600
1601#if defined(MBEDTLS_CIPHER_MODE_CBC)
1602static const mbedtls_cipher_info_t des_cbc_info = {
1603 MBEDTLS_CIPHER_DES_CBC,
1604 MBEDTLS_MODE_CBC,
1605 MBEDTLS_KEY_LENGTH_DES,
1606 "DES-CBC",
1607 8,
1608 0,
1609 8,
1610 &des_info
1611};
1612#endif /* MBEDTLS_CIPHER_MODE_CBC */
1613
1614static const mbedtls_cipher_base_t des_ede_info = {
1615 MBEDTLS_CIPHER_ID_DES,
1616 des3_crypt_ecb_wrap,
1617#if defined(MBEDTLS_CIPHER_MODE_CBC)
1618 des3_crypt_cbc_wrap,
1619#endif
1620#if defined(MBEDTLS_CIPHER_MODE_CFB)
1621 NULL,
1622#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001623#if defined(MBEDTLS_CIPHER_MODE_OFB)
1624 NULL,
1625#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001626#if defined(MBEDTLS_CIPHER_MODE_CTR)
1627 NULL,
1628#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001629#if defined(MBEDTLS_CIPHER_MODE_XTS)
1630 NULL,
1631#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001632#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1633 NULL,
1634#endif
1635 des3_set2key_enc_wrap,
1636 des3_set2key_dec_wrap,
1637 des3_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08001638 des3_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02001639 des3_ctx_free
1640};
1641
1642static const mbedtls_cipher_info_t des_ede_ecb_info = {
1643 MBEDTLS_CIPHER_DES_EDE_ECB,
1644 MBEDTLS_MODE_ECB,
1645 MBEDTLS_KEY_LENGTH_DES_EDE,
1646 "DES-EDE-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001647 0,
Jens Wiklander817466c2018-05-22 13:49:31 +02001648 0,
1649 8,
1650 &des_ede_info
1651};
1652
1653#if defined(MBEDTLS_CIPHER_MODE_CBC)
1654static const mbedtls_cipher_info_t des_ede_cbc_info = {
1655 MBEDTLS_CIPHER_DES_EDE_CBC,
1656 MBEDTLS_MODE_CBC,
1657 MBEDTLS_KEY_LENGTH_DES_EDE,
1658 "DES-EDE-CBC",
1659 8,
1660 0,
1661 8,
1662 &des_ede_info
1663};
1664#endif /* MBEDTLS_CIPHER_MODE_CBC */
1665
1666static const mbedtls_cipher_base_t des_ede3_info = {
1667 MBEDTLS_CIPHER_ID_3DES,
1668 des3_crypt_ecb_wrap,
1669#if defined(MBEDTLS_CIPHER_MODE_CBC)
1670 des3_crypt_cbc_wrap,
1671#endif
1672#if defined(MBEDTLS_CIPHER_MODE_CFB)
1673 NULL,
1674#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001675#if defined(MBEDTLS_CIPHER_MODE_OFB)
1676 NULL,
1677#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001678#if defined(MBEDTLS_CIPHER_MODE_CTR)
1679 NULL,
1680#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001681#if defined(MBEDTLS_CIPHER_MODE_XTS)
1682 NULL,
1683#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001684#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1685 NULL,
1686#endif
1687 des3_set3key_enc_wrap,
1688 des3_set3key_dec_wrap,
1689 des3_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08001690 des3_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02001691 des3_ctx_free
1692};
1693
1694static const mbedtls_cipher_info_t des_ede3_ecb_info = {
1695 MBEDTLS_CIPHER_DES_EDE3_ECB,
1696 MBEDTLS_MODE_ECB,
1697 MBEDTLS_KEY_LENGTH_DES_EDE3,
1698 "DES-EDE3-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001699 0,
Jens Wiklander817466c2018-05-22 13:49:31 +02001700 0,
1701 8,
1702 &des_ede3_info
1703};
1704#if defined(MBEDTLS_CIPHER_MODE_CBC)
1705static const mbedtls_cipher_info_t des_ede3_cbc_info = {
1706 MBEDTLS_CIPHER_DES_EDE3_CBC,
1707 MBEDTLS_MODE_CBC,
1708 MBEDTLS_KEY_LENGTH_DES_EDE3,
1709 "DES-EDE3-CBC",
1710 8,
1711 0,
1712 8,
1713 &des_ede3_info
1714};
1715#endif /* MBEDTLS_CIPHER_MODE_CBC */
1716#endif /* MBEDTLS_DES_C */
1717
1718#if defined(MBEDTLS_BLOWFISH_C)
1719
1720static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
1721 const unsigned char *input, unsigned char *output )
1722{
1723 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
1724 output );
1725}
1726
1727#if defined(MBEDTLS_CIPHER_MODE_CBC)
1728static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
1729 size_t length, unsigned char *iv, const unsigned char *input,
1730 unsigned char *output )
1731{
1732 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
1733 input, output );
1734}
1735#endif /* MBEDTLS_CIPHER_MODE_CBC */
1736
1737#if defined(MBEDTLS_CIPHER_MODE_CFB)
1738static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
1739 size_t length, size_t *iv_off, unsigned char *iv,
1740 const unsigned char *input, unsigned char *output )
1741{
1742 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
1743 iv_off, iv, input, output );
1744}
1745#endif /* MBEDTLS_CIPHER_MODE_CFB */
1746
1747#if defined(MBEDTLS_CIPHER_MODE_CTR)
1748static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
1749 unsigned char *nonce_counter, unsigned char *stream_block,
1750 const unsigned char *input, unsigned char *output )
1751{
1752 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
1753 nonce_counter, stream_block, input, output );
1754}
1755#endif /* MBEDTLS_CIPHER_MODE_CTR */
1756
1757static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
1758 unsigned int key_bitlen )
1759{
1760 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
1761}
1762
1763static void * blowfish_ctx_alloc( void )
1764{
1765 mbedtls_blowfish_context *ctx;
1766 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
1767
1768 if( ctx == NULL )
1769 return( NULL );
1770
1771 mbedtls_blowfish_init( ctx );
1772
1773 return( ctx );
1774}
1775
Edison Ai12484fc2018-12-19 15:36:28 +08001776static void blowfish_ctx_clone( void *dst, const void *src )
1777{
1778 memcpy( dst, src, sizeof( mbedtls_blowfish_context ) );
1779}
1780
Jens Wiklander817466c2018-05-22 13:49:31 +02001781static void blowfish_ctx_free( void *ctx )
1782{
1783 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
1784 mbedtls_free( ctx );
1785}
1786
1787static const mbedtls_cipher_base_t blowfish_info = {
1788 MBEDTLS_CIPHER_ID_BLOWFISH,
1789 blowfish_crypt_ecb_wrap,
1790#if defined(MBEDTLS_CIPHER_MODE_CBC)
1791 blowfish_crypt_cbc_wrap,
1792#endif
1793#if defined(MBEDTLS_CIPHER_MODE_CFB)
1794 blowfish_crypt_cfb64_wrap,
1795#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001796#if defined(MBEDTLS_CIPHER_MODE_OFB)
1797 NULL,
1798#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001799#if defined(MBEDTLS_CIPHER_MODE_CTR)
1800 blowfish_crypt_ctr_wrap,
1801#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001802#if defined(MBEDTLS_CIPHER_MODE_XTS)
1803 NULL,
1804#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001805#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1806 NULL,
1807#endif
1808 blowfish_setkey_wrap,
1809 blowfish_setkey_wrap,
1810 blowfish_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08001811 blowfish_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02001812 blowfish_ctx_free
1813};
1814
1815static const mbedtls_cipher_info_t blowfish_ecb_info = {
1816 MBEDTLS_CIPHER_BLOWFISH_ECB,
1817 MBEDTLS_MODE_ECB,
1818 128,
1819 "BLOWFISH-ECB",
Jerome Forissier79013242021-07-28 10:24:04 +02001820 0,
Jens Wiklander817466c2018-05-22 13:49:31 +02001821 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1822 8,
1823 &blowfish_info
1824};
1825
1826#if defined(MBEDTLS_CIPHER_MODE_CBC)
1827static const mbedtls_cipher_info_t blowfish_cbc_info = {
1828 MBEDTLS_CIPHER_BLOWFISH_CBC,
1829 MBEDTLS_MODE_CBC,
1830 128,
1831 "BLOWFISH-CBC",
1832 8,
1833 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1834 8,
1835 &blowfish_info
1836};
1837#endif /* MBEDTLS_CIPHER_MODE_CBC */
1838
1839#if defined(MBEDTLS_CIPHER_MODE_CFB)
1840static const mbedtls_cipher_info_t blowfish_cfb64_info = {
1841 MBEDTLS_CIPHER_BLOWFISH_CFB64,
1842 MBEDTLS_MODE_CFB,
1843 128,
1844 "BLOWFISH-CFB64",
1845 8,
1846 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1847 8,
1848 &blowfish_info
1849};
1850#endif /* MBEDTLS_CIPHER_MODE_CFB */
1851
1852#if defined(MBEDTLS_CIPHER_MODE_CTR)
1853static const mbedtls_cipher_info_t blowfish_ctr_info = {
1854 MBEDTLS_CIPHER_BLOWFISH_CTR,
1855 MBEDTLS_MODE_CTR,
1856 128,
1857 "BLOWFISH-CTR",
1858 8,
1859 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
1860 8,
1861 &blowfish_info
1862};
1863#endif /* MBEDTLS_CIPHER_MODE_CTR */
1864#endif /* MBEDTLS_BLOWFISH_C */
1865
1866#if defined(MBEDTLS_ARC4_C)
1867static int arc4_crypt_stream_wrap( void *ctx, size_t length,
1868 const unsigned char *input,
1869 unsigned char *output )
1870{
1871 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
1872}
1873
1874static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
1875 unsigned int key_bitlen )
1876{
1877 /* we get key_bitlen in bits, arc4 expects it in bytes */
1878 if( key_bitlen % 8 != 0 )
1879 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1880
1881 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
1882 return( 0 );
1883}
1884
1885static void * arc4_ctx_alloc( void )
1886{
1887 mbedtls_arc4_context *ctx;
1888 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
1889
1890 if( ctx == NULL )
1891 return( NULL );
1892
1893 mbedtls_arc4_init( ctx );
1894
1895 return( ctx );
1896}
1897
Edison Ai12484fc2018-12-19 15:36:28 +08001898static void arc4_ctx_clone( void *dst, const void *src )
1899{
1900 memcpy( dst, src, sizeof( mbedtls_arc4_context ) );
1901}
1902
Jens Wiklander817466c2018-05-22 13:49:31 +02001903static void arc4_ctx_free( void *ctx )
1904{
1905 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
1906 mbedtls_free( ctx );
1907}
1908
1909static const mbedtls_cipher_base_t arc4_base_info = {
1910 MBEDTLS_CIPHER_ID_ARC4,
1911 NULL,
1912#if defined(MBEDTLS_CIPHER_MODE_CBC)
1913 NULL,
1914#endif
1915#if defined(MBEDTLS_CIPHER_MODE_CFB)
1916 NULL,
1917#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001918#if defined(MBEDTLS_CIPHER_MODE_OFB)
1919 NULL,
1920#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001921#if defined(MBEDTLS_CIPHER_MODE_CTR)
1922 NULL,
1923#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001924#if defined(MBEDTLS_CIPHER_MODE_XTS)
1925 NULL,
1926#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02001927#if defined(MBEDTLS_CIPHER_MODE_STREAM)
1928 arc4_crypt_stream_wrap,
1929#endif
1930 arc4_setkey_wrap,
1931 arc4_setkey_wrap,
1932 arc4_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08001933 arc4_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02001934 arc4_ctx_free
1935};
1936
1937static const mbedtls_cipher_info_t arc4_128_info = {
1938 MBEDTLS_CIPHER_ARC4_128,
1939 MBEDTLS_MODE_STREAM,
1940 128,
1941 "ARC4-128",
1942 0,
1943 0,
1944 1,
1945 &arc4_base_info
1946};
1947#endif /* MBEDTLS_ARC4_C */
1948
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001949#if defined(MBEDTLS_CHACHA20_C)
1950
1951static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
1952 unsigned int key_bitlen )
1953{
1954 if( key_bitlen != 256U )
1955 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1956
1957 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
1958 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1959
1960 return( 0 );
1961}
1962
1963static int chacha20_stream_wrap( void *ctx, size_t length,
1964 const unsigned char *input,
1965 unsigned char *output )
1966{
Jerome Forissier11fa71b2020-04-20 17:17:56 +02001967 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001968
1969 ret = mbedtls_chacha20_update( ctx, length, input, output );
1970 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
1971 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
1972
1973 return( ret );
1974}
1975
1976static void * chacha20_ctx_alloc( void )
1977{
1978 mbedtls_chacha20_context *ctx;
1979 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
1980
1981 if( ctx == NULL )
1982 return( NULL );
1983
1984 mbedtls_chacha20_init( ctx );
1985
1986 return( ctx );
1987}
1988
Simon Ott23ef3872022-10-26 11:38:24 +02001989static void chacha20_ctx_clone( void *dst, const void *src )
1990{
1991 memcpy( dst, src, sizeof( mbedtls_chacha20_context ) );
1992}
1993
Jens Wiklander3d3b0592019-03-20 15:30:29 +01001994static void chacha20_ctx_free( void *ctx )
1995{
1996 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
1997 mbedtls_free( ctx );
1998}
1999
2000static const mbedtls_cipher_base_t chacha20_base_info = {
2001 MBEDTLS_CIPHER_ID_CHACHA20,
2002 NULL,
2003#if defined(MBEDTLS_CIPHER_MODE_CBC)
2004 NULL,
2005#endif
2006#if defined(MBEDTLS_CIPHER_MODE_CFB)
2007 NULL,
2008#endif
2009#if defined(MBEDTLS_CIPHER_MODE_OFB)
2010 NULL,
2011#endif
2012#if defined(MBEDTLS_CIPHER_MODE_CTR)
2013 NULL,
2014#endif
2015#if defined(MBEDTLS_CIPHER_MODE_XTS)
2016 NULL,
2017#endif
2018#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2019 chacha20_stream_wrap,
2020#endif
2021 chacha20_setkey_wrap,
2022 chacha20_setkey_wrap,
2023 chacha20_ctx_alloc,
Simon Ott23ef3872022-10-26 11:38:24 +02002024 chacha20_ctx_clone,
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002025 chacha20_ctx_free
2026};
2027static const mbedtls_cipher_info_t chacha20_info = {
2028 MBEDTLS_CIPHER_CHACHA20,
2029 MBEDTLS_MODE_STREAM,
2030 256,
2031 "CHACHA20",
2032 12,
2033 0,
2034 1,
2035 &chacha20_base_info
2036};
2037#endif /* MBEDTLS_CHACHA20_C */
2038
2039#if defined(MBEDTLS_CHACHAPOLY_C)
2040
2041static int chachapoly_setkey_wrap( void *ctx,
2042 const unsigned char *key,
2043 unsigned int key_bitlen )
2044{
2045 if( key_bitlen != 256U )
2046 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2047
2048 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
2049 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
2050
2051 return( 0 );
2052}
2053
2054static void * chachapoly_ctx_alloc( void )
2055{
2056 mbedtls_chachapoly_context *ctx;
2057 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
2058
2059 if( ctx == NULL )
2060 return( NULL );
2061
2062 mbedtls_chachapoly_init( ctx );
2063
2064 return( ctx );
2065}
2066
Simon Ott23ef3872022-10-26 11:38:24 +02002067static void chachapoly_ctx_clone( void *dst, const void *src )
2068{
2069 memcpy( dst, src, sizeof( mbedtls_chachapoly_context ) );
2070}
2071
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002072static void chachapoly_ctx_free( void *ctx )
2073{
2074 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
2075 mbedtls_free( ctx );
2076}
2077
2078static const mbedtls_cipher_base_t chachapoly_base_info = {
2079 MBEDTLS_CIPHER_ID_CHACHA20,
2080 NULL,
2081#if defined(MBEDTLS_CIPHER_MODE_CBC)
2082 NULL,
2083#endif
2084#if defined(MBEDTLS_CIPHER_MODE_CFB)
2085 NULL,
2086#endif
2087#if defined(MBEDTLS_CIPHER_MODE_OFB)
2088 NULL,
2089#endif
2090#if defined(MBEDTLS_CIPHER_MODE_CTR)
2091 NULL,
2092#endif
2093#if defined(MBEDTLS_CIPHER_MODE_XTS)
2094 NULL,
2095#endif
2096#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2097 NULL,
2098#endif
2099 chachapoly_setkey_wrap,
2100 chachapoly_setkey_wrap,
2101 chachapoly_ctx_alloc,
Simon Ott23ef3872022-10-26 11:38:24 +02002102 chachapoly_ctx_clone,
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002103 chachapoly_ctx_free
2104};
2105static const mbedtls_cipher_info_t chachapoly_info = {
2106 MBEDTLS_CIPHER_CHACHA20_POLY1305,
2107 MBEDTLS_MODE_CHACHAPOLY,
2108 256,
2109 "CHACHA20-POLY1305",
2110 12,
2111 0,
2112 1,
2113 &chachapoly_base_info
2114};
2115#endif /* MBEDTLS_CHACHAPOLY_C */
2116
Jens Wiklander817466c2018-05-22 13:49:31 +02002117#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2118static int null_crypt_stream( void *ctx, size_t length,
2119 const unsigned char *input,
2120 unsigned char *output )
2121{
2122 ((void) ctx);
2123 memmove( output, input, length );
2124 return( 0 );
2125}
2126
2127static int null_setkey( void *ctx, const unsigned char *key,
2128 unsigned int key_bitlen )
2129{
2130 ((void) ctx);
2131 ((void) key);
2132 ((void) key_bitlen);
2133
2134 return( 0 );
2135}
2136
2137static void * null_ctx_alloc( void )
2138{
2139 return( (void *) 1 );
2140}
2141
Edison Ai12484fc2018-12-19 15:36:28 +08002142static void null_ctx_clone( void *dst, const void *src )
2143{
2144 ((void) dst);
2145 ((void) src);
2146}
2147
Jens Wiklander817466c2018-05-22 13:49:31 +02002148static void null_ctx_free( void *ctx )
2149{
2150 ((void) ctx);
2151}
2152
2153static const mbedtls_cipher_base_t null_base_info = {
2154 MBEDTLS_CIPHER_ID_NULL,
2155 NULL,
2156#if defined(MBEDTLS_CIPHER_MODE_CBC)
2157 NULL,
2158#endif
2159#if defined(MBEDTLS_CIPHER_MODE_CFB)
2160 NULL,
2161#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002162#if defined(MBEDTLS_CIPHER_MODE_OFB)
2163 NULL,
2164#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02002165#if defined(MBEDTLS_CIPHER_MODE_CTR)
2166 NULL,
2167#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002168#if defined(MBEDTLS_CIPHER_MODE_XTS)
2169 NULL,
2170#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02002171#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2172 null_crypt_stream,
2173#endif
2174 null_setkey,
2175 null_setkey,
2176 null_ctx_alloc,
Edison Ai12484fc2018-12-19 15:36:28 +08002177 null_ctx_clone,
Jens Wiklander817466c2018-05-22 13:49:31 +02002178 null_ctx_free
2179};
2180
2181static const mbedtls_cipher_info_t null_cipher_info = {
2182 MBEDTLS_CIPHER_NULL,
2183 MBEDTLS_MODE_STREAM,
2184 0,
2185 "NULL",
2186 0,
2187 0,
2188 1,
2189 &null_base_info
2190};
2191#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
2192
Jerome Forissier11fa71b2020-04-20 17:17:56 +02002193#if defined(MBEDTLS_NIST_KW_C)
2194static void *kw_ctx_alloc( void )
2195{
2196 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
2197
2198 if( ctx != NULL )
2199 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
2200
2201 return( ctx );
2202}
2203
2204static void kw_ctx_free( void *ctx )
2205{
2206 mbedtls_nist_kw_free( ctx );
2207 mbedtls_free( ctx );
2208}
2209
2210static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
2211 unsigned int key_bitlen )
2212{
2213 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2214 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
2215}
2216
2217static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
2218 unsigned int key_bitlen )
2219{
2220 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
2221 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
2222}
2223
2224static const mbedtls_cipher_base_t kw_aes_info = {
2225 MBEDTLS_CIPHER_ID_AES,
2226 NULL,
2227#if defined(MBEDTLS_CIPHER_MODE_CBC)
2228 NULL,
2229#endif
2230#if defined(MBEDTLS_CIPHER_MODE_CFB)
2231 NULL,
2232#endif
2233#if defined(MBEDTLS_CIPHER_MODE_OFB)
2234 NULL,
2235#endif
2236#if defined(MBEDTLS_CIPHER_MODE_CTR)
2237 NULL,
2238#endif
2239#if defined(MBEDTLS_CIPHER_MODE_XTS)
2240 NULL,
2241#endif
2242#if defined(MBEDTLS_CIPHER_MODE_STREAM)
2243 NULL,
2244#endif
2245 kw_aes_setkey_wrap,
2246 kw_aes_setkey_unwrap,
2247 kw_ctx_alloc,
2248 kw_ctx_free,
2249};
2250
2251static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
2252 MBEDTLS_CIPHER_AES_128_KW,
2253 MBEDTLS_MODE_KW,
2254 128,
2255 "AES-128-KW",
2256 0,
2257 0,
2258 16,
2259 &kw_aes_info
2260};
2261
2262static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
2263 MBEDTLS_CIPHER_AES_192_KW,
2264 MBEDTLS_MODE_KW,
2265 192,
2266 "AES-192-KW",
2267 0,
2268 0,
2269 16,
2270 &kw_aes_info
2271};
2272
2273static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
2274 MBEDTLS_CIPHER_AES_256_KW,
2275 MBEDTLS_MODE_KW,
2276 256,
2277 "AES-256-KW",
2278 0,
2279 0,
2280 16,
2281 &kw_aes_info
2282};
2283
2284static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
2285 MBEDTLS_CIPHER_AES_128_KWP,
2286 MBEDTLS_MODE_KWP,
2287 128,
2288 "AES-128-KWP",
2289 0,
2290 0,
2291 16,
2292 &kw_aes_info
2293};
2294
2295static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
2296 MBEDTLS_CIPHER_AES_192_KWP,
2297 MBEDTLS_MODE_KWP,
2298 192,
2299 "AES-192-KWP",
2300 0,
2301 0,
2302 16,
2303 &kw_aes_info
2304};
2305
2306static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
2307 MBEDTLS_CIPHER_AES_256_KWP,
2308 MBEDTLS_MODE_KWP,
2309 256,
2310 "AES-256-KWP",
2311 0,
2312 0,
2313 16,
2314 &kw_aes_info
2315};
2316#endif /* MBEDTLS_NIST_KW_C */
2317
Jens Wiklander817466c2018-05-22 13:49:31 +02002318const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
2319{
2320#if defined(MBEDTLS_AES_C)
2321 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
2322 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
2323 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
2324#if defined(MBEDTLS_CIPHER_MODE_CBC)
2325 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
2326 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
2327 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
2328#endif
2329#if defined(MBEDTLS_CIPHER_MODE_CFB)
2330 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
2331 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
2332 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
2333#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002334#if defined(MBEDTLS_CIPHER_MODE_OFB)
2335 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
2336 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
2337 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
2338#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02002339#if defined(MBEDTLS_CIPHER_MODE_CTR)
2340 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
2341 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
2342 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
2343#endif
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002344#if defined(MBEDTLS_CIPHER_MODE_XTS)
2345 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
2346 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
2347#endif
Jens Wiklander817466c2018-05-22 13:49:31 +02002348#if defined(MBEDTLS_GCM_C)
2349 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
2350 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
2351 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
2352#endif
2353#if defined(MBEDTLS_CCM_C)
2354 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
2355 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
2356 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
2357#endif
2358#endif /* MBEDTLS_AES_C */
2359
2360#if defined(MBEDTLS_ARC4_C)
2361 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
2362#endif
2363
2364#if defined(MBEDTLS_BLOWFISH_C)
2365 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
2366#if defined(MBEDTLS_CIPHER_MODE_CBC)
2367 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
2368#endif
2369#if defined(MBEDTLS_CIPHER_MODE_CFB)
2370 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
2371#endif
2372#if defined(MBEDTLS_CIPHER_MODE_CTR)
2373 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
2374#endif
2375#endif /* MBEDTLS_BLOWFISH_C */
2376
2377#if defined(MBEDTLS_CAMELLIA_C)
2378 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
2379 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
2380 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
2381#if defined(MBEDTLS_CIPHER_MODE_CBC)
2382 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
2383 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
2384 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
2385#endif
2386#if defined(MBEDTLS_CIPHER_MODE_CFB)
2387 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
2388 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
2389 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
2390#endif
2391#if defined(MBEDTLS_CIPHER_MODE_CTR)
2392 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
2393 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
2394 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
2395#endif
2396#if defined(MBEDTLS_GCM_C)
2397 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
2398 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
2399 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
2400#endif
2401#if defined(MBEDTLS_CCM_C)
2402 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
2403 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
2404 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
2405#endif
2406#endif /* MBEDTLS_CAMELLIA_C */
2407
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002408#if defined(MBEDTLS_ARIA_C)
2409 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
2410 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
2411 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
2412#if defined(MBEDTLS_CIPHER_MODE_CBC)
2413 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
2414 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
2415 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
2416#endif
2417#if defined(MBEDTLS_CIPHER_MODE_CFB)
2418 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
2419 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
2420 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
2421#endif
2422#if defined(MBEDTLS_CIPHER_MODE_CTR)
2423 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
2424 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
2425 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
2426#endif
2427#if defined(MBEDTLS_GCM_C)
2428 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
2429 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
2430 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
2431#endif
2432#if defined(MBEDTLS_CCM_C)
2433 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
2434 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
2435 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
2436#endif
2437#endif /* MBEDTLS_ARIA_C */
2438
Jens Wiklander817466c2018-05-22 13:49:31 +02002439#if defined(MBEDTLS_DES_C)
2440 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
2441 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
2442 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
2443#if defined(MBEDTLS_CIPHER_MODE_CBC)
2444 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
2445 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
2446 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
2447#endif
2448#endif /* MBEDTLS_DES_C */
2449
Jens Wiklander3d3b0592019-03-20 15:30:29 +01002450#if defined(MBEDTLS_CHACHA20_C)
2451 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
2452#endif
2453
2454#if defined(MBEDTLS_CHACHAPOLY_C)
2455 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
2456#endif
2457
Jerome Forissier11fa71b2020-04-20 17:17:56 +02002458#if defined(MBEDTLS_NIST_KW_C)
2459 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
2460 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
2461 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
2462 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
2463 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
2464 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
2465#endif
2466
Jens Wiklander817466c2018-05-22 13:49:31 +02002467#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
2468 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
2469#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
2470
2471 { MBEDTLS_CIPHER_NONE, NULL }
2472};
2473
Jerome Forissier11fa71b2020-04-20 17:17:56 +02002474#define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
2475 sizeof(mbedtls_cipher_definitions[0]) )
Jens Wiklander817466c2018-05-22 13:49:31 +02002476int mbedtls_cipher_supported[NUM_CIPHERS];
2477
2478#endif /* MBEDTLS_CIPHER_C */