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