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