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