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