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