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