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