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