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 | |
| 289 | const cipher_info_t aes_256_gcm_info = { |
| 290 | POLARSSL_CIPHER_AES_256_GCM, |
| 291 | POLARSSL_MODE_GCM, |
| 292 | 256, |
| 293 | "AES-256-GCM", |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 294 | 12, |
| 295 | 1, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 296 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 297 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 298 | }; |
| 299 | #endif /* POLARSSL_GCM_C */ |
| 300 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 301 | #endif |
| 302 | |
| 303 | #if defined(POLARSSL_CAMELLIA_C) |
| 304 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 305 | 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] | 306 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 307 | { |
| 308 | return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output ); |
| 309 | } |
| 310 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 311 | 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] | 312 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 313 | { |
| 314 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 315 | return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output ); |
| 316 | #else |
| 317 | ((void) ctx); |
| 318 | ((void) operation); |
| 319 | ((void) length); |
| 320 | ((void) iv_off); |
| 321 | ((void) iv); |
| 322 | ((void) input); |
| 323 | ((void) output); |
| 324 | |
| 325 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 326 | #endif |
| 327 | } |
| 328 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 329 | static int camellia_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 330 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 331 | const unsigned char *input, unsigned char *output ) |
| 332 | { |
| 333 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 334 | return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter, |
| 335 | stream_block, input, output ); |
| 336 | #else |
| 337 | ((void) ctx); |
| 338 | ((void) length); |
| 339 | ((void) nc_off); |
| 340 | ((void) nonce_counter); |
| 341 | ((void) stream_block); |
| 342 | ((void) input); |
| 343 | ((void) output); |
| 344 | |
| 345 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 346 | #endif |
| 347 | } |
| 348 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 349 | 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] | 350 | { |
| 351 | return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); |
| 352 | } |
| 353 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 354 | 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] | 355 | { |
| 356 | return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); |
| 357 | } |
| 358 | |
| 359 | static void * camellia_ctx_alloc( void ) |
| 360 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 361 | return polarssl_malloc( sizeof( camellia_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static void camellia_ctx_free( void *ctx ) |
| 365 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 366 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 369 | const cipher_base_t camellia_info = { |
| 370 | POLARSSL_CIPHER_ID_CAMELLIA, |
| 371 | camellia_crypt_cbc_wrap, |
| 372 | camellia_crypt_cfb128_wrap, |
| 373 | camellia_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 374 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 375 | camellia_setkey_enc_wrap, |
| 376 | camellia_setkey_dec_wrap, |
| 377 | camellia_ctx_alloc, |
| 378 | camellia_ctx_free |
| 379 | }; |
| 380 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 381 | const cipher_info_t camellia_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 382 | POLARSSL_CIPHER_CAMELLIA_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 383 | POLARSSL_MODE_CBC, |
| 384 | 128, |
| 385 | "CAMELLIA-128-CBC", |
| 386 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 387 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 388 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 389 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 390 | }; |
| 391 | |
| 392 | const cipher_info_t camellia_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 393 | POLARSSL_CIPHER_CAMELLIA_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 394 | POLARSSL_MODE_CBC, |
| 395 | 192, |
| 396 | "CAMELLIA-192-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_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 404 | POLARSSL_CIPHER_CAMELLIA_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 405 | POLARSSL_MODE_CBC, |
| 406 | 256, |
| 407 | "CAMELLIA-256-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 | }; |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 413 | |
| 414 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 415 | const cipher_info_t camellia_128_cfb128_info = { |
| 416 | POLARSSL_CIPHER_CAMELLIA_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 417 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 418 | 128, |
| 419 | "CAMELLIA-128-CFB128", |
| 420 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 421 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 422 | 16, |
| 423 | &camellia_info |
| 424 | }; |
| 425 | |
| 426 | const cipher_info_t camellia_192_cfb128_info = { |
| 427 | POLARSSL_CIPHER_CAMELLIA_192_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 | 192, |
| 430 | "CAMELLIA-192-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_256_cfb128_info = { |
| 438 | POLARSSL_CIPHER_CAMELLIA_256_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 | 256, |
| 441 | "CAMELLIA-256-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 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 448 | |
| 449 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 450 | const cipher_info_t camellia_128_ctr_info = { |
| 451 | POLARSSL_CIPHER_CAMELLIA_128_CTR, |
| 452 | POLARSSL_MODE_CTR, |
| 453 | 128, |
| 454 | "CAMELLIA-128-CTR", |
| 455 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 456 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 457 | 16, |
| 458 | &camellia_info |
| 459 | }; |
| 460 | |
| 461 | const cipher_info_t camellia_192_ctr_info = { |
| 462 | POLARSSL_CIPHER_CAMELLIA_192_CTR, |
| 463 | POLARSSL_MODE_CTR, |
| 464 | 192, |
| 465 | "CAMELLIA-192-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_256_ctr_info = { |
| 473 | POLARSSL_CIPHER_CAMELLIA_256_CTR, |
| 474 | POLARSSL_MODE_CTR, |
| 475 | 256, |
| 476 | "CAMELLIA-256-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 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 483 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 484 | #endif |
| 485 | |
| 486 | #if defined(POLARSSL_DES_C) |
| 487 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 488 | 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] | 489 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 490 | { |
| 491 | return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output ); |
| 492 | } |
| 493 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 494 | 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] | 495 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 496 | { |
| 497 | return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output ); |
| 498 | } |
| 499 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 500 | 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] | 501 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 502 | { |
| 503 | ((void) ctx); |
| 504 | ((void) operation); |
| 505 | ((void) length); |
| 506 | ((void) iv_off); |
| 507 | ((void) iv); |
| 508 | ((void) input); |
| 509 | ((void) output); |
| 510 | |
| 511 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 512 | } |
| 513 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 514 | static int des_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 515 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 516 | const unsigned char *input, unsigned char *output ) |
| 517 | { |
| 518 | ((void) ctx); |
| 519 | ((void) length); |
| 520 | ((void) nc_off); |
| 521 | ((void) nonce_counter); |
| 522 | ((void) stream_block); |
| 523 | ((void) input); |
| 524 | ((void) output); |
| 525 | |
| 526 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 527 | } |
| 528 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 529 | 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] | 530 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 531 | ((void) key_length); |
| 532 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 533 | return des_setkey_dec( (des_context *) ctx, key ); |
| 534 | } |
| 535 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 536 | 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] | 537 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 538 | ((void) key_length); |
| 539 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 540 | return des_setkey_enc( (des_context *) ctx, key ); |
| 541 | } |
| 542 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 543 | 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] | 544 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 545 | ((void) key_length); |
| 546 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 547 | return des3_set2key_dec( (des3_context *) ctx, key ); |
| 548 | } |
| 549 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 550 | 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] | 551 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 552 | ((void) key_length); |
| 553 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 554 | return des3_set2key_enc( (des3_context *) ctx, key ); |
| 555 | } |
| 556 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 557 | 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] | 558 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 559 | ((void) key_length); |
| 560 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 561 | return des3_set3key_dec( (des3_context *) ctx, key ); |
| 562 | } |
| 563 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 564 | 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] | 565 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 566 | ((void) key_length); |
| 567 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 568 | return des3_set3key_enc( (des3_context *) ctx, key ); |
| 569 | } |
| 570 | |
| 571 | static void * des_ctx_alloc( void ) |
| 572 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 573 | return polarssl_malloc( sizeof( des_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static void * des3_ctx_alloc( void ) |
| 577 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 578 | return polarssl_malloc( sizeof( des3_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | static void des_ctx_free( void *ctx ) |
| 582 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 583 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 584 | } |
| 585 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 586 | const cipher_base_t des_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 587 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 588 | des_crypt_cbc_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 589 | des_crypt_cfb128_wrap, |
| 590 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 591 | NULL, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 592 | des_setkey_enc_wrap, |
| 593 | des_setkey_dec_wrap, |
| 594 | des_ctx_alloc, |
| 595 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 596 | }; |
| 597 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 598 | const cipher_info_t des_cbc_info = { |
| 599 | POLARSSL_CIPHER_DES_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 600 | POLARSSL_MODE_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 601 | POLARSSL_KEY_LENGTH_DES, |
| 602 | "DES-CBC", |
| 603 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 604 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 605 | 8, |
| 606 | &des_info |
| 607 | }; |
| 608 | |
| 609 | const cipher_base_t des_ede_info = { |
| 610 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 611 | des3_crypt_cbc_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 612 | des_crypt_cfb128_wrap, |
| 613 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 614 | NULL, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 615 | des3_set2key_enc_wrap, |
| 616 | des3_set2key_dec_wrap, |
| 617 | des3_ctx_alloc, |
| 618 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 619 | }; |
| 620 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 621 | const cipher_info_t des_ede_cbc_info = { |
| 622 | POLARSSL_CIPHER_DES_EDE_CBC, |
| 623 | POLARSSL_MODE_CBC, |
| 624 | POLARSSL_KEY_LENGTH_DES_EDE, |
| 625 | "DES-EDE-CBC", |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 626 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 627 | 0, |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 628 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 629 | &des_ede_info |
| 630 | }; |
| 631 | |
| 632 | const cipher_base_t des_ede3_info = { |
| 633 | POLARSSL_CIPHER_ID_DES, |
| 634 | des3_crypt_cbc_wrap, |
| 635 | des_crypt_cfb128_wrap, |
| 636 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 637 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 638 | des3_set3key_enc_wrap, |
| 639 | des3_set3key_dec_wrap, |
| 640 | des3_ctx_alloc, |
| 641 | des_ctx_free |
| 642 | }; |
| 643 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 644 | const cipher_info_t des_ede3_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 645 | POLARSSL_CIPHER_DES_EDE3_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 646 | POLARSSL_MODE_CBC, |
| 647 | POLARSSL_KEY_LENGTH_DES_EDE3, |
| 648 | "DES-EDE3-CBC", |
| 649 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 650 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 651 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 652 | &des_ede3_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 653 | }; |
| 654 | #endif |
| 655 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 656 | #if defined(POLARSSL_BLOWFISH_C) |
| 657 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 658 | 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] | 659 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 660 | { |
| 661 | return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output ); |
| 662 | } |
| 663 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 664 | 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] | 665 | size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 666 | { |
| 667 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 668 | return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output ); |
| 669 | #else |
| 670 | ((void) ctx); |
| 671 | ((void) operation); |
| 672 | ((void) length); |
| 673 | ((void) iv_off); |
| 674 | ((void) iv); |
| 675 | ((void) input); |
| 676 | ((void) output); |
| 677 | |
| 678 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 679 | #endif |
| 680 | } |
| 681 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 682 | static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 683 | size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block, |
| 684 | const unsigned char *input, unsigned char *output ) |
| 685 | { |
| 686 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 687 | return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter, |
| 688 | stream_block, input, output ); |
| 689 | #else |
| 690 | ((void) ctx); |
| 691 | ((void) length); |
| 692 | ((void) nc_off); |
| 693 | ((void) nonce_counter); |
| 694 | ((void) stream_block); |
| 695 | ((void) input); |
| 696 | ((void) output); |
| 697 | |
| 698 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 699 | #endif |
| 700 | } |
| 701 | |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 702 | 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] | 703 | { |
| 704 | return blowfish_setkey( (blowfish_context *) ctx, key, key_length ); |
| 705 | } |
| 706 | |
| 707 | static void * blowfish_ctx_alloc( void ) |
| 708 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 709 | return polarssl_malloc( sizeof( blowfish_context ) ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static void blowfish_ctx_free( void *ctx ) |
| 713 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 714 | polarssl_free( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | const cipher_base_t blowfish_info = { |
| 718 | POLARSSL_CIPHER_ID_BLOWFISH, |
| 719 | blowfish_crypt_cbc_wrap, |
| 720 | blowfish_crypt_cfb64_wrap, |
| 721 | blowfish_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 722 | NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 723 | blowfish_setkey_wrap, |
| 724 | blowfish_setkey_wrap, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 725 | blowfish_ctx_alloc, |
| 726 | blowfish_ctx_free |
| 727 | }; |
| 728 | |
| 729 | const cipher_info_t blowfish_cbc_info = { |
| 730 | POLARSSL_CIPHER_BLOWFISH_CBC, |
| 731 | POLARSSL_MODE_CBC, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 732 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 733 | "BLOWFISH-CBC", |
| 734 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 735 | 0, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 736 | 8, |
| 737 | &blowfish_info |
| 738 | }; |
| 739 | |
| 740 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 741 | const cipher_info_t blowfish_cfb64_info = { |
| 742 | POLARSSL_CIPHER_BLOWFISH_CFB64, |
| 743 | POLARSSL_MODE_CFB, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 744 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 745 | "BLOWFISH-CFB64", |
| 746 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 747 | 0, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 748 | 8, |
| 749 | &blowfish_info |
| 750 | }; |
| 751 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 752 | |
| 753 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 754 | const cipher_info_t blowfish_ctr_info = { |
| 755 | POLARSSL_CIPHER_BLOWFISH_CTR, |
| 756 | POLARSSL_MODE_CTR, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 757 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 758 | "BLOWFISH-CTR", |
| 759 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 760 | 0, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 761 | 8, |
| 762 | &blowfish_info |
| 763 | }; |
| 764 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 765 | #endif /* POLARSSL_BLOWFISH_C */ |
| 766 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 767 | #if defined(POLARSSL_ARC4_C) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 768 | static int arc4_crypt_stream_wrap( void *ctx, size_t length, |
| 769 | const unsigned char *input, |
| 770 | unsigned char *output ) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 771 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 772 | return( arc4_crypt( (arc4_context *) ctx, length, input, output ) ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 773 | } |
| 774 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 775 | static int arc4_setkey_wrap( void *ctx, const unsigned char *key, |
| 776 | unsigned int key_length ) |
| 777 | { |
| 778 | arc4_setup( (arc4_context *) ctx, key, key_length ); |
| 779 | return( 0 ); |
| 780 | } |
| 781 | |
| 782 | static void * arc4_ctx_alloc( void ) |
| 783 | { |
| 784 | return polarssl_malloc( sizeof( arc4_context ) ); |
| 785 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 786 | |
| 787 | static void arc4_ctx_free( void *ctx ) |
| 788 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 789 | polarssl_free( ctx ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | const cipher_base_t arc4_base_info = { |
| 793 | POLARSSL_CIPHER_ID_ARC4, |
| 794 | NULL, |
| 795 | NULL, |
| 796 | NULL, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 797 | arc4_crypt_stream_wrap, |
| 798 | arc4_setkey_wrap, |
| 799 | arc4_setkey_wrap, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 800 | arc4_ctx_alloc, |
| 801 | arc4_ctx_free |
| 802 | }; |
| 803 | |
| 804 | const cipher_info_t arc4_128_info = { |
| 805 | POLARSSL_CIPHER_ARC4_128, |
| 806 | POLARSSL_MODE_STREAM, |
| 807 | 128, |
| 808 | "ARC4-128", |
| 809 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 810 | 0, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 811 | 1, |
| 812 | &arc4_base_info |
| 813 | }; |
| 814 | #endif /* POLARSSL_ARC4_C */ |
| 815 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 816 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 817 | static int null_crypt_stream( void *ctx, size_t length, |
| 818 | const unsigned char *input, |
| 819 | unsigned char *output ) |
| 820 | { |
| 821 | ((void) ctx); |
| 822 | memmove( output, input, length ); |
| 823 | return( 0 ); |
| 824 | } |
| 825 | |
| 826 | static int null_setkey( void *ctx, const unsigned char *key, |
| 827 | unsigned int key_length ) |
| 828 | { |
| 829 | ((void) ctx); |
| 830 | ((void) key); |
| 831 | ((void) key_length); |
| 832 | |
| 833 | return( 0 ); |
| 834 | } |
| 835 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 836 | static void * null_ctx_alloc( void ) |
| 837 | { |
| 838 | return (void *) 1; |
| 839 | } |
| 840 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 841 | static void null_ctx_free( void *ctx ) |
| 842 | { |
| 843 | ((void) ctx); |
| 844 | } |
| 845 | |
| 846 | const cipher_base_t null_base_info = { |
| 847 | POLARSSL_CIPHER_ID_NULL, |
| 848 | NULL, |
| 849 | NULL, |
| 850 | NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 851 | null_crypt_stream, |
| 852 | null_setkey, |
| 853 | null_setkey, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 854 | null_ctx_alloc, |
| 855 | null_ctx_free |
| 856 | }; |
| 857 | |
| 858 | const cipher_info_t null_cipher_info = { |
| 859 | POLARSSL_CIPHER_NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 860 | POLARSSL_MODE_STREAM, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 861 | 0, |
| 862 | "NULL", |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 863 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame^] | 864 | 0, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 865 | 1, |
| 866 | &null_base_info |
| 867 | }; |
| 868 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 869 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 870 | #endif |