Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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