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