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