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 | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 71 | 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] | 72 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 73 | { |
| 74 | return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output ); |
| 75 | } |
| 76 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 77 | 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] | 78 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 79 | { |
| 80 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 81 | return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output ); |
| 82 | #else |
| 83 | ((void) ctx); |
| 84 | ((void) operation); |
| 85 | ((void) length); |
| 86 | ((void) iv_off); |
| 87 | ((void) iv); |
| 88 | ((void) input); |
| 89 | ((void) output); |
| 90 | |
| 91 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 92 | #endif |
| 93 | } |
| 94 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 95 | static int aes_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 96 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 97 | const unsigned char *input, unsigned char *output ) |
| 98 | { |
| 99 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 100 | return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter, |
| 101 | stream_block, input, output ); |
| 102 | #else |
| 103 | ((void) ctx); |
| 104 | ((void) length); |
| 105 | ((void) nc_off); |
| 106 | ((void) nonce_counter); |
| 107 | ((void) stream_block); |
| 108 | ((void) input); |
| 109 | ((void) output); |
| 110 | |
| 111 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 112 | #endif |
| 113 | } |
| 114 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 115 | 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] | 116 | { |
| 117 | return aes_setkey_dec( (aes_context *) ctx, key, key_length ); |
| 118 | } |
| 119 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 120 | 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] | 121 | { |
| 122 | return aes_setkey_enc( (aes_context *) ctx, key, key_length ); |
| 123 | } |
| 124 | |
| 125 | static void * aes_ctx_alloc( void ) |
| 126 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 127 | return polarssl_malloc( sizeof( aes_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void aes_ctx_free( void *ctx ) |
| 131 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 132 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 135 | const cipher_base_t aes_info = { |
| 136 | POLARSSL_CIPHER_ID_AES, |
| 137 | aes_crypt_cbc_wrap, |
| 138 | aes_crypt_cfb128_wrap, |
| 139 | aes_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 140 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 141 | aes_setkey_enc_wrap, |
| 142 | aes_setkey_dec_wrap, |
| 143 | aes_ctx_alloc, |
| 144 | aes_ctx_free |
| 145 | }; |
| 146 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 147 | const cipher_info_t aes_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 148 | POLARSSL_CIPHER_AES_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 149 | POLARSSL_MODE_CBC, |
| 150 | 128, |
| 151 | "AES-128-CBC", |
| 152 | 16, |
| 153 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 154 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | const cipher_info_t aes_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 158 | POLARSSL_CIPHER_AES_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 159 | POLARSSL_MODE_CBC, |
| 160 | 192, |
| 161 | "AES-192-CBC", |
| 162 | 16, |
| 163 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 164 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | const cipher_info_t aes_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 168 | POLARSSL_CIPHER_AES_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 169 | POLARSSL_MODE_CBC, |
| 170 | 256, |
| 171 | "AES-256-CBC", |
| 172 | 16, |
| 173 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 174 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 175 | }; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 176 | |
| 177 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 178 | const cipher_info_t aes_128_cfb128_info = { |
| 179 | POLARSSL_CIPHER_AES_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 180 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 181 | 128, |
| 182 | "AES-128-CFB128", |
| 183 | 16, |
| 184 | 16, |
| 185 | &aes_info |
| 186 | }; |
| 187 | |
| 188 | const cipher_info_t aes_192_cfb128_info = { |
| 189 | POLARSSL_CIPHER_AES_192_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 190 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 191 | 192, |
| 192 | "AES-192-CFB128", |
| 193 | 16, |
| 194 | 16, |
| 195 | &aes_info |
| 196 | }; |
| 197 | |
| 198 | const cipher_info_t aes_256_cfb128_info = { |
| 199 | POLARSSL_CIPHER_AES_256_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 200 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 201 | 256, |
| 202 | "AES-256-CFB128", |
| 203 | 16, |
| 204 | 16, |
| 205 | &aes_info |
| 206 | }; |
| 207 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 208 | |
| 209 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 210 | const cipher_info_t aes_128_ctr_info = { |
| 211 | POLARSSL_CIPHER_AES_128_CTR, |
| 212 | POLARSSL_MODE_CTR, |
| 213 | 128, |
| 214 | "AES-128-CTR", |
| 215 | 16, |
| 216 | 16, |
| 217 | &aes_info |
| 218 | }; |
| 219 | |
| 220 | const cipher_info_t aes_192_ctr_info = { |
| 221 | POLARSSL_CIPHER_AES_192_CTR, |
| 222 | POLARSSL_MODE_CTR, |
| 223 | 192, |
| 224 | "AES-192-CTR", |
| 225 | 16, |
| 226 | 16, |
| 227 | &aes_info |
| 228 | }; |
| 229 | |
| 230 | const cipher_info_t aes_256_ctr_info = { |
| 231 | POLARSSL_CIPHER_AES_256_CTR, |
| 232 | POLARSSL_MODE_CTR, |
| 233 | 256, |
| 234 | "AES-256-CTR", |
| 235 | 16, |
| 236 | 16, |
| 237 | &aes_info |
| 238 | }; |
| 239 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 240 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 241 | #if defined(POLARSSL_GCM_C) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 242 | static void *gcm_ctx_alloc( void ) |
| 243 | { |
| 244 | return polarssl_malloc( sizeof( gcm_context ) ); |
| 245 | } |
| 246 | |
| 247 | static void gcm_ctx_free( void *ctx ) |
| 248 | { |
| 249 | polarssl_free( ctx ); |
| 250 | } |
| 251 | |
| 252 | static int gcm_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length ) |
| 253 | { |
| 254 | return gcm_init( (gcm_context *) ctx, key, key_length ); |
| 255 | } |
| 256 | |
| 257 | const cipher_base_t gcm_aes_info = { |
| 258 | POLARSSL_CIPHER_ID_AES, |
| 259 | NULL, |
| 260 | NULL, |
| 261 | NULL, |
| 262 | NULL, |
| 263 | gcm_setkey_wrap, |
| 264 | gcm_setkey_wrap, |
| 265 | gcm_ctx_alloc, |
| 266 | gcm_ctx_free, |
| 267 | }; |
| 268 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 269 | const cipher_info_t aes_128_gcm_info = { |
| 270 | POLARSSL_CIPHER_AES_128_GCM, |
| 271 | POLARSSL_MODE_GCM, |
| 272 | 128, |
| 273 | "AES-128-GCM", |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 274 | 0, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 275 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 276 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | const cipher_info_t aes_256_gcm_info = { |
| 280 | POLARSSL_CIPHER_AES_256_GCM, |
| 281 | POLARSSL_MODE_GCM, |
| 282 | 256, |
| 283 | "AES-256-GCM", |
Manuel Pégourié-Gonnard | 9241be7 | 2013-08-31 17:31:03 +0200 | [diff] [blame] | 284 | 0, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 285 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 286 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 287 | }; |
| 288 | #endif /* POLARSSL_GCM_C */ |
| 289 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 290 | #endif |
| 291 | |
| 292 | #if defined(POLARSSL_CAMELLIA_C) |
| 293 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 294 | 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] | 295 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 296 | { |
| 297 | return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output ); |
| 298 | } |
| 299 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 300 | 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] | 301 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 302 | { |
| 303 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 304 | return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output ); |
| 305 | #else |
| 306 | ((void) ctx); |
| 307 | ((void) operation); |
| 308 | ((void) length); |
| 309 | ((void) iv_off); |
| 310 | ((void) iv); |
| 311 | ((void) input); |
| 312 | ((void) output); |
| 313 | |
| 314 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 315 | #endif |
| 316 | } |
| 317 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 318 | static int camellia_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 319 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 320 | const unsigned char *input, unsigned char *output ) |
| 321 | { |
| 322 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 323 | return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter, |
| 324 | stream_block, input, output ); |
| 325 | #else |
| 326 | ((void) ctx); |
| 327 | ((void) length); |
| 328 | ((void) nc_off); |
| 329 | ((void) nonce_counter); |
| 330 | ((void) stream_block); |
| 331 | ((void) input); |
| 332 | ((void) output); |
| 333 | |
| 334 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 335 | #endif |
| 336 | } |
| 337 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 338 | 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] | 339 | { |
| 340 | return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); |
| 341 | } |
| 342 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 343 | 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] | 344 | { |
| 345 | return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); |
| 346 | } |
| 347 | |
| 348 | static void * camellia_ctx_alloc( void ) |
| 349 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 350 | return polarssl_malloc( sizeof( camellia_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static void camellia_ctx_free( void *ctx ) |
| 354 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 355 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 358 | const cipher_base_t camellia_info = { |
| 359 | POLARSSL_CIPHER_ID_CAMELLIA, |
| 360 | camellia_crypt_cbc_wrap, |
| 361 | camellia_crypt_cfb128_wrap, |
| 362 | camellia_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 363 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 364 | camellia_setkey_enc_wrap, |
| 365 | camellia_setkey_dec_wrap, |
| 366 | camellia_ctx_alloc, |
| 367 | camellia_ctx_free |
| 368 | }; |
| 369 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 370 | const cipher_info_t camellia_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 371 | POLARSSL_CIPHER_CAMELLIA_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 372 | POLARSSL_MODE_CBC, |
| 373 | 128, |
| 374 | "CAMELLIA-128-CBC", |
| 375 | 16, |
| 376 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 377 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | const cipher_info_t camellia_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 381 | POLARSSL_CIPHER_CAMELLIA_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 382 | POLARSSL_MODE_CBC, |
| 383 | 192, |
| 384 | "CAMELLIA-192-CBC", |
| 385 | 16, |
| 386 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 387 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | const cipher_info_t camellia_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 391 | POLARSSL_CIPHER_CAMELLIA_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 392 | POLARSSL_MODE_CBC, |
| 393 | 256, |
| 394 | "CAMELLIA-256-CBC", |
| 395 | 16, |
| 396 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 397 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 398 | }; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 399 | |
| 400 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 401 | const cipher_info_t camellia_128_cfb128_info = { |
| 402 | POLARSSL_CIPHER_CAMELLIA_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 403 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 404 | 128, |
| 405 | "CAMELLIA-128-CFB128", |
| 406 | 16, |
| 407 | 16, |
| 408 | &camellia_info |
| 409 | }; |
| 410 | |
| 411 | const cipher_info_t camellia_192_cfb128_info = { |
| 412 | POLARSSL_CIPHER_CAMELLIA_192_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 413 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 414 | 192, |
| 415 | "CAMELLIA-192-CFB128", |
| 416 | 16, |
| 417 | 16, |
| 418 | &camellia_info |
| 419 | }; |
| 420 | |
| 421 | const cipher_info_t camellia_256_cfb128_info = { |
| 422 | POLARSSL_CIPHER_CAMELLIA_256_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 423 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 424 | 256, |
| 425 | "CAMELLIA-256-CFB128", |
| 426 | 16, |
| 427 | 16, |
| 428 | &camellia_info |
| 429 | }; |
| 430 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 431 | |
| 432 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 433 | const cipher_info_t camellia_128_ctr_info = { |
| 434 | POLARSSL_CIPHER_CAMELLIA_128_CTR, |
| 435 | POLARSSL_MODE_CTR, |
| 436 | 128, |
| 437 | "CAMELLIA-128-CTR", |
| 438 | 16, |
| 439 | 16, |
| 440 | &camellia_info |
| 441 | }; |
| 442 | |
| 443 | const cipher_info_t camellia_192_ctr_info = { |
| 444 | POLARSSL_CIPHER_CAMELLIA_192_CTR, |
| 445 | POLARSSL_MODE_CTR, |
| 446 | 192, |
| 447 | "CAMELLIA-192-CTR", |
| 448 | 16, |
| 449 | 16, |
| 450 | &camellia_info |
| 451 | }; |
| 452 | |
| 453 | const cipher_info_t camellia_256_ctr_info = { |
| 454 | POLARSSL_CIPHER_CAMELLIA_256_CTR, |
| 455 | POLARSSL_MODE_CTR, |
| 456 | 256, |
| 457 | "CAMELLIA-256-CTR", |
| 458 | 16, |
| 459 | 16, |
| 460 | &camellia_info |
| 461 | }; |
| 462 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 463 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 464 | #endif |
| 465 | |
| 466 | #if defined(POLARSSL_DES_C) |
| 467 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 468 | 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] | 469 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 470 | { |
| 471 | return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output ); |
| 472 | } |
| 473 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 474 | 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] | 475 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 476 | { |
| 477 | return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output ); |
| 478 | } |
| 479 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 480 | 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] | 481 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 482 | { |
| 483 | ((void) ctx); |
| 484 | ((void) operation); |
| 485 | ((void) length); |
| 486 | ((void) iv_off); |
| 487 | ((void) iv); |
| 488 | ((void) input); |
| 489 | ((void) output); |
| 490 | |
| 491 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 492 | } |
| 493 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 494 | static int des_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 495 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 496 | const unsigned char *input, unsigned char *output ) |
| 497 | { |
| 498 | ((void) ctx); |
| 499 | ((void) length); |
| 500 | ((void) nc_off); |
| 501 | ((void) nonce_counter); |
| 502 | ((void) stream_block); |
| 503 | ((void) input); |
| 504 | ((void) output); |
| 505 | |
| 506 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 507 | } |
| 508 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 509 | 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] | 510 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 511 | ((void) key_length); |
| 512 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 513 | return des_setkey_dec( (des_context *) ctx, key ); |
| 514 | } |
| 515 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 516 | 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] | 517 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 518 | ((void) key_length); |
| 519 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 520 | return des_setkey_enc( (des_context *) ctx, key ); |
| 521 | } |
| 522 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 523 | 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] | 524 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 525 | ((void) key_length); |
| 526 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 527 | return des3_set2key_dec( (des3_context *) ctx, key ); |
| 528 | } |
| 529 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 530 | 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] | 531 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 532 | ((void) key_length); |
| 533 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 534 | return des3_set2key_enc( (des3_context *) ctx, key ); |
| 535 | } |
| 536 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 537 | 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] | 538 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 539 | ((void) key_length); |
| 540 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 541 | return des3_set3key_dec( (des3_context *) ctx, key ); |
| 542 | } |
| 543 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 544 | 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] | 545 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 546 | ((void) key_length); |
| 547 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 548 | return des3_set3key_enc( (des3_context *) ctx, key ); |
| 549 | } |
| 550 | |
| 551 | static void * des_ctx_alloc( void ) |
| 552 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 553 | return polarssl_malloc( sizeof( des_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static void * des3_ctx_alloc( void ) |
| 557 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 558 | return polarssl_malloc( sizeof( des3_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static void des_ctx_free( void *ctx ) |
| 562 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 563 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 566 | const cipher_base_t des_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 567 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 568 | des_crypt_cbc_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 569 | des_crypt_cfb128_wrap, |
| 570 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 571 | NULL, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 572 | des_setkey_enc_wrap, |
| 573 | des_setkey_dec_wrap, |
| 574 | des_ctx_alloc, |
| 575 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 576 | }; |
| 577 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 578 | const cipher_info_t des_cbc_info = { |
| 579 | POLARSSL_CIPHER_DES_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 580 | POLARSSL_MODE_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 581 | POLARSSL_KEY_LENGTH_DES, |
| 582 | "DES-CBC", |
| 583 | 8, |
| 584 | 8, |
| 585 | &des_info |
| 586 | }; |
| 587 | |
| 588 | const cipher_base_t des_ede_info = { |
| 589 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 590 | des3_crypt_cbc_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 591 | des_crypt_cfb128_wrap, |
| 592 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 593 | NULL, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 594 | des3_set2key_enc_wrap, |
| 595 | des3_set2key_dec_wrap, |
| 596 | des3_ctx_alloc, |
| 597 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 598 | }; |
| 599 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 600 | const cipher_info_t des_ede_cbc_info = { |
| 601 | POLARSSL_CIPHER_DES_EDE_CBC, |
| 602 | POLARSSL_MODE_CBC, |
| 603 | POLARSSL_KEY_LENGTH_DES_EDE, |
| 604 | "DES-EDE-CBC", |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 605 | 8, |
| 606 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 607 | &des_ede_info |
| 608 | }; |
| 609 | |
| 610 | const cipher_base_t des_ede3_info = { |
| 611 | POLARSSL_CIPHER_ID_DES, |
| 612 | des3_crypt_cbc_wrap, |
| 613 | des_crypt_cfb128_wrap, |
| 614 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 615 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 616 | des3_set3key_enc_wrap, |
| 617 | des3_set3key_dec_wrap, |
| 618 | des3_ctx_alloc, |
| 619 | des_ctx_free |
| 620 | }; |
| 621 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 622 | const cipher_info_t des_ede3_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 623 | POLARSSL_CIPHER_DES_EDE3_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 624 | POLARSSL_MODE_CBC, |
| 625 | POLARSSL_KEY_LENGTH_DES_EDE3, |
| 626 | "DES-EDE3-CBC", |
| 627 | 8, |
| 628 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 629 | &des_ede3_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 630 | }; |
| 631 | #endif |
| 632 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 633 | #if defined(POLARSSL_BLOWFISH_C) |
| 634 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 635 | 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] | 636 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 637 | { |
| 638 | return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output ); |
| 639 | } |
| 640 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 641 | 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] | 642 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 643 | { |
| 644 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 645 | return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output ); |
| 646 | #else |
| 647 | ((void) ctx); |
| 648 | ((void) operation); |
| 649 | ((void) length); |
| 650 | ((void) iv_off); |
| 651 | ((void) iv); |
| 652 | ((void) input); |
| 653 | ((void) output); |
| 654 | |
| 655 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 656 | #endif |
| 657 | } |
| 658 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 659 | static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 660 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 661 | const unsigned char *input, unsigned char *output ) |
| 662 | { |
| 663 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 664 | return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter, |
| 665 | stream_block, input, output ); |
| 666 | #else |
| 667 | ((void) ctx); |
| 668 | ((void) length); |
| 669 | ((void) nc_off); |
| 670 | ((void) nonce_counter); |
| 671 | ((void) stream_block); |
| 672 | ((void) input); |
| 673 | ((void) output); |
| 674 | |
| 675 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 676 | #endif |
| 677 | } |
| 678 | |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 679 | 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] | 680 | { |
| 681 | return blowfish_setkey( (blowfish_context *) ctx, key, key_length ); |
| 682 | } |
| 683 | |
| 684 | static void * blowfish_ctx_alloc( void ) |
| 685 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 686 | return polarssl_malloc( sizeof( blowfish_context ) ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static void blowfish_ctx_free( void *ctx ) |
| 690 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 691 | polarssl_free( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | const cipher_base_t blowfish_info = { |
| 695 | POLARSSL_CIPHER_ID_BLOWFISH, |
| 696 | blowfish_crypt_cbc_wrap, |
| 697 | blowfish_crypt_cfb64_wrap, |
| 698 | blowfish_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 699 | NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 700 | blowfish_setkey_wrap, |
| 701 | blowfish_setkey_wrap, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 702 | blowfish_ctx_alloc, |
| 703 | blowfish_ctx_free |
| 704 | }; |
| 705 | |
| 706 | const cipher_info_t blowfish_cbc_info = { |
| 707 | POLARSSL_CIPHER_BLOWFISH_CBC, |
| 708 | POLARSSL_MODE_CBC, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 709 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 710 | "BLOWFISH-CBC", |
| 711 | 8, |
| 712 | 8, |
| 713 | &blowfish_info |
| 714 | }; |
| 715 | |
| 716 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 717 | const cipher_info_t blowfish_cfb64_info = { |
| 718 | POLARSSL_CIPHER_BLOWFISH_CFB64, |
| 719 | POLARSSL_MODE_CFB, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 720 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 721 | "BLOWFISH-CFB64", |
| 722 | 8, |
| 723 | 8, |
| 724 | &blowfish_info |
| 725 | }; |
| 726 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 727 | |
| 728 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 729 | const cipher_info_t blowfish_ctr_info = { |
| 730 | POLARSSL_CIPHER_BLOWFISH_CTR, |
| 731 | POLARSSL_MODE_CTR, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 732 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 733 | "BLOWFISH-CTR", |
| 734 | 8, |
| 735 | 8, |
| 736 | &blowfish_info |
| 737 | }; |
| 738 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 739 | #endif /* POLARSSL_BLOWFISH_C */ |
| 740 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 741 | #if defined(POLARSSL_ARC4_C) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 742 | static int arc4_crypt_stream_wrap( void *ctx, size_t length, |
| 743 | const unsigned char *input, |
| 744 | unsigned char *output ) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 745 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 746 | return( arc4_crypt( (arc4_context *) ctx, length, input, output ) ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 749 | static int arc4_setkey_wrap( void *ctx, const unsigned char *key, |
| 750 | unsigned int key_length ) |
| 751 | { |
| 752 | arc4_setup( (arc4_context *) ctx, key, key_length ); |
| 753 | return( 0 ); |
| 754 | } |
| 755 | |
| 756 | static void * arc4_ctx_alloc( void ) |
| 757 | { |
| 758 | return polarssl_malloc( sizeof( arc4_context ) ); |
| 759 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 760 | |
| 761 | static void arc4_ctx_free( void *ctx ) |
| 762 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 763 | polarssl_free( ctx ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | const cipher_base_t arc4_base_info = { |
| 767 | POLARSSL_CIPHER_ID_ARC4, |
| 768 | NULL, |
| 769 | NULL, |
| 770 | NULL, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 771 | arc4_crypt_stream_wrap, |
| 772 | arc4_setkey_wrap, |
| 773 | arc4_setkey_wrap, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 774 | arc4_ctx_alloc, |
| 775 | arc4_ctx_free |
| 776 | }; |
| 777 | |
| 778 | const cipher_info_t arc4_128_info = { |
| 779 | POLARSSL_CIPHER_ARC4_128, |
| 780 | POLARSSL_MODE_STREAM, |
| 781 | 128, |
| 782 | "ARC4-128", |
| 783 | 0, |
| 784 | 1, |
| 785 | &arc4_base_info |
| 786 | }; |
| 787 | #endif /* POLARSSL_ARC4_C */ |
| 788 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 789 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 790 | static int null_crypt_stream( void *ctx, size_t length, |
| 791 | const unsigned char *input, |
| 792 | unsigned char *output ) |
| 793 | { |
| 794 | ((void) ctx); |
| 795 | memmove( output, input, length ); |
| 796 | return( 0 ); |
| 797 | } |
| 798 | |
| 799 | static int null_setkey( void *ctx, const unsigned char *key, |
| 800 | unsigned int key_length ) |
| 801 | { |
| 802 | ((void) ctx); |
| 803 | ((void) key); |
| 804 | ((void) key_length); |
| 805 | |
| 806 | return( 0 ); |
| 807 | } |
| 808 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 809 | static void * null_ctx_alloc( void ) |
| 810 | { |
| 811 | return (void *) 1; |
| 812 | } |
| 813 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 814 | static void null_ctx_free( void *ctx ) |
| 815 | { |
| 816 | ((void) ctx); |
| 817 | } |
| 818 | |
| 819 | const cipher_base_t null_base_info = { |
| 820 | POLARSSL_CIPHER_ID_NULL, |
| 821 | NULL, |
| 822 | NULL, |
| 823 | NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 824 | null_crypt_stream, |
| 825 | null_setkey, |
| 826 | null_setkey, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 827 | null_ctx_alloc, |
| 828 | null_ctx_free |
| 829 | }; |
| 830 | |
| 831 | const cipher_info_t null_cipher_info = { |
| 832 | POLARSSL_CIPHER_NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 833 | POLARSSL_MODE_STREAM, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 834 | 0, |
| 835 | "NULL", |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 836 | 0, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 837 | 1, |
| 838 | &null_base_info |
| 839 | }; |
| 840 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 841 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 842 | #endif |