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