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 | 9af723c | 2014-05-01 13:03:14 +0200 | [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 | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 8 | * Copyright (C) 2006-2014, 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 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 30 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 31 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 32 | #else |
| 33 | #include POLARSSL_CONFIG_FILE |
| 34 | #endif |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 35 | |
| 36 | #if defined(POLARSSL_CIPHER_C) |
| 37 | |
| 38 | #include "polarssl/cipher_wrap.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 39 | |
| 40 | #if defined(POLARSSL_AES_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 41 | #include "polarssl/aes.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 44 | #if defined(POLARSSL_ARC4_C) |
| 45 | #include "polarssl/arc4.h" |
| 46 | #endif |
| 47 | |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 48 | #if defined(POLARSSL_CAMELLIA_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 49 | #include "polarssl/camellia.h" |
Paul Bakker | f654371 | 2012-03-05 14:01:29 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
| 52 | #if defined(POLARSSL_DES_C) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 53 | #include "polarssl/des.h" |
Paul Bakker | 02f6169 | 2012-03-15 10:54:25 +0000 | [diff] [blame] | 54 | #endif |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 55 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 56 | #if defined(POLARSSL_BLOWFISH_C) |
| 57 | #include "polarssl/blowfish.h" |
| 58 | #endif |
| 59 | |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 60 | #if defined(POLARSSL_GCM_C) |
| 61 | #include "polarssl/gcm.h" |
| 62 | #endif |
| 63 | |
Paul Bakker | 7dc4c44 | 2014-02-01 22:50:26 +0100 | [diff] [blame] | 64 | #if defined(POLARSSL_PLATFORM_C) |
| 65 | #include "polarssl/platform.h" |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 66 | #else |
| 67 | #define polarssl_malloc malloc |
| 68 | #define polarssl_free free |
| 69 | #endif |
| 70 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 71 | #include <stdlib.h> |
| 72 | |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 73 | #if defined(POLARSSL_GCM_C) |
| 74 | /* shared by all GCM ciphers */ |
| 75 | static void *gcm_ctx_alloc( void ) |
| 76 | { |
| 77 | return polarssl_malloc( sizeof( gcm_context ) ); |
| 78 | } |
| 79 | |
| 80 | static void gcm_ctx_free( void *ctx ) |
| 81 | { |
| 82 | gcm_free( ctx ); |
| 83 | polarssl_free( ctx ); |
| 84 | } |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 85 | #endif /* POLARSSL_GCM_C */ |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 86 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 87 | #if defined(POLARSSL_AES_C) |
| 88 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 89 | static int aes_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 90 | const unsigned char *input, unsigned char *output ) |
| 91 | { |
| 92 | return aes_crypt_ecb( (aes_context *) ctx, operation, input, output ); |
| 93 | } |
| 94 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 95 | 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] | 96 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 97 | { |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 98 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 99 | return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, |
| 100 | output ); |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 101 | #else |
| 102 | ((void) ctx); |
| 103 | ((void) operation); |
| 104 | ((void) length); |
| 105 | ((void) iv); |
| 106 | ((void) input); |
| 107 | ((void) output); |
| 108 | |
| 109 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 110 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 113 | static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, |
| 114 | size_t length, size_t *iv_off, unsigned char *iv, |
| 115 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 116 | { |
| 117 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 118 | return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, |
| 119 | input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 120 | #else |
| 121 | ((void) ctx); |
| 122 | ((void) operation); |
| 123 | ((void) length); |
| 124 | ((void) iv_off); |
| 125 | ((void) iv); |
| 126 | ((void) input); |
| 127 | ((void) output); |
| 128 | |
| 129 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 130 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 133 | static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 134 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 135 | const unsigned char *input, unsigned char *output ) |
| 136 | { |
| 137 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 138 | return aes_crypt_ctr( (aes_context *) ctx, length, nc_off, nonce_counter, |
| 139 | stream_block, input, output ); |
| 140 | #else |
| 141 | ((void) ctx); |
| 142 | ((void) length); |
| 143 | ((void) nc_off); |
| 144 | ((void) nonce_counter); |
| 145 | ((void) stream_block); |
| 146 | ((void) input); |
| 147 | ((void) output); |
| 148 | |
| 149 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 150 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 153 | static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 154 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 155 | { |
| 156 | return aes_setkey_dec( (aes_context *) ctx, key, key_length ); |
| 157 | } |
| 158 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 159 | static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 160 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 161 | { |
| 162 | return aes_setkey_enc( (aes_context *) ctx, key, key_length ); |
| 163 | } |
| 164 | |
| 165 | static void * aes_ctx_alloc( void ) |
| 166 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 167 | return polarssl_malloc( sizeof( aes_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | static void aes_ctx_free( void *ctx ) |
| 171 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 172 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 175 | const cipher_base_t aes_info = { |
| 176 | POLARSSL_CIPHER_ID_AES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 177 | aes_crypt_ecb_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 178 | aes_crypt_cbc_wrap, |
| 179 | aes_crypt_cfb128_wrap, |
| 180 | aes_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 181 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 182 | aes_setkey_enc_wrap, |
| 183 | aes_setkey_dec_wrap, |
| 184 | aes_ctx_alloc, |
| 185 | aes_ctx_free |
| 186 | }; |
| 187 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 188 | const cipher_info_t aes_128_ecb_info = { |
| 189 | POLARSSL_CIPHER_AES_128_ECB, |
| 190 | POLARSSL_MODE_ECB, |
| 191 | 128, |
| 192 | "AES-128-ECB", |
| 193 | 16, |
| 194 | 0, |
| 195 | 16, |
| 196 | &aes_info |
| 197 | }; |
| 198 | |
| 199 | const cipher_info_t aes_192_ecb_info = { |
| 200 | POLARSSL_CIPHER_AES_192_ECB, |
| 201 | POLARSSL_MODE_ECB, |
| 202 | 192, |
| 203 | "AES-192-ECB", |
| 204 | 16, |
| 205 | 0, |
| 206 | 16, |
| 207 | &aes_info |
| 208 | }; |
| 209 | |
| 210 | const cipher_info_t aes_256_ecb_info = { |
| 211 | POLARSSL_CIPHER_AES_256_ECB, |
| 212 | POLARSSL_MODE_ECB, |
| 213 | 256, |
| 214 | "AES-256-ECB", |
| 215 | 16, |
| 216 | 0, |
| 217 | 16, |
| 218 | &aes_info |
| 219 | }; |
| 220 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 221 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 222 | const cipher_info_t aes_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 223 | POLARSSL_CIPHER_AES_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 224 | POLARSSL_MODE_CBC, |
| 225 | 128, |
| 226 | "AES-128-CBC", |
| 227 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 228 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 229 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 230 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | const cipher_info_t aes_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 234 | POLARSSL_CIPHER_AES_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 235 | POLARSSL_MODE_CBC, |
| 236 | 192, |
| 237 | "AES-192-CBC", |
| 238 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 239 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 240 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 241 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | const cipher_info_t aes_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 245 | POLARSSL_CIPHER_AES_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 246 | POLARSSL_MODE_CBC, |
| 247 | 256, |
| 248 | "AES-256-CBC", |
| 249 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 250 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 251 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 252 | &aes_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 253 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 254 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 255 | |
| 256 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 257 | const cipher_info_t aes_128_cfb128_info = { |
| 258 | POLARSSL_CIPHER_AES_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 259 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 260 | 128, |
| 261 | "AES-128-CFB128", |
| 262 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 263 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 264 | 16, |
| 265 | &aes_info |
| 266 | }; |
| 267 | |
| 268 | const cipher_info_t aes_192_cfb128_info = { |
| 269 | POLARSSL_CIPHER_AES_192_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 270 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 271 | 192, |
| 272 | "AES-192-CFB128", |
| 273 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 274 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 275 | 16, |
| 276 | &aes_info |
| 277 | }; |
| 278 | |
| 279 | const cipher_info_t aes_256_cfb128_info = { |
| 280 | POLARSSL_CIPHER_AES_256_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 281 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 282 | 256, |
| 283 | "AES-256-CFB128", |
| 284 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 285 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 286 | 16, |
| 287 | &aes_info |
| 288 | }; |
| 289 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 290 | |
| 291 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 292 | const cipher_info_t aes_128_ctr_info = { |
| 293 | POLARSSL_CIPHER_AES_128_CTR, |
| 294 | POLARSSL_MODE_CTR, |
| 295 | 128, |
| 296 | "AES-128-CTR", |
| 297 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 298 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 299 | 16, |
| 300 | &aes_info |
| 301 | }; |
| 302 | |
| 303 | const cipher_info_t aes_192_ctr_info = { |
| 304 | POLARSSL_CIPHER_AES_192_CTR, |
| 305 | POLARSSL_MODE_CTR, |
| 306 | 192, |
| 307 | "AES-192-CTR", |
| 308 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 309 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 310 | 16, |
| 311 | &aes_info |
| 312 | }; |
| 313 | |
| 314 | const cipher_info_t aes_256_ctr_info = { |
| 315 | POLARSSL_CIPHER_AES_256_CTR, |
| 316 | POLARSSL_MODE_CTR, |
| 317 | 256, |
| 318 | "AES-256-CTR", |
| 319 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 320 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 321 | 16, |
| 322 | &aes_info |
| 323 | }; |
| 324 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 325 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 326 | #if defined(POLARSSL_GCM_C) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 327 | static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, |
| 328 | unsigned int key_length ) |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 329 | { |
Paul Bakker | 43aff2a | 2013-09-09 00:10:27 +0200 | [diff] [blame] | 330 | return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES, |
| 331 | key, key_length ); |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | const cipher_base_t gcm_aes_info = { |
| 335 | POLARSSL_CIPHER_ID_AES, |
| 336 | NULL, |
| 337 | NULL, |
| 338 | NULL, |
| 339 | NULL, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 340 | NULL, |
Paul Bakker | 43aff2a | 2013-09-09 00:10:27 +0200 | [diff] [blame] | 341 | gcm_aes_setkey_wrap, |
| 342 | gcm_aes_setkey_wrap, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 343 | gcm_ctx_alloc, |
| 344 | gcm_ctx_free, |
| 345 | }; |
| 346 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 347 | const cipher_info_t aes_128_gcm_info = { |
| 348 | POLARSSL_CIPHER_AES_128_GCM, |
| 349 | POLARSSL_MODE_GCM, |
| 350 | 128, |
| 351 | "AES-128-GCM", |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 352 | 12, |
| 353 | 1, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 354 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 355 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 356 | }; |
| 357 | |
Manuel Pégourié-Gonnard | 83f3fc0 | 2013-09-04 12:07:24 +0200 | [diff] [blame] | 358 | const cipher_info_t aes_192_gcm_info = { |
| 359 | POLARSSL_CIPHER_AES_192_GCM, |
| 360 | POLARSSL_MODE_GCM, |
| 361 | 192, |
| 362 | "AES-192-GCM", |
| 363 | 12, |
| 364 | 1, |
| 365 | 16, |
| 366 | &gcm_aes_info |
| 367 | }; |
| 368 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 369 | const cipher_info_t aes_256_gcm_info = { |
| 370 | POLARSSL_CIPHER_AES_256_GCM, |
| 371 | POLARSSL_MODE_GCM, |
| 372 | 256, |
| 373 | "AES-256-GCM", |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 374 | 12, |
| 375 | 1, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 376 | 16, |
Manuel Pégourié-Gonnard | 07f8fa5 | 2013-08-30 18:34:08 +0200 | [diff] [blame] | 377 | &gcm_aes_info |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 378 | }; |
| 379 | #endif /* POLARSSL_GCM_C */ |
| 380 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 381 | #endif /* POLARSSL_AES_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 382 | |
| 383 | #if defined(POLARSSL_CAMELLIA_C) |
| 384 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 385 | static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 386 | const unsigned char *input, unsigned char *output ) |
| 387 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 388 | return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, |
| 389 | output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 390 | } |
| 391 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 392 | static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, |
| 393 | size_t length, unsigned char *iv, |
| 394 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 395 | { |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 396 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 397 | return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, |
| 398 | input, output ); |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 399 | #else |
| 400 | ((void) ctx); |
| 401 | ((void) operation); |
| 402 | ((void) length); |
| 403 | ((void) iv); |
| 404 | ((void) input); |
| 405 | ((void) output); |
| 406 | |
| 407 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 408 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 411 | static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, |
| 412 | size_t length, size_t *iv_off, unsigned char *iv, |
| 413 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 414 | { |
| 415 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 416 | return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, |
| 417 | iv_off, iv, input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 418 | #else |
| 419 | ((void) ctx); |
| 420 | ((void) operation); |
| 421 | ((void) length); |
| 422 | ((void) iv_off); |
| 423 | ((void) iv); |
| 424 | ((void) input); |
| 425 | ((void) output); |
| 426 | |
| 427 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 428 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 431 | static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 432 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 433 | const unsigned char *input, unsigned char *output ) |
| 434 | { |
| 435 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 436 | return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, |
| 437 | nonce_counter, stream_block, input, output ); |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 438 | #else |
| 439 | ((void) ctx); |
| 440 | ((void) length); |
| 441 | ((void) nc_off); |
| 442 | ((void) nonce_counter); |
| 443 | ((void) stream_block); |
| 444 | ((void) input); |
| 445 | ((void) output); |
| 446 | |
| 447 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 448 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 451 | static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 452 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 453 | { |
| 454 | return camellia_setkey_dec( (camellia_context *) ctx, key, key_length ); |
| 455 | } |
| 456 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 457 | static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 458 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 459 | { |
| 460 | return camellia_setkey_enc( (camellia_context *) ctx, key, key_length ); |
| 461 | } |
| 462 | |
| 463 | static void * camellia_ctx_alloc( void ) |
| 464 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 465 | return polarssl_malloc( sizeof( camellia_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static void camellia_ctx_free( void *ctx ) |
| 469 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 470 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 473 | const cipher_base_t camellia_info = { |
| 474 | POLARSSL_CIPHER_ID_CAMELLIA, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 475 | camellia_crypt_ecb_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 476 | camellia_crypt_cbc_wrap, |
| 477 | camellia_crypt_cfb128_wrap, |
| 478 | camellia_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 479 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 480 | camellia_setkey_enc_wrap, |
| 481 | camellia_setkey_dec_wrap, |
| 482 | camellia_ctx_alloc, |
| 483 | camellia_ctx_free |
| 484 | }; |
| 485 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 486 | const cipher_info_t camellia_128_ecb_info = { |
| 487 | POLARSSL_CIPHER_CAMELLIA_128_ECB, |
| 488 | POLARSSL_MODE_ECB, |
| 489 | 128, |
| 490 | "CAMELLIA-128-ECB", |
| 491 | 16, |
| 492 | 0, |
| 493 | 16, |
| 494 | &camellia_info |
| 495 | }; |
| 496 | |
| 497 | const cipher_info_t camellia_192_ecb_info = { |
| 498 | POLARSSL_CIPHER_CAMELLIA_192_ECB, |
| 499 | POLARSSL_MODE_ECB, |
| 500 | 192, |
| 501 | "CAMELLIA-192-ECB", |
| 502 | 16, |
| 503 | 0, |
| 504 | 16, |
| 505 | &camellia_info |
| 506 | }; |
| 507 | |
| 508 | const cipher_info_t camellia_256_ecb_info = { |
| 509 | POLARSSL_CIPHER_CAMELLIA_256_ECB, |
| 510 | POLARSSL_MODE_ECB, |
| 511 | 256, |
| 512 | "CAMELLIA-256-ECB", |
| 513 | 16, |
| 514 | 0, |
| 515 | 16, |
| 516 | &camellia_info |
| 517 | }; |
| 518 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 519 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 520 | const cipher_info_t camellia_128_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 521 | POLARSSL_CIPHER_CAMELLIA_128_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 522 | POLARSSL_MODE_CBC, |
| 523 | 128, |
| 524 | "CAMELLIA-128-CBC", |
| 525 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 526 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 527 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 528 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | const cipher_info_t camellia_192_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 532 | POLARSSL_CIPHER_CAMELLIA_192_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 533 | POLARSSL_MODE_CBC, |
| 534 | 192, |
| 535 | "CAMELLIA-192-CBC", |
| 536 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 537 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 538 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 539 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 540 | }; |
| 541 | |
| 542 | const cipher_info_t camellia_256_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 543 | POLARSSL_CIPHER_CAMELLIA_256_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 544 | POLARSSL_MODE_CBC, |
| 545 | 256, |
| 546 | "CAMELLIA-256-CBC", |
| 547 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 548 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 549 | 16, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 550 | &camellia_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 551 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 552 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 553 | |
| 554 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 555 | const cipher_info_t camellia_128_cfb128_info = { |
| 556 | POLARSSL_CIPHER_CAMELLIA_128_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 557 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 558 | 128, |
| 559 | "CAMELLIA-128-CFB128", |
| 560 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 561 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 562 | 16, |
| 563 | &camellia_info |
| 564 | }; |
| 565 | |
| 566 | const cipher_info_t camellia_192_cfb128_info = { |
| 567 | POLARSSL_CIPHER_CAMELLIA_192_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 568 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 569 | 192, |
| 570 | "CAMELLIA-192-CFB128", |
| 571 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 572 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 573 | 16, |
| 574 | &camellia_info |
| 575 | }; |
| 576 | |
| 577 | const cipher_info_t camellia_256_cfb128_info = { |
| 578 | POLARSSL_CIPHER_CAMELLIA_256_CFB128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 579 | POLARSSL_MODE_CFB, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 580 | 256, |
| 581 | "CAMELLIA-256-CFB128", |
| 582 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 583 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 584 | 16, |
| 585 | &camellia_info |
| 586 | }; |
| 587 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 588 | |
| 589 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 590 | const cipher_info_t camellia_128_ctr_info = { |
| 591 | POLARSSL_CIPHER_CAMELLIA_128_CTR, |
| 592 | POLARSSL_MODE_CTR, |
| 593 | 128, |
| 594 | "CAMELLIA-128-CTR", |
| 595 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 596 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 597 | 16, |
| 598 | &camellia_info |
| 599 | }; |
| 600 | |
| 601 | const cipher_info_t camellia_192_ctr_info = { |
| 602 | POLARSSL_CIPHER_CAMELLIA_192_CTR, |
| 603 | POLARSSL_MODE_CTR, |
| 604 | 192, |
| 605 | "CAMELLIA-192-CTR", |
| 606 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 607 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 608 | 16, |
| 609 | &camellia_info |
| 610 | }; |
| 611 | |
| 612 | const cipher_info_t camellia_256_ctr_info = { |
| 613 | POLARSSL_CIPHER_CAMELLIA_256_CTR, |
| 614 | POLARSSL_MODE_CTR, |
| 615 | 256, |
| 616 | "CAMELLIA-256-CTR", |
| 617 | 16, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 618 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 619 | 16, |
| 620 | &camellia_info |
| 621 | }; |
| 622 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 623 | |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 624 | #if defined(POLARSSL_GCM_C) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 625 | static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key, |
| 626 | unsigned int key_length ) |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 627 | { |
| 628 | return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA, |
| 629 | key, key_length ); |
| 630 | } |
| 631 | |
| 632 | const cipher_base_t gcm_camellia_info = { |
| 633 | POLARSSL_CIPHER_ID_CAMELLIA, |
| 634 | NULL, |
| 635 | NULL, |
| 636 | NULL, |
| 637 | NULL, |
| 638 | NULL, |
| 639 | gcm_camellia_setkey_wrap, |
| 640 | gcm_camellia_setkey_wrap, |
| 641 | gcm_ctx_alloc, |
| 642 | gcm_ctx_free, |
| 643 | }; |
| 644 | |
| 645 | const cipher_info_t camellia_128_gcm_info = { |
| 646 | POLARSSL_CIPHER_CAMELLIA_128_GCM, |
| 647 | POLARSSL_MODE_GCM, |
| 648 | 128, |
| 649 | "CAMELLIA-128-GCM", |
| 650 | 12, |
| 651 | 1, |
| 652 | 16, |
| 653 | &gcm_camellia_info |
| 654 | }; |
| 655 | |
| 656 | const cipher_info_t camellia_192_gcm_info = { |
| 657 | POLARSSL_CIPHER_CAMELLIA_192_GCM, |
| 658 | POLARSSL_MODE_GCM, |
| 659 | 192, |
| 660 | "CAMELLIA-192-GCM", |
| 661 | 12, |
| 662 | 1, |
| 663 | 16, |
| 664 | &gcm_camellia_info |
| 665 | }; |
| 666 | |
| 667 | const cipher_info_t camellia_256_gcm_info = { |
| 668 | POLARSSL_CIPHER_CAMELLIA_256_GCM, |
| 669 | POLARSSL_MODE_GCM, |
| 670 | 256, |
| 671 | "CAMELLIA-256-GCM", |
| 672 | 12, |
| 673 | 1, |
| 674 | 16, |
| 675 | &gcm_camellia_info |
| 676 | }; |
| 677 | #endif /* POLARSSL_GCM_C */ |
| 678 | |
| 679 | #endif /* POLARSSL_CAMELLIA_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 680 | |
| 681 | #if defined(POLARSSL_DES_C) |
| 682 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 683 | static int des_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 684 | const unsigned char *input, unsigned char *output ) |
| 685 | { |
| 686 | ((void) operation); |
| 687 | return des_crypt_ecb( (des_context *) ctx, input, output ); |
| 688 | } |
| 689 | |
| 690 | static int des3_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 691 | const unsigned char *input, unsigned char *output ) |
| 692 | { |
| 693 | ((void) operation); |
| 694 | return des3_crypt_ecb( (des3_context *) ctx, input, output ); |
| 695 | } |
| 696 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 697 | 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] | 698 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 699 | { |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 700 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 701 | return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, |
| 702 | output ); |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 703 | #else |
| 704 | ((void) ctx); |
| 705 | ((void) operation); |
| 706 | ((void) length); |
| 707 | ((void) iv); |
| 708 | ((void) input); |
| 709 | ((void) output); |
| 710 | |
| 711 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 712 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Paul Bakker | fae35f0 | 2013-03-13 10:33:51 +0100 | [diff] [blame] | 715 | 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] | 716 | unsigned char *iv, const unsigned char *input, unsigned char *output ) |
| 717 | { |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 718 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 719 | return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, |
| 720 | output ); |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 721 | #else |
| 722 | ((void) ctx); |
| 723 | ((void) operation); |
| 724 | ((void) length); |
| 725 | ((void) iv); |
| 726 | ((void) input); |
| 727 | ((void) output); |
| 728 | |
| 729 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 730 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 731 | } |
| 732 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 733 | static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, |
| 734 | size_t length, size_t *iv_off, unsigned char *iv, |
| 735 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 736 | { |
| 737 | ((void) ctx); |
| 738 | ((void) operation); |
| 739 | ((void) length); |
| 740 | ((void) iv_off); |
| 741 | ((void) iv); |
| 742 | ((void) input); |
| 743 | ((void) output); |
| 744 | |
| 745 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 746 | } |
| 747 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 748 | static int des_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 749 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 750 | const unsigned char *input, unsigned char *output ) |
| 751 | { |
| 752 | ((void) ctx); |
| 753 | ((void) length); |
| 754 | ((void) nc_off); |
| 755 | ((void) nonce_counter); |
| 756 | ((void) stream_block); |
| 757 | ((void) input); |
| 758 | ((void) output); |
| 759 | |
| 760 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 761 | } |
| 762 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 763 | static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, |
| 764 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 765 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 766 | ((void) key_length); |
| 767 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 768 | return des_setkey_dec( (des_context *) ctx, key ); |
| 769 | } |
| 770 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 771 | static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, |
| 772 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 773 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 774 | ((void) key_length); |
| 775 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 776 | return des_setkey_enc( (des_context *) ctx, key ); |
| 777 | } |
| 778 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 779 | static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, |
| 780 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 781 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 782 | ((void) key_length); |
| 783 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 784 | return des3_set2key_dec( (des3_context *) ctx, key ); |
| 785 | } |
| 786 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 787 | static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, |
| 788 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 789 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 790 | ((void) key_length); |
| 791 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 792 | return des3_set2key_enc( (des3_context *) ctx, key ); |
| 793 | } |
| 794 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 795 | static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, |
| 796 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 797 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 798 | ((void) key_length); |
| 799 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 800 | return des3_set3key_dec( (des3_context *) ctx, key ); |
| 801 | } |
| 802 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 803 | static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, |
| 804 | unsigned int key_length ) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 805 | { |
Paul Bakker | d61e7d9 | 2011-01-18 16:17:47 +0000 | [diff] [blame] | 806 | ((void) key_length); |
| 807 | |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 808 | return des3_set3key_enc( (des3_context *) ctx, key ); |
| 809 | } |
| 810 | |
| 811 | static void * des_ctx_alloc( void ) |
| 812 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 813 | return polarssl_malloc( sizeof( des_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void * des3_ctx_alloc( void ) |
| 817 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 818 | return polarssl_malloc( sizeof( des3_context ) ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | static void des_ctx_free( void *ctx ) |
| 822 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 823 | polarssl_free( ctx ); |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 826 | const cipher_base_t des_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 827 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 828 | des_crypt_ecb_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 829 | des_crypt_cbc_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 830 | des_crypt_cfb128_wrap, |
| 831 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 832 | NULL, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 833 | des_setkey_enc_wrap, |
| 834 | des_setkey_dec_wrap, |
| 835 | des_ctx_alloc, |
| 836 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 837 | }; |
| 838 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 839 | const cipher_info_t des_ecb_info = { |
| 840 | POLARSSL_CIPHER_DES_ECB, |
| 841 | POLARSSL_MODE_ECB, |
| 842 | POLARSSL_KEY_LENGTH_DES, |
| 843 | "DES-ECB", |
| 844 | 8, |
| 845 | 0, |
| 846 | 8, |
| 847 | &des_info |
| 848 | }; |
| 849 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 850 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 851 | const cipher_info_t des_cbc_info = { |
| 852 | POLARSSL_CIPHER_DES_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 853 | POLARSSL_MODE_CBC, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 854 | POLARSSL_KEY_LENGTH_DES, |
| 855 | "DES-CBC", |
| 856 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 857 | 0, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 858 | 8, |
| 859 | &des_info |
| 860 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 861 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 862 | |
| 863 | const cipher_base_t des_ede_info = { |
| 864 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 865 | des3_crypt_ecb_wrap, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 866 | des3_crypt_cbc_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 867 | des_crypt_cfb128_wrap, |
| 868 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 869 | NULL, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 870 | des3_set2key_enc_wrap, |
| 871 | des3_set2key_dec_wrap, |
| 872 | des3_ctx_alloc, |
| 873 | des_ctx_free |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 874 | }; |
| 875 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 876 | const cipher_info_t des_ede_ecb_info = { |
| 877 | POLARSSL_CIPHER_DES_EDE_ECB, |
| 878 | POLARSSL_MODE_ECB, |
| 879 | POLARSSL_KEY_LENGTH_DES_EDE, |
| 880 | "DES-EDE-ECB", |
| 881 | 8, |
| 882 | 0, |
| 883 | 8, |
| 884 | &des_ede_info |
| 885 | }; |
| 886 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 887 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 888 | const cipher_info_t des_ede_cbc_info = { |
| 889 | POLARSSL_CIPHER_DES_EDE_CBC, |
| 890 | POLARSSL_MODE_CBC, |
| 891 | POLARSSL_KEY_LENGTH_DES_EDE, |
| 892 | "DES-EDE-CBC", |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 893 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 894 | 0, |
Paul Bakker | 0e34235 | 2013-06-24 19:33:02 +0200 | [diff] [blame] | 895 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 896 | &des_ede_info |
| 897 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 898 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 899 | |
| 900 | const cipher_base_t des_ede3_info = { |
| 901 | POLARSSL_CIPHER_ID_DES, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 902 | des3_crypt_ecb_wrap, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 903 | des3_crypt_cbc_wrap, |
| 904 | des_crypt_cfb128_wrap, |
| 905 | des_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 906 | NULL, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 907 | des3_set3key_enc_wrap, |
| 908 | des3_set3key_dec_wrap, |
| 909 | des3_ctx_alloc, |
| 910 | des_ctx_free |
| 911 | }; |
| 912 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 913 | const cipher_info_t des_ede3_ecb_info = { |
| 914 | POLARSSL_CIPHER_DES_EDE3_ECB, |
| 915 | POLARSSL_MODE_ECB, |
| 916 | POLARSSL_KEY_LENGTH_DES_EDE3, |
| 917 | "DES-EDE3-ECB", |
| 918 | 8, |
| 919 | 0, |
| 920 | 8, |
| 921 | &des_ede3_info |
| 922 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 923 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 924 | const cipher_info_t des_ede3_cbc_info = { |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 925 | POLARSSL_CIPHER_DES_EDE3_CBC, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 926 | POLARSSL_MODE_CBC, |
| 927 | POLARSSL_KEY_LENGTH_DES_EDE3, |
| 928 | "DES-EDE3-CBC", |
| 929 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 930 | 0, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 931 | 8, |
Paul Bakker | 343a870 | 2011-06-09 14:27:58 +0000 | [diff] [blame] | 932 | &des_ede3_info |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 933 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 934 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 935 | #endif /* POLARSSL_DES_C */ |
Paul Bakker | 8123e9d | 2011-01-06 15:37:30 +0000 | [diff] [blame] | 936 | |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 937 | #if defined(POLARSSL_BLOWFISH_C) |
| 938 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 939 | static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation, |
| 940 | const unsigned char *input, unsigned char *output ) |
| 941 | { |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 942 | return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, |
| 943 | output ); |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 944 | } |
| 945 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 946 | static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, |
| 947 | size_t length, unsigned char *iv, const unsigned char *input, |
| 948 | unsigned char *output ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 949 | { |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 950 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 951 | return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, |
| 952 | input, output ); |
Manuel Pégourié-Gonnard | 92cb1d3 | 2013-09-13 16:24:20 +0200 | [diff] [blame] | 953 | #else |
| 954 | ((void) ctx); |
| 955 | ((void) operation); |
| 956 | ((void) length); |
| 957 | ((void) iv); |
| 958 | ((void) input); |
| 959 | ((void) output); |
| 960 | |
| 961 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
| 962 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 963 | } |
| 964 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 965 | static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, |
| 966 | size_t length, size_t *iv_off, unsigned char *iv, |
| 967 | const unsigned char *input, unsigned char *output ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 968 | { |
| 969 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 970 | return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, |
| 971 | iv_off, iv, input, output ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 972 | #else |
| 973 | ((void) ctx); |
| 974 | ((void) operation); |
| 975 | ((void) length); |
| 976 | ((void) iv_off); |
| 977 | ((void) iv); |
| 978 | ((void) input); |
| 979 | ((void) output); |
| 980 | |
| 981 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 982 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 983 | } |
| 984 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 985 | static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off, |
| 986 | unsigned char *nonce_counter, unsigned char *stream_block, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 987 | const unsigned char *input, unsigned char *output ) |
| 988 | { |
| 989 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 990 | return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, |
| 991 | nonce_counter, stream_block, input, output ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 992 | #else |
| 993 | ((void) ctx); |
| 994 | ((void) length); |
| 995 | ((void) nc_off); |
| 996 | ((void) nonce_counter); |
| 997 | ((void) stream_block); |
| 998 | ((void) input); |
| 999 | ((void) output); |
| 1000 | |
| 1001 | return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE; |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 1002 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Paul Bakker | b9e4e2c | 2014-05-01 14:18:25 +0200 | [diff] [blame^] | 1005 | static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, |
| 1006 | unsigned int key_length ) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1007 | { |
| 1008 | return blowfish_setkey( (blowfish_context *) ctx, key, key_length ); |
| 1009 | } |
| 1010 | |
| 1011 | static void * blowfish_ctx_alloc( void ) |
| 1012 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 1013 | return polarssl_malloc( sizeof( blowfish_context ) ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | static void blowfish_ctx_free( void *ctx ) |
| 1017 | { |
Paul Bakker | 6e339b5 | 2013-07-03 13:37:05 +0200 | [diff] [blame] | 1018 | polarssl_free( ctx ); |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | const cipher_base_t blowfish_info = { |
| 1022 | POLARSSL_CIPHER_ID_BLOWFISH, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1023 | blowfish_crypt_ecb_wrap, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1024 | blowfish_crypt_cbc_wrap, |
| 1025 | blowfish_crypt_cfb64_wrap, |
| 1026 | blowfish_crypt_ctr_wrap, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1027 | NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1028 | blowfish_setkey_wrap, |
| 1029 | blowfish_setkey_wrap, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1030 | blowfish_ctx_alloc, |
| 1031 | blowfish_ctx_free |
| 1032 | }; |
| 1033 | |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1034 | const cipher_info_t blowfish_ecb_info = { |
| 1035 | POLARSSL_CIPHER_BLOWFISH_ECB, |
| 1036 | POLARSSL_MODE_ECB, |
| 1037 | 128, |
| 1038 | "BLOWFISH-ECB", |
| 1039 | 8, |
| 1040 | 0, |
| 1041 | 8, |
| 1042 | &blowfish_info |
| 1043 | }; |
| 1044 | |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1045 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1046 | const cipher_info_t blowfish_cbc_info = { |
| 1047 | POLARSSL_CIPHER_BLOWFISH_CBC, |
| 1048 | POLARSSL_MODE_CBC, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1049 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1050 | "BLOWFISH-CBC", |
| 1051 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1052 | 0, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1053 | 8, |
| 1054 | &blowfish_info |
| 1055 | }; |
Manuel Pégourié-Gonnard | 989ed38 | 2013-09-13 14:41:45 +0200 | [diff] [blame] | 1056 | #endif /* POLARSSL_CIPHER_MODE_CBC */ |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1057 | |
| 1058 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1059 | const cipher_info_t blowfish_cfb64_info = { |
| 1060 | POLARSSL_CIPHER_BLOWFISH_CFB64, |
| 1061 | POLARSSL_MODE_CFB, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1062 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1063 | "BLOWFISH-CFB64", |
| 1064 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1065 | 0, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1066 | 8, |
| 1067 | &blowfish_info |
| 1068 | }; |
| 1069 | #endif /* POLARSSL_CIPHER_MODE_CFB */ |
| 1070 | |
| 1071 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1072 | const cipher_info_t blowfish_ctr_info = { |
| 1073 | POLARSSL_CIPHER_BLOWFISH_CTR, |
| 1074 | POLARSSL_MODE_CTR, |
Paul Bakker | bfe671f | 2013-04-07 22:35:44 +0200 | [diff] [blame] | 1075 | 128, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1076 | "BLOWFISH-CTR", |
| 1077 | 8, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1078 | 0, |
Paul Bakker | 6132d0a | 2012-07-04 17:10:40 +0000 | [diff] [blame] | 1079 | 8, |
| 1080 | &blowfish_info |
| 1081 | }; |
| 1082 | #endif /* POLARSSL_CIPHER_MODE_CTR */ |
| 1083 | #endif /* POLARSSL_BLOWFISH_C */ |
| 1084 | |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1085 | #if defined(POLARSSL_ARC4_C) |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1086 | static int arc4_crypt_stream_wrap( void *ctx, size_t length, |
| 1087 | const unsigned char *input, |
| 1088 | unsigned char *output ) |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1089 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1090 | return( arc4_crypt( (arc4_context *) ctx, length, input, output ) ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1093 | static int arc4_setkey_wrap( void *ctx, const unsigned char *key, |
| 1094 | unsigned int key_length ) |
| 1095 | { |
Manuel Pégourié-Gonnard | ce41125 | 2013-09-04 12:28:37 +0200 | [diff] [blame] | 1096 | /* we get key_length in bits, arc4 expects it in bytes */ |
| 1097 | if( key_length % 8 != 0) |
| 1098 | return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA ); |
| 1099 | |
| 1100 | arc4_setup( (arc4_context *) ctx, key, key_length / 8 ); |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1101 | return( 0 ); |
| 1102 | } |
| 1103 | |
| 1104 | static void * arc4_ctx_alloc( void ) |
| 1105 | { |
| 1106 | return polarssl_malloc( sizeof( arc4_context ) ); |
| 1107 | } |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1108 | |
| 1109 | static void arc4_ctx_free( void *ctx ) |
| 1110 | { |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1111 | polarssl_free( ctx ); |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | const cipher_base_t arc4_base_info = { |
| 1115 | POLARSSL_CIPHER_ID_ARC4, |
| 1116 | NULL, |
| 1117 | NULL, |
| 1118 | NULL, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1119 | NULL, |
Manuel Pégourié-Gonnard | 37e230c | 2013-08-28 13:50:42 +0200 | [diff] [blame] | 1120 | arc4_crypt_stream_wrap, |
| 1121 | arc4_setkey_wrap, |
| 1122 | arc4_setkey_wrap, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1123 | arc4_ctx_alloc, |
| 1124 | arc4_ctx_free |
| 1125 | }; |
| 1126 | |
| 1127 | const cipher_info_t arc4_128_info = { |
| 1128 | POLARSSL_CIPHER_ARC4_128, |
| 1129 | POLARSSL_MODE_STREAM, |
| 1130 | 128, |
| 1131 | "ARC4-128", |
| 1132 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1133 | 0, |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1134 | 1, |
| 1135 | &arc4_base_info |
| 1136 | }; |
| 1137 | #endif /* POLARSSL_ARC4_C */ |
| 1138 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1139 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1140 | static int null_crypt_stream( void *ctx, size_t length, |
| 1141 | const unsigned char *input, |
| 1142 | unsigned char *output ) |
| 1143 | { |
| 1144 | ((void) ctx); |
| 1145 | memmove( output, input, length ); |
| 1146 | return( 0 ); |
| 1147 | } |
| 1148 | |
| 1149 | static int null_setkey( void *ctx, const unsigned char *key, |
| 1150 | unsigned int key_length ) |
| 1151 | { |
| 1152 | ((void) ctx); |
| 1153 | ((void) key); |
| 1154 | ((void) key_length); |
| 1155 | |
| 1156 | return( 0 ); |
| 1157 | } |
| 1158 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1159 | static void * null_ctx_alloc( void ) |
| 1160 | { |
| 1161 | return (void *) 1; |
| 1162 | } |
| 1163 | |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1164 | static void null_ctx_free( void *ctx ) |
| 1165 | { |
| 1166 | ((void) ctx); |
| 1167 | } |
| 1168 | |
| 1169 | const cipher_base_t null_base_info = { |
| 1170 | POLARSSL_CIPHER_ID_NULL, |
| 1171 | NULL, |
| 1172 | NULL, |
| 1173 | NULL, |
Paul Bakker | 5e0efa7 | 2013-09-08 23:04:04 +0200 | [diff] [blame] | 1174 | NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1175 | null_crypt_stream, |
| 1176 | null_setkey, |
| 1177 | null_setkey, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1178 | null_ctx_alloc, |
| 1179 | null_ctx_free |
| 1180 | }; |
| 1181 | |
| 1182 | const cipher_info_t null_cipher_info = { |
| 1183 | POLARSSL_CIPHER_NULL, |
Manuel Pégourié-Gonnard | b5e8588 | 2013-08-28 16:36:14 +0200 | [diff] [blame] | 1184 | POLARSSL_MODE_STREAM, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1185 | 0, |
| 1186 | "NULL", |
Paul Bakker | 68884e3 | 2013-01-07 18:20:04 +0100 | [diff] [blame] | 1187 | 0, |
Manuel Pégourié-Gonnard | a235b5b | 2013-09-03 13:25:52 +0200 | [diff] [blame] | 1188 | 0, |
Paul Bakker | fab5c82 | 2012-02-06 16:45:10 +0000 | [diff] [blame] | 1189 | 1, |
| 1190 | &null_base_info |
| 1191 | }; |
| 1192 | #endif /* defined(POLARSSL_CIPHER_NULL_CIPHER) */ |
| 1193 | |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1194 | const cipher_definition_t cipher_definitions[] = |
| 1195 | { |
| 1196 | #if defined(POLARSSL_AES_C) |
| 1197 | { POLARSSL_CIPHER_AES_128_ECB, &aes_128_ecb_info }, |
| 1198 | { POLARSSL_CIPHER_AES_192_ECB, &aes_192_ecb_info }, |
| 1199 | { POLARSSL_CIPHER_AES_256_ECB, &aes_256_ecb_info }, |
| 1200 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1201 | { POLARSSL_CIPHER_AES_128_CBC, &aes_128_cbc_info }, |
| 1202 | { POLARSSL_CIPHER_AES_192_CBC, &aes_192_cbc_info }, |
| 1203 | { POLARSSL_CIPHER_AES_256_CBC, &aes_256_cbc_info }, |
| 1204 | #endif |
| 1205 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1206 | { POLARSSL_CIPHER_AES_128_CFB128, &aes_128_cfb128_info }, |
| 1207 | { POLARSSL_CIPHER_AES_192_CFB128, &aes_192_cfb128_info }, |
| 1208 | { POLARSSL_CIPHER_AES_256_CFB128, &aes_256_cfb128_info }, |
| 1209 | #endif |
| 1210 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1211 | { POLARSSL_CIPHER_AES_128_CTR, &aes_128_ctr_info }, |
| 1212 | { POLARSSL_CIPHER_AES_192_CTR, &aes_192_ctr_info }, |
| 1213 | { POLARSSL_CIPHER_AES_256_CTR, &aes_256_ctr_info }, |
| 1214 | #endif |
| 1215 | #if defined(POLARSSL_GCM_C) |
| 1216 | { POLARSSL_CIPHER_AES_128_GCM, &aes_128_gcm_info }, |
| 1217 | { POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info }, |
| 1218 | { POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info }, |
| 1219 | #endif |
| 1220 | #endif /* POLARSSL_AES_C */ |
| 1221 | |
| 1222 | #if defined(POLARSSL_ARC4_C) |
| 1223 | { POLARSSL_CIPHER_ARC4_128, &arc4_128_info }, |
| 1224 | #endif |
| 1225 | |
| 1226 | #if defined(POLARSSL_BLOWFISH_C) |
| 1227 | { POLARSSL_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info }, |
| 1228 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1229 | { POLARSSL_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info }, |
| 1230 | #endif |
| 1231 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1232 | { POLARSSL_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info }, |
| 1233 | #endif |
| 1234 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1235 | { POLARSSL_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info }, |
| 1236 | #endif |
| 1237 | #endif /* POLARSSL_BLOWFISH_C */ |
| 1238 | |
| 1239 | #if defined(POLARSSL_CAMELLIA_C) |
| 1240 | { POLARSSL_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info }, |
| 1241 | { POLARSSL_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info }, |
Manuel Pégourié-Gonnard | 13e0d44 | 2013-10-24 12:59:00 +0200 | [diff] [blame] | 1242 | { POLARSSL_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1243 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1244 | { POLARSSL_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info }, |
| 1245 | { POLARSSL_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info }, |
| 1246 | { POLARSSL_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info }, |
| 1247 | #endif |
| 1248 | #if defined(POLARSSL_CIPHER_MODE_CFB) |
| 1249 | { POLARSSL_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info }, |
| 1250 | { POLARSSL_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info }, |
| 1251 | { POLARSSL_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info }, |
| 1252 | #endif |
| 1253 | #if defined(POLARSSL_CIPHER_MODE_CTR) |
| 1254 | { POLARSSL_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info }, |
| 1255 | { POLARSSL_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info }, |
| 1256 | { POLARSSL_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info }, |
| 1257 | #endif |
Manuel Pégourié-Gonnard | 87181d1 | 2013-10-24 14:02:40 +0200 | [diff] [blame] | 1258 | #if defined(POLARSSL_GCM_C) |
| 1259 | { POLARSSL_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info }, |
| 1260 | { POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info }, |
| 1261 | { POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info }, |
| 1262 | #endif |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1263 | #endif /* POLARSSL_CAMELLIA_C */ |
| 1264 | |
| 1265 | #if defined(POLARSSL_DES_C) |
| 1266 | { POLARSSL_CIPHER_DES_ECB, &des_ecb_info }, |
| 1267 | { POLARSSL_CIPHER_DES_EDE_ECB, &des_ede_ecb_info }, |
| 1268 | { POLARSSL_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info }, |
| 1269 | #if defined(POLARSSL_CIPHER_MODE_CBC) |
| 1270 | { POLARSSL_CIPHER_DES_CBC, &des_cbc_info }, |
| 1271 | { POLARSSL_CIPHER_DES_EDE_CBC, &des_ede_cbc_info }, |
| 1272 | { POLARSSL_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info }, |
| 1273 | #endif |
| 1274 | #endif /* POLARSSL_DES_C */ |
| 1275 | |
| 1276 | #if defined(POLARSSL_CIPHER_NULL_CIPHER) |
Manuel Pégourié-Gonnard | 057e0cf | 2013-10-14 14:19:31 +0200 | [diff] [blame] | 1277 | { POLARSSL_CIPHER_NULL, &null_cipher_info }, |
Manuel Pégourié-Gonnard | dace82f | 2013-09-18 15:12:07 +0200 | [diff] [blame] | 1278 | #endif /* POLARSSL_CIPHER_NULL_CIPHER */ |
| 1279 | |
| 1280 | { 0, NULL } |
| 1281 | }; |
| 1282 | |
| 1283 | #define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0] |
| 1284 | int supported_ciphers[NUM_CIPHERS]; |
| 1285 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 1286 | #endif /* POLARSSL_CIPHER_C */ |