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