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 | { |
Manuel Pégourié-Gonnard | 08c337d | 2018-05-22 13:18:01 +0200 | [diff] [blame^] | 834 | (void) operation; |
| 835 | return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input, |
Markku-Juhani O. Saarinen | c06e101 | 2017-12-07 11:51:13 +0000 | [diff] [blame] | 836 | output ); |
| 837 | } |
| 838 | |
| 839 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 840 | static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, |
| 841 | size_t length, unsigned char *iv, |
| 842 | const unsigned char *input, unsigned char *output ) |
| 843 | { |
Manuel Pégourié-Gonnard | 08c337d | 2018-05-22 13:18:01 +0200 | [diff] [blame^] | 844 | (void) operation; |
| 845 | return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, length, iv, |
Markku-Juhani O. Saarinen | c06e101 | 2017-12-07 11:51:13 +0000 | [diff] [blame] | 846 | input, output ); |
| 847 | } |
| 848 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 849 | |
| 850 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 851 | static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation, |
| 852 | size_t length, size_t *iv_off, unsigned char *iv, |
| 853 | const unsigned char *input, unsigned char *output ) |
| 854 | { |
| 855 | return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length, |
| 856 | iv_off, iv, input, output ); |
| 857 | } |
| 858 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 859 | |
| 860 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 861 | static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 862 | unsigned char *nonce_counter, unsigned char *stream_block, |
| 863 | const unsigned char *input, unsigned char *output ) |
| 864 | { |
| 865 | return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off, |
| 866 | nonce_counter, stream_block, input, output ); |
| 867 | } |
| 868 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 869 | |
| 870 | static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 871 | unsigned int key_bitlen ) |
| 872 | { |
| 873 | return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen ); |
| 874 | } |
| 875 | |
| 876 | static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 877 | unsigned int key_bitlen ) |
| 878 | { |
| 879 | return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen ); |
| 880 | } |
| 881 | |
| 882 | static void * aria_ctx_alloc( void ) |
| 883 | { |
| 884 | mbedtls_aria_context *ctx; |
| 885 | ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) ); |
| 886 | |
| 887 | if( ctx == NULL ) |
| 888 | return( NULL ); |
| 889 | |
| 890 | mbedtls_aria_init( ctx ); |
| 891 | |
| 892 | return( ctx ); |
| 893 | } |
| 894 | |
| 895 | static void aria_ctx_free( void *ctx ) |
| 896 | { |
| 897 | mbedtls_aria_free( (mbedtls_aria_context *) ctx ); |
| 898 | mbedtls_free( ctx ); |
| 899 | } |
| 900 | |
| 901 | static const mbedtls_cipher_base_t aria_info = { |
| 902 | MBEDTLS_CIPHER_ID_ARIA, |
| 903 | aria_crypt_ecb_wrap, |
| 904 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 905 | aria_crypt_cbc_wrap, |
| 906 | #endif |
| 907 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 908 | aria_crypt_cfb128_wrap, |
| 909 | #endif |
| 910 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 911 | aria_crypt_ctr_wrap, |
| 912 | #endif |
| 913 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
| 914 | NULL, |
| 915 | #endif |
| 916 | aria_setkey_enc_wrap, |
| 917 | aria_setkey_dec_wrap, |
| 918 | aria_ctx_alloc, |
| 919 | aria_ctx_free |
| 920 | }; |
| 921 | |
| 922 | static const mbedtls_cipher_info_t aria_128_ecb_info = { |
| 923 | MBEDTLS_CIPHER_ARIA_128_ECB, |
| 924 | MBEDTLS_MODE_ECB, |
| 925 | 128, |
| 926 | "ARIA-128-ECB", |
| 927 | 16, |
| 928 | 0, |
| 929 | 16, |
| 930 | &aria_info |
| 931 | }; |
| 932 | |
| 933 | static const mbedtls_cipher_info_t aria_192_ecb_info = { |
| 934 | MBEDTLS_CIPHER_ARIA_192_ECB, |
| 935 | MBEDTLS_MODE_ECB, |
| 936 | 192, |
| 937 | "ARIA-192-ECB", |
| 938 | 16, |
| 939 | 0, |
| 940 | 16, |
| 941 | &aria_info |
| 942 | }; |
| 943 | |
| 944 | static const mbedtls_cipher_info_t aria_256_ecb_info = { |
| 945 | MBEDTLS_CIPHER_ARIA_256_ECB, |
| 946 | MBEDTLS_MODE_ECB, |
| 947 | 256, |
| 948 | "ARIA-256-ECB", |
| 949 | 16, |
| 950 | 0, |
| 951 | 16, |
| 952 | &aria_info |
| 953 | }; |
| 954 | |
| 955 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 956 | static const mbedtls_cipher_info_t aria_128_cbc_info = { |
| 957 | MBEDTLS_CIPHER_ARIA_128_CBC, |
| 958 | MBEDTLS_MODE_CBC, |
| 959 | 128, |
| 960 | "ARIA-128-CBC", |
| 961 | 16, |
| 962 | 0, |
| 963 | 16, |
| 964 | &aria_info |
| 965 | }; |
| 966 | |
| 967 | static const mbedtls_cipher_info_t aria_192_cbc_info = { |
| 968 | MBEDTLS_CIPHER_ARIA_192_CBC, |
| 969 | MBEDTLS_MODE_CBC, |
| 970 | 192, |
| 971 | "ARIA-192-CBC", |
| 972 | 16, |
| 973 | 0, |
| 974 | 16, |
| 975 | &aria_info |
| 976 | }; |
| 977 | |
| 978 | static const mbedtls_cipher_info_t aria_256_cbc_info = { |
| 979 | MBEDTLS_CIPHER_ARIA_256_CBC, |
| 980 | MBEDTLS_MODE_CBC, |
| 981 | 256, |
| 982 | "ARIA-256-CBC", |
| 983 | 16, |
| 984 | 0, |
| 985 | 16, |
| 986 | &aria_info |
| 987 | }; |
| 988 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 989 | |
| 990 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 991 | static const mbedtls_cipher_info_t aria_128_cfb128_info = { |
| 992 | MBEDTLS_CIPHER_ARIA_128_CFB128, |
| 993 | MBEDTLS_MODE_CFB, |
| 994 | 128, |
| 995 | "ARIA-128-CFB128", |
| 996 | 16, |
| 997 | 0, |
| 998 | 16, |
| 999 | &aria_info |
| 1000 | }; |
| 1001 | |
| 1002 | static const mbedtls_cipher_info_t aria_192_cfb128_info = { |
| 1003 | MBEDTLS_CIPHER_ARIA_192_CFB128, |
| 1004 | MBEDTLS_MODE_CFB, |
| 1005 | 192, |
| 1006 | "ARIA-192-CFB128", |
| 1007 | 16, |
| 1008 | 0, |
| 1009 | 16, |
| 1010 | &aria_info |
| 1011 | }; |
| 1012 | |
| 1013 | static const mbedtls_cipher_info_t aria_256_cfb128_info = { |
| 1014 | MBEDTLS_CIPHER_ARIA_256_CFB128, |
| 1015 | MBEDTLS_MODE_CFB, |
| 1016 | 256, |
| 1017 | "ARIA-256-CFB128", |
| 1018 | 16, |
| 1019 | 0, |
| 1020 | 16, |
| 1021 | &aria_info |
| 1022 | }; |
| 1023 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 1024 | |
| 1025 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1026 | static const mbedtls_cipher_info_t aria_128_ctr_info = { |
| 1027 | MBEDTLS_CIPHER_ARIA_128_CTR, |
| 1028 | MBEDTLS_MODE_CTR, |
| 1029 | 128, |
| 1030 | "ARIA-128-CTR", |
| 1031 | 16, |
| 1032 | 0, |
| 1033 | 16, |
| 1034 | &aria_info |
| 1035 | }; |
| 1036 | |
| 1037 | static const mbedtls_cipher_info_t aria_192_ctr_info = { |
| 1038 | MBEDTLS_CIPHER_ARIA_192_CTR, |
| 1039 | MBEDTLS_MODE_CTR, |
| 1040 | 192, |
| 1041 | "ARIA-192-CTR", |
| 1042 | 16, |
| 1043 | 0, |
| 1044 | 16, |
| 1045 | &aria_info |
| 1046 | }; |
| 1047 | |
| 1048 | static const mbedtls_cipher_info_t aria_256_ctr_info = { |
| 1049 | MBEDTLS_CIPHER_ARIA_256_CTR, |
| 1050 | MBEDTLS_MODE_CTR, |
| 1051 | 256, |
| 1052 | "ARIA-256-CTR", |
| 1053 | 16, |
| 1054 | 0, |
| 1055 | 16, |
| 1056 | &aria_info |
| 1057 | }; |
| 1058 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 1059 | |
| 1060 | #if defined(MBEDTLS_GCM_C) |
| 1061 | static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key, |
| 1062 | unsigned int key_bitlen ) |
| 1063 | { |
| 1064 | return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA, |
| 1065 | key, key_bitlen ); |
| 1066 | } |
| 1067 | |
| 1068 | static const mbedtls_cipher_base_t gcm_aria_info = { |
| 1069 | MBEDTLS_CIPHER_ID_ARIA, |
| 1070 | NULL, |
| 1071 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1072 | NULL, |
| 1073 | #endif |
| 1074 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1075 | NULL, |
| 1076 | #endif |
| 1077 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1078 | NULL, |
| 1079 | #endif |
| 1080 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
| 1081 | NULL, |
| 1082 | #endif |
| 1083 | gcm_aria_setkey_wrap, |
| 1084 | gcm_aria_setkey_wrap, |
| 1085 | gcm_ctx_alloc, |
| 1086 | gcm_ctx_free, |
| 1087 | }; |
| 1088 | |
| 1089 | static const mbedtls_cipher_info_t aria_128_gcm_info = { |
| 1090 | MBEDTLS_CIPHER_ARIA_128_GCM, |
| 1091 | MBEDTLS_MODE_GCM, |
| 1092 | 128, |
| 1093 | "ARIA-128-GCM", |
| 1094 | 12, |
| 1095 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
| 1096 | 16, |
| 1097 | &gcm_aria_info |
| 1098 | }; |
| 1099 | |
| 1100 | static const mbedtls_cipher_info_t aria_192_gcm_info = { |
| 1101 | MBEDTLS_CIPHER_ARIA_192_GCM, |
| 1102 | MBEDTLS_MODE_GCM, |
| 1103 | 192, |
| 1104 | "ARIA-192-GCM", |
| 1105 | 12, |
| 1106 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
| 1107 | 16, |
| 1108 | &gcm_aria_info |
| 1109 | }; |
| 1110 | |
| 1111 | static const mbedtls_cipher_info_t aria_256_gcm_info = { |
| 1112 | MBEDTLS_CIPHER_ARIA_256_GCM, |
| 1113 | MBEDTLS_MODE_GCM, |
| 1114 | 256, |
| 1115 | "ARIA-256-GCM", |
| 1116 | 12, |
| 1117 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
| 1118 | 16, |
| 1119 | &gcm_aria_info |
| 1120 | }; |
| 1121 | #endif /* MBEDTLS_GCM_C */ |
| 1122 | |
| 1123 | #if defined(MBEDTLS_CCM_C) |
| 1124 | static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key, |
| 1125 | unsigned int key_bitlen ) |
| 1126 | { |
| 1127 | return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA, |
| 1128 | key, key_bitlen ); |
| 1129 | } |
| 1130 | |
| 1131 | static const mbedtls_cipher_base_t ccm_aria_info = { |
| 1132 | MBEDTLS_CIPHER_ID_ARIA, |
| 1133 | NULL, |
| 1134 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1135 | NULL, |
| 1136 | #endif |
| 1137 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1138 | NULL, |
| 1139 | #endif |
| 1140 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1141 | NULL, |
| 1142 | #endif |
| 1143 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
| 1144 | NULL, |
| 1145 | #endif |
| 1146 | ccm_aria_setkey_wrap, |
| 1147 | ccm_aria_setkey_wrap, |
| 1148 | ccm_ctx_alloc, |
| 1149 | ccm_ctx_free, |
| 1150 | }; |
| 1151 | |
| 1152 | static const mbedtls_cipher_info_t aria_128_ccm_info = { |
| 1153 | MBEDTLS_CIPHER_ARIA_128_CCM, |
| 1154 | MBEDTLS_MODE_CCM, |
| 1155 | 128, |
| 1156 | "ARIA-128-CCM", |
| 1157 | 12, |
| 1158 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
| 1159 | 16, |
| 1160 | &ccm_aria_info |
| 1161 | }; |
| 1162 | |
| 1163 | static const mbedtls_cipher_info_t aria_192_ccm_info = { |
| 1164 | MBEDTLS_CIPHER_ARIA_192_CCM, |
| 1165 | MBEDTLS_MODE_CCM, |
| 1166 | 192, |
| 1167 | "ARIA-192-CCM", |
| 1168 | 12, |
| 1169 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
| 1170 | 16, |
| 1171 | &ccm_aria_info |
| 1172 | }; |
| 1173 | |
| 1174 | static const mbedtls_cipher_info_t aria_256_ccm_info = { |
| 1175 | MBEDTLS_CIPHER_ARIA_256_CCM, |
| 1176 | MBEDTLS_MODE_CCM, |
| 1177 | 256, |
| 1178 | "ARIA-256-CCM", |
| 1179 | 12, |
| 1180 | MBEDTLS_CIPHER_VARIABLE_IV_LEN, |
| 1181 | 16, |
| 1182 | &ccm_aria_info |
| 1183 | }; |
| 1184 | #endif /* MBEDTLS_CCM_C */ |
| 1185 | |
| 1186 | #endif /* MBEDTLS_ARIA_C */ |
| 1187 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1188 | #if defined(MBEDTLS_DES_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1189 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1190 | static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1191 | const unsigned char *input, unsigned char *output ) |
| 1192 | { |
| 1193 | ((void) operation); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1194 | return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1197 | static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1198 | const unsigned char *input, unsigned char *output ) |
| 1199 | { |
| 1200 | ((void) operation); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1201 | return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1202 | } |
| 1203 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1204 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1205 | 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] | 1206 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 1207 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1208 | 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] | 1209 | output ); |
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 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1212 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1213 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1214 | 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] | 1215 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 1216 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1217 | 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] | 1218 | output ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1219 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1220 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1221 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1222 | 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] | 1223 | unsigned int key_bitlen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1224 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1225 | ((void) key_bitlen); |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 1226 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1227 | return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1230 | 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] | 1231 | unsigned int key_bitlen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1232 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1233 | ((void) key_bitlen); |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 1234 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1235 | return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1238 | 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] | 1239 | unsigned int key_bitlen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1240 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1241 | ((void) key_bitlen); |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 1242 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1243 | return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1246 | 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] | 1247 | unsigned int key_bitlen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1248 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1249 | ((void) key_bitlen); |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 1250 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1251 | return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1254 | 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] | 1255 | unsigned int key_bitlen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1256 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1257 | ((void) key_bitlen); |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 1258 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1259 | return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1260 | } |
| 1261 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1262 | 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] | 1263 | unsigned int key_bitlen ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1264 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1265 | ((void) key_bitlen); |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 1266 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1267 | return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | static void * des_ctx_alloc( void ) |
| 1271 | { |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 1272 | mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1273 | |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1274 | if( des == NULL ) |
| 1275 | return( NULL ); |
| 1276 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1277 | mbedtls_des_init( des ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1278 | |
| 1279 | return( des ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static void des_ctx_free( void *ctx ) |
| 1283 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1284 | mbedtls_des_free( (mbedtls_des_context *) ctx ); |
| 1285 | mbedtls_free( ctx ); |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 1286 | } |
| 1287 | |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1288 | static void * des3_ctx_alloc( void ) |
| 1289 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1290 | mbedtls_des3_context *des3; |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 1291 | des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1292 | |
| 1293 | if( des3 == NULL ) |
| 1294 | return( NULL ); |
| 1295 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1296 | mbedtls_des3_init( des3 ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1297 | |
| 1298 | return( des3 ); |
| 1299 | } |
| 1300 | |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 1301 | static void des3_ctx_free( void *ctx ) |
| 1302 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1303 | mbedtls_des3_free( (mbedtls_des3_context *) ctx ); |
| 1304 | mbedtls_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1307 | static const mbedtls_cipher_base_t des_info = { |
| 1308 | MBEDTLS_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1309 | des_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1310 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1311 | des_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1312 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1313 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1314 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1315 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1316 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1317 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1318 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1319 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1320 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1321 | #endif |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1322 | des_setkey_enc_wrap, |
| 1323 | des_setkey_dec_wrap, |
| 1324 | des_ctx_alloc, |
| 1325 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1326 | }; |
| 1327 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1328 | static const mbedtls_cipher_info_t des_ecb_info = { |
| 1329 | MBEDTLS_CIPHER_DES_ECB, |
| 1330 | MBEDTLS_MODE_ECB, |
| 1331 | MBEDTLS_KEY_LENGTH_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1332 | "DES-ECB", |
| 1333 | 8, |
| 1334 | 0, |
| 1335 | 8, |
| 1336 | &des_info |
| 1337 | }; |
| 1338 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1339 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1340 | static const mbedtls_cipher_info_t des_cbc_info = { |
| 1341 | MBEDTLS_CIPHER_DES_CBC, |
| 1342 | MBEDTLS_MODE_CBC, |
| 1343 | MBEDTLS_KEY_LENGTH_DES, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1344 | "DES-CBC", |
| 1345 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1346 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1347 | 8, |
| 1348 | &des_info |
| 1349 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1350 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1351 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1352 | static const mbedtls_cipher_base_t des_ede_info = { |
| 1353 | MBEDTLS_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1354 | des3_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1355 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1356 | des3_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1357 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1358 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1359 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1360 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1361 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1362 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1363 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1364 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1365 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1366 | #endif |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1367 | des3_set2key_enc_wrap, |
| 1368 | des3_set2key_dec_wrap, |
| 1369 | des3_ctx_alloc, |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 1370 | des3_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1371 | }; |
| 1372 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1373 | static const mbedtls_cipher_info_t des_ede_ecb_info = { |
| 1374 | MBEDTLS_CIPHER_DES_EDE_ECB, |
| 1375 | MBEDTLS_MODE_ECB, |
| 1376 | MBEDTLS_KEY_LENGTH_DES_EDE, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1377 | "DES-EDE-ECB", |
| 1378 | 8, |
| 1379 | 0, |
| 1380 | 8, |
| 1381 | &des_ede_info |
| 1382 | }; |
| 1383 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1384 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1385 | static const mbedtls_cipher_info_t des_ede_cbc_info = { |
| 1386 | MBEDTLS_CIPHER_DES_EDE_CBC, |
| 1387 | MBEDTLS_MODE_CBC, |
| 1388 | MBEDTLS_KEY_LENGTH_DES_EDE, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1389 | "DES-EDE-CBC", |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 1390 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1391 | 0, |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 1392 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1393 | &des_ede_info |
| 1394 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1395 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1396 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1397 | static const mbedtls_cipher_base_t des_ede3_info = { |
Manuel Pégourié-Gonnard | 9d51583 | 2015-06-02 10:00:04 +0100 | [diff] [blame] | 1398 | MBEDTLS_CIPHER_ID_3DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1399 | des3_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1400 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1401 | des3_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1402 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1403 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1404 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1405 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1406 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1407 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1408 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1409 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1410 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1411 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1412 | des3_set3key_enc_wrap, |
| 1413 | des3_set3key_dec_wrap, |
| 1414 | des3_ctx_alloc, |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 1415 | des3_ctx_free |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1416 | }; |
| 1417 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1418 | static const mbedtls_cipher_info_t des_ede3_ecb_info = { |
| 1419 | MBEDTLS_CIPHER_DES_EDE3_ECB, |
| 1420 | MBEDTLS_MODE_ECB, |
| 1421 | MBEDTLS_KEY_LENGTH_DES_EDE3, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1422 | "DES-EDE3-ECB", |
| 1423 | 8, |
| 1424 | 0, |
| 1425 | 8, |
| 1426 | &des_ede3_info |
| 1427 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1428 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1429 | static const mbedtls_cipher_info_t des_ede3_cbc_info = { |
| 1430 | MBEDTLS_CIPHER_DES_EDE3_CBC, |
| 1431 | MBEDTLS_MODE_CBC, |
| 1432 | MBEDTLS_KEY_LENGTH_DES_EDE3, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1433 | "DES-EDE3-CBC", |
| 1434 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1435 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1436 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1437 | &des_ede3_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1438 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1439 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 1440 | #endif /* MBEDTLS_DES_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1441 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1442 | #if defined(MBEDTLS_BLOWFISH_C) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1443 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1444 | static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1445 | const unsigned char *input, unsigned char *output ) |
| 1446 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1447 | return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1448 | output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1449 | } |
| 1450 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1451 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1452 | static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1453 | size_t length, unsigned char *iv, const unsigned char *input, |
| 1454 | unsigned char *output ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1455 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1456 | return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1457 | input, output ); |
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 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1460 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1461 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1462 | static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1463 | size_t length, size_t *iv_off, unsigned char *iv, |
| 1464 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1465 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1466 | return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1467 | iv_off, iv, input, output ); |
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 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1470 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1471 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1472 | static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 1473 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1474 | const unsigned char *input, unsigned char *output ) |
| 1475 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1476 | return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off, |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1477 | nonce_counter, stream_block, input, output ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1478 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1479 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1480 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1481 | 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] | 1482 | unsigned int key_bitlen ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1483 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1484 | return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | static void * blowfish_ctx_alloc( void ) |
| 1488 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1489 | mbedtls_blowfish_context *ctx; |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 1490 | ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1491 | |
| 1492 | if( ctx == NULL ) |
| 1493 | return( NULL ); |
| 1494 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1495 | mbedtls_blowfish_init( ctx ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1496 | |
| 1497 | return( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static void blowfish_ctx_free( void *ctx ) |
| 1501 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1502 | mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx ); |
| 1503 | mbedtls_free( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1506 | static const mbedtls_cipher_base_t blowfish_info = { |
| 1507 | MBEDTLS_CIPHER_ID_BLOWFISH, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1508 | blowfish_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1509 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1510 | blowfish_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1511 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1512 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1513 | blowfish_crypt_cfb64_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1514 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1515 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1516 | blowfish_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1517 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1518 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1519 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1520 | #endif |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1521 | blowfish_setkey_wrap, |
| 1522 | blowfish_setkey_wrap, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1523 | blowfish_ctx_alloc, |
| 1524 | blowfish_ctx_free |
| 1525 | }; |
| 1526 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1527 | static const mbedtls_cipher_info_t blowfish_ecb_info = { |
| 1528 | MBEDTLS_CIPHER_BLOWFISH_ECB, |
| 1529 | MBEDTLS_MODE_ECB, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1530 | 128, |
| 1531 | "BLOWFISH-ECB", |
| 1532 | 8, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1533 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1534 | 8, |
| 1535 | &blowfish_info |
| 1536 | }; |
| 1537 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1538 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1539 | static const mbedtls_cipher_info_t blowfish_cbc_info = { |
| 1540 | MBEDTLS_CIPHER_BLOWFISH_CBC, |
| 1541 | MBEDTLS_MODE_CBC, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1542 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1543 | "BLOWFISH-CBC", |
| 1544 | 8, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1545 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1546 | 8, |
| 1547 | &blowfish_info |
| 1548 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1549 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1550 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1551 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1552 | static const mbedtls_cipher_info_t blowfish_cfb64_info = { |
| 1553 | MBEDTLS_CIPHER_BLOWFISH_CFB64, |
| 1554 | MBEDTLS_MODE_CFB, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1555 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1556 | "BLOWFISH-CFB64", |
| 1557 | 8, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1558 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1559 | 8, |
| 1560 | &blowfish_info |
| 1561 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1562 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1563 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1564 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1565 | static const mbedtls_cipher_info_t blowfish_ctr_info = { |
| 1566 | MBEDTLS_CIPHER_BLOWFISH_CTR, |
| 1567 | MBEDTLS_MODE_CTR, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1568 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1569 | "BLOWFISH-CTR", |
| 1570 | 8, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1571 | MBEDTLS_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1572 | 8, |
| 1573 | &blowfish_info |
| 1574 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1575 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 1576 | #endif /* MBEDTLS_BLOWFISH_C */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1577 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1578 | #if defined(MBEDTLS_ARC4_C) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1579 | static int arc4_crypt_stream_wrap( void *ctx, size_t length, |
| 1580 | const unsigned char *input, |
| 1581 | unsigned char *output ) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1582 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1583 | return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1586 | 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] | 1587 | unsigned int key_bitlen ) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1588 | { |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1589 | /* we get key_bitlen in bits, arc4 expects it in bytes */ |
| 1590 | if( key_bitlen % 8 != 0 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1591 | return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); |
Manuel Pégourié-Gonnard | ce41125 | 2013-09-04 12:28:37 +0200 | [diff] [blame] | 1592 | |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1593 | 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] | 1594 | return( 0 ); |
| 1595 | } |
| 1596 | |
| 1597 | static void * arc4_ctx_alloc( void ) |
| 1598 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1599 | mbedtls_arc4_context *ctx; |
Manuel Pégourié-Gonnard | 7551cb9 | 2015-05-26 16:04:06 +0200 | [diff] [blame] | 1600 | ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1601 | |
| 1602 | if( ctx == NULL ) |
| 1603 | return( NULL ); |
| 1604 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1605 | mbedtls_arc4_init( ctx ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1606 | |
| 1607 | return( ctx ); |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1608 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1609 | |
| 1610 | static void arc4_ctx_free( void *ctx ) |
| 1611 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1612 | mbedtls_arc4_free( (mbedtls_arc4_context *) ctx ); |
| 1613 | mbedtls_free( ctx ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1616 | static const mbedtls_cipher_base_t arc4_base_info = { |
| 1617 | MBEDTLS_CIPHER_ID_ARC4, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1618 | NULL, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1619 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1620 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1621 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1622 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1623 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1624 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1625 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1626 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1627 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1628 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1629 | arc4_crypt_stream_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1630 | #endif |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1631 | arc4_setkey_wrap, |
| 1632 | arc4_setkey_wrap, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1633 | arc4_ctx_alloc, |
| 1634 | arc4_ctx_free |
| 1635 | }; |
| 1636 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1637 | static const mbedtls_cipher_info_t arc4_128_info = { |
| 1638 | MBEDTLS_CIPHER_ARC4_128, |
| 1639 | MBEDTLS_MODE_STREAM, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1640 | 128, |
| 1641 | "ARC4-128", |
| 1642 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1643 | 0, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1644 | 1, |
| 1645 | &arc4_base_info |
| 1646 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1647 | #endif /* MBEDTLS_ARC4_C */ |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1648 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1649 | #if defined(MBEDTLS_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1650 | static int null_crypt_stream( void *ctx, size_t length, |
| 1651 | const unsigned char *input, |
| 1652 | unsigned char *output ) |
| 1653 | { |
| 1654 | ((void) ctx); |
| 1655 | memmove( output, input, length ); |
| 1656 | return( 0 ); |
| 1657 | } |
| 1658 | |
| 1659 | static int null_setkey( void *ctx, const unsigned char *key, |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1660 | unsigned int key_bitlen ) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1661 | { |
| 1662 | ((void) ctx); |
| 1663 | ((void) key); |
Manuel Pégourié-Gonnard | 898e0aa | 2015-06-18 15:28:12 +0200 | [diff] [blame] | 1664 | ((void) key_bitlen); |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1665 | |
| 1666 | return( 0 ); |
| 1667 | } |
| 1668 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1669 | static void * null_ctx_alloc( void ) |
| 1670 | { |
Manuel Pégourié-Gonnard | 86bbc7f | 2014-07-12 02:14:41 +0200 | [diff] [blame] | 1671 | return( (void *) 1 ); |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1674 | static void null_ctx_free( void *ctx ) |
| 1675 | { |
| 1676 | ((void) ctx); |
| 1677 | } |
| 1678 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1679 | static const mbedtls_cipher_base_t null_base_info = { |
| 1680 | MBEDTLS_CIPHER_ID_NULL, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1681 | NULL, |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1682 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1683 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1684 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1685 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1686 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1687 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1688 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1689 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1690 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1691 | #if defined(MBEDTLS_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1692 | null_crypt_stream, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame] | 1693 | #endif |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1694 | null_setkey, |
| 1695 | null_setkey, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1696 | null_ctx_alloc, |
| 1697 | null_ctx_free |
| 1698 | }; |
| 1699 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1700 | static const mbedtls_cipher_info_t null_cipher_info = { |
| 1701 | MBEDTLS_CIPHER_NULL, |
| 1702 | MBEDTLS_MODE_STREAM, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1703 | 0, |
| 1704 | "NULL", |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1705 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1706 | 0, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1707 | 1, |
| 1708 | &null_base_info |
| 1709 | }; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1710 | #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */ |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1711 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1712 | const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] = |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1713 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1714 | #if defined(MBEDTLS_AES_C) |
| 1715 | { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info }, |
| 1716 | { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info }, |
| 1717 | { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info }, |
| 1718 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1719 | { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info }, |
| 1720 | { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info }, |
| 1721 | { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1722 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1723 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1724 | { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info }, |
| 1725 | { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info }, |
| 1726 | { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1727 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1728 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1729 | { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info }, |
| 1730 | { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info }, |
| 1731 | { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1732 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1733 | #if defined(MBEDTLS_GCM_C) |
| 1734 | { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info }, |
| 1735 | { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info }, |
| 1736 | { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1737 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1738 | #if defined(MBEDTLS_CCM_C) |
| 1739 | { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info }, |
| 1740 | { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info }, |
| 1741 | { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info }, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 1742 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1743 | #endif /* MBEDTLS_AES_C */ |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1744 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1745 | #if defined(MBEDTLS_ARC4_C) |
| 1746 | { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1747 | #endif |
| 1748 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1749 | #if defined(MBEDTLS_BLOWFISH_C) |
| 1750 | { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info }, |
| 1751 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1752 | { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1753 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1754 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1755 | { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1756 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1757 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1758 | { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1759 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1760 | #endif /* MBEDTLS_BLOWFISH_C */ |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1761 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1762 | #if defined(MBEDTLS_CAMELLIA_C) |
| 1763 | { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info }, |
| 1764 | { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info }, |
| 1765 | { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info }, |
| 1766 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1767 | { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info }, |
| 1768 | { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info }, |
| 1769 | { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1770 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1771 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1772 | { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info }, |
| 1773 | { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info }, |
| 1774 | { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1775 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1776 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1777 | { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info }, |
| 1778 | { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info }, |
| 1779 | { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1780 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1781 | #if defined(MBEDTLS_GCM_C) |
| 1782 | { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info }, |
| 1783 | { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info }, |
| 1784 | { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info }, |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 1785 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1786 | #if defined(MBEDTLS_CCM_C) |
| 1787 | { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info }, |
| 1788 | { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info }, |
| 1789 | { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info }, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 1790 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1791 | #endif /* MBEDTLS_CAMELLIA_C */ |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1792 | |
Markku-Juhani O. Saarinen | c06e101 | 2017-12-07 11:51:13 +0000 | [diff] [blame] | 1793 | #if defined(MBEDTLS_ARIA_C) |
| 1794 | { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info }, |
| 1795 | { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info }, |
| 1796 | { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info }, |
| 1797 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1798 | { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info }, |
| 1799 | { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info }, |
| 1800 | { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info }, |
| 1801 | #endif |
| 1802 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 1803 | { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info }, |
| 1804 | { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info }, |
| 1805 | { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info }, |
| 1806 | #endif |
| 1807 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 1808 | { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info }, |
| 1809 | { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info }, |
| 1810 | { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info }, |
| 1811 | #endif |
| 1812 | #if defined(MBEDTLS_GCM_C) |
| 1813 | { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info }, |
| 1814 | { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info }, |
| 1815 | { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info }, |
| 1816 | #endif |
| 1817 | #if defined(MBEDTLS_CCM_C) |
| 1818 | { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info }, |
| 1819 | { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info }, |
| 1820 | { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info }, |
| 1821 | #endif |
| 1822 | #endif /* MBEDTLS_ARIA_C */ |
| 1823 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1824 | #if defined(MBEDTLS_DES_C) |
| 1825 | { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info }, |
| 1826 | { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info }, |
| 1827 | { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info }, |
| 1828 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 1829 | { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info }, |
| 1830 | { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info }, |
| 1831 | { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1832 | #endif |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1833 | #endif /* MBEDTLS_DES_C */ |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1834 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1835 | #if defined(MBEDTLS_CIPHER_NULL_CIPHER) |
| 1836 | { MBEDTLS_CIPHER_NULL, &null_cipher_info }, |
| 1837 | #endif /* MBEDTLS_CIPHER_NULL_CIPHER */ |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1838 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1839 | { MBEDTLS_CIPHER_NONE, NULL } |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1840 | }; |
| 1841 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1842 | #define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0] |
| 1843 | int mbedtls_cipher_supported[NUM_CIPHERS]; |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1844 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 1845 | #endif /* MBEDTLS_CIPHER_C */ |