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