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 | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 8 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 9 | * |
Manuel Pégourié-Gonnard | 860b516 | 2015-01-28 17:12:07 +0000 | [diff] [blame] | 10 | * This file is part of mbed TLS (https://polarssl.org) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 11 | * |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License along |
| 23 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 25 | */ |
| 26 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 28 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
| 30 | #include POLARSSL_CONFIG_FILE |
| 31 | #endif |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 32 | |
| 33 | #if defined(POLARSSL_CIPHER_C) |
| 34 | |
| 35 | #include "polarssl/cipher_wrap.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 36 | |
| 37 | #if defined(POLARSSL_AES_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 38 | #include "polarssl/aes.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 41 | #if defined(POLARSSL_ARC4_C) |
| 42 | #include "polarssl/arc4.h" |
| 43 | #endif |
| 44 | |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 45 | #if defined(POLARSSL_CAMELLIA_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 46 | #include "polarssl/camellia.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 47 | #endif |
| 48 | |
| 49 | #if defined(POLARSSL_DES_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 50 | #include "polarssl/des.h" |
Paul Bakker | 02f6169 | 2012-03-15 10:54:25 +0000 | [diff] [blame] | 51 | #endif |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 52 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 53 | #if defined(POLARSSL_BLOWFISH_C) |
| 54 | #include "polarssl/blowfish.h" |
| 55 | #endif |
| 56 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 57 | #if defined(POLARSSL_GCM_C) |
| 58 | #include "polarssl/gcm.h" |
| 59 | #endif |
| 60 | |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 61 | #if defined(POLARSSL_CCM_C) |
| 62 | #include "polarssl/ccm.h" |
| 63 | #endif |
| 64 | |
Manuel Pégourié-Gonnard | 0c851ee | 2015-02-10 12:47:52 +0000 | [diff] [blame] | 65 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
| 66 | #include <string.h> |
| 67 | #endif |
| 68 | |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 69 | #if defined(POLARSSL_PLATFORM_C) |
| 70 | #include "polarssl/platform.h" |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 71 | #else |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 72 | #include <stdlib.h> |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 73 | #define polarssl_malloc malloc |
| 74 | #define polarssl_free free |
| 75 | #endif |
| 76 | |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 77 | #if defined(POLARSSL_GCM_C) |
| 78 | /* shared by all GCM ciphers */ |
| 79 | static void *gcm_ctx_alloc( void ) |
| 80 | { |
| 81 | return polarssl_malloc( sizeof( gcm_context ) ); |
| 82 | } |
| 83 | |
| 84 | static void gcm_ctx_free( void *ctx ) |
| 85 | { |
| 86 | gcm_free( ctx ); |
| 87 | polarssl_free( ctx ); |
| 88 | } |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 89 | #endif /* POLARSSL_GCM_C */ |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 90 | |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 91 | #if defined(POLARSSL_CCM_C) |
| 92 | /* shared by all CCM ciphers */ |
| 93 | static void *ccm_ctx_alloc( void ) |
| 94 | { |
| 95 | return polarssl_malloc( sizeof( ccm_context ) ); |
| 96 | } |
| 97 | |
| 98 | static void ccm_ctx_free( void *ctx ) |
| 99 | { |
| 100 | ccm_free( ctx ); |
| 101 | polarssl_free( ctx ); |
| 102 | } |
| 103 | #endif /* POLARSSL_CCM_C */ |
| 104 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 105 | #if defined(POLARSSL_AES_C) |
| 106 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 107 | static int aes_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 108 | const unsigned char *input, unsigned char *output ) |
| 109 | { |
| 110 | return aes_crypt_ecb( (aes_context *) ctx, operation, input, output ); |
| 111 | } |
| 112 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 113 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 114 | static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 115 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 116 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 117 | return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, |
| 118 | output ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 119 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 120 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 121 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 122 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 123 | static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, |
| 124 | size_t length, size_t *iv_off, unsigned char *iv, |
| 125 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 126 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 127 | return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, |
| 128 | input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 129 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 130 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 131 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 132 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 133 | static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 134 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 135 | const unsigned char *input, unsigned char *output ) |
| 136 | { |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 137 | return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter, |
| 138 | stream_block, input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 139 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 140 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 141 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 142 | static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 143 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 144 | { |
| 145 | return aes_setkey_dec( (aes_context *) ctx, key, key_length ); |
| 146 | } |
| 147 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 148 | static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 149 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 150 | { |
| 151 | return aes_setkey_enc( (aes_context *) ctx, key, key_length ); |
| 152 | } |
| 153 | |
| 154 | static void * aes_ctx_alloc( void ) |
| 155 | { |
Mansour Moufid | c531b4a | 2015-02-15 17:35:38 -0500 | [diff] [blame] | 156 | aes_context *aes = polarssl_malloc( sizeof( aes_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 157 | |
| 158 | if( aes == NULL ) |
| 159 | return( NULL ); |
| 160 | |
| 161 | aes_init( aes ); |
| 162 | |
| 163 | return( aes ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void aes_ctx_free( void *ctx ) |
| 167 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 168 | aes_free( (aes_context *) ctx ); |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 169 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 172 | const cipher_base_t aes_info = { |
| 173 | POLARSSL_CIPHER_ID_AES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 174 | aes_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 175 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 176 | aes_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 177 | #endif |
| 178 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 179 | aes_crypt_cfb128_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 180 | #endif |
| 181 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 182 | aes_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 183 | #endif |
| 184 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 185 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 186 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 187 | aes_setkey_enc_wrap, |
| 188 | aes_setkey_dec_wrap, |
| 189 | aes_ctx_alloc, |
| 190 | aes_ctx_free |
| 191 | }; |
| 192 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 193 | const cipher_info_t aes_128_ecb_info = { |
| 194 | POLARSSL_CIPHER_AES_128_ECB, |
| 195 | POLARSSL_MODE_ECB, |
| 196 | 128, |
| 197 | "AES-128-ECB", |
| 198 | 16, |
| 199 | 0, |
| 200 | 16, |
| 201 | &aes_info |
| 202 | }; |
| 203 | |
| 204 | const cipher_info_t aes_192_ecb_info = { |
| 205 | POLARSSL_CIPHER_AES_192_ECB, |
| 206 | POLARSSL_MODE_ECB, |
| 207 | 192, |
| 208 | "AES-192-ECB", |
| 209 | 16, |
| 210 | 0, |
| 211 | 16, |
| 212 | &aes_info |
| 213 | }; |
| 214 | |
| 215 | const cipher_info_t aes_256_ecb_info = { |
| 216 | POLARSSL_CIPHER_AES_256_ECB, |
| 217 | POLARSSL_MODE_ECB, |
| 218 | 256, |
| 219 | "AES-256-ECB", |
| 220 | 16, |
| 221 | 0, |
| 222 | 16, |
| 223 | &aes_info |
| 224 | }; |
| 225 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 226 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 227 | const cipher_info_t aes_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 228 | POLARSSL_CIPHER_AES_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 229 | POLARSSL_MODE_CBC, |
| 230 | 128, |
| 231 | "AES-128-CBC", |
| 232 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 233 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 234 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 235 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | const cipher_info_t aes_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 239 | POLARSSL_CIPHER_AES_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 240 | POLARSSL_MODE_CBC, |
| 241 | 192, |
| 242 | "AES-192-CBC", |
| 243 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 244 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 245 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 246 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | const cipher_info_t aes_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 250 | POLARSSL_CIPHER_AES_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 251 | POLARSSL_MODE_CBC, |
| 252 | 256, |
| 253 | "AES-256-CBC", |
| 254 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 255 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 256 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 257 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 258 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 259 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 260 | |
| 261 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 262 | const cipher_info_t aes_128_cfb128_info = { |
| 263 | POLARSSL_CIPHER_AES_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 264 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 265 | 128, |
| 266 | "AES-128-CFB128", |
| 267 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 268 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 269 | 16, |
| 270 | &aes_info |
| 271 | }; |
| 272 | |
| 273 | const cipher_info_t aes_192_cfb128_info = { |
| 274 | POLARSSL_CIPHER_AES_192_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 275 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 276 | 192, |
| 277 | "AES-192-CFB128", |
| 278 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 279 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 280 | 16, |
| 281 | &aes_info |
| 282 | }; |
| 283 | |
| 284 | const cipher_info_t aes_256_cfb128_info = { |
| 285 | POLARSSL_CIPHER_AES_256_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 286 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 287 | 256, |
| 288 | "AES-256-CFB128", |
| 289 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 290 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 291 | 16, |
| 292 | &aes_info |
| 293 | }; |
| 294 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 295 | |
| 296 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 297 | const cipher_info_t aes_128_ctr_info = { |
| 298 | POLARSSL_CIPHER_AES_128_CTR, |
| 299 | POLARSSL_MODE_CTR, |
| 300 | 128, |
| 301 | "AES-128-CTR", |
| 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 | }; |
| 307 | |
| 308 | const cipher_info_t aes_192_ctr_info = { |
| 309 | POLARSSL_CIPHER_AES_192_CTR, |
| 310 | POLARSSL_MODE_CTR, |
| 311 | 192, |
| 312 | "AES-192-CTR", |
| 313 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 314 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 315 | 16, |
| 316 | &aes_info |
| 317 | }; |
| 318 | |
| 319 | const cipher_info_t aes_256_ctr_info = { |
| 320 | POLARSSL_CIPHER_AES_256_CTR, |
| 321 | POLARSSL_MODE_CTR, |
| 322 | 256, |
| 323 | "AES-256-CTR", |
| 324 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 325 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 326 | 16, |
| 327 | &aes_info |
| 328 | }; |
| 329 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 330 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 331 | #if defined(POLARSSL_GCM_C) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 332 | static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, |
| 333 | unsigned int key_length ) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 334 | { |
Paul Bakker | 43aff2a | 2013-09-09 00:10:27 +0200 | [diff] [blame] | 335 | return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES, |
| 336 | key, key_length ); |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | const cipher_base_t gcm_aes_info = { |
| 340 | POLARSSL_CIPHER_ID_AES, |
| 341 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 342 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 343 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 344 | #endif |
| 345 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 346 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 347 | #endif |
| 348 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 349 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 350 | #endif |
| 351 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 352 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 353 | #endif |
Paul Bakker | 43aff2a | 2013-09-09 00:10:27 +0200 | [diff] [blame] | 354 | gcm_aes_setkey_wrap, |
| 355 | gcm_aes_setkey_wrap, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 356 | gcm_ctx_alloc, |
| 357 | gcm_ctx_free, |
| 358 | }; |
| 359 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 360 | const cipher_info_t aes_128_gcm_info = { |
| 361 | POLARSSL_CIPHER_AES_128_GCM, |
| 362 | POLARSSL_MODE_GCM, |
| 363 | 128, |
| 364 | "AES-128-GCM", |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 365 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 366 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 367 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 368 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 369 | }; |
| 370 | |
Manuel Pégourié-Gonnard | 83f3fc0 | 2013-09-04 12:07:24 +0200 | [diff] [blame] | 371 | const cipher_info_t aes_192_gcm_info = { |
| 372 | POLARSSL_CIPHER_AES_192_GCM, |
| 373 | POLARSSL_MODE_GCM, |
| 374 | 192, |
| 375 | "AES-192-GCM", |
| 376 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 377 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 83f3fc0 | 2013-09-04 12:07:24 +0200 | [diff] [blame] | 378 | 16, |
| 379 | &gcm_aes_info |
| 380 | }; |
| 381 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 382 | const cipher_info_t aes_256_gcm_info = { |
| 383 | POLARSSL_CIPHER_AES_256_GCM, |
| 384 | POLARSSL_MODE_GCM, |
| 385 | 256, |
| 386 | "AES-256-GCM", |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 387 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 388 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 389 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 390 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 391 | }; |
| 392 | #endif /* POLARSSL_GCM_C */ |
| 393 | |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 394 | #if defined(POLARSSL_CCM_C) |
| 395 | static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key, |
| 396 | unsigned int key_length ) |
| 397 | { |
| 398 | return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_AES, |
| 399 | key, key_length ); |
| 400 | } |
| 401 | |
| 402 | const cipher_base_t ccm_aes_info = { |
| 403 | POLARSSL_CIPHER_ID_AES, |
| 404 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 405 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 406 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 407 | #endif |
| 408 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 409 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 410 | #endif |
| 411 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 412 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 413 | #endif |
| 414 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 415 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 416 | #endif |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 417 | ccm_aes_setkey_wrap, |
| 418 | ccm_aes_setkey_wrap, |
| 419 | ccm_ctx_alloc, |
| 420 | ccm_ctx_free, |
| 421 | }; |
| 422 | |
| 423 | const cipher_info_t aes_128_ccm_info = { |
| 424 | POLARSSL_CIPHER_AES_128_CCM, |
| 425 | POLARSSL_MODE_CCM, |
| 426 | 128, |
| 427 | "AES-128-CCM", |
| 428 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 429 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 430 | 16, |
| 431 | &ccm_aes_info |
| 432 | }; |
| 433 | |
| 434 | const cipher_info_t aes_192_ccm_info = { |
| 435 | POLARSSL_CIPHER_AES_192_CCM, |
| 436 | POLARSSL_MODE_CCM, |
| 437 | 192, |
| 438 | "AES-192-CCM", |
| 439 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 440 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 441 | 16, |
| 442 | &ccm_aes_info |
| 443 | }; |
| 444 | |
| 445 | const cipher_info_t aes_256_ccm_info = { |
| 446 | POLARSSL_CIPHER_AES_256_CCM, |
| 447 | POLARSSL_MODE_CCM, |
| 448 | 256, |
| 449 | "AES-256-CCM", |
| 450 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 451 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 452 | 16, |
| 453 | &ccm_aes_info |
| 454 | }; |
| 455 | #endif /* POLARSSL_CCM_C */ |
| 456 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 457 | #endif /* POLARSSL_AES_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 458 | |
| 459 | #if defined(POLARSSL_CAMELLIA_C) |
| 460 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 461 | static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 462 | const unsigned char *input, unsigned char *output ) |
| 463 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 464 | return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, |
| 465 | output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 468 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 469 | static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, |
| 470 | size_t length, unsigned char *iv, |
| 471 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 472 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 473 | return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, |
| 474 | input, output ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 475 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 476 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 477 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 478 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 479 | static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, |
| 480 | size_t length, size_t *iv_off, unsigned char *iv, |
| 481 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 482 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 483 | return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, |
| 484 | iv_off, iv, input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 485 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 486 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 487 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 488 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 489 | static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 490 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 491 | const unsigned char *input, unsigned char *output ) |
| 492 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 493 | return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, |
| 494 | nonce_counter, stream_block, input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 495 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 496 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 497 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 498 | static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 499 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 500 | { |
| 501 | return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); |
| 502 | } |
| 503 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 504 | static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 505 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 506 | { |
| 507 | return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); |
| 508 | } |
| 509 | |
| 510 | static void * camellia_ctx_alloc( void ) |
| 511 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 512 | camellia_context *ctx; |
Mansour Moufid | c531b4a | 2015-02-15 17:35:38 -0500 | [diff] [blame] | 513 | ctx = polarssl_malloc( sizeof( camellia_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 514 | |
| 515 | if( ctx == NULL ) |
| 516 | return( NULL ); |
| 517 | |
| 518 | camellia_init( ctx ); |
| 519 | |
| 520 | return( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | static void camellia_ctx_free( void *ctx ) |
| 524 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 525 | camellia_free( (camellia_context *) ctx ); |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 526 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 529 | const cipher_base_t camellia_info = { |
| 530 | POLARSSL_CIPHER_ID_CAMELLIA, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 531 | camellia_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 532 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 533 | camellia_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 534 | #endif |
| 535 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 536 | camellia_crypt_cfb128_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 537 | #endif |
| 538 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 539 | camellia_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 540 | #endif |
| 541 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 542 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 543 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 544 | camellia_setkey_enc_wrap, |
| 545 | camellia_setkey_dec_wrap, |
| 546 | camellia_ctx_alloc, |
| 547 | camellia_ctx_free |
| 548 | }; |
| 549 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 550 | const cipher_info_t camellia_128_ecb_info = { |
| 551 | POLARSSL_CIPHER_CAMELLIA_128_ECB, |
| 552 | POLARSSL_MODE_ECB, |
| 553 | 128, |
| 554 | "CAMELLIA-128-ECB", |
| 555 | 16, |
| 556 | 0, |
| 557 | 16, |
| 558 | &camellia_info |
| 559 | }; |
| 560 | |
| 561 | const cipher_info_t camellia_192_ecb_info = { |
| 562 | POLARSSL_CIPHER_CAMELLIA_192_ECB, |
| 563 | POLARSSL_MODE_ECB, |
| 564 | 192, |
| 565 | "CAMELLIA-192-ECB", |
| 566 | 16, |
| 567 | 0, |
| 568 | 16, |
| 569 | &camellia_info |
| 570 | }; |
| 571 | |
| 572 | const cipher_info_t camellia_256_ecb_info = { |
| 573 | POLARSSL_CIPHER_CAMELLIA_256_ECB, |
| 574 | POLARSSL_MODE_ECB, |
| 575 | 256, |
| 576 | "CAMELLIA-256-ECB", |
| 577 | 16, |
| 578 | 0, |
| 579 | 16, |
| 580 | &camellia_info |
| 581 | }; |
| 582 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 583 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 584 | const cipher_info_t camellia_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 585 | POLARSSL_CIPHER_CAMELLIA_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 586 | POLARSSL_MODE_CBC, |
| 587 | 128, |
| 588 | "CAMELLIA-128-CBC", |
| 589 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 590 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 591 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 592 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | const cipher_info_t camellia_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 596 | POLARSSL_CIPHER_CAMELLIA_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 597 | POLARSSL_MODE_CBC, |
| 598 | 192, |
| 599 | "CAMELLIA-192-CBC", |
| 600 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 601 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 602 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 603 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | const cipher_info_t camellia_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 607 | POLARSSL_CIPHER_CAMELLIA_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 608 | POLARSSL_MODE_CBC, |
| 609 | 256, |
| 610 | "CAMELLIA-256-CBC", |
| 611 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 612 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 613 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 614 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 615 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 616 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 617 | |
| 618 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 619 | const cipher_info_t camellia_128_cfb128_info = { |
| 620 | POLARSSL_CIPHER_CAMELLIA_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 621 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 622 | 128, |
| 623 | "CAMELLIA-128-CFB128", |
| 624 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 625 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 626 | 16, |
| 627 | &camellia_info |
| 628 | }; |
| 629 | |
| 630 | const cipher_info_t camellia_192_cfb128_info = { |
| 631 | POLARSSL_CIPHER_CAMELLIA_192_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 632 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 633 | 192, |
| 634 | "CAMELLIA-192-CFB128", |
| 635 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 636 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 637 | 16, |
| 638 | &camellia_info |
| 639 | }; |
| 640 | |
| 641 | const cipher_info_t camellia_256_cfb128_info = { |
| 642 | POLARSSL_CIPHER_CAMELLIA_256_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 643 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 644 | 256, |
| 645 | "CAMELLIA-256-CFB128", |
| 646 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 647 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 648 | 16, |
| 649 | &camellia_info |
| 650 | }; |
| 651 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 652 | |
| 653 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 654 | const cipher_info_t camellia_128_ctr_info = { |
| 655 | POLARSSL_CIPHER_CAMELLIA_128_CTR, |
| 656 | POLARSSL_MODE_CTR, |
| 657 | 128, |
| 658 | "CAMELLIA-128-CTR", |
| 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 | }; |
| 664 | |
| 665 | const cipher_info_t camellia_192_ctr_info = { |
| 666 | POLARSSL_CIPHER_CAMELLIA_192_CTR, |
| 667 | POLARSSL_MODE_CTR, |
| 668 | 192, |
| 669 | "CAMELLIA-192-CTR", |
| 670 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 671 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 672 | 16, |
| 673 | &camellia_info |
| 674 | }; |
| 675 | |
| 676 | const cipher_info_t camellia_256_ctr_info = { |
| 677 | POLARSSL_CIPHER_CAMELLIA_256_CTR, |
| 678 | POLARSSL_MODE_CTR, |
| 679 | 256, |
| 680 | "CAMELLIA-256-CTR", |
| 681 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 682 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 683 | 16, |
| 684 | &camellia_info |
| 685 | }; |
| 686 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 687 | |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 688 | #if defined(POLARSSL_GCM_C) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 689 | static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key, |
| 690 | unsigned int key_length ) |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 691 | { |
| 692 | return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA, |
| 693 | key, key_length ); |
| 694 | } |
| 695 | |
| 696 | const cipher_base_t gcm_camellia_info = { |
| 697 | POLARSSL_CIPHER_ID_CAMELLIA, |
| 698 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 699 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 700 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 701 | #endif |
| 702 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 703 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 704 | #endif |
| 705 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 706 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 707 | #endif |
| 708 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 709 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 710 | #endif |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 711 | gcm_camellia_setkey_wrap, |
| 712 | gcm_camellia_setkey_wrap, |
| 713 | gcm_ctx_alloc, |
| 714 | gcm_ctx_free, |
| 715 | }; |
| 716 | |
| 717 | const cipher_info_t camellia_128_gcm_info = { |
| 718 | POLARSSL_CIPHER_CAMELLIA_128_GCM, |
| 719 | POLARSSL_MODE_GCM, |
| 720 | 128, |
| 721 | "CAMELLIA-128-GCM", |
| 722 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 723 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 724 | 16, |
| 725 | &gcm_camellia_info |
| 726 | }; |
| 727 | |
| 728 | const cipher_info_t camellia_192_gcm_info = { |
| 729 | POLARSSL_CIPHER_CAMELLIA_192_GCM, |
| 730 | POLARSSL_MODE_GCM, |
| 731 | 192, |
| 732 | "CAMELLIA-192-GCM", |
| 733 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 734 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 735 | 16, |
| 736 | &gcm_camellia_info |
| 737 | }; |
| 738 | |
| 739 | const cipher_info_t camellia_256_gcm_info = { |
| 740 | POLARSSL_CIPHER_CAMELLIA_256_GCM, |
| 741 | POLARSSL_MODE_GCM, |
| 742 | 256, |
| 743 | "CAMELLIA-256-GCM", |
| 744 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 745 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 746 | 16, |
| 747 | &gcm_camellia_info |
| 748 | }; |
| 749 | #endif /* POLARSSL_GCM_C */ |
| 750 | |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 751 | #if defined(POLARSSL_CCM_C) |
| 752 | static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key, |
| 753 | unsigned int key_length ) |
| 754 | { |
| 755 | return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA, |
| 756 | key, key_length ); |
| 757 | } |
| 758 | |
| 759 | const cipher_base_t ccm_camellia_info = { |
| 760 | POLARSSL_CIPHER_ID_CAMELLIA, |
| 761 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 762 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 763 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 764 | #endif |
| 765 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 766 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 767 | #endif |
| 768 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 769 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 770 | #endif |
| 771 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 772 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 773 | #endif |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 774 | ccm_camellia_setkey_wrap, |
| 775 | ccm_camellia_setkey_wrap, |
| 776 | ccm_ctx_alloc, |
| 777 | ccm_ctx_free, |
| 778 | }; |
| 779 | |
| 780 | const cipher_info_t camellia_128_ccm_info = { |
| 781 | POLARSSL_CIPHER_CAMELLIA_128_CCM, |
| 782 | POLARSSL_MODE_CCM, |
| 783 | 128, |
| 784 | "CAMELLIA-128-CCM", |
| 785 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 786 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 787 | 16, |
| 788 | &ccm_camellia_info |
| 789 | }; |
| 790 | |
| 791 | const cipher_info_t camellia_192_ccm_info = { |
| 792 | POLARSSL_CIPHER_CAMELLIA_192_CCM, |
| 793 | POLARSSL_MODE_CCM, |
| 794 | 192, |
| 795 | "CAMELLIA-192-CCM", |
| 796 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 797 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 798 | 16, |
| 799 | &ccm_camellia_info |
| 800 | }; |
| 801 | |
| 802 | const cipher_info_t camellia_256_ccm_info = { |
| 803 | POLARSSL_CIPHER_CAMELLIA_256_CCM, |
| 804 | POLARSSL_MODE_CCM, |
| 805 | 256, |
| 806 | "CAMELLIA-256-CCM", |
| 807 | 12, |
Manuel Pégourié-Gonnard | 81754a0 | 2014-06-23 11:33:18 +0200 | [diff] [blame] | 808 | POLARSSL_CIPHER_VARIABLE_IV_LEN, |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 809 | 16, |
| 810 | &ccm_camellia_info |
| 811 | }; |
| 812 | #endif /* POLARSSL_CCM_C */ |
| 813 | |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 814 | #endif /* POLARSSL_CAMELLIA_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 815 | |
| 816 | #if defined(POLARSSL_DES_C) |
| 817 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 818 | static int des_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 819 | const unsigned char *input, unsigned char *output ) |
| 820 | { |
| 821 | ((void) operation); |
| 822 | return des_crypt_ecb( (des_context *) ctx, input, output ); |
| 823 | } |
| 824 | |
| 825 | static int des3_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 826 | const unsigned char *input, unsigned char *output ) |
| 827 | { |
| 828 | ((void) operation); |
| 829 | return des3_crypt_ecb( (des3_context *) ctx, input, output ); |
| 830 | } |
| 831 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 832 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 833 | static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 834 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 835 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 836 | return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, |
| 837 | output ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 838 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 839 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 840 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 841 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 842 | static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length, |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 843 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 844 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 845 | return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, |
| 846 | output ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 847 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 848 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 849 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 850 | static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 851 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 852 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 853 | ((void) key_length); |
| 854 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 855 | return des_setkey_dec( (des_context *) ctx, key ); |
| 856 | } |
| 857 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 858 | static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 859 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 860 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 861 | ((void) key_length); |
| 862 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 863 | return des_setkey_enc( (des_context *) ctx, key ); |
| 864 | } |
| 865 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 866 | static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, |
| 867 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 868 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 869 | ((void) key_length); |
| 870 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 871 | return des3_set2key_dec( (des3_context *) ctx, key ); |
| 872 | } |
| 873 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 874 | static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, |
| 875 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 876 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 877 | ((void) key_length); |
| 878 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 879 | return des3_set2key_enc( (des3_context *) ctx, key ); |
| 880 | } |
| 881 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 882 | static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, |
| 883 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 884 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 885 | ((void) key_length); |
| 886 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 887 | return des3_set3key_dec( (des3_context *) ctx, key ); |
| 888 | } |
| 889 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 890 | static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, |
| 891 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 892 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 893 | ((void) key_length); |
| 894 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 895 | return des3_set3key_enc( (des3_context *) ctx, key ); |
| 896 | } |
| 897 | |
| 898 | static void * des_ctx_alloc( void ) |
| 899 | { |
Mansour Moufid | c531b4a | 2015-02-15 17:35:38 -0500 | [diff] [blame] | 900 | des_context *des = polarssl_malloc( sizeof( des_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 901 | |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 902 | if( des == NULL ) |
| 903 | return( NULL ); |
| 904 | |
| 905 | des_init( des ); |
| 906 | |
| 907 | return( des ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static void des_ctx_free( void *ctx ) |
| 911 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 912 | des_free( (des_context *) ctx ); |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 913 | polarssl_free( ctx ); |
| 914 | } |
| 915 | |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 916 | static void * des3_ctx_alloc( void ) |
| 917 | { |
| 918 | des3_context *des3; |
Mansour Moufid | c531b4a | 2015-02-15 17:35:38 -0500 | [diff] [blame] | 919 | des3 = polarssl_malloc( sizeof( des3_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 920 | |
| 921 | if( des3 == NULL ) |
| 922 | return( NULL ); |
| 923 | |
| 924 | des3_init( des3 ); |
| 925 | |
| 926 | return( des3 ); |
| 927 | } |
| 928 | |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 929 | static void des3_ctx_free( void *ctx ) |
| 930 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 931 | des3_free( (des3_context *) ctx ); |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 932 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 935 | const cipher_base_t des_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 936 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 937 | des_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 938 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 939 | des_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 940 | #endif |
| 941 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 942 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 943 | #endif |
| 944 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 945 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 946 | #endif |
| 947 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 948 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 949 | #endif |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 950 | des_setkey_enc_wrap, |
| 951 | des_setkey_dec_wrap, |
| 952 | des_ctx_alloc, |
| 953 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 954 | }; |
| 955 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 956 | const cipher_info_t des_ecb_info = { |
| 957 | POLARSSL_CIPHER_DES_ECB, |
| 958 | POLARSSL_MODE_ECB, |
| 959 | POLARSSL_KEY_LENGTH_DES, |
| 960 | "DES-ECB", |
| 961 | 8, |
| 962 | 0, |
| 963 | 8, |
| 964 | &des_info |
| 965 | }; |
| 966 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 967 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 968 | const cipher_info_t des_cbc_info = { |
| 969 | POLARSSL_CIPHER_DES_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 970 | POLARSSL_MODE_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 971 | POLARSSL_KEY_LENGTH_DES, |
| 972 | "DES-CBC", |
| 973 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 974 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 975 | 8, |
| 976 | &des_info |
| 977 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 978 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 979 | |
| 980 | const cipher_base_t des_ede_info = { |
| 981 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 982 | des3_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 983 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 984 | des3_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 985 | #endif |
| 986 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 987 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 988 | #endif |
| 989 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 990 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 991 | #endif |
| 992 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 993 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 994 | #endif |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 995 | des3_set2key_enc_wrap, |
| 996 | des3_set2key_dec_wrap, |
| 997 | des3_ctx_alloc, |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 998 | des3_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 999 | }; |
| 1000 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1001 | const cipher_info_t des_ede_ecb_info = { |
| 1002 | POLARSSL_CIPHER_DES_EDE_ECB, |
| 1003 | POLARSSL_MODE_ECB, |
| 1004 | POLARSSL_KEY_LENGTH_DES_EDE, |
| 1005 | "DES-EDE-ECB", |
| 1006 | 8, |
| 1007 | 0, |
| 1008 | 8, |
| 1009 | &des_ede_info |
| 1010 | }; |
| 1011 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1012 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1013 | const cipher_info_t des_ede_cbc_info = { |
| 1014 | POLARSSL_CIPHER_DES_EDE_CBC, |
| 1015 | POLARSSL_MODE_CBC, |
| 1016 | POLARSSL_KEY_LENGTH_DES_EDE, |
| 1017 | "DES-EDE-CBC", |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 1018 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1019 | 0, |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 1020 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1021 | &des_ede_info |
| 1022 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1023 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1024 | |
| 1025 | const cipher_base_t des_ede3_info = { |
| 1026 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1027 | des3_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1028 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1029 | des3_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1030 | #endif |
| 1031 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1032 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1033 | #endif |
| 1034 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Manuel Pégourié-Gonnard | b912616 | 2014-06-13 15:06:59 +0200 | [diff] [blame] | 1035 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1036 | #endif |
| 1037 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1038 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1039 | #endif |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1040 | des3_set3key_enc_wrap, |
| 1041 | des3_set3key_dec_wrap, |
| 1042 | des3_ctx_alloc, |
Paul Bakker | 3461772 | 2014-06-13 17:20:13 +0200 | [diff] [blame] | 1043 | des3_ctx_free |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1044 | }; |
| 1045 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1046 | const cipher_info_t des_ede3_ecb_info = { |
| 1047 | POLARSSL_CIPHER_DES_EDE3_ECB, |
| 1048 | POLARSSL_MODE_ECB, |
| 1049 | POLARSSL_KEY_LENGTH_DES_EDE3, |
| 1050 | "DES-EDE3-ECB", |
| 1051 | 8, |
| 1052 | 0, |
| 1053 | 8, |
| 1054 | &des_ede3_info |
| 1055 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1056 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1057 | const cipher_info_t des_ede3_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1058 | POLARSSL_CIPHER_DES_EDE3_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1059 | POLARSSL_MODE_CBC, |
| 1060 | POLARSSL_KEY_LENGTH_DES_EDE3, |
| 1061 | "DES-EDE3-CBC", |
| 1062 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1063 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 1064 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 1065 | &des_ede3_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1066 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1067 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 1068 | #endif /* POLARSSL_DES_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 1069 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1070 | #if defined(POLARSSL_BLOWFISH_C) |
| 1071 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1072 | static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 1073 | const unsigned char *input, unsigned char *output ) |
| 1074 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1075 | return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, |
| 1076 | output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1079 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1080 | static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, |
| 1081 | size_t length, unsigned char *iv, const unsigned char *input, |
| 1082 | unsigned char *output ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1083 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1084 | return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, |
| 1085 | input, output ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1086 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1087 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1088 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1089 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1090 | static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, |
| 1091 | size_t length, size_t *iv_off, unsigned char *iv, |
| 1092 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1093 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1094 | return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, |
| 1095 | iv_off, iv, input, output ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1096 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1097 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1098 | |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1099 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1100 | static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 1101 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1102 | const unsigned char *input, unsigned char *output ) |
| 1103 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1104 | return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, |
| 1105 | nonce_counter, stream_block, input, output ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1106 | } |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1107 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1108 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame] | 1109 | static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, |
| 1110 | unsigned int key_length ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1111 | { |
| 1112 | return blowfish_setkey( (blowfish_context *) ctx, key, key_length ); |
| 1113 | } |
| 1114 | |
| 1115 | static void * blowfish_ctx_alloc( void ) |
| 1116 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1117 | blowfish_context *ctx; |
Mansour Moufid | c531b4a | 2015-02-15 17:35:38 -0500 | [diff] [blame] | 1118 | ctx = polarssl_malloc( sizeof( blowfish_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1119 | |
| 1120 | if( ctx == NULL ) |
| 1121 | return( NULL ); |
| 1122 | |
| 1123 | blowfish_init( ctx ); |
| 1124 | |
| 1125 | return( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | static void blowfish_ctx_free( void *ctx ) |
| 1129 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1130 | blowfish_free( (blowfish_context *) ctx ); |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 1131 | polarssl_free( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | const cipher_base_t blowfish_info = { |
| 1135 | POLARSSL_CIPHER_ID_BLOWFISH, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1136 | blowfish_crypt_ecb_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1137 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1138 | blowfish_crypt_cbc_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1139 | #endif |
| 1140 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1141 | blowfish_crypt_cfb64_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1142 | #endif |
| 1143 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1144 | blowfish_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1145 | #endif |
| 1146 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1147 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1148 | #endif |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1149 | blowfish_setkey_wrap, |
| 1150 | blowfish_setkey_wrap, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1151 | blowfish_ctx_alloc, |
| 1152 | blowfish_ctx_free |
| 1153 | }; |
| 1154 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1155 | const cipher_info_t blowfish_ecb_info = { |
| 1156 | POLARSSL_CIPHER_BLOWFISH_ECB, |
| 1157 | POLARSSL_MODE_ECB, |
| 1158 | 128, |
| 1159 | "BLOWFISH-ECB", |
| 1160 | 8, |
Manuel Pégourié-Gonnard | 398c57b | 2014-06-23 12:10:59 +0200 | [diff] [blame] | 1161 | POLARSSL_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1162 | 8, |
| 1163 | &blowfish_info |
| 1164 | }; |
| 1165 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1166 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1167 | const cipher_info_t blowfish_cbc_info = { |
| 1168 | POLARSSL_CIPHER_BLOWFISH_CBC, |
| 1169 | POLARSSL_MODE_CBC, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1170 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1171 | "BLOWFISH-CBC", |
| 1172 | 8, |
Manuel Pégourié-Gonnard | 398c57b | 2014-06-23 12:10:59 +0200 | [diff] [blame] | 1173 | POLARSSL_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1174 | 8, |
| 1175 | &blowfish_info |
| 1176 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1177 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1178 | |
| 1179 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1180 | const cipher_info_t blowfish_cfb64_info = { |
| 1181 | POLARSSL_CIPHER_BLOWFISH_CFB64, |
| 1182 | POLARSSL_MODE_CFB, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1183 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1184 | "BLOWFISH-CFB64", |
| 1185 | 8, |
Manuel Pégourié-Gonnard | 398c57b | 2014-06-23 12:10:59 +0200 | [diff] [blame] | 1186 | POLARSSL_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1187 | 8, |
| 1188 | &blowfish_info |
| 1189 | }; |
| 1190 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 1191 | |
| 1192 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1193 | const cipher_info_t blowfish_ctr_info = { |
| 1194 | POLARSSL_CIPHER_BLOWFISH_CTR, |
| 1195 | POLARSSL_MODE_CTR, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1196 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1197 | "BLOWFISH-CTR", |
| 1198 | 8, |
Manuel Pégourié-Gonnard | 398c57b | 2014-06-23 12:10:59 +0200 | [diff] [blame] | 1199 | POLARSSL_CIPHER_VARIABLE_KEY_LEN, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1200 | 8, |
| 1201 | &blowfish_info |
| 1202 | }; |
| 1203 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 1204 | #endif /* POLARSSL_BLOWFISH_C */ |
| 1205 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1206 | #if defined(POLARSSL_ARC4_C) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1207 | static int arc4_crypt_stream_wrap( void *ctx, size_t length, |
| 1208 | const unsigned char *input, |
| 1209 | unsigned char *output ) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1210 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1211 | return( arc4_crypt( (arc4_context *) ctx, length, input, output ) ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1212 | } |
| 1213 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1214 | static int arc4_setkey_wrap( void *ctx, const unsigned char *key, |
| 1215 | unsigned int key_length ) |
| 1216 | { |
Manuel Pégourié-Gonnard | ce41125 | 2013-09-04 12:28:37 +0200 | [diff] [blame] | 1217 | /* we get key_length in bits, arc4 expects it in bytes */ |
Paul Bakker | 66d5d07 | 2014-06-17 16:39:18 +0200 | [diff] [blame] | 1218 | if( key_length % 8 != 0 ) |
Manuel Pégourié-Gonnard | ce41125 | 2013-09-04 12:28:37 +0200 | [diff] [blame] | 1219 | return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA ); |
| 1220 | |
| 1221 | arc4_setup( (arc4_context *) ctx, key, key_length / 8 ); |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1222 | return( 0 ); |
| 1223 | } |
| 1224 | |
| 1225 | static void * arc4_ctx_alloc( void ) |
| 1226 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1227 | arc4_context *ctx; |
Mansour Moufid | c531b4a | 2015-02-15 17:35:38 -0500 | [diff] [blame] | 1228 | ctx = polarssl_malloc( sizeof( arc4_context ) ); |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1229 | |
| 1230 | if( ctx == NULL ) |
| 1231 | return( NULL ); |
| 1232 | |
| 1233 | arc4_init( ctx ); |
| 1234 | |
| 1235 | return( ctx ); |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1236 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1237 | |
| 1238 | static void arc4_ctx_free( void *ctx ) |
| 1239 | { |
Paul Bakker | c7ea99a | 2014-06-18 11:12:03 +0200 | [diff] [blame] | 1240 | arc4_free( (arc4_context *) ctx ); |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1241 | polarssl_free( ctx ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | const cipher_base_t arc4_base_info = { |
| 1245 | POLARSSL_CIPHER_ID_ARC4, |
| 1246 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1247 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1248 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1249 | #endif |
| 1250 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1251 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1252 | #endif |
| 1253 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1254 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1255 | #endif |
| 1256 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1257 | arc4_crypt_stream_wrap, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1258 | #endif |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1259 | arc4_setkey_wrap, |
| 1260 | arc4_setkey_wrap, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1261 | arc4_ctx_alloc, |
| 1262 | arc4_ctx_free |
| 1263 | }; |
| 1264 | |
| 1265 | const cipher_info_t arc4_128_info = { |
| 1266 | POLARSSL_CIPHER_ARC4_128, |
| 1267 | POLARSSL_MODE_STREAM, |
| 1268 | 128, |
| 1269 | "ARC4-128", |
| 1270 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1271 | 0, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1272 | 1, |
| 1273 | &arc4_base_info |
| 1274 | }; |
| 1275 | #endif /* POLARSSL_ARC4_C */ |
| 1276 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1277 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1278 | static int null_crypt_stream( void *ctx, size_t length, |
| 1279 | const unsigned char *input, |
| 1280 | unsigned char *output ) |
| 1281 | { |
| 1282 | ((void) ctx); |
| 1283 | memmove( output, input, length ); |
| 1284 | return( 0 ); |
| 1285 | } |
| 1286 | |
| 1287 | static int null_setkey( void *ctx, const unsigned char *key, |
| 1288 | unsigned int key_length ) |
| 1289 | { |
| 1290 | ((void) ctx); |
| 1291 | ((void) key); |
| 1292 | ((void) key_length); |
| 1293 | |
| 1294 | return( 0 ); |
| 1295 | } |
| 1296 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1297 | static void * null_ctx_alloc( void ) |
| 1298 | { |
Manuel Pégourié-Gonnard | 86bbc7f | 2014-07-12 02:14:41 +0200 | [diff] [blame] | 1299 | return( (void *) 1 ); |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1302 | static void null_ctx_free( void *ctx ) |
| 1303 | { |
| 1304 | ((void) ctx); |
| 1305 | } |
| 1306 | |
| 1307 | const cipher_base_t null_base_info = { |
| 1308 | POLARSSL_CIPHER_ID_NULL, |
| 1309 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1310 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1311 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1312 | #endif |
| 1313 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1314 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1315 | #endif |
| 1316 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1317 | NULL, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1318 | #endif |
| 1319 | #if defined(POLARSSL_CIPHER_MODE_STREAM) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1320 | null_crypt_stream, |
Manuel Pégourié-Gonnard | b8ca723 | 2014-12-02 10:09:10 +0100 | [diff] [blame^] | 1321 | #endif |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1322 | null_setkey, |
| 1323 | null_setkey, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1324 | null_ctx_alloc, |
| 1325 | null_ctx_free |
| 1326 | }; |
| 1327 | |
| 1328 | const cipher_info_t null_cipher_info = { |
| 1329 | POLARSSL_CIPHER_NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1330 | POLARSSL_MODE_STREAM, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1331 | 0, |
| 1332 | "NULL", |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1333 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1334 | 0, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1335 | 1, |
| 1336 | &null_base_info |
| 1337 | }; |
| 1338 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 1339 | |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1340 | const cipher_definition_t cipher_definitions[] = |
| 1341 | { |
| 1342 | #if defined(POLARSSL_AES_C) |
| 1343 | { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info }, |
| 1344 | { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info }, |
| 1345 | { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info }, |
| 1346 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1347 | { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info }, |
| 1348 | { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info }, |
| 1349 | { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info }, |
| 1350 | #endif |
| 1351 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1352 | { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info }, |
| 1353 | { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info }, |
| 1354 | { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info }, |
| 1355 | #endif |
| 1356 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1357 | { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info }, |
| 1358 | { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info }, |
| 1359 | { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info }, |
| 1360 | #endif |
| 1361 | #if defined(POLARSSL_GCM_C) |
| 1362 | { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info }, |
| 1363 | { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info }, |
| 1364 | { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info }, |
| 1365 | #endif |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 1366 | #if defined(POLARSSL_CCM_C) |
| 1367 | { POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info }, |
| 1368 | { POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info }, |
| 1369 | { POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info }, |
| 1370 | #endif |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1371 | #endif /* POLARSSL_AES_C */ |
| 1372 | |
| 1373 | #if defined(POLARSSL_ARC4_C) |
| 1374 | { POLARSSL_CIPHER_ARC4_128, &arc4_128_info }, |
| 1375 | #endif |
| 1376 | |
| 1377 | #if defined(POLARSSL_BLOWFISH_C) |
| 1378 | { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info }, |
| 1379 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1380 | { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info }, |
| 1381 | #endif |
| 1382 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1383 | { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info }, |
| 1384 | #endif |
| 1385 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1386 | { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info }, |
| 1387 | #endif |
| 1388 | #endif /* POLARSSL_BLOWFISH_C */ |
| 1389 | |
| 1390 | #if defined(POLARSSL_CAMELLIA_C) |
| 1391 | { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info }, |
| 1392 | { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info }, |
Manuel Pégourié-Gonnard | 13e0d44 | 2013-10-24 12:59:00 +0200 | [diff] [blame] | 1393 | { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1394 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1395 | { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info }, |
| 1396 | { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info }, |
| 1397 | { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info }, |
| 1398 | #endif |
| 1399 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1400 | { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info }, |
| 1401 | { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info }, |
| 1402 | { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info }, |
| 1403 | #endif |
| 1404 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1405 | { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info }, |
| 1406 | { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info }, |
| 1407 | { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info }, |
| 1408 | #endif |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 1409 | #if defined(POLARSSL_GCM_C) |
| 1410 | { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info }, |
| 1411 | { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info }, |
| 1412 | { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info }, |
| 1413 | #endif |
Manuel Pégourié-Gonnard | 4193695 | 2014-05-13 13:18:17 +0200 | [diff] [blame] | 1414 | #if defined(POLARSSL_CCM_C) |
| 1415 | { POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info }, |
| 1416 | { POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info }, |
| 1417 | { POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info }, |
| 1418 | #endif |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1419 | #endif /* POLARSSL_CAMELLIA_C */ |
| 1420 | |
| 1421 | #if defined(POLARSSL_DES_C) |
| 1422 | { POLARSSL_CIPHER_DES_ECB, &des_ecb_info }, |
| 1423 | { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info }, |
| 1424 | { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info }, |
| 1425 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1426 | { POLARSSL_CIPHER_DES_CBC, &des_cbc_info }, |
| 1427 | { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info }, |
| 1428 | { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info }, |
| 1429 | #endif |
| 1430 | #endif /* POLARSSL_DES_C */ |
| 1431 | |
| 1432 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | 057e0cf | 2013-10-14 14:19:31 +0200 | [diff] [blame] | 1433 | { POLARSSL_CIPHER_NULL, &null_cipher_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1434 | #endif /* POLARSSL_CIPHER_NULL_CIPHER */ |
| 1435 | |
Manuel Pégourié-Gonnard | a273371 | 2015-02-10 17:32:14 +0100 | [diff] [blame] | 1436 | { POLARSSL_CIPHER_NONE, NULL } |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1437 | }; |
| 1438 | |
| 1439 | #define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0] |
| 1440 | int supported_ciphers[NUM_CIPHERS]; |
| 1441 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 1442 | #endif /* POLARSSL_CIPHER_C */ |