mbed TLS library

Dependents:   HTTPClient-SSL WS_SERVER

Committer:
ansond
Date:
Thu Jun 11 03:27:03 2015 +0000
Revision:
0:137634ff4186
initial commit

Who changed what in which revision?

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