Nitin Shukla / LED_Demo

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

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