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