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