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