mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /**
kenjiArai 0:5b88d5760320 2 * \file cipher_wrap.c
kenjiArai 0:5b88d5760320 3 *
kenjiArai 0:5b88d5760320 4 * \brief Generic cipher wrapper for mbed TLS
kenjiArai 0:5b88d5760320 5 *
kenjiArai 0:5b88d5760320 6 * \author Adriaan de Jong <dejong@fox-it.com>
kenjiArai 0:5b88d5760320 7 *
kenjiArai 0:5b88d5760320 8 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
kenjiArai 0:5b88d5760320 9 * SPDX-License-Identifier: Apache-2.0
kenjiArai 0:5b88d5760320 10 *
kenjiArai 0:5b88d5760320 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may
kenjiArai 0:5b88d5760320 12 * not use this file except in compliance with the License.
kenjiArai 0:5b88d5760320 13 * You may obtain a copy of the License at
kenjiArai 0:5b88d5760320 14 *
kenjiArai 0:5b88d5760320 15 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 0:5b88d5760320 16 *
kenjiArai 0:5b88d5760320 17 * Unless required by applicable law or agreed to in writing, software
kenjiArai 0:5b88d5760320 18 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
kenjiArai 0:5b88d5760320 19 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 0:5b88d5760320 20 * See the License for the specific language governing permissions and
kenjiArai 0:5b88d5760320 21 * limitations under the License.
kenjiArai 0:5b88d5760320 22 *
kenjiArai 0:5b88d5760320 23 * This file is part of mbed TLS (https://tls.mbed.org)
kenjiArai 0:5b88d5760320 24 */
kenjiArai 0:5b88d5760320 25
kenjiArai 0:5b88d5760320 26 #if !defined(MBEDTLS_CONFIG_FILE)
kenjiArai 0:5b88d5760320 27 #include "mbedtls/config.h"
kenjiArai 0:5b88d5760320 28 #else
kenjiArai 0:5b88d5760320 29 #include MBEDTLS_CONFIG_FILE
kenjiArai 0:5b88d5760320 30 #endif
kenjiArai 0:5b88d5760320 31
kenjiArai 0:5b88d5760320 32 #if defined(MBEDTLS_CIPHER_C)
kenjiArai 0:5b88d5760320 33
kenjiArai 0:5b88d5760320 34 #include "mbedtls/cipher_internal.h"
kenjiArai 0:5b88d5760320 35
kenjiArai 0:5b88d5760320 36 #if defined(MBEDTLS_CHACHAPOLY_C)
kenjiArai 0:5b88d5760320 37 #include "mbedtls/chachapoly.h"
kenjiArai 0:5b88d5760320 38 #endif
kenjiArai 0:5b88d5760320 39
kenjiArai 0:5b88d5760320 40 #if defined(MBEDTLS_AES_C)
kenjiArai 0:5b88d5760320 41 #include "mbedtls/aes.h"
kenjiArai 0:5b88d5760320 42 #endif
kenjiArai 0:5b88d5760320 43
kenjiArai 0:5b88d5760320 44 #if defined(MBEDTLS_ARC4_C)
kenjiArai 0:5b88d5760320 45 #include "mbedtls/arc4.h"
kenjiArai 0:5b88d5760320 46 #endif
kenjiArai 0:5b88d5760320 47
kenjiArai 0:5b88d5760320 48 #if defined(MBEDTLS_CAMELLIA_C)
kenjiArai 0:5b88d5760320 49 #include "mbedtls/camellia.h"
kenjiArai 0:5b88d5760320 50 #endif
kenjiArai 0:5b88d5760320 51
kenjiArai 0:5b88d5760320 52 #if defined(MBEDTLS_ARIA_C)
kenjiArai 0:5b88d5760320 53 #include "mbedtls/aria.h"
kenjiArai 0:5b88d5760320 54 #endif
kenjiArai 0:5b88d5760320 55
kenjiArai 0:5b88d5760320 56 #if defined(MBEDTLS_DES_C)
kenjiArai 0:5b88d5760320 57 #include "mbedtls/des.h"
kenjiArai 0:5b88d5760320 58 #endif
kenjiArai 0:5b88d5760320 59
kenjiArai 0:5b88d5760320 60 #if defined(MBEDTLS_BLOWFISH_C)
kenjiArai 0:5b88d5760320 61 #include "mbedtls/blowfish.h"
kenjiArai 0:5b88d5760320 62 #endif
kenjiArai 0:5b88d5760320 63
kenjiArai 0:5b88d5760320 64 #if defined(MBEDTLS_CHACHA20_C)
kenjiArai 0:5b88d5760320 65 #include "mbedtls/chacha20.h"
kenjiArai 0:5b88d5760320 66 #endif
kenjiArai 0:5b88d5760320 67
kenjiArai 0:5b88d5760320 68 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 69 #include "mbedtls/gcm.h"
kenjiArai 0:5b88d5760320 70 #endif
kenjiArai 0:5b88d5760320 71
kenjiArai 0:5b88d5760320 72 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 73 #include "mbedtls/ccm.h"
kenjiArai 0:5b88d5760320 74 #endif
kenjiArai 0:5b88d5760320 75
kenjiArai 0:5b88d5760320 76 #if defined(MBEDTLS_NIST_KW_C)
kenjiArai 0:5b88d5760320 77 #include "mbedtls/nist_kw.h"
kenjiArai 0:5b88d5760320 78 #endif
kenjiArai 0:5b88d5760320 79
kenjiArai 0:5b88d5760320 80 #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
kenjiArai 0:5b88d5760320 81 #include <string.h>
kenjiArai 0:5b88d5760320 82 #endif
kenjiArai 0:5b88d5760320 83
kenjiArai 0:5b88d5760320 84 #if defined(MBEDTLS_PLATFORM_C)
kenjiArai 0:5b88d5760320 85 #include "mbedtls/platform.h"
kenjiArai 0:5b88d5760320 86 #else
kenjiArai 0:5b88d5760320 87 #include <stdlib.h>
kenjiArai 0:5b88d5760320 88 #define mbedtls_calloc calloc
kenjiArai 0:5b88d5760320 89 #define mbedtls_free free
kenjiArai 0:5b88d5760320 90 #endif
kenjiArai 0:5b88d5760320 91
kenjiArai 0:5b88d5760320 92 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 93 /* shared by all GCM ciphers */
kenjiArai 0:5b88d5760320 94 static void *gcm_ctx_alloc( void )
kenjiArai 0:5b88d5760320 95 {
kenjiArai 0:5b88d5760320 96 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
kenjiArai 0:5b88d5760320 97
kenjiArai 0:5b88d5760320 98 if( ctx != NULL )
kenjiArai 0:5b88d5760320 99 mbedtls_gcm_init( (mbedtls_gcm_context *) ctx );
kenjiArai 0:5b88d5760320 100
kenjiArai 0:5b88d5760320 101 return( ctx );
kenjiArai 0:5b88d5760320 102 }
kenjiArai 0:5b88d5760320 103
kenjiArai 0:5b88d5760320 104 static void gcm_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 105 {
kenjiArai 0:5b88d5760320 106 mbedtls_gcm_free( ctx );
kenjiArai 0:5b88d5760320 107 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 108 }
kenjiArai 0:5b88d5760320 109 #endif /* MBEDTLS_GCM_C */
kenjiArai 0:5b88d5760320 110
kenjiArai 0:5b88d5760320 111 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 112 /* shared by all CCM ciphers */
kenjiArai 0:5b88d5760320 113 static void *ccm_ctx_alloc( void )
kenjiArai 0:5b88d5760320 114 {
kenjiArai 0:5b88d5760320 115 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
kenjiArai 0:5b88d5760320 116
kenjiArai 0:5b88d5760320 117 if( ctx != NULL )
kenjiArai 0:5b88d5760320 118 mbedtls_ccm_init( (mbedtls_ccm_context *) ctx );
kenjiArai 0:5b88d5760320 119
kenjiArai 0:5b88d5760320 120 return( ctx );
kenjiArai 0:5b88d5760320 121 }
kenjiArai 0:5b88d5760320 122
kenjiArai 0:5b88d5760320 123 static void ccm_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 124 {
kenjiArai 0:5b88d5760320 125 mbedtls_ccm_free( ctx );
kenjiArai 0:5b88d5760320 126 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 127 }
kenjiArai 0:5b88d5760320 128 #endif /* MBEDTLS_CCM_C */
kenjiArai 0:5b88d5760320 129
kenjiArai 0:5b88d5760320 130 #if defined(MBEDTLS_AES_C)
kenjiArai 0:5b88d5760320 131
kenjiArai 0:5b88d5760320 132 static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 133 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 134 {
kenjiArai 0:5b88d5760320 135 return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
kenjiArai 0:5b88d5760320 136 }
kenjiArai 0:5b88d5760320 137
kenjiArai 0:5b88d5760320 138 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 139 static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
kenjiArai 0:5b88d5760320 140 unsigned char *iv, const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 141 {
kenjiArai 0:5b88d5760320 142 return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
kenjiArai 0:5b88d5760320 143 output );
kenjiArai 0:5b88d5760320 144 }
kenjiArai 0:5b88d5760320 145 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 146
kenjiArai 0:5b88d5760320 147 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 148 static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 149 size_t length, size_t *iv_off, unsigned char *iv,
kenjiArai 0:5b88d5760320 150 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 151 {
kenjiArai 0:5b88d5760320 152 return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
kenjiArai 0:5b88d5760320 153 input, output );
kenjiArai 0:5b88d5760320 154 }
kenjiArai 0:5b88d5760320 155 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 156
kenjiArai 0:5b88d5760320 157 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 158 static int aes_crypt_ofb_wrap( void *ctx, size_t length, size_t *iv_off,
kenjiArai 0:5b88d5760320 159 unsigned char *iv, const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 160 {
kenjiArai 0:5b88d5760320 161 return mbedtls_aes_crypt_ofb( (mbedtls_aes_context *) ctx, length, iv_off,
kenjiArai 0:5b88d5760320 162 iv, input, output );
kenjiArai 0:5b88d5760320 163 }
kenjiArai 0:5b88d5760320 164 #endif /* MBEDTLS_CIPHER_MODE_OFB */
kenjiArai 0:5b88d5760320 165
kenjiArai 0:5b88d5760320 166 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 167 static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
kenjiArai 0:5b88d5760320 168 unsigned char *nonce_counter, unsigned char *stream_block,
kenjiArai 0:5b88d5760320 169 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 170 {
kenjiArai 0:5b88d5760320 171 return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
kenjiArai 0:5b88d5760320 172 stream_block, input, output );
kenjiArai 0:5b88d5760320 173 }
kenjiArai 0:5b88d5760320 174 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 175
kenjiArai 0:5b88d5760320 176 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 177 static int aes_crypt_xts_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 178 size_t length,
kenjiArai 0:5b88d5760320 179 const unsigned char data_unit[16],
kenjiArai 0:5b88d5760320 180 const unsigned char *input,
kenjiArai 0:5b88d5760320 181 unsigned char *output )
kenjiArai 0:5b88d5760320 182 {
kenjiArai 0:5b88d5760320 183 mbedtls_aes_xts_context *xts_ctx = ctx;
kenjiArai 0:5b88d5760320 184 int mode;
kenjiArai 0:5b88d5760320 185
kenjiArai 0:5b88d5760320 186 switch( operation )
kenjiArai 0:5b88d5760320 187 {
kenjiArai 0:5b88d5760320 188 case MBEDTLS_ENCRYPT:
kenjiArai 0:5b88d5760320 189 mode = MBEDTLS_AES_ENCRYPT;
kenjiArai 0:5b88d5760320 190 break;
kenjiArai 0:5b88d5760320 191 case MBEDTLS_DECRYPT:
kenjiArai 0:5b88d5760320 192 mode = MBEDTLS_AES_DECRYPT;
kenjiArai 0:5b88d5760320 193 break;
kenjiArai 0:5b88d5760320 194 default:
kenjiArai 0:5b88d5760320 195 return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
kenjiArai 0:5b88d5760320 196 }
kenjiArai 0:5b88d5760320 197
kenjiArai 0:5b88d5760320 198 return mbedtls_aes_crypt_xts( xts_ctx, mode, length,
kenjiArai 0:5b88d5760320 199 data_unit, input, output );
kenjiArai 0:5b88d5760320 200 }
kenjiArai 0:5b88d5760320 201 #endif /* MBEDTLS_CIPHER_MODE_XTS */
kenjiArai 0:5b88d5760320 202
kenjiArai 0:5b88d5760320 203 static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 204 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 205 {
kenjiArai 0:5b88d5760320 206 return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 207 }
kenjiArai 0:5b88d5760320 208
kenjiArai 0:5b88d5760320 209 static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 210 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 211 {
kenjiArai 0:5b88d5760320 212 return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 213 }
kenjiArai 0:5b88d5760320 214
kenjiArai 0:5b88d5760320 215 static void * aes_ctx_alloc( void )
kenjiArai 0:5b88d5760320 216 {
kenjiArai 0:5b88d5760320 217 mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
kenjiArai 0:5b88d5760320 218
kenjiArai 0:5b88d5760320 219 if( aes == NULL )
kenjiArai 0:5b88d5760320 220 return( NULL );
kenjiArai 0:5b88d5760320 221
kenjiArai 0:5b88d5760320 222 mbedtls_aes_init( aes );
kenjiArai 0:5b88d5760320 223
kenjiArai 0:5b88d5760320 224 return( aes );
kenjiArai 0:5b88d5760320 225 }
kenjiArai 0:5b88d5760320 226
kenjiArai 0:5b88d5760320 227 static void aes_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 228 {
kenjiArai 0:5b88d5760320 229 mbedtls_aes_free( (mbedtls_aes_context *) ctx );
kenjiArai 0:5b88d5760320 230 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 231 }
kenjiArai 0:5b88d5760320 232
kenjiArai 0:5b88d5760320 233 static const mbedtls_cipher_base_t aes_info = {
kenjiArai 0:5b88d5760320 234 MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 235 aes_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 236 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 237 aes_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 238 #endif
kenjiArai 0:5b88d5760320 239 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 240 aes_crypt_cfb128_wrap,
kenjiArai 0:5b88d5760320 241 #endif
kenjiArai 0:5b88d5760320 242 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 243 aes_crypt_ofb_wrap,
kenjiArai 0:5b88d5760320 244 #endif
kenjiArai 0:5b88d5760320 245 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 246 aes_crypt_ctr_wrap,
kenjiArai 0:5b88d5760320 247 #endif
kenjiArai 0:5b88d5760320 248 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 249 NULL,
kenjiArai 0:5b88d5760320 250 #endif
kenjiArai 0:5b88d5760320 251 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 252 NULL,
kenjiArai 0:5b88d5760320 253 #endif
kenjiArai 0:5b88d5760320 254 aes_setkey_enc_wrap,
kenjiArai 0:5b88d5760320 255 aes_setkey_dec_wrap,
kenjiArai 0:5b88d5760320 256 aes_ctx_alloc,
kenjiArai 0:5b88d5760320 257 aes_ctx_free
kenjiArai 0:5b88d5760320 258 };
kenjiArai 0:5b88d5760320 259
kenjiArai 0:5b88d5760320 260 static const mbedtls_cipher_info_t aes_128_ecb_info = {
kenjiArai 0:5b88d5760320 261 MBEDTLS_CIPHER_AES_128_ECB,
kenjiArai 0:5b88d5760320 262 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 263 128,
kenjiArai 0:5b88d5760320 264 "AES-128-ECB",
kenjiArai 0:5b88d5760320 265 0,
kenjiArai 0:5b88d5760320 266 0,
kenjiArai 0:5b88d5760320 267 16,
kenjiArai 0:5b88d5760320 268 &aes_info
kenjiArai 0:5b88d5760320 269 };
kenjiArai 0:5b88d5760320 270
kenjiArai 0:5b88d5760320 271 static const mbedtls_cipher_info_t aes_192_ecb_info = {
kenjiArai 0:5b88d5760320 272 MBEDTLS_CIPHER_AES_192_ECB,
kenjiArai 0:5b88d5760320 273 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 274 192,
kenjiArai 0:5b88d5760320 275 "AES-192-ECB",
kenjiArai 0:5b88d5760320 276 0,
kenjiArai 0:5b88d5760320 277 0,
kenjiArai 0:5b88d5760320 278 16,
kenjiArai 0:5b88d5760320 279 &aes_info
kenjiArai 0:5b88d5760320 280 };
kenjiArai 0:5b88d5760320 281
kenjiArai 0:5b88d5760320 282 static const mbedtls_cipher_info_t aes_256_ecb_info = {
kenjiArai 0:5b88d5760320 283 MBEDTLS_CIPHER_AES_256_ECB,
kenjiArai 0:5b88d5760320 284 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 285 256,
kenjiArai 0:5b88d5760320 286 "AES-256-ECB",
kenjiArai 0:5b88d5760320 287 0,
kenjiArai 0:5b88d5760320 288 0,
kenjiArai 0:5b88d5760320 289 16,
kenjiArai 0:5b88d5760320 290 &aes_info
kenjiArai 0:5b88d5760320 291 };
kenjiArai 0:5b88d5760320 292
kenjiArai 0:5b88d5760320 293 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 294 static const mbedtls_cipher_info_t aes_128_cbc_info = {
kenjiArai 0:5b88d5760320 295 MBEDTLS_CIPHER_AES_128_CBC,
kenjiArai 0:5b88d5760320 296 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 297 128,
kenjiArai 0:5b88d5760320 298 "AES-128-CBC",
kenjiArai 0:5b88d5760320 299 16,
kenjiArai 0:5b88d5760320 300 0,
kenjiArai 0:5b88d5760320 301 16,
kenjiArai 0:5b88d5760320 302 &aes_info
kenjiArai 0:5b88d5760320 303 };
kenjiArai 0:5b88d5760320 304
kenjiArai 0:5b88d5760320 305 static const mbedtls_cipher_info_t aes_192_cbc_info = {
kenjiArai 0:5b88d5760320 306 MBEDTLS_CIPHER_AES_192_CBC,
kenjiArai 0:5b88d5760320 307 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 308 192,
kenjiArai 0:5b88d5760320 309 "AES-192-CBC",
kenjiArai 0:5b88d5760320 310 16,
kenjiArai 0:5b88d5760320 311 0,
kenjiArai 0:5b88d5760320 312 16,
kenjiArai 0:5b88d5760320 313 &aes_info
kenjiArai 0:5b88d5760320 314 };
kenjiArai 0:5b88d5760320 315
kenjiArai 0:5b88d5760320 316 static const mbedtls_cipher_info_t aes_256_cbc_info = {
kenjiArai 0:5b88d5760320 317 MBEDTLS_CIPHER_AES_256_CBC,
kenjiArai 0:5b88d5760320 318 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 319 256,
kenjiArai 0:5b88d5760320 320 "AES-256-CBC",
kenjiArai 0:5b88d5760320 321 16,
kenjiArai 0:5b88d5760320 322 0,
kenjiArai 0:5b88d5760320 323 16,
kenjiArai 0:5b88d5760320 324 &aes_info
kenjiArai 0:5b88d5760320 325 };
kenjiArai 0:5b88d5760320 326 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 327
kenjiArai 0:5b88d5760320 328 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 329 static const mbedtls_cipher_info_t aes_128_cfb128_info = {
kenjiArai 0:5b88d5760320 330 MBEDTLS_CIPHER_AES_128_CFB128,
kenjiArai 0:5b88d5760320 331 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 332 128,
kenjiArai 0:5b88d5760320 333 "AES-128-CFB128",
kenjiArai 0:5b88d5760320 334 16,
kenjiArai 0:5b88d5760320 335 0,
kenjiArai 0:5b88d5760320 336 16,
kenjiArai 0:5b88d5760320 337 &aes_info
kenjiArai 0:5b88d5760320 338 };
kenjiArai 0:5b88d5760320 339
kenjiArai 0:5b88d5760320 340 static const mbedtls_cipher_info_t aes_192_cfb128_info = {
kenjiArai 0:5b88d5760320 341 MBEDTLS_CIPHER_AES_192_CFB128,
kenjiArai 0:5b88d5760320 342 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 343 192,
kenjiArai 0:5b88d5760320 344 "AES-192-CFB128",
kenjiArai 0:5b88d5760320 345 16,
kenjiArai 0:5b88d5760320 346 0,
kenjiArai 0:5b88d5760320 347 16,
kenjiArai 0:5b88d5760320 348 &aes_info
kenjiArai 0:5b88d5760320 349 };
kenjiArai 0:5b88d5760320 350
kenjiArai 0:5b88d5760320 351 static const mbedtls_cipher_info_t aes_256_cfb128_info = {
kenjiArai 0:5b88d5760320 352 MBEDTLS_CIPHER_AES_256_CFB128,
kenjiArai 0:5b88d5760320 353 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 354 256,
kenjiArai 0:5b88d5760320 355 "AES-256-CFB128",
kenjiArai 0:5b88d5760320 356 16,
kenjiArai 0:5b88d5760320 357 0,
kenjiArai 0:5b88d5760320 358 16,
kenjiArai 0:5b88d5760320 359 &aes_info
kenjiArai 0:5b88d5760320 360 };
kenjiArai 0:5b88d5760320 361 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 362
kenjiArai 0:5b88d5760320 363 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 364 static const mbedtls_cipher_info_t aes_128_ofb_info = {
kenjiArai 0:5b88d5760320 365 MBEDTLS_CIPHER_AES_128_OFB,
kenjiArai 0:5b88d5760320 366 MBEDTLS_MODE_OFB,
kenjiArai 0:5b88d5760320 367 128,
kenjiArai 0:5b88d5760320 368 "AES-128-OFB",
kenjiArai 0:5b88d5760320 369 16,
kenjiArai 0:5b88d5760320 370 0,
kenjiArai 0:5b88d5760320 371 16,
kenjiArai 0:5b88d5760320 372 &aes_info
kenjiArai 0:5b88d5760320 373 };
kenjiArai 0:5b88d5760320 374
kenjiArai 0:5b88d5760320 375 static const mbedtls_cipher_info_t aes_192_ofb_info = {
kenjiArai 0:5b88d5760320 376 MBEDTLS_CIPHER_AES_192_OFB,
kenjiArai 0:5b88d5760320 377 MBEDTLS_MODE_OFB,
kenjiArai 0:5b88d5760320 378 192,
kenjiArai 0:5b88d5760320 379 "AES-192-OFB",
kenjiArai 0:5b88d5760320 380 16,
kenjiArai 0:5b88d5760320 381 0,
kenjiArai 0:5b88d5760320 382 16,
kenjiArai 0:5b88d5760320 383 &aes_info
kenjiArai 0:5b88d5760320 384 };
kenjiArai 0:5b88d5760320 385
kenjiArai 0:5b88d5760320 386 static const mbedtls_cipher_info_t aes_256_ofb_info = {
kenjiArai 0:5b88d5760320 387 MBEDTLS_CIPHER_AES_256_OFB,
kenjiArai 0:5b88d5760320 388 MBEDTLS_MODE_OFB,
kenjiArai 0:5b88d5760320 389 256,
kenjiArai 0:5b88d5760320 390 "AES-256-OFB",
kenjiArai 0:5b88d5760320 391 16,
kenjiArai 0:5b88d5760320 392 0,
kenjiArai 0:5b88d5760320 393 16,
kenjiArai 0:5b88d5760320 394 &aes_info
kenjiArai 0:5b88d5760320 395 };
kenjiArai 0:5b88d5760320 396 #endif /* MBEDTLS_CIPHER_MODE_OFB */
kenjiArai 0:5b88d5760320 397
kenjiArai 0:5b88d5760320 398 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 399 static const mbedtls_cipher_info_t aes_128_ctr_info = {
kenjiArai 0:5b88d5760320 400 MBEDTLS_CIPHER_AES_128_CTR,
kenjiArai 0:5b88d5760320 401 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 402 128,
kenjiArai 0:5b88d5760320 403 "AES-128-CTR",
kenjiArai 0:5b88d5760320 404 16,
kenjiArai 0:5b88d5760320 405 0,
kenjiArai 0:5b88d5760320 406 16,
kenjiArai 0:5b88d5760320 407 &aes_info
kenjiArai 0:5b88d5760320 408 };
kenjiArai 0:5b88d5760320 409
kenjiArai 0:5b88d5760320 410 static const mbedtls_cipher_info_t aes_192_ctr_info = {
kenjiArai 0:5b88d5760320 411 MBEDTLS_CIPHER_AES_192_CTR,
kenjiArai 0:5b88d5760320 412 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 413 192,
kenjiArai 0:5b88d5760320 414 "AES-192-CTR",
kenjiArai 0:5b88d5760320 415 16,
kenjiArai 0:5b88d5760320 416 0,
kenjiArai 0:5b88d5760320 417 16,
kenjiArai 0:5b88d5760320 418 &aes_info
kenjiArai 0:5b88d5760320 419 };
kenjiArai 0:5b88d5760320 420
kenjiArai 0:5b88d5760320 421 static const mbedtls_cipher_info_t aes_256_ctr_info = {
kenjiArai 0:5b88d5760320 422 MBEDTLS_CIPHER_AES_256_CTR,
kenjiArai 0:5b88d5760320 423 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 424 256,
kenjiArai 0:5b88d5760320 425 "AES-256-CTR",
kenjiArai 0:5b88d5760320 426 16,
kenjiArai 0:5b88d5760320 427 0,
kenjiArai 0:5b88d5760320 428 16,
kenjiArai 0:5b88d5760320 429 &aes_info
kenjiArai 0:5b88d5760320 430 };
kenjiArai 0:5b88d5760320 431 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 432
kenjiArai 0:5b88d5760320 433 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 434 static int xts_aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 435 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 436 {
kenjiArai 0:5b88d5760320 437 mbedtls_aes_xts_context *xts_ctx = ctx;
kenjiArai 0:5b88d5760320 438 return( mbedtls_aes_xts_setkey_enc( xts_ctx, key, key_bitlen ) );
kenjiArai 0:5b88d5760320 439 }
kenjiArai 0:5b88d5760320 440
kenjiArai 0:5b88d5760320 441 static int xts_aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 442 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 443 {
kenjiArai 0:5b88d5760320 444 mbedtls_aes_xts_context *xts_ctx = ctx;
kenjiArai 0:5b88d5760320 445 return( mbedtls_aes_xts_setkey_dec( xts_ctx, key, key_bitlen ) );
kenjiArai 0:5b88d5760320 446 }
kenjiArai 0:5b88d5760320 447
kenjiArai 0:5b88d5760320 448 static void *xts_aes_ctx_alloc( void )
kenjiArai 0:5b88d5760320 449 {
kenjiArai 0:5b88d5760320 450 mbedtls_aes_xts_context *xts_ctx = mbedtls_calloc( 1, sizeof( *xts_ctx ) );
kenjiArai 0:5b88d5760320 451
kenjiArai 0:5b88d5760320 452 if( xts_ctx != NULL )
kenjiArai 0:5b88d5760320 453 mbedtls_aes_xts_init( xts_ctx );
kenjiArai 0:5b88d5760320 454
kenjiArai 0:5b88d5760320 455 return( xts_ctx );
kenjiArai 0:5b88d5760320 456 }
kenjiArai 0:5b88d5760320 457
kenjiArai 0:5b88d5760320 458 static void xts_aes_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 459 {
kenjiArai 0:5b88d5760320 460 mbedtls_aes_xts_context *xts_ctx = ctx;
kenjiArai 0:5b88d5760320 461
kenjiArai 0:5b88d5760320 462 if( xts_ctx == NULL )
kenjiArai 0:5b88d5760320 463 return;
kenjiArai 0:5b88d5760320 464
kenjiArai 0:5b88d5760320 465 mbedtls_aes_xts_free( xts_ctx );
kenjiArai 0:5b88d5760320 466 mbedtls_free( xts_ctx );
kenjiArai 0:5b88d5760320 467 }
kenjiArai 0:5b88d5760320 468
kenjiArai 0:5b88d5760320 469 static const mbedtls_cipher_base_t xts_aes_info = {
kenjiArai 0:5b88d5760320 470 MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 471 NULL,
kenjiArai 0:5b88d5760320 472 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 473 NULL,
kenjiArai 0:5b88d5760320 474 #endif
kenjiArai 0:5b88d5760320 475 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 476 NULL,
kenjiArai 0:5b88d5760320 477 #endif
kenjiArai 0:5b88d5760320 478 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 479 NULL,
kenjiArai 0:5b88d5760320 480 #endif
kenjiArai 0:5b88d5760320 481 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 482 NULL,
kenjiArai 0:5b88d5760320 483 #endif
kenjiArai 0:5b88d5760320 484 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 485 aes_crypt_xts_wrap,
kenjiArai 0:5b88d5760320 486 #endif
kenjiArai 0:5b88d5760320 487 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 488 NULL,
kenjiArai 0:5b88d5760320 489 #endif
kenjiArai 0:5b88d5760320 490 xts_aes_setkey_enc_wrap,
kenjiArai 0:5b88d5760320 491 xts_aes_setkey_dec_wrap,
kenjiArai 0:5b88d5760320 492 xts_aes_ctx_alloc,
kenjiArai 0:5b88d5760320 493 xts_aes_ctx_free
kenjiArai 0:5b88d5760320 494 };
kenjiArai 0:5b88d5760320 495
kenjiArai 0:5b88d5760320 496 static const mbedtls_cipher_info_t aes_128_xts_info = {
kenjiArai 0:5b88d5760320 497 MBEDTLS_CIPHER_AES_128_XTS,
kenjiArai 0:5b88d5760320 498 MBEDTLS_MODE_XTS,
kenjiArai 0:5b88d5760320 499 256,
kenjiArai 0:5b88d5760320 500 "AES-128-XTS",
kenjiArai 0:5b88d5760320 501 16,
kenjiArai 0:5b88d5760320 502 0,
kenjiArai 0:5b88d5760320 503 16,
kenjiArai 0:5b88d5760320 504 &xts_aes_info
kenjiArai 0:5b88d5760320 505 };
kenjiArai 0:5b88d5760320 506
kenjiArai 0:5b88d5760320 507 static const mbedtls_cipher_info_t aes_256_xts_info = {
kenjiArai 0:5b88d5760320 508 MBEDTLS_CIPHER_AES_256_XTS,
kenjiArai 0:5b88d5760320 509 MBEDTLS_MODE_XTS,
kenjiArai 0:5b88d5760320 510 512,
kenjiArai 0:5b88d5760320 511 "AES-256-XTS",
kenjiArai 0:5b88d5760320 512 16,
kenjiArai 0:5b88d5760320 513 0,
kenjiArai 0:5b88d5760320 514 16,
kenjiArai 0:5b88d5760320 515 &xts_aes_info
kenjiArai 0:5b88d5760320 516 };
kenjiArai 0:5b88d5760320 517 #endif /* MBEDTLS_CIPHER_MODE_XTS */
kenjiArai 0:5b88d5760320 518
kenjiArai 0:5b88d5760320 519 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 520 static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 521 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 522 {
kenjiArai 0:5b88d5760320 523 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 524 key, key_bitlen );
kenjiArai 0:5b88d5760320 525 }
kenjiArai 0:5b88d5760320 526
kenjiArai 0:5b88d5760320 527 static const mbedtls_cipher_base_t gcm_aes_info = {
kenjiArai 0:5b88d5760320 528 MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 529 NULL,
kenjiArai 0:5b88d5760320 530 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 531 NULL,
kenjiArai 0:5b88d5760320 532 #endif
kenjiArai 0:5b88d5760320 533 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 534 NULL,
kenjiArai 0:5b88d5760320 535 #endif
kenjiArai 0:5b88d5760320 536 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 537 NULL,
kenjiArai 0:5b88d5760320 538 #endif
kenjiArai 0:5b88d5760320 539 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 540 NULL,
kenjiArai 0:5b88d5760320 541 #endif
kenjiArai 0:5b88d5760320 542 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 543 NULL,
kenjiArai 0:5b88d5760320 544 #endif
kenjiArai 0:5b88d5760320 545 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 546 NULL,
kenjiArai 0:5b88d5760320 547 #endif
kenjiArai 0:5b88d5760320 548 gcm_aes_setkey_wrap,
kenjiArai 0:5b88d5760320 549 gcm_aes_setkey_wrap,
kenjiArai 0:5b88d5760320 550 gcm_ctx_alloc,
kenjiArai 0:5b88d5760320 551 gcm_ctx_free,
kenjiArai 0:5b88d5760320 552 };
kenjiArai 0:5b88d5760320 553
kenjiArai 0:5b88d5760320 554 static const mbedtls_cipher_info_t aes_128_gcm_info = {
kenjiArai 0:5b88d5760320 555 MBEDTLS_CIPHER_AES_128_GCM,
kenjiArai 0:5b88d5760320 556 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 557 128,
kenjiArai 0:5b88d5760320 558 "AES-128-GCM",
kenjiArai 0:5b88d5760320 559 12,
kenjiArai 0:5b88d5760320 560 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 561 16,
kenjiArai 0:5b88d5760320 562 &gcm_aes_info
kenjiArai 0:5b88d5760320 563 };
kenjiArai 0:5b88d5760320 564
kenjiArai 0:5b88d5760320 565 static const mbedtls_cipher_info_t aes_192_gcm_info = {
kenjiArai 0:5b88d5760320 566 MBEDTLS_CIPHER_AES_192_GCM,
kenjiArai 0:5b88d5760320 567 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 568 192,
kenjiArai 0:5b88d5760320 569 "AES-192-GCM",
kenjiArai 0:5b88d5760320 570 12,
kenjiArai 0:5b88d5760320 571 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 572 16,
kenjiArai 0:5b88d5760320 573 &gcm_aes_info
kenjiArai 0:5b88d5760320 574 };
kenjiArai 0:5b88d5760320 575
kenjiArai 0:5b88d5760320 576 static const mbedtls_cipher_info_t aes_256_gcm_info = {
kenjiArai 0:5b88d5760320 577 MBEDTLS_CIPHER_AES_256_GCM,
kenjiArai 0:5b88d5760320 578 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 579 256,
kenjiArai 0:5b88d5760320 580 "AES-256-GCM",
kenjiArai 0:5b88d5760320 581 12,
kenjiArai 0:5b88d5760320 582 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 583 16,
kenjiArai 0:5b88d5760320 584 &gcm_aes_info
kenjiArai 0:5b88d5760320 585 };
kenjiArai 0:5b88d5760320 586 #endif /* MBEDTLS_GCM_C */
kenjiArai 0:5b88d5760320 587
kenjiArai 0:5b88d5760320 588 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 589 static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 590 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 591 {
kenjiArai 0:5b88d5760320 592 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 593 key, key_bitlen );
kenjiArai 0:5b88d5760320 594 }
kenjiArai 0:5b88d5760320 595
kenjiArai 0:5b88d5760320 596 static const mbedtls_cipher_base_t ccm_aes_info = {
kenjiArai 0:5b88d5760320 597 MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 598 NULL,
kenjiArai 0:5b88d5760320 599 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 600 NULL,
kenjiArai 0:5b88d5760320 601 #endif
kenjiArai 0:5b88d5760320 602 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 603 NULL,
kenjiArai 0:5b88d5760320 604 #endif
kenjiArai 0:5b88d5760320 605 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 606 NULL,
kenjiArai 0:5b88d5760320 607 #endif
kenjiArai 0:5b88d5760320 608 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 609 NULL,
kenjiArai 0:5b88d5760320 610 #endif
kenjiArai 0:5b88d5760320 611 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 612 NULL,
kenjiArai 0:5b88d5760320 613 #endif
kenjiArai 0:5b88d5760320 614 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 615 NULL,
kenjiArai 0:5b88d5760320 616 #endif
kenjiArai 0:5b88d5760320 617 ccm_aes_setkey_wrap,
kenjiArai 0:5b88d5760320 618 ccm_aes_setkey_wrap,
kenjiArai 0:5b88d5760320 619 ccm_ctx_alloc,
kenjiArai 0:5b88d5760320 620 ccm_ctx_free,
kenjiArai 0:5b88d5760320 621 };
kenjiArai 0:5b88d5760320 622
kenjiArai 0:5b88d5760320 623 static const mbedtls_cipher_info_t aes_128_ccm_info = {
kenjiArai 0:5b88d5760320 624 MBEDTLS_CIPHER_AES_128_CCM,
kenjiArai 0:5b88d5760320 625 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 626 128,
kenjiArai 0:5b88d5760320 627 "AES-128-CCM",
kenjiArai 0:5b88d5760320 628 12,
kenjiArai 0:5b88d5760320 629 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 630 16,
kenjiArai 0:5b88d5760320 631 &ccm_aes_info
kenjiArai 0:5b88d5760320 632 };
kenjiArai 0:5b88d5760320 633
kenjiArai 0:5b88d5760320 634 static const mbedtls_cipher_info_t aes_192_ccm_info = {
kenjiArai 0:5b88d5760320 635 MBEDTLS_CIPHER_AES_192_CCM,
kenjiArai 0:5b88d5760320 636 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 637 192,
kenjiArai 0:5b88d5760320 638 "AES-192-CCM",
kenjiArai 0:5b88d5760320 639 12,
kenjiArai 0:5b88d5760320 640 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 641 16,
kenjiArai 0:5b88d5760320 642 &ccm_aes_info
kenjiArai 0:5b88d5760320 643 };
kenjiArai 0:5b88d5760320 644
kenjiArai 0:5b88d5760320 645 static const mbedtls_cipher_info_t aes_256_ccm_info = {
kenjiArai 0:5b88d5760320 646 MBEDTLS_CIPHER_AES_256_CCM,
kenjiArai 0:5b88d5760320 647 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 648 256,
kenjiArai 0:5b88d5760320 649 "AES-256-CCM",
kenjiArai 0:5b88d5760320 650 12,
kenjiArai 0:5b88d5760320 651 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 652 16,
kenjiArai 0:5b88d5760320 653 &ccm_aes_info
kenjiArai 0:5b88d5760320 654 };
kenjiArai 0:5b88d5760320 655 #endif /* MBEDTLS_CCM_C */
kenjiArai 0:5b88d5760320 656
kenjiArai 0:5b88d5760320 657 #endif /* MBEDTLS_AES_C */
kenjiArai 0:5b88d5760320 658
kenjiArai 0:5b88d5760320 659 #if defined(MBEDTLS_CAMELLIA_C)
kenjiArai 0:5b88d5760320 660
kenjiArai 0:5b88d5760320 661 static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 662 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 663 {
kenjiArai 0:5b88d5760320 664 return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
kenjiArai 0:5b88d5760320 665 output );
kenjiArai 0:5b88d5760320 666 }
kenjiArai 0:5b88d5760320 667
kenjiArai 0:5b88d5760320 668 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 669 static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 670 size_t length, unsigned char *iv,
kenjiArai 0:5b88d5760320 671 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 672 {
kenjiArai 0:5b88d5760320 673 return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
kenjiArai 0:5b88d5760320 674 input, output );
kenjiArai 0:5b88d5760320 675 }
kenjiArai 0:5b88d5760320 676 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 677
kenjiArai 0:5b88d5760320 678 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 679 static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 680 size_t length, size_t *iv_off, unsigned char *iv,
kenjiArai 0:5b88d5760320 681 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 682 {
kenjiArai 0:5b88d5760320 683 return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
kenjiArai 0:5b88d5760320 684 iv_off, iv, input, output );
kenjiArai 0:5b88d5760320 685 }
kenjiArai 0:5b88d5760320 686 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 687
kenjiArai 0:5b88d5760320 688 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 689 static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
kenjiArai 0:5b88d5760320 690 unsigned char *nonce_counter, unsigned char *stream_block,
kenjiArai 0:5b88d5760320 691 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 692 {
kenjiArai 0:5b88d5760320 693 return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
kenjiArai 0:5b88d5760320 694 nonce_counter, stream_block, input, output );
kenjiArai 0:5b88d5760320 695 }
kenjiArai 0:5b88d5760320 696 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 697
kenjiArai 0:5b88d5760320 698 static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 699 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 700 {
kenjiArai 0:5b88d5760320 701 return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 702 }
kenjiArai 0:5b88d5760320 703
kenjiArai 0:5b88d5760320 704 static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 705 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 706 {
kenjiArai 0:5b88d5760320 707 return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 708 }
kenjiArai 0:5b88d5760320 709
kenjiArai 0:5b88d5760320 710 static void * camellia_ctx_alloc( void )
kenjiArai 0:5b88d5760320 711 {
kenjiArai 0:5b88d5760320 712 mbedtls_camellia_context *ctx;
kenjiArai 0:5b88d5760320 713 ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
kenjiArai 0:5b88d5760320 714
kenjiArai 0:5b88d5760320 715 if( ctx == NULL )
kenjiArai 0:5b88d5760320 716 return( NULL );
kenjiArai 0:5b88d5760320 717
kenjiArai 0:5b88d5760320 718 mbedtls_camellia_init( ctx );
kenjiArai 0:5b88d5760320 719
kenjiArai 0:5b88d5760320 720 return( ctx );
kenjiArai 0:5b88d5760320 721 }
kenjiArai 0:5b88d5760320 722
kenjiArai 0:5b88d5760320 723 static void camellia_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 724 {
kenjiArai 0:5b88d5760320 725 mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
kenjiArai 0:5b88d5760320 726 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 727 }
kenjiArai 0:5b88d5760320 728
kenjiArai 0:5b88d5760320 729 static const mbedtls_cipher_base_t camellia_info = {
kenjiArai 0:5b88d5760320 730 MBEDTLS_CIPHER_ID_CAMELLIA,
kenjiArai 0:5b88d5760320 731 camellia_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 732 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 733 camellia_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 734 #endif
kenjiArai 0:5b88d5760320 735 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 736 camellia_crypt_cfb128_wrap,
kenjiArai 0:5b88d5760320 737 #endif
kenjiArai 0:5b88d5760320 738 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 739 NULL,
kenjiArai 0:5b88d5760320 740 #endif
kenjiArai 0:5b88d5760320 741 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 742 camellia_crypt_ctr_wrap,
kenjiArai 0:5b88d5760320 743 #endif
kenjiArai 0:5b88d5760320 744 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 745 NULL,
kenjiArai 0:5b88d5760320 746 #endif
kenjiArai 0:5b88d5760320 747 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 748 NULL,
kenjiArai 0:5b88d5760320 749 #endif
kenjiArai 0:5b88d5760320 750 camellia_setkey_enc_wrap,
kenjiArai 0:5b88d5760320 751 camellia_setkey_dec_wrap,
kenjiArai 0:5b88d5760320 752 camellia_ctx_alloc,
kenjiArai 0:5b88d5760320 753 camellia_ctx_free
kenjiArai 0:5b88d5760320 754 };
kenjiArai 0:5b88d5760320 755
kenjiArai 0:5b88d5760320 756 static const mbedtls_cipher_info_t camellia_128_ecb_info = {
kenjiArai 0:5b88d5760320 757 MBEDTLS_CIPHER_CAMELLIA_128_ECB,
kenjiArai 0:5b88d5760320 758 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 759 128,
kenjiArai 0:5b88d5760320 760 "CAMELLIA-128-ECB",
kenjiArai 0:5b88d5760320 761 16,
kenjiArai 0:5b88d5760320 762 0,
kenjiArai 0:5b88d5760320 763 16,
kenjiArai 0:5b88d5760320 764 &camellia_info
kenjiArai 0:5b88d5760320 765 };
kenjiArai 0:5b88d5760320 766
kenjiArai 0:5b88d5760320 767 static const mbedtls_cipher_info_t camellia_192_ecb_info = {
kenjiArai 0:5b88d5760320 768 MBEDTLS_CIPHER_CAMELLIA_192_ECB,
kenjiArai 0:5b88d5760320 769 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 770 192,
kenjiArai 0:5b88d5760320 771 "CAMELLIA-192-ECB",
kenjiArai 0:5b88d5760320 772 16,
kenjiArai 0:5b88d5760320 773 0,
kenjiArai 0:5b88d5760320 774 16,
kenjiArai 0:5b88d5760320 775 &camellia_info
kenjiArai 0:5b88d5760320 776 };
kenjiArai 0:5b88d5760320 777
kenjiArai 0:5b88d5760320 778 static const mbedtls_cipher_info_t camellia_256_ecb_info = {
kenjiArai 0:5b88d5760320 779 MBEDTLS_CIPHER_CAMELLIA_256_ECB,
kenjiArai 0:5b88d5760320 780 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 781 256,
kenjiArai 0:5b88d5760320 782 "CAMELLIA-256-ECB",
kenjiArai 0:5b88d5760320 783 16,
kenjiArai 0:5b88d5760320 784 0,
kenjiArai 0:5b88d5760320 785 16,
kenjiArai 0:5b88d5760320 786 &camellia_info
kenjiArai 0:5b88d5760320 787 };
kenjiArai 0:5b88d5760320 788
kenjiArai 0:5b88d5760320 789 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 790 static const mbedtls_cipher_info_t camellia_128_cbc_info = {
kenjiArai 0:5b88d5760320 791 MBEDTLS_CIPHER_CAMELLIA_128_CBC,
kenjiArai 0:5b88d5760320 792 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 793 128,
kenjiArai 0:5b88d5760320 794 "CAMELLIA-128-CBC",
kenjiArai 0:5b88d5760320 795 16,
kenjiArai 0:5b88d5760320 796 0,
kenjiArai 0:5b88d5760320 797 16,
kenjiArai 0:5b88d5760320 798 &camellia_info
kenjiArai 0:5b88d5760320 799 };
kenjiArai 0:5b88d5760320 800
kenjiArai 0:5b88d5760320 801 static const mbedtls_cipher_info_t camellia_192_cbc_info = {
kenjiArai 0:5b88d5760320 802 MBEDTLS_CIPHER_CAMELLIA_192_CBC,
kenjiArai 0:5b88d5760320 803 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 804 192,
kenjiArai 0:5b88d5760320 805 "CAMELLIA-192-CBC",
kenjiArai 0:5b88d5760320 806 16,
kenjiArai 0:5b88d5760320 807 0,
kenjiArai 0:5b88d5760320 808 16,
kenjiArai 0:5b88d5760320 809 &camellia_info
kenjiArai 0:5b88d5760320 810 };
kenjiArai 0:5b88d5760320 811
kenjiArai 0:5b88d5760320 812 static const mbedtls_cipher_info_t camellia_256_cbc_info = {
kenjiArai 0:5b88d5760320 813 MBEDTLS_CIPHER_CAMELLIA_256_CBC,
kenjiArai 0:5b88d5760320 814 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 815 256,
kenjiArai 0:5b88d5760320 816 "CAMELLIA-256-CBC",
kenjiArai 0:5b88d5760320 817 16,
kenjiArai 0:5b88d5760320 818 0,
kenjiArai 0:5b88d5760320 819 16,
kenjiArai 0:5b88d5760320 820 &camellia_info
kenjiArai 0:5b88d5760320 821 };
kenjiArai 0:5b88d5760320 822 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 823
kenjiArai 0:5b88d5760320 824 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 825 static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
kenjiArai 0:5b88d5760320 826 MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
kenjiArai 0:5b88d5760320 827 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 828 128,
kenjiArai 0:5b88d5760320 829 "CAMELLIA-128-CFB128",
kenjiArai 0:5b88d5760320 830 16,
kenjiArai 0:5b88d5760320 831 0,
kenjiArai 0:5b88d5760320 832 16,
kenjiArai 0:5b88d5760320 833 &camellia_info
kenjiArai 0:5b88d5760320 834 };
kenjiArai 0:5b88d5760320 835
kenjiArai 0:5b88d5760320 836 static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
kenjiArai 0:5b88d5760320 837 MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
kenjiArai 0:5b88d5760320 838 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 839 192,
kenjiArai 0:5b88d5760320 840 "CAMELLIA-192-CFB128",
kenjiArai 0:5b88d5760320 841 16,
kenjiArai 0:5b88d5760320 842 0,
kenjiArai 0:5b88d5760320 843 16,
kenjiArai 0:5b88d5760320 844 &camellia_info
kenjiArai 0:5b88d5760320 845 };
kenjiArai 0:5b88d5760320 846
kenjiArai 0:5b88d5760320 847 static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
kenjiArai 0:5b88d5760320 848 MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
kenjiArai 0:5b88d5760320 849 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 850 256,
kenjiArai 0:5b88d5760320 851 "CAMELLIA-256-CFB128",
kenjiArai 0:5b88d5760320 852 16,
kenjiArai 0:5b88d5760320 853 0,
kenjiArai 0:5b88d5760320 854 16,
kenjiArai 0:5b88d5760320 855 &camellia_info
kenjiArai 0:5b88d5760320 856 };
kenjiArai 0:5b88d5760320 857 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 858
kenjiArai 0:5b88d5760320 859 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 860 static const mbedtls_cipher_info_t camellia_128_ctr_info = {
kenjiArai 0:5b88d5760320 861 MBEDTLS_CIPHER_CAMELLIA_128_CTR,
kenjiArai 0:5b88d5760320 862 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 863 128,
kenjiArai 0:5b88d5760320 864 "CAMELLIA-128-CTR",
kenjiArai 0:5b88d5760320 865 16,
kenjiArai 0:5b88d5760320 866 0,
kenjiArai 0:5b88d5760320 867 16,
kenjiArai 0:5b88d5760320 868 &camellia_info
kenjiArai 0:5b88d5760320 869 };
kenjiArai 0:5b88d5760320 870
kenjiArai 0:5b88d5760320 871 static const mbedtls_cipher_info_t camellia_192_ctr_info = {
kenjiArai 0:5b88d5760320 872 MBEDTLS_CIPHER_CAMELLIA_192_CTR,
kenjiArai 0:5b88d5760320 873 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 874 192,
kenjiArai 0:5b88d5760320 875 "CAMELLIA-192-CTR",
kenjiArai 0:5b88d5760320 876 16,
kenjiArai 0:5b88d5760320 877 0,
kenjiArai 0:5b88d5760320 878 16,
kenjiArai 0:5b88d5760320 879 &camellia_info
kenjiArai 0:5b88d5760320 880 };
kenjiArai 0:5b88d5760320 881
kenjiArai 0:5b88d5760320 882 static const mbedtls_cipher_info_t camellia_256_ctr_info = {
kenjiArai 0:5b88d5760320 883 MBEDTLS_CIPHER_CAMELLIA_256_CTR,
kenjiArai 0:5b88d5760320 884 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 885 256,
kenjiArai 0:5b88d5760320 886 "CAMELLIA-256-CTR",
kenjiArai 0:5b88d5760320 887 16,
kenjiArai 0:5b88d5760320 888 0,
kenjiArai 0:5b88d5760320 889 16,
kenjiArai 0:5b88d5760320 890 &camellia_info
kenjiArai 0:5b88d5760320 891 };
kenjiArai 0:5b88d5760320 892 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 893
kenjiArai 0:5b88d5760320 894 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 895 static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 896 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 897 {
kenjiArai 0:5b88d5760320 898 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
kenjiArai 0:5b88d5760320 899 key, key_bitlen );
kenjiArai 0:5b88d5760320 900 }
kenjiArai 0:5b88d5760320 901
kenjiArai 0:5b88d5760320 902 static const mbedtls_cipher_base_t gcm_camellia_info = {
kenjiArai 0:5b88d5760320 903 MBEDTLS_CIPHER_ID_CAMELLIA,
kenjiArai 0:5b88d5760320 904 NULL,
kenjiArai 0:5b88d5760320 905 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 906 NULL,
kenjiArai 0:5b88d5760320 907 #endif
kenjiArai 0:5b88d5760320 908 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 909 NULL,
kenjiArai 0:5b88d5760320 910 #endif
kenjiArai 0:5b88d5760320 911 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 912 NULL,
kenjiArai 0:5b88d5760320 913 #endif
kenjiArai 0:5b88d5760320 914 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 915 NULL,
kenjiArai 0:5b88d5760320 916 #endif
kenjiArai 0:5b88d5760320 917 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 918 NULL,
kenjiArai 0:5b88d5760320 919 #endif
kenjiArai 0:5b88d5760320 920 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 921 NULL,
kenjiArai 0:5b88d5760320 922 #endif
kenjiArai 0:5b88d5760320 923 gcm_camellia_setkey_wrap,
kenjiArai 0:5b88d5760320 924 gcm_camellia_setkey_wrap,
kenjiArai 0:5b88d5760320 925 gcm_ctx_alloc,
kenjiArai 0:5b88d5760320 926 gcm_ctx_free,
kenjiArai 0:5b88d5760320 927 };
kenjiArai 0:5b88d5760320 928
kenjiArai 0:5b88d5760320 929 static const mbedtls_cipher_info_t camellia_128_gcm_info = {
kenjiArai 0:5b88d5760320 930 MBEDTLS_CIPHER_CAMELLIA_128_GCM,
kenjiArai 0:5b88d5760320 931 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 932 128,
kenjiArai 0:5b88d5760320 933 "CAMELLIA-128-GCM",
kenjiArai 0:5b88d5760320 934 12,
kenjiArai 0:5b88d5760320 935 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 936 16,
kenjiArai 0:5b88d5760320 937 &gcm_camellia_info
kenjiArai 0:5b88d5760320 938 };
kenjiArai 0:5b88d5760320 939
kenjiArai 0:5b88d5760320 940 static const mbedtls_cipher_info_t camellia_192_gcm_info = {
kenjiArai 0:5b88d5760320 941 MBEDTLS_CIPHER_CAMELLIA_192_GCM,
kenjiArai 0:5b88d5760320 942 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 943 192,
kenjiArai 0:5b88d5760320 944 "CAMELLIA-192-GCM",
kenjiArai 0:5b88d5760320 945 12,
kenjiArai 0:5b88d5760320 946 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 947 16,
kenjiArai 0:5b88d5760320 948 &gcm_camellia_info
kenjiArai 0:5b88d5760320 949 };
kenjiArai 0:5b88d5760320 950
kenjiArai 0:5b88d5760320 951 static const mbedtls_cipher_info_t camellia_256_gcm_info = {
kenjiArai 0:5b88d5760320 952 MBEDTLS_CIPHER_CAMELLIA_256_GCM,
kenjiArai 0:5b88d5760320 953 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 954 256,
kenjiArai 0:5b88d5760320 955 "CAMELLIA-256-GCM",
kenjiArai 0:5b88d5760320 956 12,
kenjiArai 0:5b88d5760320 957 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 958 16,
kenjiArai 0:5b88d5760320 959 &gcm_camellia_info
kenjiArai 0:5b88d5760320 960 };
kenjiArai 0:5b88d5760320 961 #endif /* MBEDTLS_GCM_C */
kenjiArai 0:5b88d5760320 962
kenjiArai 0:5b88d5760320 963 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 964 static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 965 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 966 {
kenjiArai 0:5b88d5760320 967 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
kenjiArai 0:5b88d5760320 968 key, key_bitlen );
kenjiArai 0:5b88d5760320 969 }
kenjiArai 0:5b88d5760320 970
kenjiArai 0:5b88d5760320 971 static const mbedtls_cipher_base_t ccm_camellia_info = {
kenjiArai 0:5b88d5760320 972 MBEDTLS_CIPHER_ID_CAMELLIA,
kenjiArai 0:5b88d5760320 973 NULL,
kenjiArai 0:5b88d5760320 974 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 975 NULL,
kenjiArai 0:5b88d5760320 976 #endif
kenjiArai 0:5b88d5760320 977 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 978 NULL,
kenjiArai 0:5b88d5760320 979 #endif
kenjiArai 0:5b88d5760320 980 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 981 NULL,
kenjiArai 0:5b88d5760320 982 #endif
kenjiArai 0:5b88d5760320 983 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 984 NULL,
kenjiArai 0:5b88d5760320 985 #endif
kenjiArai 0:5b88d5760320 986 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 987 NULL,
kenjiArai 0:5b88d5760320 988 #endif
kenjiArai 0:5b88d5760320 989 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 990 NULL,
kenjiArai 0:5b88d5760320 991 #endif
kenjiArai 0:5b88d5760320 992 ccm_camellia_setkey_wrap,
kenjiArai 0:5b88d5760320 993 ccm_camellia_setkey_wrap,
kenjiArai 0:5b88d5760320 994 ccm_ctx_alloc,
kenjiArai 0:5b88d5760320 995 ccm_ctx_free,
kenjiArai 0:5b88d5760320 996 };
kenjiArai 0:5b88d5760320 997
kenjiArai 0:5b88d5760320 998 static const mbedtls_cipher_info_t camellia_128_ccm_info = {
kenjiArai 0:5b88d5760320 999 MBEDTLS_CIPHER_CAMELLIA_128_CCM,
kenjiArai 0:5b88d5760320 1000 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 1001 128,
kenjiArai 0:5b88d5760320 1002 "CAMELLIA-128-CCM",
kenjiArai 0:5b88d5760320 1003 12,
kenjiArai 0:5b88d5760320 1004 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1005 16,
kenjiArai 0:5b88d5760320 1006 &ccm_camellia_info
kenjiArai 0:5b88d5760320 1007 };
kenjiArai 0:5b88d5760320 1008
kenjiArai 0:5b88d5760320 1009 static const mbedtls_cipher_info_t camellia_192_ccm_info = {
kenjiArai 0:5b88d5760320 1010 MBEDTLS_CIPHER_CAMELLIA_192_CCM,
kenjiArai 0:5b88d5760320 1011 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 1012 192,
kenjiArai 0:5b88d5760320 1013 "CAMELLIA-192-CCM",
kenjiArai 0:5b88d5760320 1014 12,
kenjiArai 0:5b88d5760320 1015 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1016 16,
kenjiArai 0:5b88d5760320 1017 &ccm_camellia_info
kenjiArai 0:5b88d5760320 1018 };
kenjiArai 0:5b88d5760320 1019
kenjiArai 0:5b88d5760320 1020 static const mbedtls_cipher_info_t camellia_256_ccm_info = {
kenjiArai 0:5b88d5760320 1021 MBEDTLS_CIPHER_CAMELLIA_256_CCM,
kenjiArai 0:5b88d5760320 1022 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 1023 256,
kenjiArai 0:5b88d5760320 1024 "CAMELLIA-256-CCM",
kenjiArai 0:5b88d5760320 1025 12,
kenjiArai 0:5b88d5760320 1026 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1027 16,
kenjiArai 0:5b88d5760320 1028 &ccm_camellia_info
kenjiArai 0:5b88d5760320 1029 };
kenjiArai 0:5b88d5760320 1030 #endif /* MBEDTLS_CCM_C */
kenjiArai 0:5b88d5760320 1031
kenjiArai 0:5b88d5760320 1032 #endif /* MBEDTLS_CAMELLIA_C */
kenjiArai 0:5b88d5760320 1033
kenjiArai 0:5b88d5760320 1034 #if defined(MBEDTLS_ARIA_C)
kenjiArai 0:5b88d5760320 1035
kenjiArai 0:5b88d5760320 1036 static int aria_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1037 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1038 {
kenjiArai 0:5b88d5760320 1039 (void) operation;
kenjiArai 0:5b88d5760320 1040 return mbedtls_aria_crypt_ecb( (mbedtls_aria_context *) ctx, input,
kenjiArai 0:5b88d5760320 1041 output );
kenjiArai 0:5b88d5760320 1042 }
kenjiArai 0:5b88d5760320 1043
kenjiArai 0:5b88d5760320 1044 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1045 static int aria_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1046 size_t length, unsigned char *iv,
kenjiArai 0:5b88d5760320 1047 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1048 {
kenjiArai 0:5b88d5760320 1049 return mbedtls_aria_crypt_cbc( (mbedtls_aria_context *) ctx, operation, length, iv,
kenjiArai 0:5b88d5760320 1050 input, output );
kenjiArai 0:5b88d5760320 1051 }
kenjiArai 0:5b88d5760320 1052 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1053
kenjiArai 0:5b88d5760320 1054 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1055 static int aria_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1056 size_t length, size_t *iv_off, unsigned char *iv,
kenjiArai 0:5b88d5760320 1057 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1058 {
kenjiArai 0:5b88d5760320 1059 return mbedtls_aria_crypt_cfb128( (mbedtls_aria_context *) ctx, operation, length,
kenjiArai 0:5b88d5760320 1060 iv_off, iv, input, output );
kenjiArai 0:5b88d5760320 1061 }
kenjiArai 0:5b88d5760320 1062 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 1063
kenjiArai 0:5b88d5760320 1064 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1065 static int aria_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
kenjiArai 0:5b88d5760320 1066 unsigned char *nonce_counter, unsigned char *stream_block,
kenjiArai 0:5b88d5760320 1067 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1068 {
kenjiArai 0:5b88d5760320 1069 return mbedtls_aria_crypt_ctr( (mbedtls_aria_context *) ctx, length, nc_off,
kenjiArai 0:5b88d5760320 1070 nonce_counter, stream_block, input, output );
kenjiArai 0:5b88d5760320 1071 }
kenjiArai 0:5b88d5760320 1072 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 1073
kenjiArai 0:5b88d5760320 1074 static int aria_setkey_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1075 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1076 {
kenjiArai 0:5b88d5760320 1077 return mbedtls_aria_setkey_dec( (mbedtls_aria_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 1078 }
kenjiArai 0:5b88d5760320 1079
kenjiArai 0:5b88d5760320 1080 static int aria_setkey_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1081 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1082 {
kenjiArai 0:5b88d5760320 1083 return mbedtls_aria_setkey_enc( (mbedtls_aria_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 1084 }
kenjiArai 0:5b88d5760320 1085
kenjiArai 0:5b88d5760320 1086 static void * aria_ctx_alloc( void )
kenjiArai 0:5b88d5760320 1087 {
kenjiArai 0:5b88d5760320 1088 mbedtls_aria_context *ctx;
kenjiArai 0:5b88d5760320 1089 ctx = mbedtls_calloc( 1, sizeof( mbedtls_aria_context ) );
kenjiArai 0:5b88d5760320 1090
kenjiArai 0:5b88d5760320 1091 if( ctx == NULL )
kenjiArai 0:5b88d5760320 1092 return( NULL );
kenjiArai 0:5b88d5760320 1093
kenjiArai 0:5b88d5760320 1094 mbedtls_aria_init( ctx );
kenjiArai 0:5b88d5760320 1095
kenjiArai 0:5b88d5760320 1096 return( ctx );
kenjiArai 0:5b88d5760320 1097 }
kenjiArai 0:5b88d5760320 1098
kenjiArai 0:5b88d5760320 1099 static void aria_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 1100 {
kenjiArai 0:5b88d5760320 1101 mbedtls_aria_free( (mbedtls_aria_context *) ctx );
kenjiArai 0:5b88d5760320 1102 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 1103 }
kenjiArai 0:5b88d5760320 1104
kenjiArai 0:5b88d5760320 1105 static const mbedtls_cipher_base_t aria_info = {
kenjiArai 0:5b88d5760320 1106 MBEDTLS_CIPHER_ID_ARIA,
kenjiArai 0:5b88d5760320 1107 aria_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 1108 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1109 aria_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 1110 #endif
kenjiArai 0:5b88d5760320 1111 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1112 aria_crypt_cfb128_wrap,
kenjiArai 0:5b88d5760320 1113 #endif
kenjiArai 0:5b88d5760320 1114 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1115 NULL,
kenjiArai 0:5b88d5760320 1116 #endif
kenjiArai 0:5b88d5760320 1117 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1118 aria_crypt_ctr_wrap,
kenjiArai 0:5b88d5760320 1119 #endif
kenjiArai 0:5b88d5760320 1120 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1121 NULL,
kenjiArai 0:5b88d5760320 1122 #endif
kenjiArai 0:5b88d5760320 1123 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1124 NULL,
kenjiArai 0:5b88d5760320 1125 #endif
kenjiArai 0:5b88d5760320 1126 aria_setkey_enc_wrap,
kenjiArai 0:5b88d5760320 1127 aria_setkey_dec_wrap,
kenjiArai 0:5b88d5760320 1128 aria_ctx_alloc,
kenjiArai 0:5b88d5760320 1129 aria_ctx_free
kenjiArai 0:5b88d5760320 1130 };
kenjiArai 0:5b88d5760320 1131
kenjiArai 0:5b88d5760320 1132 static const mbedtls_cipher_info_t aria_128_ecb_info = {
kenjiArai 0:5b88d5760320 1133 MBEDTLS_CIPHER_ARIA_128_ECB,
kenjiArai 0:5b88d5760320 1134 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1135 128,
kenjiArai 0:5b88d5760320 1136 "ARIA-128-ECB",
kenjiArai 0:5b88d5760320 1137 16,
kenjiArai 0:5b88d5760320 1138 0,
kenjiArai 0:5b88d5760320 1139 16,
kenjiArai 0:5b88d5760320 1140 &aria_info
kenjiArai 0:5b88d5760320 1141 };
kenjiArai 0:5b88d5760320 1142
kenjiArai 0:5b88d5760320 1143 static const mbedtls_cipher_info_t aria_192_ecb_info = {
kenjiArai 0:5b88d5760320 1144 MBEDTLS_CIPHER_ARIA_192_ECB,
kenjiArai 0:5b88d5760320 1145 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1146 192,
kenjiArai 0:5b88d5760320 1147 "ARIA-192-ECB",
kenjiArai 0:5b88d5760320 1148 16,
kenjiArai 0:5b88d5760320 1149 0,
kenjiArai 0:5b88d5760320 1150 16,
kenjiArai 0:5b88d5760320 1151 &aria_info
kenjiArai 0:5b88d5760320 1152 };
kenjiArai 0:5b88d5760320 1153
kenjiArai 0:5b88d5760320 1154 static const mbedtls_cipher_info_t aria_256_ecb_info = {
kenjiArai 0:5b88d5760320 1155 MBEDTLS_CIPHER_ARIA_256_ECB,
kenjiArai 0:5b88d5760320 1156 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1157 256,
kenjiArai 0:5b88d5760320 1158 "ARIA-256-ECB",
kenjiArai 0:5b88d5760320 1159 16,
kenjiArai 0:5b88d5760320 1160 0,
kenjiArai 0:5b88d5760320 1161 16,
kenjiArai 0:5b88d5760320 1162 &aria_info
kenjiArai 0:5b88d5760320 1163 };
kenjiArai 0:5b88d5760320 1164
kenjiArai 0:5b88d5760320 1165 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1166 static const mbedtls_cipher_info_t aria_128_cbc_info = {
kenjiArai 0:5b88d5760320 1167 MBEDTLS_CIPHER_ARIA_128_CBC,
kenjiArai 0:5b88d5760320 1168 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1169 128,
kenjiArai 0:5b88d5760320 1170 "ARIA-128-CBC",
kenjiArai 0:5b88d5760320 1171 16,
kenjiArai 0:5b88d5760320 1172 0,
kenjiArai 0:5b88d5760320 1173 16,
kenjiArai 0:5b88d5760320 1174 &aria_info
kenjiArai 0:5b88d5760320 1175 };
kenjiArai 0:5b88d5760320 1176
kenjiArai 0:5b88d5760320 1177 static const mbedtls_cipher_info_t aria_192_cbc_info = {
kenjiArai 0:5b88d5760320 1178 MBEDTLS_CIPHER_ARIA_192_CBC,
kenjiArai 0:5b88d5760320 1179 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1180 192,
kenjiArai 0:5b88d5760320 1181 "ARIA-192-CBC",
kenjiArai 0:5b88d5760320 1182 16,
kenjiArai 0:5b88d5760320 1183 0,
kenjiArai 0:5b88d5760320 1184 16,
kenjiArai 0:5b88d5760320 1185 &aria_info
kenjiArai 0:5b88d5760320 1186 };
kenjiArai 0:5b88d5760320 1187
kenjiArai 0:5b88d5760320 1188 static const mbedtls_cipher_info_t aria_256_cbc_info = {
kenjiArai 0:5b88d5760320 1189 MBEDTLS_CIPHER_ARIA_256_CBC,
kenjiArai 0:5b88d5760320 1190 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1191 256,
kenjiArai 0:5b88d5760320 1192 "ARIA-256-CBC",
kenjiArai 0:5b88d5760320 1193 16,
kenjiArai 0:5b88d5760320 1194 0,
kenjiArai 0:5b88d5760320 1195 16,
kenjiArai 0:5b88d5760320 1196 &aria_info
kenjiArai 0:5b88d5760320 1197 };
kenjiArai 0:5b88d5760320 1198 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1199
kenjiArai 0:5b88d5760320 1200 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1201 static const mbedtls_cipher_info_t aria_128_cfb128_info = {
kenjiArai 0:5b88d5760320 1202 MBEDTLS_CIPHER_ARIA_128_CFB128,
kenjiArai 0:5b88d5760320 1203 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 1204 128,
kenjiArai 0:5b88d5760320 1205 "ARIA-128-CFB128",
kenjiArai 0:5b88d5760320 1206 16,
kenjiArai 0:5b88d5760320 1207 0,
kenjiArai 0:5b88d5760320 1208 16,
kenjiArai 0:5b88d5760320 1209 &aria_info
kenjiArai 0:5b88d5760320 1210 };
kenjiArai 0:5b88d5760320 1211
kenjiArai 0:5b88d5760320 1212 static const mbedtls_cipher_info_t aria_192_cfb128_info = {
kenjiArai 0:5b88d5760320 1213 MBEDTLS_CIPHER_ARIA_192_CFB128,
kenjiArai 0:5b88d5760320 1214 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 1215 192,
kenjiArai 0:5b88d5760320 1216 "ARIA-192-CFB128",
kenjiArai 0:5b88d5760320 1217 16,
kenjiArai 0:5b88d5760320 1218 0,
kenjiArai 0:5b88d5760320 1219 16,
kenjiArai 0:5b88d5760320 1220 &aria_info
kenjiArai 0:5b88d5760320 1221 };
kenjiArai 0:5b88d5760320 1222
kenjiArai 0:5b88d5760320 1223 static const mbedtls_cipher_info_t aria_256_cfb128_info = {
kenjiArai 0:5b88d5760320 1224 MBEDTLS_CIPHER_ARIA_256_CFB128,
kenjiArai 0:5b88d5760320 1225 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 1226 256,
kenjiArai 0:5b88d5760320 1227 "ARIA-256-CFB128",
kenjiArai 0:5b88d5760320 1228 16,
kenjiArai 0:5b88d5760320 1229 0,
kenjiArai 0:5b88d5760320 1230 16,
kenjiArai 0:5b88d5760320 1231 &aria_info
kenjiArai 0:5b88d5760320 1232 };
kenjiArai 0:5b88d5760320 1233 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 1234
kenjiArai 0:5b88d5760320 1235 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1236 static const mbedtls_cipher_info_t aria_128_ctr_info = {
kenjiArai 0:5b88d5760320 1237 MBEDTLS_CIPHER_ARIA_128_CTR,
kenjiArai 0:5b88d5760320 1238 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 1239 128,
kenjiArai 0:5b88d5760320 1240 "ARIA-128-CTR",
kenjiArai 0:5b88d5760320 1241 16,
kenjiArai 0:5b88d5760320 1242 0,
kenjiArai 0:5b88d5760320 1243 16,
kenjiArai 0:5b88d5760320 1244 &aria_info
kenjiArai 0:5b88d5760320 1245 };
kenjiArai 0:5b88d5760320 1246
kenjiArai 0:5b88d5760320 1247 static const mbedtls_cipher_info_t aria_192_ctr_info = {
kenjiArai 0:5b88d5760320 1248 MBEDTLS_CIPHER_ARIA_192_CTR,
kenjiArai 0:5b88d5760320 1249 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 1250 192,
kenjiArai 0:5b88d5760320 1251 "ARIA-192-CTR",
kenjiArai 0:5b88d5760320 1252 16,
kenjiArai 0:5b88d5760320 1253 0,
kenjiArai 0:5b88d5760320 1254 16,
kenjiArai 0:5b88d5760320 1255 &aria_info
kenjiArai 0:5b88d5760320 1256 };
kenjiArai 0:5b88d5760320 1257
kenjiArai 0:5b88d5760320 1258 static const mbedtls_cipher_info_t aria_256_ctr_info = {
kenjiArai 0:5b88d5760320 1259 MBEDTLS_CIPHER_ARIA_256_CTR,
kenjiArai 0:5b88d5760320 1260 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 1261 256,
kenjiArai 0:5b88d5760320 1262 "ARIA-256-CTR",
kenjiArai 0:5b88d5760320 1263 16,
kenjiArai 0:5b88d5760320 1264 0,
kenjiArai 0:5b88d5760320 1265 16,
kenjiArai 0:5b88d5760320 1266 &aria_info
kenjiArai 0:5b88d5760320 1267 };
kenjiArai 0:5b88d5760320 1268 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 1269
kenjiArai 0:5b88d5760320 1270 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 1271 static int gcm_aria_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1272 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1273 {
kenjiArai 0:5b88d5760320 1274 return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
kenjiArai 0:5b88d5760320 1275 key, key_bitlen );
kenjiArai 0:5b88d5760320 1276 }
kenjiArai 0:5b88d5760320 1277
kenjiArai 0:5b88d5760320 1278 static const mbedtls_cipher_base_t gcm_aria_info = {
kenjiArai 0:5b88d5760320 1279 MBEDTLS_CIPHER_ID_ARIA,
kenjiArai 0:5b88d5760320 1280 NULL,
kenjiArai 0:5b88d5760320 1281 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1282 NULL,
kenjiArai 0:5b88d5760320 1283 #endif
kenjiArai 0:5b88d5760320 1284 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1285 NULL,
kenjiArai 0:5b88d5760320 1286 #endif
kenjiArai 0:5b88d5760320 1287 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1288 NULL,
kenjiArai 0:5b88d5760320 1289 #endif
kenjiArai 0:5b88d5760320 1290 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1291 NULL,
kenjiArai 0:5b88d5760320 1292 #endif
kenjiArai 0:5b88d5760320 1293 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1294 NULL,
kenjiArai 0:5b88d5760320 1295 #endif
kenjiArai 0:5b88d5760320 1296 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1297 NULL,
kenjiArai 0:5b88d5760320 1298 #endif
kenjiArai 0:5b88d5760320 1299 gcm_aria_setkey_wrap,
kenjiArai 0:5b88d5760320 1300 gcm_aria_setkey_wrap,
kenjiArai 0:5b88d5760320 1301 gcm_ctx_alloc,
kenjiArai 0:5b88d5760320 1302 gcm_ctx_free,
kenjiArai 0:5b88d5760320 1303 };
kenjiArai 0:5b88d5760320 1304
kenjiArai 0:5b88d5760320 1305 static const mbedtls_cipher_info_t aria_128_gcm_info = {
kenjiArai 0:5b88d5760320 1306 MBEDTLS_CIPHER_ARIA_128_GCM,
kenjiArai 0:5b88d5760320 1307 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 1308 128,
kenjiArai 0:5b88d5760320 1309 "ARIA-128-GCM",
kenjiArai 0:5b88d5760320 1310 12,
kenjiArai 0:5b88d5760320 1311 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1312 16,
kenjiArai 0:5b88d5760320 1313 &gcm_aria_info
kenjiArai 0:5b88d5760320 1314 };
kenjiArai 0:5b88d5760320 1315
kenjiArai 0:5b88d5760320 1316 static const mbedtls_cipher_info_t aria_192_gcm_info = {
kenjiArai 0:5b88d5760320 1317 MBEDTLS_CIPHER_ARIA_192_GCM,
kenjiArai 0:5b88d5760320 1318 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 1319 192,
kenjiArai 0:5b88d5760320 1320 "ARIA-192-GCM",
kenjiArai 0:5b88d5760320 1321 12,
kenjiArai 0:5b88d5760320 1322 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1323 16,
kenjiArai 0:5b88d5760320 1324 &gcm_aria_info
kenjiArai 0:5b88d5760320 1325 };
kenjiArai 0:5b88d5760320 1326
kenjiArai 0:5b88d5760320 1327 static const mbedtls_cipher_info_t aria_256_gcm_info = {
kenjiArai 0:5b88d5760320 1328 MBEDTLS_CIPHER_ARIA_256_GCM,
kenjiArai 0:5b88d5760320 1329 MBEDTLS_MODE_GCM,
kenjiArai 0:5b88d5760320 1330 256,
kenjiArai 0:5b88d5760320 1331 "ARIA-256-GCM",
kenjiArai 0:5b88d5760320 1332 12,
kenjiArai 0:5b88d5760320 1333 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1334 16,
kenjiArai 0:5b88d5760320 1335 &gcm_aria_info
kenjiArai 0:5b88d5760320 1336 };
kenjiArai 0:5b88d5760320 1337 #endif /* MBEDTLS_GCM_C */
kenjiArai 0:5b88d5760320 1338
kenjiArai 0:5b88d5760320 1339 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 1340 static int ccm_aria_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1341 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1342 {
kenjiArai 0:5b88d5760320 1343 return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_ARIA,
kenjiArai 0:5b88d5760320 1344 key, key_bitlen );
kenjiArai 0:5b88d5760320 1345 }
kenjiArai 0:5b88d5760320 1346
kenjiArai 0:5b88d5760320 1347 static const mbedtls_cipher_base_t ccm_aria_info = {
kenjiArai 0:5b88d5760320 1348 MBEDTLS_CIPHER_ID_ARIA,
kenjiArai 0:5b88d5760320 1349 NULL,
kenjiArai 0:5b88d5760320 1350 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1351 NULL,
kenjiArai 0:5b88d5760320 1352 #endif
kenjiArai 0:5b88d5760320 1353 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1354 NULL,
kenjiArai 0:5b88d5760320 1355 #endif
kenjiArai 0:5b88d5760320 1356 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1357 NULL,
kenjiArai 0:5b88d5760320 1358 #endif
kenjiArai 0:5b88d5760320 1359 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1360 NULL,
kenjiArai 0:5b88d5760320 1361 #endif
kenjiArai 0:5b88d5760320 1362 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1363 NULL,
kenjiArai 0:5b88d5760320 1364 #endif
kenjiArai 0:5b88d5760320 1365 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1366 NULL,
kenjiArai 0:5b88d5760320 1367 #endif
kenjiArai 0:5b88d5760320 1368 ccm_aria_setkey_wrap,
kenjiArai 0:5b88d5760320 1369 ccm_aria_setkey_wrap,
kenjiArai 0:5b88d5760320 1370 ccm_ctx_alloc,
kenjiArai 0:5b88d5760320 1371 ccm_ctx_free,
kenjiArai 0:5b88d5760320 1372 };
kenjiArai 0:5b88d5760320 1373
kenjiArai 0:5b88d5760320 1374 static const mbedtls_cipher_info_t aria_128_ccm_info = {
kenjiArai 0:5b88d5760320 1375 MBEDTLS_CIPHER_ARIA_128_CCM,
kenjiArai 0:5b88d5760320 1376 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 1377 128,
kenjiArai 0:5b88d5760320 1378 "ARIA-128-CCM",
kenjiArai 0:5b88d5760320 1379 12,
kenjiArai 0:5b88d5760320 1380 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1381 16,
kenjiArai 0:5b88d5760320 1382 &ccm_aria_info
kenjiArai 0:5b88d5760320 1383 };
kenjiArai 0:5b88d5760320 1384
kenjiArai 0:5b88d5760320 1385 static const mbedtls_cipher_info_t aria_192_ccm_info = {
kenjiArai 0:5b88d5760320 1386 MBEDTLS_CIPHER_ARIA_192_CCM,
kenjiArai 0:5b88d5760320 1387 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 1388 192,
kenjiArai 0:5b88d5760320 1389 "ARIA-192-CCM",
kenjiArai 0:5b88d5760320 1390 12,
kenjiArai 0:5b88d5760320 1391 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1392 16,
kenjiArai 0:5b88d5760320 1393 &ccm_aria_info
kenjiArai 0:5b88d5760320 1394 };
kenjiArai 0:5b88d5760320 1395
kenjiArai 0:5b88d5760320 1396 static const mbedtls_cipher_info_t aria_256_ccm_info = {
kenjiArai 0:5b88d5760320 1397 MBEDTLS_CIPHER_ARIA_256_CCM,
kenjiArai 0:5b88d5760320 1398 MBEDTLS_MODE_CCM,
kenjiArai 0:5b88d5760320 1399 256,
kenjiArai 0:5b88d5760320 1400 "ARIA-256-CCM",
kenjiArai 0:5b88d5760320 1401 12,
kenjiArai 0:5b88d5760320 1402 MBEDTLS_CIPHER_VARIABLE_IV_LEN,
kenjiArai 0:5b88d5760320 1403 16,
kenjiArai 0:5b88d5760320 1404 &ccm_aria_info
kenjiArai 0:5b88d5760320 1405 };
kenjiArai 0:5b88d5760320 1406 #endif /* MBEDTLS_CCM_C */
kenjiArai 0:5b88d5760320 1407
kenjiArai 0:5b88d5760320 1408 #endif /* MBEDTLS_ARIA_C */
kenjiArai 0:5b88d5760320 1409
kenjiArai 0:5b88d5760320 1410 #if defined(MBEDTLS_DES_C)
kenjiArai 0:5b88d5760320 1411
kenjiArai 0:5b88d5760320 1412 static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1413 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1414 {
kenjiArai 0:5b88d5760320 1415 ((void) operation);
kenjiArai 0:5b88d5760320 1416 return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
kenjiArai 0:5b88d5760320 1417 }
kenjiArai 0:5b88d5760320 1418
kenjiArai 0:5b88d5760320 1419 static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1420 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1421 {
kenjiArai 0:5b88d5760320 1422 ((void) operation);
kenjiArai 0:5b88d5760320 1423 return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
kenjiArai 0:5b88d5760320 1424 }
kenjiArai 0:5b88d5760320 1425
kenjiArai 0:5b88d5760320 1426 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1427 static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
kenjiArai 0:5b88d5760320 1428 unsigned char *iv, const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1429 {
kenjiArai 0:5b88d5760320 1430 return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
kenjiArai 0:5b88d5760320 1431 output );
kenjiArai 0:5b88d5760320 1432 }
kenjiArai 0:5b88d5760320 1433 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1434
kenjiArai 0:5b88d5760320 1435 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1436 static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
kenjiArai 0:5b88d5760320 1437 unsigned char *iv, const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1438 {
kenjiArai 0:5b88d5760320 1439 return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
kenjiArai 0:5b88d5760320 1440 output );
kenjiArai 0:5b88d5760320 1441 }
kenjiArai 0:5b88d5760320 1442 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1443
kenjiArai 0:5b88d5760320 1444 static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1445 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1446 {
kenjiArai 0:5b88d5760320 1447 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 1448
kenjiArai 0:5b88d5760320 1449 return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
kenjiArai 0:5b88d5760320 1450 }
kenjiArai 0:5b88d5760320 1451
kenjiArai 0:5b88d5760320 1452 static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1453 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1454 {
kenjiArai 0:5b88d5760320 1455 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 1456
kenjiArai 0:5b88d5760320 1457 return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
kenjiArai 0:5b88d5760320 1458 }
kenjiArai 0:5b88d5760320 1459
kenjiArai 0:5b88d5760320 1460 static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1461 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1462 {
kenjiArai 0:5b88d5760320 1463 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 1464
kenjiArai 0:5b88d5760320 1465 return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
kenjiArai 0:5b88d5760320 1466 }
kenjiArai 0:5b88d5760320 1467
kenjiArai 0:5b88d5760320 1468 static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1469 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1470 {
kenjiArai 0:5b88d5760320 1471 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 1472
kenjiArai 0:5b88d5760320 1473 return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
kenjiArai 0:5b88d5760320 1474 }
kenjiArai 0:5b88d5760320 1475
kenjiArai 0:5b88d5760320 1476 static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1477 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1478 {
kenjiArai 0:5b88d5760320 1479 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 1480
kenjiArai 0:5b88d5760320 1481 return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
kenjiArai 0:5b88d5760320 1482 }
kenjiArai 0:5b88d5760320 1483
kenjiArai 0:5b88d5760320 1484 static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1485 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1486 {
kenjiArai 0:5b88d5760320 1487 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 1488
kenjiArai 0:5b88d5760320 1489 return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
kenjiArai 0:5b88d5760320 1490 }
kenjiArai 0:5b88d5760320 1491
kenjiArai 0:5b88d5760320 1492 static void * des_ctx_alloc( void )
kenjiArai 0:5b88d5760320 1493 {
kenjiArai 0:5b88d5760320 1494 mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
kenjiArai 0:5b88d5760320 1495
kenjiArai 0:5b88d5760320 1496 if( des == NULL )
kenjiArai 0:5b88d5760320 1497 return( NULL );
kenjiArai 0:5b88d5760320 1498
kenjiArai 0:5b88d5760320 1499 mbedtls_des_init( des );
kenjiArai 0:5b88d5760320 1500
kenjiArai 0:5b88d5760320 1501 return( des );
kenjiArai 0:5b88d5760320 1502 }
kenjiArai 0:5b88d5760320 1503
kenjiArai 0:5b88d5760320 1504 static void des_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 1505 {
kenjiArai 0:5b88d5760320 1506 mbedtls_des_free( (mbedtls_des_context *) ctx );
kenjiArai 0:5b88d5760320 1507 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 1508 }
kenjiArai 0:5b88d5760320 1509
kenjiArai 0:5b88d5760320 1510 static void * des3_ctx_alloc( void )
kenjiArai 0:5b88d5760320 1511 {
kenjiArai 0:5b88d5760320 1512 mbedtls_des3_context *des3;
kenjiArai 0:5b88d5760320 1513 des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
kenjiArai 0:5b88d5760320 1514
kenjiArai 0:5b88d5760320 1515 if( des3 == NULL )
kenjiArai 0:5b88d5760320 1516 return( NULL );
kenjiArai 0:5b88d5760320 1517
kenjiArai 0:5b88d5760320 1518 mbedtls_des3_init( des3 );
kenjiArai 0:5b88d5760320 1519
kenjiArai 0:5b88d5760320 1520 return( des3 );
kenjiArai 0:5b88d5760320 1521 }
kenjiArai 0:5b88d5760320 1522
kenjiArai 0:5b88d5760320 1523 static void des3_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 1524 {
kenjiArai 0:5b88d5760320 1525 mbedtls_des3_free( (mbedtls_des3_context *) ctx );
kenjiArai 0:5b88d5760320 1526 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 1527 }
kenjiArai 0:5b88d5760320 1528
kenjiArai 0:5b88d5760320 1529 static const mbedtls_cipher_base_t des_info = {
kenjiArai 0:5b88d5760320 1530 MBEDTLS_CIPHER_ID_DES,
kenjiArai 0:5b88d5760320 1531 des_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 1532 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1533 des_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 1534 #endif
kenjiArai 0:5b88d5760320 1535 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1536 NULL,
kenjiArai 0:5b88d5760320 1537 #endif
kenjiArai 0:5b88d5760320 1538 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1539 NULL,
kenjiArai 0:5b88d5760320 1540 #endif
kenjiArai 0:5b88d5760320 1541 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1542 NULL,
kenjiArai 0:5b88d5760320 1543 #endif
kenjiArai 0:5b88d5760320 1544 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1545 NULL,
kenjiArai 0:5b88d5760320 1546 #endif
kenjiArai 0:5b88d5760320 1547 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1548 NULL,
kenjiArai 0:5b88d5760320 1549 #endif
kenjiArai 0:5b88d5760320 1550 des_setkey_enc_wrap,
kenjiArai 0:5b88d5760320 1551 des_setkey_dec_wrap,
kenjiArai 0:5b88d5760320 1552 des_ctx_alloc,
kenjiArai 0:5b88d5760320 1553 des_ctx_free
kenjiArai 0:5b88d5760320 1554 };
kenjiArai 0:5b88d5760320 1555
kenjiArai 0:5b88d5760320 1556 static const mbedtls_cipher_info_t des_ecb_info = {
kenjiArai 0:5b88d5760320 1557 MBEDTLS_CIPHER_DES_ECB,
kenjiArai 0:5b88d5760320 1558 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1559 MBEDTLS_KEY_LENGTH_DES,
kenjiArai 0:5b88d5760320 1560 "DES-ECB",
kenjiArai 0:5b88d5760320 1561 8,
kenjiArai 0:5b88d5760320 1562 0,
kenjiArai 0:5b88d5760320 1563 8,
kenjiArai 0:5b88d5760320 1564 &des_info
kenjiArai 0:5b88d5760320 1565 };
kenjiArai 0:5b88d5760320 1566
kenjiArai 0:5b88d5760320 1567 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1568 static const mbedtls_cipher_info_t des_cbc_info = {
kenjiArai 0:5b88d5760320 1569 MBEDTLS_CIPHER_DES_CBC,
kenjiArai 0:5b88d5760320 1570 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1571 MBEDTLS_KEY_LENGTH_DES,
kenjiArai 0:5b88d5760320 1572 "DES-CBC",
kenjiArai 0:5b88d5760320 1573 8,
kenjiArai 0:5b88d5760320 1574 0,
kenjiArai 0:5b88d5760320 1575 8,
kenjiArai 0:5b88d5760320 1576 &des_info
kenjiArai 0:5b88d5760320 1577 };
kenjiArai 0:5b88d5760320 1578 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1579
kenjiArai 0:5b88d5760320 1580 static const mbedtls_cipher_base_t des_ede_info = {
kenjiArai 0:5b88d5760320 1581 MBEDTLS_CIPHER_ID_DES,
kenjiArai 0:5b88d5760320 1582 des3_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 1583 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1584 des3_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 1585 #endif
kenjiArai 0:5b88d5760320 1586 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1587 NULL,
kenjiArai 0:5b88d5760320 1588 #endif
kenjiArai 0:5b88d5760320 1589 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1590 NULL,
kenjiArai 0:5b88d5760320 1591 #endif
kenjiArai 0:5b88d5760320 1592 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1593 NULL,
kenjiArai 0:5b88d5760320 1594 #endif
kenjiArai 0:5b88d5760320 1595 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1596 NULL,
kenjiArai 0:5b88d5760320 1597 #endif
kenjiArai 0:5b88d5760320 1598 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1599 NULL,
kenjiArai 0:5b88d5760320 1600 #endif
kenjiArai 0:5b88d5760320 1601 des3_set2key_enc_wrap,
kenjiArai 0:5b88d5760320 1602 des3_set2key_dec_wrap,
kenjiArai 0:5b88d5760320 1603 des3_ctx_alloc,
kenjiArai 0:5b88d5760320 1604 des3_ctx_free
kenjiArai 0:5b88d5760320 1605 };
kenjiArai 0:5b88d5760320 1606
kenjiArai 0:5b88d5760320 1607 static const mbedtls_cipher_info_t des_ede_ecb_info = {
kenjiArai 0:5b88d5760320 1608 MBEDTLS_CIPHER_DES_EDE_ECB,
kenjiArai 0:5b88d5760320 1609 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1610 MBEDTLS_KEY_LENGTH_DES_EDE,
kenjiArai 0:5b88d5760320 1611 "DES-EDE-ECB",
kenjiArai 0:5b88d5760320 1612 8,
kenjiArai 0:5b88d5760320 1613 0,
kenjiArai 0:5b88d5760320 1614 8,
kenjiArai 0:5b88d5760320 1615 &des_ede_info
kenjiArai 0:5b88d5760320 1616 };
kenjiArai 0:5b88d5760320 1617
kenjiArai 0:5b88d5760320 1618 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1619 static const mbedtls_cipher_info_t des_ede_cbc_info = {
kenjiArai 0:5b88d5760320 1620 MBEDTLS_CIPHER_DES_EDE_CBC,
kenjiArai 0:5b88d5760320 1621 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1622 MBEDTLS_KEY_LENGTH_DES_EDE,
kenjiArai 0:5b88d5760320 1623 "DES-EDE-CBC",
kenjiArai 0:5b88d5760320 1624 8,
kenjiArai 0:5b88d5760320 1625 0,
kenjiArai 0:5b88d5760320 1626 8,
kenjiArai 0:5b88d5760320 1627 &des_ede_info
kenjiArai 0:5b88d5760320 1628 };
kenjiArai 0:5b88d5760320 1629 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1630
kenjiArai 0:5b88d5760320 1631 static const mbedtls_cipher_base_t des_ede3_info = {
kenjiArai 0:5b88d5760320 1632 MBEDTLS_CIPHER_ID_3DES,
kenjiArai 0:5b88d5760320 1633 des3_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 1634 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1635 des3_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 1636 #endif
kenjiArai 0:5b88d5760320 1637 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1638 NULL,
kenjiArai 0:5b88d5760320 1639 #endif
kenjiArai 0:5b88d5760320 1640 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1641 NULL,
kenjiArai 0:5b88d5760320 1642 #endif
kenjiArai 0:5b88d5760320 1643 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1644 NULL,
kenjiArai 0:5b88d5760320 1645 #endif
kenjiArai 0:5b88d5760320 1646 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1647 NULL,
kenjiArai 0:5b88d5760320 1648 #endif
kenjiArai 0:5b88d5760320 1649 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1650 NULL,
kenjiArai 0:5b88d5760320 1651 #endif
kenjiArai 0:5b88d5760320 1652 des3_set3key_enc_wrap,
kenjiArai 0:5b88d5760320 1653 des3_set3key_dec_wrap,
kenjiArai 0:5b88d5760320 1654 des3_ctx_alloc,
kenjiArai 0:5b88d5760320 1655 des3_ctx_free
kenjiArai 0:5b88d5760320 1656 };
kenjiArai 0:5b88d5760320 1657
kenjiArai 0:5b88d5760320 1658 static const mbedtls_cipher_info_t des_ede3_ecb_info = {
kenjiArai 0:5b88d5760320 1659 MBEDTLS_CIPHER_DES_EDE3_ECB,
kenjiArai 0:5b88d5760320 1660 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1661 MBEDTLS_KEY_LENGTH_DES_EDE3,
kenjiArai 0:5b88d5760320 1662 "DES-EDE3-ECB",
kenjiArai 0:5b88d5760320 1663 8,
kenjiArai 0:5b88d5760320 1664 0,
kenjiArai 0:5b88d5760320 1665 8,
kenjiArai 0:5b88d5760320 1666 &des_ede3_info
kenjiArai 0:5b88d5760320 1667 };
kenjiArai 0:5b88d5760320 1668 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1669 static const mbedtls_cipher_info_t des_ede3_cbc_info = {
kenjiArai 0:5b88d5760320 1670 MBEDTLS_CIPHER_DES_EDE3_CBC,
kenjiArai 0:5b88d5760320 1671 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1672 MBEDTLS_KEY_LENGTH_DES_EDE3,
kenjiArai 0:5b88d5760320 1673 "DES-EDE3-CBC",
kenjiArai 0:5b88d5760320 1674 8,
kenjiArai 0:5b88d5760320 1675 0,
kenjiArai 0:5b88d5760320 1676 8,
kenjiArai 0:5b88d5760320 1677 &des_ede3_info
kenjiArai 0:5b88d5760320 1678 };
kenjiArai 0:5b88d5760320 1679 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1680 #endif /* MBEDTLS_DES_C */
kenjiArai 0:5b88d5760320 1681
kenjiArai 0:5b88d5760320 1682 #if defined(MBEDTLS_BLOWFISH_C)
kenjiArai 0:5b88d5760320 1683
kenjiArai 0:5b88d5760320 1684 static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1685 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1686 {
kenjiArai 0:5b88d5760320 1687 return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
kenjiArai 0:5b88d5760320 1688 output );
kenjiArai 0:5b88d5760320 1689 }
kenjiArai 0:5b88d5760320 1690
kenjiArai 0:5b88d5760320 1691 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1692 static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1693 size_t length, unsigned char *iv, const unsigned char *input,
kenjiArai 0:5b88d5760320 1694 unsigned char *output )
kenjiArai 0:5b88d5760320 1695 {
kenjiArai 0:5b88d5760320 1696 return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
kenjiArai 0:5b88d5760320 1697 input, output );
kenjiArai 0:5b88d5760320 1698 }
kenjiArai 0:5b88d5760320 1699 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1700
kenjiArai 0:5b88d5760320 1701 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1702 static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
kenjiArai 0:5b88d5760320 1703 size_t length, size_t *iv_off, unsigned char *iv,
kenjiArai 0:5b88d5760320 1704 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1705 {
kenjiArai 0:5b88d5760320 1706 return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
kenjiArai 0:5b88d5760320 1707 iv_off, iv, input, output );
kenjiArai 0:5b88d5760320 1708 }
kenjiArai 0:5b88d5760320 1709 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 1710
kenjiArai 0:5b88d5760320 1711 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1712 static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
kenjiArai 0:5b88d5760320 1713 unsigned char *nonce_counter, unsigned char *stream_block,
kenjiArai 0:5b88d5760320 1714 const unsigned char *input, unsigned char *output )
kenjiArai 0:5b88d5760320 1715 {
kenjiArai 0:5b88d5760320 1716 return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
kenjiArai 0:5b88d5760320 1717 nonce_counter, stream_block, input, output );
kenjiArai 0:5b88d5760320 1718 }
kenjiArai 0:5b88d5760320 1719 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 1720
kenjiArai 0:5b88d5760320 1721 static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1722 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1723 {
kenjiArai 0:5b88d5760320 1724 return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
kenjiArai 0:5b88d5760320 1725 }
kenjiArai 0:5b88d5760320 1726
kenjiArai 0:5b88d5760320 1727 static void * blowfish_ctx_alloc( void )
kenjiArai 0:5b88d5760320 1728 {
kenjiArai 0:5b88d5760320 1729 mbedtls_blowfish_context *ctx;
kenjiArai 0:5b88d5760320 1730 ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
kenjiArai 0:5b88d5760320 1731
kenjiArai 0:5b88d5760320 1732 if( ctx == NULL )
kenjiArai 0:5b88d5760320 1733 return( NULL );
kenjiArai 0:5b88d5760320 1734
kenjiArai 0:5b88d5760320 1735 mbedtls_blowfish_init( ctx );
kenjiArai 0:5b88d5760320 1736
kenjiArai 0:5b88d5760320 1737 return( ctx );
kenjiArai 0:5b88d5760320 1738 }
kenjiArai 0:5b88d5760320 1739
kenjiArai 0:5b88d5760320 1740 static void blowfish_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 1741 {
kenjiArai 0:5b88d5760320 1742 mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
kenjiArai 0:5b88d5760320 1743 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 1744 }
kenjiArai 0:5b88d5760320 1745
kenjiArai 0:5b88d5760320 1746 static const mbedtls_cipher_base_t blowfish_info = {
kenjiArai 0:5b88d5760320 1747 MBEDTLS_CIPHER_ID_BLOWFISH,
kenjiArai 0:5b88d5760320 1748 blowfish_crypt_ecb_wrap,
kenjiArai 0:5b88d5760320 1749 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1750 blowfish_crypt_cbc_wrap,
kenjiArai 0:5b88d5760320 1751 #endif
kenjiArai 0:5b88d5760320 1752 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1753 blowfish_crypt_cfb64_wrap,
kenjiArai 0:5b88d5760320 1754 #endif
kenjiArai 0:5b88d5760320 1755 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1756 NULL,
kenjiArai 0:5b88d5760320 1757 #endif
kenjiArai 0:5b88d5760320 1758 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1759 blowfish_crypt_ctr_wrap,
kenjiArai 0:5b88d5760320 1760 #endif
kenjiArai 0:5b88d5760320 1761 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1762 NULL,
kenjiArai 0:5b88d5760320 1763 #endif
kenjiArai 0:5b88d5760320 1764 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1765 NULL,
kenjiArai 0:5b88d5760320 1766 #endif
kenjiArai 0:5b88d5760320 1767 blowfish_setkey_wrap,
kenjiArai 0:5b88d5760320 1768 blowfish_setkey_wrap,
kenjiArai 0:5b88d5760320 1769 blowfish_ctx_alloc,
kenjiArai 0:5b88d5760320 1770 blowfish_ctx_free
kenjiArai 0:5b88d5760320 1771 };
kenjiArai 0:5b88d5760320 1772
kenjiArai 0:5b88d5760320 1773 static const mbedtls_cipher_info_t blowfish_ecb_info = {
kenjiArai 0:5b88d5760320 1774 MBEDTLS_CIPHER_BLOWFISH_ECB,
kenjiArai 0:5b88d5760320 1775 MBEDTLS_MODE_ECB,
kenjiArai 0:5b88d5760320 1776 128,
kenjiArai 0:5b88d5760320 1777 "BLOWFISH-ECB",
kenjiArai 0:5b88d5760320 1778 8,
kenjiArai 0:5b88d5760320 1779 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
kenjiArai 0:5b88d5760320 1780 8,
kenjiArai 0:5b88d5760320 1781 &blowfish_info
kenjiArai 0:5b88d5760320 1782 };
kenjiArai 0:5b88d5760320 1783
kenjiArai 0:5b88d5760320 1784 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1785 static const mbedtls_cipher_info_t blowfish_cbc_info = {
kenjiArai 0:5b88d5760320 1786 MBEDTLS_CIPHER_BLOWFISH_CBC,
kenjiArai 0:5b88d5760320 1787 MBEDTLS_MODE_CBC,
kenjiArai 0:5b88d5760320 1788 128,
kenjiArai 0:5b88d5760320 1789 "BLOWFISH-CBC",
kenjiArai 0:5b88d5760320 1790 8,
kenjiArai 0:5b88d5760320 1791 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
kenjiArai 0:5b88d5760320 1792 8,
kenjiArai 0:5b88d5760320 1793 &blowfish_info
kenjiArai 0:5b88d5760320 1794 };
kenjiArai 0:5b88d5760320 1795 #endif /* MBEDTLS_CIPHER_MODE_CBC */
kenjiArai 0:5b88d5760320 1796
kenjiArai 0:5b88d5760320 1797 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1798 static const mbedtls_cipher_info_t blowfish_cfb64_info = {
kenjiArai 0:5b88d5760320 1799 MBEDTLS_CIPHER_BLOWFISH_CFB64,
kenjiArai 0:5b88d5760320 1800 MBEDTLS_MODE_CFB,
kenjiArai 0:5b88d5760320 1801 128,
kenjiArai 0:5b88d5760320 1802 "BLOWFISH-CFB64",
kenjiArai 0:5b88d5760320 1803 8,
kenjiArai 0:5b88d5760320 1804 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
kenjiArai 0:5b88d5760320 1805 8,
kenjiArai 0:5b88d5760320 1806 &blowfish_info
kenjiArai 0:5b88d5760320 1807 };
kenjiArai 0:5b88d5760320 1808 #endif /* MBEDTLS_CIPHER_MODE_CFB */
kenjiArai 0:5b88d5760320 1809
kenjiArai 0:5b88d5760320 1810 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1811 static const mbedtls_cipher_info_t blowfish_ctr_info = {
kenjiArai 0:5b88d5760320 1812 MBEDTLS_CIPHER_BLOWFISH_CTR,
kenjiArai 0:5b88d5760320 1813 MBEDTLS_MODE_CTR,
kenjiArai 0:5b88d5760320 1814 128,
kenjiArai 0:5b88d5760320 1815 "BLOWFISH-CTR",
kenjiArai 0:5b88d5760320 1816 8,
kenjiArai 0:5b88d5760320 1817 MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
kenjiArai 0:5b88d5760320 1818 8,
kenjiArai 0:5b88d5760320 1819 &blowfish_info
kenjiArai 0:5b88d5760320 1820 };
kenjiArai 0:5b88d5760320 1821 #endif /* MBEDTLS_CIPHER_MODE_CTR */
kenjiArai 0:5b88d5760320 1822 #endif /* MBEDTLS_BLOWFISH_C */
kenjiArai 0:5b88d5760320 1823
kenjiArai 0:5b88d5760320 1824 #if defined(MBEDTLS_ARC4_C)
kenjiArai 0:5b88d5760320 1825 static int arc4_crypt_stream_wrap( void *ctx, size_t length,
kenjiArai 0:5b88d5760320 1826 const unsigned char *input,
kenjiArai 0:5b88d5760320 1827 unsigned char *output )
kenjiArai 0:5b88d5760320 1828 {
kenjiArai 0:5b88d5760320 1829 return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
kenjiArai 0:5b88d5760320 1830 }
kenjiArai 0:5b88d5760320 1831
kenjiArai 0:5b88d5760320 1832 static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1833 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1834 {
kenjiArai 0:5b88d5760320 1835 /* we get key_bitlen in bits, arc4 expects it in bytes */
kenjiArai 0:5b88d5760320 1836 if( key_bitlen % 8 != 0 )
kenjiArai 0:5b88d5760320 1837 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
kenjiArai 0:5b88d5760320 1838
kenjiArai 0:5b88d5760320 1839 mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
kenjiArai 0:5b88d5760320 1840 return( 0 );
kenjiArai 0:5b88d5760320 1841 }
kenjiArai 0:5b88d5760320 1842
kenjiArai 0:5b88d5760320 1843 static void * arc4_ctx_alloc( void )
kenjiArai 0:5b88d5760320 1844 {
kenjiArai 0:5b88d5760320 1845 mbedtls_arc4_context *ctx;
kenjiArai 0:5b88d5760320 1846 ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
kenjiArai 0:5b88d5760320 1847
kenjiArai 0:5b88d5760320 1848 if( ctx == NULL )
kenjiArai 0:5b88d5760320 1849 return( NULL );
kenjiArai 0:5b88d5760320 1850
kenjiArai 0:5b88d5760320 1851 mbedtls_arc4_init( ctx );
kenjiArai 0:5b88d5760320 1852
kenjiArai 0:5b88d5760320 1853 return( ctx );
kenjiArai 0:5b88d5760320 1854 }
kenjiArai 0:5b88d5760320 1855
kenjiArai 0:5b88d5760320 1856 static void arc4_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 1857 {
kenjiArai 0:5b88d5760320 1858 mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
kenjiArai 0:5b88d5760320 1859 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 1860 }
kenjiArai 0:5b88d5760320 1861
kenjiArai 0:5b88d5760320 1862 static const mbedtls_cipher_base_t arc4_base_info = {
kenjiArai 0:5b88d5760320 1863 MBEDTLS_CIPHER_ID_ARC4,
kenjiArai 0:5b88d5760320 1864 NULL,
kenjiArai 0:5b88d5760320 1865 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1866 NULL,
kenjiArai 0:5b88d5760320 1867 #endif
kenjiArai 0:5b88d5760320 1868 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1869 NULL,
kenjiArai 0:5b88d5760320 1870 #endif
kenjiArai 0:5b88d5760320 1871 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1872 NULL,
kenjiArai 0:5b88d5760320 1873 #endif
kenjiArai 0:5b88d5760320 1874 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1875 NULL,
kenjiArai 0:5b88d5760320 1876 #endif
kenjiArai 0:5b88d5760320 1877 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1878 NULL,
kenjiArai 0:5b88d5760320 1879 #endif
kenjiArai 0:5b88d5760320 1880 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1881 arc4_crypt_stream_wrap,
kenjiArai 0:5b88d5760320 1882 #endif
kenjiArai 0:5b88d5760320 1883 arc4_setkey_wrap,
kenjiArai 0:5b88d5760320 1884 arc4_setkey_wrap,
kenjiArai 0:5b88d5760320 1885 arc4_ctx_alloc,
kenjiArai 0:5b88d5760320 1886 arc4_ctx_free
kenjiArai 0:5b88d5760320 1887 };
kenjiArai 0:5b88d5760320 1888
kenjiArai 0:5b88d5760320 1889 static const mbedtls_cipher_info_t arc4_128_info = {
kenjiArai 0:5b88d5760320 1890 MBEDTLS_CIPHER_ARC4_128,
kenjiArai 0:5b88d5760320 1891 MBEDTLS_MODE_STREAM,
kenjiArai 0:5b88d5760320 1892 128,
kenjiArai 0:5b88d5760320 1893 "ARC4-128",
kenjiArai 0:5b88d5760320 1894 0,
kenjiArai 0:5b88d5760320 1895 0,
kenjiArai 0:5b88d5760320 1896 1,
kenjiArai 0:5b88d5760320 1897 &arc4_base_info
kenjiArai 0:5b88d5760320 1898 };
kenjiArai 0:5b88d5760320 1899 #endif /* MBEDTLS_ARC4_C */
kenjiArai 0:5b88d5760320 1900
kenjiArai 0:5b88d5760320 1901 #if defined(MBEDTLS_CHACHA20_C)
kenjiArai 0:5b88d5760320 1902
kenjiArai 0:5b88d5760320 1903 static int chacha20_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 1904 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1905 {
kenjiArai 0:5b88d5760320 1906 if( key_bitlen != 256U )
kenjiArai 0:5b88d5760320 1907 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
kenjiArai 0:5b88d5760320 1908
kenjiArai 0:5b88d5760320 1909 if ( 0 != mbedtls_chacha20_setkey( (mbedtls_chacha20_context*)ctx, key ) )
kenjiArai 0:5b88d5760320 1910 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
kenjiArai 0:5b88d5760320 1911
kenjiArai 0:5b88d5760320 1912 return( 0 );
kenjiArai 0:5b88d5760320 1913 }
kenjiArai 0:5b88d5760320 1914
kenjiArai 0:5b88d5760320 1915 static int chacha20_stream_wrap( void *ctx, size_t length,
kenjiArai 0:5b88d5760320 1916 const unsigned char *input,
kenjiArai 0:5b88d5760320 1917 unsigned char *output )
kenjiArai 0:5b88d5760320 1918 {
kenjiArai 0:5b88d5760320 1919 int ret;
kenjiArai 0:5b88d5760320 1920
kenjiArai 0:5b88d5760320 1921 ret = mbedtls_chacha20_update( ctx, length, input, output );
kenjiArai 0:5b88d5760320 1922 if( ret == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA )
kenjiArai 0:5b88d5760320 1923 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
kenjiArai 0:5b88d5760320 1924
kenjiArai 0:5b88d5760320 1925 return( ret );
kenjiArai 0:5b88d5760320 1926 }
kenjiArai 0:5b88d5760320 1927
kenjiArai 0:5b88d5760320 1928 static void * chacha20_ctx_alloc( void )
kenjiArai 0:5b88d5760320 1929 {
kenjiArai 0:5b88d5760320 1930 mbedtls_chacha20_context *ctx;
kenjiArai 0:5b88d5760320 1931 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chacha20_context ) );
kenjiArai 0:5b88d5760320 1932
kenjiArai 0:5b88d5760320 1933 if( ctx == NULL )
kenjiArai 0:5b88d5760320 1934 return( NULL );
kenjiArai 0:5b88d5760320 1935
kenjiArai 0:5b88d5760320 1936 mbedtls_chacha20_init( ctx );
kenjiArai 0:5b88d5760320 1937
kenjiArai 0:5b88d5760320 1938 return( ctx );
kenjiArai 0:5b88d5760320 1939 }
kenjiArai 0:5b88d5760320 1940
kenjiArai 0:5b88d5760320 1941 static void chacha20_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 1942 {
kenjiArai 0:5b88d5760320 1943 mbedtls_chacha20_free( (mbedtls_chacha20_context *) ctx );
kenjiArai 0:5b88d5760320 1944 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 1945 }
kenjiArai 0:5b88d5760320 1946
kenjiArai 0:5b88d5760320 1947 static const mbedtls_cipher_base_t chacha20_base_info = {
kenjiArai 0:5b88d5760320 1948 MBEDTLS_CIPHER_ID_CHACHA20,
kenjiArai 0:5b88d5760320 1949 NULL,
kenjiArai 0:5b88d5760320 1950 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 1951 NULL,
kenjiArai 0:5b88d5760320 1952 #endif
kenjiArai 0:5b88d5760320 1953 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 1954 NULL,
kenjiArai 0:5b88d5760320 1955 #endif
kenjiArai 0:5b88d5760320 1956 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 1957 NULL,
kenjiArai 0:5b88d5760320 1958 #endif
kenjiArai 0:5b88d5760320 1959 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 1960 NULL,
kenjiArai 0:5b88d5760320 1961 #endif
kenjiArai 0:5b88d5760320 1962 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 1963 NULL,
kenjiArai 0:5b88d5760320 1964 #endif
kenjiArai 0:5b88d5760320 1965 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 1966 chacha20_stream_wrap,
kenjiArai 0:5b88d5760320 1967 #endif
kenjiArai 0:5b88d5760320 1968 chacha20_setkey_wrap,
kenjiArai 0:5b88d5760320 1969 chacha20_setkey_wrap,
kenjiArai 0:5b88d5760320 1970 chacha20_ctx_alloc,
kenjiArai 0:5b88d5760320 1971 chacha20_ctx_free
kenjiArai 0:5b88d5760320 1972 };
kenjiArai 0:5b88d5760320 1973 static const mbedtls_cipher_info_t chacha20_info = {
kenjiArai 0:5b88d5760320 1974 MBEDTLS_CIPHER_CHACHA20,
kenjiArai 0:5b88d5760320 1975 MBEDTLS_MODE_STREAM,
kenjiArai 0:5b88d5760320 1976 256,
kenjiArai 0:5b88d5760320 1977 "CHACHA20",
kenjiArai 0:5b88d5760320 1978 12,
kenjiArai 0:5b88d5760320 1979 0,
kenjiArai 0:5b88d5760320 1980 1,
kenjiArai 0:5b88d5760320 1981 &chacha20_base_info
kenjiArai 0:5b88d5760320 1982 };
kenjiArai 0:5b88d5760320 1983 #endif /* MBEDTLS_CHACHA20_C */
kenjiArai 0:5b88d5760320 1984
kenjiArai 0:5b88d5760320 1985 #if defined(MBEDTLS_CHACHAPOLY_C)
kenjiArai 0:5b88d5760320 1986
kenjiArai 0:5b88d5760320 1987 static int chachapoly_setkey_wrap( void *ctx,
kenjiArai 0:5b88d5760320 1988 const unsigned char *key,
kenjiArai 0:5b88d5760320 1989 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 1990 {
kenjiArai 0:5b88d5760320 1991 if( key_bitlen != 256U )
kenjiArai 0:5b88d5760320 1992 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
kenjiArai 0:5b88d5760320 1993
kenjiArai 0:5b88d5760320 1994 if ( 0 != mbedtls_chachapoly_setkey( (mbedtls_chachapoly_context*)ctx, key ) )
kenjiArai 0:5b88d5760320 1995 return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
kenjiArai 0:5b88d5760320 1996
kenjiArai 0:5b88d5760320 1997 return( 0 );
kenjiArai 0:5b88d5760320 1998 }
kenjiArai 0:5b88d5760320 1999
kenjiArai 0:5b88d5760320 2000 static void * chachapoly_ctx_alloc( void )
kenjiArai 0:5b88d5760320 2001 {
kenjiArai 0:5b88d5760320 2002 mbedtls_chachapoly_context *ctx;
kenjiArai 0:5b88d5760320 2003 ctx = mbedtls_calloc( 1, sizeof( mbedtls_chachapoly_context ) );
kenjiArai 0:5b88d5760320 2004
kenjiArai 0:5b88d5760320 2005 if( ctx == NULL )
kenjiArai 0:5b88d5760320 2006 return( NULL );
kenjiArai 0:5b88d5760320 2007
kenjiArai 0:5b88d5760320 2008 mbedtls_chachapoly_init( ctx );
kenjiArai 0:5b88d5760320 2009
kenjiArai 0:5b88d5760320 2010 return( ctx );
kenjiArai 0:5b88d5760320 2011 }
kenjiArai 0:5b88d5760320 2012
kenjiArai 0:5b88d5760320 2013 static void chachapoly_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 2014 {
kenjiArai 0:5b88d5760320 2015 mbedtls_chachapoly_free( (mbedtls_chachapoly_context *) ctx );
kenjiArai 0:5b88d5760320 2016 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 2017 }
kenjiArai 0:5b88d5760320 2018
kenjiArai 0:5b88d5760320 2019 static const mbedtls_cipher_base_t chachapoly_base_info = {
kenjiArai 0:5b88d5760320 2020 MBEDTLS_CIPHER_ID_CHACHA20,
kenjiArai 0:5b88d5760320 2021 NULL,
kenjiArai 0:5b88d5760320 2022 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2023 NULL,
kenjiArai 0:5b88d5760320 2024 #endif
kenjiArai 0:5b88d5760320 2025 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2026 NULL,
kenjiArai 0:5b88d5760320 2027 #endif
kenjiArai 0:5b88d5760320 2028 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 2029 NULL,
kenjiArai 0:5b88d5760320 2030 #endif
kenjiArai 0:5b88d5760320 2031 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2032 NULL,
kenjiArai 0:5b88d5760320 2033 #endif
kenjiArai 0:5b88d5760320 2034 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 2035 NULL,
kenjiArai 0:5b88d5760320 2036 #endif
kenjiArai 0:5b88d5760320 2037 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 2038 NULL,
kenjiArai 0:5b88d5760320 2039 #endif
kenjiArai 0:5b88d5760320 2040 chachapoly_setkey_wrap,
kenjiArai 0:5b88d5760320 2041 chachapoly_setkey_wrap,
kenjiArai 0:5b88d5760320 2042 chachapoly_ctx_alloc,
kenjiArai 0:5b88d5760320 2043 chachapoly_ctx_free
kenjiArai 0:5b88d5760320 2044 };
kenjiArai 0:5b88d5760320 2045 static const mbedtls_cipher_info_t chachapoly_info = {
kenjiArai 0:5b88d5760320 2046 MBEDTLS_CIPHER_CHACHA20_POLY1305,
kenjiArai 0:5b88d5760320 2047 MBEDTLS_MODE_CHACHAPOLY,
kenjiArai 0:5b88d5760320 2048 256,
kenjiArai 0:5b88d5760320 2049 "CHACHA20-POLY1305",
kenjiArai 0:5b88d5760320 2050 12,
kenjiArai 0:5b88d5760320 2051 0,
kenjiArai 0:5b88d5760320 2052 1,
kenjiArai 0:5b88d5760320 2053 &chachapoly_base_info
kenjiArai 0:5b88d5760320 2054 };
kenjiArai 0:5b88d5760320 2055 #endif /* MBEDTLS_CHACHAPOLY_C */
kenjiArai 0:5b88d5760320 2056
kenjiArai 0:5b88d5760320 2057 #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
kenjiArai 0:5b88d5760320 2058 static int null_crypt_stream( void *ctx, size_t length,
kenjiArai 0:5b88d5760320 2059 const unsigned char *input,
kenjiArai 0:5b88d5760320 2060 unsigned char *output )
kenjiArai 0:5b88d5760320 2061 {
kenjiArai 0:5b88d5760320 2062 ((void) ctx);
kenjiArai 0:5b88d5760320 2063 memmove( output, input, length );
kenjiArai 0:5b88d5760320 2064 return( 0 );
kenjiArai 0:5b88d5760320 2065 }
kenjiArai 0:5b88d5760320 2066
kenjiArai 0:5b88d5760320 2067 static int null_setkey( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 2068 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 2069 {
kenjiArai 0:5b88d5760320 2070 ((void) ctx);
kenjiArai 0:5b88d5760320 2071 ((void) key);
kenjiArai 0:5b88d5760320 2072 ((void) key_bitlen);
kenjiArai 0:5b88d5760320 2073
kenjiArai 0:5b88d5760320 2074 return( 0 );
kenjiArai 0:5b88d5760320 2075 }
kenjiArai 0:5b88d5760320 2076
kenjiArai 0:5b88d5760320 2077 static void * null_ctx_alloc( void )
kenjiArai 0:5b88d5760320 2078 {
kenjiArai 0:5b88d5760320 2079 return( (void *) 1 );
kenjiArai 0:5b88d5760320 2080 }
kenjiArai 0:5b88d5760320 2081
kenjiArai 0:5b88d5760320 2082 static void null_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 2083 {
kenjiArai 0:5b88d5760320 2084 ((void) ctx);
kenjiArai 0:5b88d5760320 2085 }
kenjiArai 0:5b88d5760320 2086
kenjiArai 0:5b88d5760320 2087 static const mbedtls_cipher_base_t null_base_info = {
kenjiArai 0:5b88d5760320 2088 MBEDTLS_CIPHER_ID_NULL,
kenjiArai 0:5b88d5760320 2089 NULL,
kenjiArai 0:5b88d5760320 2090 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2091 NULL,
kenjiArai 0:5b88d5760320 2092 #endif
kenjiArai 0:5b88d5760320 2093 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2094 NULL,
kenjiArai 0:5b88d5760320 2095 #endif
kenjiArai 0:5b88d5760320 2096 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 2097 NULL,
kenjiArai 0:5b88d5760320 2098 #endif
kenjiArai 0:5b88d5760320 2099 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2100 NULL,
kenjiArai 0:5b88d5760320 2101 #endif
kenjiArai 0:5b88d5760320 2102 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 2103 NULL,
kenjiArai 0:5b88d5760320 2104 #endif
kenjiArai 0:5b88d5760320 2105 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 2106 null_crypt_stream,
kenjiArai 0:5b88d5760320 2107 #endif
kenjiArai 0:5b88d5760320 2108 null_setkey,
kenjiArai 0:5b88d5760320 2109 null_setkey,
kenjiArai 0:5b88d5760320 2110 null_ctx_alloc,
kenjiArai 0:5b88d5760320 2111 null_ctx_free
kenjiArai 0:5b88d5760320 2112 };
kenjiArai 0:5b88d5760320 2113
kenjiArai 0:5b88d5760320 2114 static const mbedtls_cipher_info_t null_cipher_info = {
kenjiArai 0:5b88d5760320 2115 MBEDTLS_CIPHER_NULL,
kenjiArai 0:5b88d5760320 2116 MBEDTLS_MODE_STREAM,
kenjiArai 0:5b88d5760320 2117 0,
kenjiArai 0:5b88d5760320 2118 "NULL",
kenjiArai 0:5b88d5760320 2119 0,
kenjiArai 0:5b88d5760320 2120 0,
kenjiArai 0:5b88d5760320 2121 1,
kenjiArai 0:5b88d5760320 2122 &null_base_info
kenjiArai 0:5b88d5760320 2123 };
kenjiArai 0:5b88d5760320 2124 #endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
kenjiArai 0:5b88d5760320 2125
kenjiArai 0:5b88d5760320 2126 #if defined(MBEDTLS_NIST_KW_C)
kenjiArai 0:5b88d5760320 2127 static void *kw_ctx_alloc( void )
kenjiArai 0:5b88d5760320 2128 {
kenjiArai 0:5b88d5760320 2129 void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_nist_kw_context ) );
kenjiArai 0:5b88d5760320 2130
kenjiArai 0:5b88d5760320 2131 if( ctx != NULL )
kenjiArai 0:5b88d5760320 2132 mbedtls_nist_kw_init( (mbedtls_nist_kw_context *) ctx );
kenjiArai 0:5b88d5760320 2133
kenjiArai 0:5b88d5760320 2134 return( ctx );
kenjiArai 0:5b88d5760320 2135 }
kenjiArai 0:5b88d5760320 2136
kenjiArai 0:5b88d5760320 2137 static void kw_ctx_free( void *ctx )
kenjiArai 0:5b88d5760320 2138 {
kenjiArai 0:5b88d5760320 2139 mbedtls_nist_kw_free( ctx );
kenjiArai 0:5b88d5760320 2140 mbedtls_free( ctx );
kenjiArai 0:5b88d5760320 2141 }
kenjiArai 0:5b88d5760320 2142
kenjiArai 0:5b88d5760320 2143 static int kw_aes_setkey_wrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 2144 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 2145 {
kenjiArai 0:5b88d5760320 2146 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
kenjiArai 0:5b88d5760320 2147 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 1 );
kenjiArai 0:5b88d5760320 2148 }
kenjiArai 0:5b88d5760320 2149
kenjiArai 0:5b88d5760320 2150 static int kw_aes_setkey_unwrap( void *ctx, const unsigned char *key,
kenjiArai 0:5b88d5760320 2151 unsigned int key_bitlen )
kenjiArai 0:5b88d5760320 2152 {
kenjiArai 0:5b88d5760320 2153 return mbedtls_nist_kw_setkey( (mbedtls_nist_kw_context *) ctx,
kenjiArai 0:5b88d5760320 2154 MBEDTLS_CIPHER_ID_AES, key, key_bitlen, 0 );
kenjiArai 0:5b88d5760320 2155 }
kenjiArai 0:5b88d5760320 2156
kenjiArai 0:5b88d5760320 2157 static const mbedtls_cipher_base_t kw_aes_info = {
kenjiArai 0:5b88d5760320 2158 MBEDTLS_CIPHER_ID_AES,
kenjiArai 0:5b88d5760320 2159 NULL,
kenjiArai 0:5b88d5760320 2160 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2161 NULL,
kenjiArai 0:5b88d5760320 2162 #endif
kenjiArai 0:5b88d5760320 2163 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2164 NULL,
kenjiArai 0:5b88d5760320 2165 #endif
kenjiArai 0:5b88d5760320 2166 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 2167 NULL,
kenjiArai 0:5b88d5760320 2168 #endif
kenjiArai 0:5b88d5760320 2169 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2170 NULL,
kenjiArai 0:5b88d5760320 2171 #endif
kenjiArai 0:5b88d5760320 2172 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 2173 NULL,
kenjiArai 0:5b88d5760320 2174 #endif
kenjiArai 0:5b88d5760320 2175 #if defined(MBEDTLS_CIPHER_MODE_STREAM)
kenjiArai 0:5b88d5760320 2176 NULL,
kenjiArai 0:5b88d5760320 2177 #endif
kenjiArai 0:5b88d5760320 2178 kw_aes_setkey_wrap,
kenjiArai 0:5b88d5760320 2179 kw_aes_setkey_unwrap,
kenjiArai 0:5b88d5760320 2180 kw_ctx_alloc,
kenjiArai 0:5b88d5760320 2181 kw_ctx_free,
kenjiArai 0:5b88d5760320 2182 };
kenjiArai 0:5b88d5760320 2183
kenjiArai 0:5b88d5760320 2184 static const mbedtls_cipher_info_t aes_128_nist_kw_info = {
kenjiArai 0:5b88d5760320 2185 MBEDTLS_CIPHER_AES_128_KW,
kenjiArai 0:5b88d5760320 2186 MBEDTLS_MODE_KW,
kenjiArai 0:5b88d5760320 2187 128,
kenjiArai 0:5b88d5760320 2188 "AES-128-KW",
kenjiArai 0:5b88d5760320 2189 0,
kenjiArai 0:5b88d5760320 2190 0,
kenjiArai 0:5b88d5760320 2191 16,
kenjiArai 0:5b88d5760320 2192 &kw_aes_info
kenjiArai 0:5b88d5760320 2193 };
kenjiArai 0:5b88d5760320 2194
kenjiArai 0:5b88d5760320 2195 static const mbedtls_cipher_info_t aes_192_nist_kw_info = {
kenjiArai 0:5b88d5760320 2196 MBEDTLS_CIPHER_AES_192_KW,
kenjiArai 0:5b88d5760320 2197 MBEDTLS_MODE_KW,
kenjiArai 0:5b88d5760320 2198 192,
kenjiArai 0:5b88d5760320 2199 "AES-192-KW",
kenjiArai 0:5b88d5760320 2200 0,
kenjiArai 0:5b88d5760320 2201 0,
kenjiArai 0:5b88d5760320 2202 16,
kenjiArai 0:5b88d5760320 2203 &kw_aes_info
kenjiArai 0:5b88d5760320 2204 };
kenjiArai 0:5b88d5760320 2205
kenjiArai 0:5b88d5760320 2206 static const mbedtls_cipher_info_t aes_256_nist_kw_info = {
kenjiArai 0:5b88d5760320 2207 MBEDTLS_CIPHER_AES_256_KW,
kenjiArai 0:5b88d5760320 2208 MBEDTLS_MODE_KW,
kenjiArai 0:5b88d5760320 2209 256,
kenjiArai 0:5b88d5760320 2210 "AES-256-KW",
kenjiArai 0:5b88d5760320 2211 0,
kenjiArai 0:5b88d5760320 2212 0,
kenjiArai 0:5b88d5760320 2213 16,
kenjiArai 0:5b88d5760320 2214 &kw_aes_info
kenjiArai 0:5b88d5760320 2215 };
kenjiArai 0:5b88d5760320 2216
kenjiArai 0:5b88d5760320 2217 static const mbedtls_cipher_info_t aes_128_nist_kwp_info = {
kenjiArai 0:5b88d5760320 2218 MBEDTLS_CIPHER_AES_128_KWP,
kenjiArai 0:5b88d5760320 2219 MBEDTLS_MODE_KWP,
kenjiArai 0:5b88d5760320 2220 128,
kenjiArai 0:5b88d5760320 2221 "AES-128-KWP",
kenjiArai 0:5b88d5760320 2222 0,
kenjiArai 0:5b88d5760320 2223 0,
kenjiArai 0:5b88d5760320 2224 16,
kenjiArai 0:5b88d5760320 2225 &kw_aes_info
kenjiArai 0:5b88d5760320 2226 };
kenjiArai 0:5b88d5760320 2227
kenjiArai 0:5b88d5760320 2228 static const mbedtls_cipher_info_t aes_192_nist_kwp_info = {
kenjiArai 0:5b88d5760320 2229 MBEDTLS_CIPHER_AES_192_KWP,
kenjiArai 0:5b88d5760320 2230 MBEDTLS_MODE_KWP,
kenjiArai 0:5b88d5760320 2231 192,
kenjiArai 0:5b88d5760320 2232 "AES-192-KWP",
kenjiArai 0:5b88d5760320 2233 0,
kenjiArai 0:5b88d5760320 2234 0,
kenjiArai 0:5b88d5760320 2235 16,
kenjiArai 0:5b88d5760320 2236 &kw_aes_info
kenjiArai 0:5b88d5760320 2237 };
kenjiArai 0:5b88d5760320 2238
kenjiArai 0:5b88d5760320 2239 static const mbedtls_cipher_info_t aes_256_nist_kwp_info = {
kenjiArai 0:5b88d5760320 2240 MBEDTLS_CIPHER_AES_256_KWP,
kenjiArai 0:5b88d5760320 2241 MBEDTLS_MODE_KWP,
kenjiArai 0:5b88d5760320 2242 256,
kenjiArai 0:5b88d5760320 2243 "AES-256-KWP",
kenjiArai 0:5b88d5760320 2244 0,
kenjiArai 0:5b88d5760320 2245 0,
kenjiArai 0:5b88d5760320 2246 16,
kenjiArai 0:5b88d5760320 2247 &kw_aes_info
kenjiArai 0:5b88d5760320 2248 };
kenjiArai 0:5b88d5760320 2249 #endif /* MBEDTLS_NIST_KW_C */
kenjiArai 0:5b88d5760320 2250
kenjiArai 0:5b88d5760320 2251 const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
kenjiArai 0:5b88d5760320 2252 {
kenjiArai 0:5b88d5760320 2253 #if defined(MBEDTLS_AES_C)
kenjiArai 0:5b88d5760320 2254 { MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
kenjiArai 0:5b88d5760320 2255 { MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
kenjiArai 0:5b88d5760320 2256 { MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
kenjiArai 0:5b88d5760320 2257 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2258 { MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
kenjiArai 0:5b88d5760320 2259 { MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
kenjiArai 0:5b88d5760320 2260 { MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
kenjiArai 0:5b88d5760320 2261 #endif
kenjiArai 0:5b88d5760320 2262 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2263 { MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
kenjiArai 0:5b88d5760320 2264 { MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
kenjiArai 0:5b88d5760320 2265 { MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
kenjiArai 0:5b88d5760320 2266 #endif
kenjiArai 0:5b88d5760320 2267 #if defined(MBEDTLS_CIPHER_MODE_OFB)
kenjiArai 0:5b88d5760320 2268 { MBEDTLS_CIPHER_AES_128_OFB, &aes_128_ofb_info },
kenjiArai 0:5b88d5760320 2269 { MBEDTLS_CIPHER_AES_192_OFB, &aes_192_ofb_info },
kenjiArai 0:5b88d5760320 2270 { MBEDTLS_CIPHER_AES_256_OFB, &aes_256_ofb_info },
kenjiArai 0:5b88d5760320 2271 #endif
kenjiArai 0:5b88d5760320 2272 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2273 { MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
kenjiArai 0:5b88d5760320 2274 { MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
kenjiArai 0:5b88d5760320 2275 { MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
kenjiArai 0:5b88d5760320 2276 #endif
kenjiArai 0:5b88d5760320 2277 #if defined(MBEDTLS_CIPHER_MODE_XTS)
kenjiArai 0:5b88d5760320 2278 { MBEDTLS_CIPHER_AES_128_XTS, &aes_128_xts_info },
kenjiArai 0:5b88d5760320 2279 { MBEDTLS_CIPHER_AES_256_XTS, &aes_256_xts_info },
kenjiArai 0:5b88d5760320 2280 #endif
kenjiArai 0:5b88d5760320 2281 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 2282 { MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
kenjiArai 0:5b88d5760320 2283 { MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
kenjiArai 0:5b88d5760320 2284 { MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
kenjiArai 0:5b88d5760320 2285 #endif
kenjiArai 0:5b88d5760320 2286 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 2287 { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
kenjiArai 0:5b88d5760320 2288 { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
kenjiArai 0:5b88d5760320 2289 { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
kenjiArai 0:5b88d5760320 2290 #endif
kenjiArai 0:5b88d5760320 2291 #endif /* MBEDTLS_AES_C */
kenjiArai 0:5b88d5760320 2292
kenjiArai 0:5b88d5760320 2293 #if defined(MBEDTLS_ARC4_C)
kenjiArai 0:5b88d5760320 2294 { MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
kenjiArai 0:5b88d5760320 2295 #endif
kenjiArai 0:5b88d5760320 2296
kenjiArai 0:5b88d5760320 2297 #if defined(MBEDTLS_BLOWFISH_C)
kenjiArai 0:5b88d5760320 2298 { MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
kenjiArai 0:5b88d5760320 2299 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2300 { MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
kenjiArai 0:5b88d5760320 2301 #endif
kenjiArai 0:5b88d5760320 2302 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2303 { MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
kenjiArai 0:5b88d5760320 2304 #endif
kenjiArai 0:5b88d5760320 2305 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2306 { MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
kenjiArai 0:5b88d5760320 2307 #endif
kenjiArai 0:5b88d5760320 2308 #endif /* MBEDTLS_BLOWFISH_C */
kenjiArai 0:5b88d5760320 2309
kenjiArai 0:5b88d5760320 2310 #if defined(MBEDTLS_CAMELLIA_C)
kenjiArai 0:5b88d5760320 2311 { MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
kenjiArai 0:5b88d5760320 2312 { MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
kenjiArai 0:5b88d5760320 2313 { MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
kenjiArai 0:5b88d5760320 2314 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2315 { MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
kenjiArai 0:5b88d5760320 2316 { MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
kenjiArai 0:5b88d5760320 2317 { MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
kenjiArai 0:5b88d5760320 2318 #endif
kenjiArai 0:5b88d5760320 2319 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2320 { MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
kenjiArai 0:5b88d5760320 2321 { MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
kenjiArai 0:5b88d5760320 2322 { MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
kenjiArai 0:5b88d5760320 2323 #endif
kenjiArai 0:5b88d5760320 2324 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2325 { MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
kenjiArai 0:5b88d5760320 2326 { MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
kenjiArai 0:5b88d5760320 2327 { MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
kenjiArai 0:5b88d5760320 2328 #endif
kenjiArai 0:5b88d5760320 2329 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 2330 { MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
kenjiArai 0:5b88d5760320 2331 { MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
kenjiArai 0:5b88d5760320 2332 { MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
kenjiArai 0:5b88d5760320 2333 #endif
kenjiArai 0:5b88d5760320 2334 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 2335 { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
kenjiArai 0:5b88d5760320 2336 { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
kenjiArai 0:5b88d5760320 2337 { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
kenjiArai 0:5b88d5760320 2338 #endif
kenjiArai 0:5b88d5760320 2339 #endif /* MBEDTLS_CAMELLIA_C */
kenjiArai 0:5b88d5760320 2340
kenjiArai 0:5b88d5760320 2341 #if defined(MBEDTLS_ARIA_C)
kenjiArai 0:5b88d5760320 2342 { MBEDTLS_CIPHER_ARIA_128_ECB, &aria_128_ecb_info },
kenjiArai 0:5b88d5760320 2343 { MBEDTLS_CIPHER_ARIA_192_ECB, &aria_192_ecb_info },
kenjiArai 0:5b88d5760320 2344 { MBEDTLS_CIPHER_ARIA_256_ECB, &aria_256_ecb_info },
kenjiArai 0:5b88d5760320 2345 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2346 { MBEDTLS_CIPHER_ARIA_128_CBC, &aria_128_cbc_info },
kenjiArai 0:5b88d5760320 2347 { MBEDTLS_CIPHER_ARIA_192_CBC, &aria_192_cbc_info },
kenjiArai 0:5b88d5760320 2348 { MBEDTLS_CIPHER_ARIA_256_CBC, &aria_256_cbc_info },
kenjiArai 0:5b88d5760320 2349 #endif
kenjiArai 0:5b88d5760320 2350 #if defined(MBEDTLS_CIPHER_MODE_CFB)
kenjiArai 0:5b88d5760320 2351 { MBEDTLS_CIPHER_ARIA_128_CFB128, &aria_128_cfb128_info },
kenjiArai 0:5b88d5760320 2352 { MBEDTLS_CIPHER_ARIA_192_CFB128, &aria_192_cfb128_info },
kenjiArai 0:5b88d5760320 2353 { MBEDTLS_CIPHER_ARIA_256_CFB128, &aria_256_cfb128_info },
kenjiArai 0:5b88d5760320 2354 #endif
kenjiArai 0:5b88d5760320 2355 #if defined(MBEDTLS_CIPHER_MODE_CTR)
kenjiArai 0:5b88d5760320 2356 { MBEDTLS_CIPHER_ARIA_128_CTR, &aria_128_ctr_info },
kenjiArai 0:5b88d5760320 2357 { MBEDTLS_CIPHER_ARIA_192_CTR, &aria_192_ctr_info },
kenjiArai 0:5b88d5760320 2358 { MBEDTLS_CIPHER_ARIA_256_CTR, &aria_256_ctr_info },
kenjiArai 0:5b88d5760320 2359 #endif
kenjiArai 0:5b88d5760320 2360 #if defined(MBEDTLS_GCM_C)
kenjiArai 0:5b88d5760320 2361 { MBEDTLS_CIPHER_ARIA_128_GCM, &aria_128_gcm_info },
kenjiArai 0:5b88d5760320 2362 { MBEDTLS_CIPHER_ARIA_192_GCM, &aria_192_gcm_info },
kenjiArai 0:5b88d5760320 2363 { MBEDTLS_CIPHER_ARIA_256_GCM, &aria_256_gcm_info },
kenjiArai 0:5b88d5760320 2364 #endif
kenjiArai 0:5b88d5760320 2365 #if defined(MBEDTLS_CCM_C)
kenjiArai 0:5b88d5760320 2366 { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
kenjiArai 0:5b88d5760320 2367 { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
kenjiArai 0:5b88d5760320 2368 { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
kenjiArai 0:5b88d5760320 2369 #endif
kenjiArai 0:5b88d5760320 2370 #endif /* MBEDTLS_ARIA_C */
kenjiArai 0:5b88d5760320 2371
kenjiArai 0:5b88d5760320 2372 #if defined(MBEDTLS_DES_C)
kenjiArai 0:5b88d5760320 2373 { MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
kenjiArai 0:5b88d5760320 2374 { MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
kenjiArai 0:5b88d5760320 2375 { MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
kenjiArai 0:5b88d5760320 2376 #if defined(MBEDTLS_CIPHER_MODE_CBC)
kenjiArai 0:5b88d5760320 2377 { MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
kenjiArai 0:5b88d5760320 2378 { MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
kenjiArai 0:5b88d5760320 2379 { MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
kenjiArai 0:5b88d5760320 2380 #endif
kenjiArai 0:5b88d5760320 2381 #endif /* MBEDTLS_DES_C */
kenjiArai 0:5b88d5760320 2382
kenjiArai 0:5b88d5760320 2383 #if defined(MBEDTLS_CHACHA20_C)
kenjiArai 0:5b88d5760320 2384 { MBEDTLS_CIPHER_CHACHA20, &chacha20_info },
kenjiArai 0:5b88d5760320 2385 #endif
kenjiArai 0:5b88d5760320 2386
kenjiArai 0:5b88d5760320 2387 #if defined(MBEDTLS_CHACHAPOLY_C)
kenjiArai 0:5b88d5760320 2388 { MBEDTLS_CIPHER_CHACHA20_POLY1305, &chachapoly_info },
kenjiArai 0:5b88d5760320 2389 #endif
kenjiArai 0:5b88d5760320 2390
kenjiArai 0:5b88d5760320 2391 #if defined(MBEDTLS_NIST_KW_C)
kenjiArai 0:5b88d5760320 2392 { MBEDTLS_CIPHER_AES_128_KW, &aes_128_nist_kw_info },
kenjiArai 0:5b88d5760320 2393 { MBEDTLS_CIPHER_AES_192_KW, &aes_192_nist_kw_info },
kenjiArai 0:5b88d5760320 2394 { MBEDTLS_CIPHER_AES_256_KW, &aes_256_nist_kw_info },
kenjiArai 0:5b88d5760320 2395 { MBEDTLS_CIPHER_AES_128_KWP, &aes_128_nist_kwp_info },
kenjiArai 0:5b88d5760320 2396 { MBEDTLS_CIPHER_AES_192_KWP, &aes_192_nist_kwp_info },
kenjiArai 0:5b88d5760320 2397 { MBEDTLS_CIPHER_AES_256_KWP, &aes_256_nist_kwp_info },
kenjiArai 0:5b88d5760320 2398 #endif
kenjiArai 0:5b88d5760320 2399
kenjiArai 0:5b88d5760320 2400 #if defined(MBEDTLS_CIPHER_NULL_CIPHER)
kenjiArai 0:5b88d5760320 2401 { MBEDTLS_CIPHER_NULL, &null_cipher_info },
kenjiArai 0:5b88d5760320 2402 #endif /* MBEDTLS_CIPHER_NULL_CIPHER */
kenjiArai 0:5b88d5760320 2403
kenjiArai 0:5b88d5760320 2404 { MBEDTLS_CIPHER_NONE, NULL }
kenjiArai 0:5b88d5760320 2405 };
kenjiArai 0:5b88d5760320 2406
kenjiArai 0:5b88d5760320 2407 #define NUM_CIPHERS ( sizeof(mbedtls_cipher_definitions) / \
kenjiArai 0:5b88d5760320 2408 sizeof(mbedtls_cipher_definitions[0]) )
kenjiArai 0:5b88d5760320 2409 int mbedtls_cipher_supported[NUM_CIPHERS];
kenjiArai 0:5b88d5760320 2410
kenjiArai 0:5b88d5760320 2411 #endif /* MBEDTLS_CIPHER_C */