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