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