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