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