2011-01-06 16:37:30 +01:00
|
|
|
/**
|
2013-03-13 10:33:51 +01:00
|
|
|
* \file cipher_wrap.c
|
2014-05-01 13:03:14 +02:00
|
|
|
*
|
2015-01-22 17:11:05 +01:00
|
|
|
* \brief Generic cipher wrapper for mbed TLS
|
2011-01-06 16:37:30 +01:00
|
|
|
*
|
|
|
|
* \author Adriaan de Jong <dejong@fox-it.com>
|
|
|
|
*
|
2015-01-23 10:45:19 +01:00
|
|
|
* Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
|
2011-01-06 16:37:30 +01:00
|
|
|
*
|
2015-03-06 14:17:10 +01:00
|
|
|
* This file is part of mbed TLS (https://tls.mbed.org)
|
2011-01-06 16:37:30 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if !defined(MBEDTLS_CONFIG_FILE)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/config.h"
|
2014-04-29 12:39:06 +02:00
|
|
|
#else
|
2015-04-08 12:49:31 +02:00
|
|
|
#include MBEDTLS_CONFIG_FILE
|
2014-04-29 12:39:06 +02:00
|
|
|
#endif
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_C)
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-05-26 11:04:15 +02:00
|
|
|
#include "mbedtls/cipher_internal.h"
|
2012-03-05 15:01:29 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_AES_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/aes.h"
|
2012-03-05 15:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_ARC4_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/arc4.h"
|
2013-08-28 13:50:42 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CAMELLIA_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/camellia.h"
|
2012-03-05 15:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_DES_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/des.h"
|
2012-03-15 11:54:25 +01:00
|
|
|
#endif
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_BLOWFISH_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/blowfish.h"
|
2012-07-04 19:10:40 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_GCM_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/gcm.h"
|
2013-08-30 18:34:08 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CCM_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/ccm.h"
|
2014-05-13 13:18:17 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
2015-02-10 13:47:52 +01:00
|
|
|
#include <string.h>
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_PLATFORM_C)
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/platform.h"
|
2013-07-03 13:37:05 +02:00
|
|
|
#else
|
2015-02-06 14:43:58 +01:00
|
|
|
#include <stdlib.h>
|
2015-04-08 12:49:31 +02:00
|
|
|
#define mbedtls_malloc malloc
|
|
|
|
#define mbedtls_free free
|
2013-07-03 13:37:05 +02:00
|
|
|
#endif
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_GCM_C)
|
2013-10-24 14:02:40 +02:00
|
|
|
/* shared by all GCM ciphers */
|
|
|
|
static void *gcm_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_malloc( sizeof( mbedtls_gcm_context ) );
|
2013-10-24 14:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gcm_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_gcm_free( ctx );
|
|
|
|
mbedtls_free( ctx );
|
2013-10-24 14:02:40 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_GCM_C */
|
2013-10-24 14:02:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CCM_C)
|
2014-05-13 13:18:17 +02:00
|
|
|
/* shared by all CCM ciphers */
|
|
|
|
static void *ccm_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_malloc( sizeof( mbedtls_ccm_context ) );
|
2014-05-13 13:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ccm_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ccm_free( ctx );
|
|
|
|
mbedtls_free( ctx );
|
2014-05-13 13:18:17 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CCM_C */
|
2014-05-13 13:18:17 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_AES_C)
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static int aes_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
|
2013-09-08 23:04:04 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_aes_crypt_ecb( (mbedtls_aes_context *) ctx, operation, input, output );
|
2013-09-08 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static int aes_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
|
2011-01-06 16:37:30 +01:00
|
|
|
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_aes_crypt_cbc( (mbedtls_aes_context *) ctx, operation, length, iv, input,
|
2014-05-01 14:18:25 +02:00
|
|
|
output );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
static int aes_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
|
2014-05-01 14:18:25 +02:00
|
|
|
size_t length, size_t *iv_off, unsigned char *iv,
|
|
|
|
const unsigned char *input, unsigned char *output )
|
2011-06-09 16:27:58 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_aes_crypt_cfb128( (mbedtls_aes_context *) ctx, operation, length, iv_off, iv,
|
2014-05-01 14:18:25 +02:00
|
|
|
input, output );
|
2011-06-09 16:27:58 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-05-01 14:18:25 +02:00
|
|
|
static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
|
|
|
unsigned char *nonce_counter, unsigned char *stream_block,
|
2011-06-09 16:27:58 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_aes_crypt_ctr( (mbedtls_aes_context *) ctx, length, nc_off, nonce_counter,
|
2011-06-09 16:27:58 +02:00
|
|
|
stream_block, input, output );
|
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_length );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_length );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void * aes_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_aes_context *aes = mbedtls_malloc( sizeof( mbedtls_aes_context ) );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
if( aes == NULL )
|
|
|
|
return( NULL );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_aes_init( aes );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
return( aes );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void aes_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_aes_free( (mbedtls_aes_context *) ctx );
|
|
|
|
mbedtls_free( ctx );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t aes_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_AES,
|
2013-09-08 23:04:04 +02:00
|
|
|
aes_crypt_ecb_wrap,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2011-06-09 16:27:58 +02:00
|
|
|
aes_crypt_cbc_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2011-06-09 16:27:58 +02:00
|
|
|
aes_crypt_cfb128_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2011-06-09 16:27:58 +02:00
|
|
|
aes_crypt_ctr_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2011-06-09 16:27:58 +02:00
|
|
|
aes_setkey_enc_wrap,
|
|
|
|
aes_setkey_dec_wrap,
|
|
|
|
aes_ctx_alloc,
|
|
|
|
aes_ctx_free
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_128_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_128_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
128,
|
|
|
|
"AES-128-ECB",
|
|
|
|
16,
|
|
|
|
0,
|
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_192_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_192_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
192,
|
|
|
|
"AES-192-ECB",
|
|
|
|
16,
|
|
|
|
0,
|
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_256_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_256_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
256,
|
|
|
|
"AES-256-ECB",
|
|
|
|
16,
|
|
|
|
0,
|
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static const mbedtls_cipher_info_t aes_128_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_128_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2011-04-24 10:57:21 +02:00
|
|
|
128,
|
|
|
|
"AES-128-CBC",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
16,
|
2011-06-09 16:27:58 +02:00
|
|
|
&aes_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_192_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_192_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2011-04-24 10:57:21 +02:00
|
|
|
192,
|
|
|
|
"AES-192-CBC",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
16,
|
2011-06-09 16:27:58 +02:00
|
|
|
&aes_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_256_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_256_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2011-04-24 10:57:21 +02:00
|
|
|
256,
|
|
|
|
"AES-256-CBC",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
16,
|
2011-06-09 16:27:58 +02:00
|
|
|
&aes_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
static const mbedtls_cipher_info_t aes_128_cfb128_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_128_CFB128,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2011-06-09 16:27:58 +02:00
|
|
|
128,
|
|
|
|
"AES-128-CFB128",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_192_cfb128_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_192_CFB128,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2011-06-09 16:27:58 +02:00
|
|
|
192,
|
|
|
|
"AES-192-CFB128",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_256_cfb128_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_256_CFB128,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2011-06-09 16:27:58 +02:00
|
|
|
256,
|
|
|
|
"AES-256-CFB128",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
static const mbedtls_cipher_info_t aes_128_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_128_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2011-06-09 16:27:58 +02:00
|
|
|
128,
|
|
|
|
"AES-128-CTR",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&aes_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_192_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_192_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2011-06-09 16:27:58 +02:00
|
|
|
192,
|
|
|
|
"AES-192-CTR",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_256_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_256_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2011-06-09 16:27:58 +02:00
|
|
|
256,
|
|
|
|
"AES-256-CTR",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&aes_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_GCM_C)
|
2014-05-01 14:18:25 +02:00
|
|
|
static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2013-08-30 18:34:08 +02:00
|
|
|
{
|
2015-04-28 21:42:17 +02:00
|
|
|
return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
|
2013-09-09 00:10:27 +02:00
|
|
|
key, key_length );
|
2013-08-30 18:34:08 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t gcm_aes_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_AES,
|
2013-08-30 18:34:08 +02:00
|
|
|
NULL,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2013-08-30 18:34:08 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2013-08-30 18:34:08 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2013-08-30 18:34:08 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-09-08 23:04:04 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2013-09-09 00:10:27 +02:00
|
|
|
gcm_aes_setkey_wrap,
|
|
|
|
gcm_aes_setkey_wrap,
|
2013-08-30 18:34:08 +02:00
|
|
|
gcm_ctx_alloc,
|
|
|
|
gcm_ctx_free,
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_128_gcm_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_128_GCM,
|
|
|
|
MBEDTLS_MODE_GCM,
|
2013-01-07 18:20:04 +01:00
|
|
|
128,
|
|
|
|
"AES-128-GCM",
|
2013-09-03 13:25:52 +02:00
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2013-01-07 18:20:04 +01:00
|
|
|
16,
|
2013-08-30 18:34:08 +02:00
|
|
|
&gcm_aes_info
|
2013-01-07 18:20:04 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_192_gcm_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_192_GCM,
|
|
|
|
MBEDTLS_MODE_GCM,
|
2013-09-04 12:07:24 +02:00
|
|
|
192,
|
|
|
|
"AES-192-GCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2013-09-04 12:07:24 +02:00
|
|
|
16,
|
|
|
|
&gcm_aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_256_gcm_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_256_GCM,
|
|
|
|
MBEDTLS_MODE_GCM,
|
2013-01-07 18:20:04 +01:00
|
|
|
256,
|
|
|
|
"AES-256-GCM",
|
2013-09-03 13:25:52 +02:00
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2013-01-07 18:20:04 +01:00
|
|
|
16,
|
2013-08-30 18:34:08 +02:00
|
|
|
&gcm_aes_info
|
2013-01-07 18:20:04 +01:00
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_GCM_C */
|
2013-01-07 18:20:04 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CCM_C)
|
2014-05-13 13:18:17 +02:00
|
|
|
static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
|
|
|
{
|
2015-04-28 18:02:54 +02:00
|
|
|
return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
|
2014-05-13 13:18:17 +02:00
|
|
|
key, key_length );
|
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t ccm_aes_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_AES,
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2014-05-13 13:18:17 +02:00
|
|
|
ccm_aes_setkey_wrap,
|
|
|
|
ccm_aes_setkey_wrap,
|
|
|
|
ccm_ctx_alloc,
|
|
|
|
ccm_ctx_free,
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_128_ccm_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_128_CCM,
|
|
|
|
MBEDTLS_MODE_CCM,
|
2014-05-13 13:18:17 +02:00
|
|
|
128,
|
|
|
|
"AES-128-CCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2014-05-13 13:18:17 +02:00
|
|
|
16,
|
|
|
|
&ccm_aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_192_ccm_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_192_CCM,
|
|
|
|
MBEDTLS_MODE_CCM,
|
2014-05-13 13:18:17 +02:00
|
|
|
192,
|
|
|
|
"AES-192-CCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2014-05-13 13:18:17 +02:00
|
|
|
16,
|
|
|
|
&ccm_aes_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t aes_256_ccm_info = {
|
|
|
|
MBEDTLS_CIPHER_AES_256_CCM,
|
|
|
|
MBEDTLS_MODE_CCM,
|
2014-05-13 13:18:17 +02:00
|
|
|
256,
|
|
|
|
"AES-256-CCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2014-05-13 13:18:17 +02:00
|
|
|
16,
|
|
|
|
&ccm_aes_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CCM_C */
|
2014-05-13 13:18:17 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_AES_C */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CAMELLIA_C)
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static int camellia_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
|
2013-09-08 23:04:04 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_camellia_crypt_ecb( (mbedtls_camellia_context *) ctx, operation, input,
|
2014-05-01 14:18:25 +02:00
|
|
|
output );
|
2013-09-08 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static int camellia_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
|
2014-05-01 14:18:25 +02:00
|
|
|
size_t length, unsigned char *iv,
|
|
|
|
const unsigned char *input, unsigned char *output )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_camellia_crypt_cbc( (mbedtls_camellia_context *) ctx, operation, length, iv,
|
2014-05-01 14:18:25 +02:00
|
|
|
input, output );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
static int camellia_crypt_cfb128_wrap( void *ctx, mbedtls_operation_t operation,
|
2014-05-01 14:18:25 +02:00
|
|
|
size_t length, size_t *iv_off, unsigned char *iv,
|
|
|
|
const unsigned char *input, unsigned char *output )
|
2011-06-09 16:27:58 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_camellia_crypt_cfb128( (mbedtls_camellia_context *) ctx, operation, length,
|
2014-05-01 14:18:25 +02:00
|
|
|
iv_off, iv, input, output );
|
2011-06-09 16:27:58 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-05-01 14:18:25 +02:00
|
|
|
static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
|
|
|
unsigned char *nonce_counter, unsigned char *stream_block,
|
2011-06-09 16:27:58 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_camellia_crypt_ctr( (mbedtls_camellia_context *) ctx, length, nc_off,
|
2014-05-01 14:18:25 +02:00
|
|
|
nonce_counter, stream_block, input, output );
|
2011-06-09 16:27:58 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_length );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_length );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void * camellia_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_camellia_context *ctx;
|
|
|
|
ctx = mbedtls_malloc( sizeof( mbedtls_camellia_context ) );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
if( ctx == NULL )
|
|
|
|
return( NULL );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_camellia_init( ctx );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
return( ctx );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void camellia_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_camellia_free( (mbedtls_camellia_context *) ctx );
|
|
|
|
mbedtls_free( ctx );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t camellia_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_CAMELLIA,
|
2013-09-08 23:04:04 +02:00
|
|
|
camellia_crypt_ecb_wrap,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2011-06-09 16:27:58 +02:00
|
|
|
camellia_crypt_cbc_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2011-06-09 16:27:58 +02:00
|
|
|
camellia_crypt_cfb128_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2011-06-09 16:27:58 +02:00
|
|
|
camellia_crypt_ctr_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2011-06-09 16:27:58 +02:00
|
|
|
camellia_setkey_enc_wrap,
|
|
|
|
camellia_setkey_dec_wrap,
|
|
|
|
camellia_ctx_alloc,
|
|
|
|
camellia_ctx_free
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_128_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_128_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
128,
|
|
|
|
"CAMELLIA-128-ECB",
|
|
|
|
16,
|
|
|
|
0,
|
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_192_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_192_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
192,
|
|
|
|
"CAMELLIA-192-ECB",
|
|
|
|
16,
|
|
|
|
0,
|
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_256_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_256_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
256,
|
|
|
|
"CAMELLIA-256-ECB",
|
|
|
|
16,
|
|
|
|
0,
|
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static const mbedtls_cipher_info_t camellia_128_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_128_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2011-04-24 10:57:21 +02:00
|
|
|
128,
|
|
|
|
"CAMELLIA-128-CBC",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
16,
|
2011-06-09 16:27:58 +02:00
|
|
|
&camellia_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_192_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_192_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2011-04-24 10:57:21 +02:00
|
|
|
192,
|
|
|
|
"CAMELLIA-192-CBC",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
16,
|
2011-06-09 16:27:58 +02:00
|
|
|
&camellia_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_256_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_256_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2011-04-24 10:57:21 +02:00
|
|
|
256,
|
|
|
|
"CAMELLIA-256-CBC",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
16,
|
2011-06-09 16:27:58 +02:00
|
|
|
&camellia_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
static const mbedtls_cipher_info_t camellia_128_cfb128_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_128_CFB128,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2011-06-09 16:27:58 +02:00
|
|
|
128,
|
|
|
|
"CAMELLIA-128-CFB128",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_192_cfb128_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_192_CFB128,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2011-06-09 16:27:58 +02:00
|
|
|
192,
|
|
|
|
"CAMELLIA-192-CFB128",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_256_cfb128_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_256_CFB128,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2011-06-09 16:27:58 +02:00
|
|
|
256,
|
|
|
|
"CAMELLIA-256-CFB128",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
static const mbedtls_cipher_info_t camellia_128_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_128_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2011-06-09 16:27:58 +02:00
|
|
|
128,
|
|
|
|
"CAMELLIA-128-CTR",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_192_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_192_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2011-06-09 16:27:58 +02:00
|
|
|
192,
|
|
|
|
"CAMELLIA-192-CTR",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_256_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_256_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2011-06-09 16:27:58 +02:00
|
|
|
256,
|
|
|
|
"CAMELLIA-256-CTR",
|
|
|
|
16,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-06-09 16:27:58 +02:00
|
|
|
16,
|
|
|
|
&camellia_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_GCM_C)
|
2014-05-01 14:18:25 +02:00
|
|
|
static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2013-10-24 14:02:40 +02:00
|
|
|
{
|
2015-04-28 21:42:17 +02:00
|
|
|
return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
|
2013-10-24 14:02:40 +02:00
|
|
|
key, key_length );
|
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t gcm_camellia_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_CAMELLIA,
|
2013-10-24 14:02:40 +02:00
|
|
|
NULL,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2013-10-24 14:02:40 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2013-10-24 14:02:40 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2013-10-24 14:02:40 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-10-24 14:02:40 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2013-10-24 14:02:40 +02:00
|
|
|
gcm_camellia_setkey_wrap,
|
|
|
|
gcm_camellia_setkey_wrap,
|
|
|
|
gcm_ctx_alloc,
|
|
|
|
gcm_ctx_free,
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_128_gcm_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_128_GCM,
|
|
|
|
MBEDTLS_MODE_GCM,
|
2013-10-24 14:02:40 +02:00
|
|
|
128,
|
|
|
|
"CAMELLIA-128-GCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2013-10-24 14:02:40 +02:00
|
|
|
16,
|
|
|
|
&gcm_camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_192_gcm_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_192_GCM,
|
|
|
|
MBEDTLS_MODE_GCM,
|
2013-10-24 14:02:40 +02:00
|
|
|
192,
|
|
|
|
"CAMELLIA-192-GCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2013-10-24 14:02:40 +02:00
|
|
|
16,
|
|
|
|
&gcm_camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_256_gcm_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_256_GCM,
|
|
|
|
MBEDTLS_MODE_GCM,
|
2013-10-24 14:02:40 +02:00
|
|
|
256,
|
|
|
|
"CAMELLIA-256-GCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2013-10-24 14:02:40 +02:00
|
|
|
16,
|
|
|
|
&gcm_camellia_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_GCM_C */
|
2013-10-24 14:02:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CCM_C)
|
2014-05-13 13:18:17 +02:00
|
|
|
static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
|
|
|
{
|
2015-04-28 18:02:54 +02:00
|
|
|
return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
|
2014-05-13 13:18:17 +02:00
|
|
|
key, key_length );
|
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t ccm_camellia_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_CAMELLIA,
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2014-05-13 13:18:17 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2014-05-13 13:18:17 +02:00
|
|
|
ccm_camellia_setkey_wrap,
|
|
|
|
ccm_camellia_setkey_wrap,
|
|
|
|
ccm_ctx_alloc,
|
|
|
|
ccm_ctx_free,
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_128_ccm_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_128_CCM,
|
|
|
|
MBEDTLS_MODE_CCM,
|
2014-05-13 13:18:17 +02:00
|
|
|
128,
|
|
|
|
"CAMELLIA-128-CCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2014-05-13 13:18:17 +02:00
|
|
|
16,
|
|
|
|
&ccm_camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_192_ccm_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_192_CCM,
|
|
|
|
MBEDTLS_MODE_CCM,
|
2014-05-13 13:18:17 +02:00
|
|
|
192,
|
|
|
|
"CAMELLIA-192-CCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2014-05-13 13:18:17 +02:00
|
|
|
16,
|
|
|
|
&ccm_camellia_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t camellia_256_ccm_info = {
|
|
|
|
MBEDTLS_CIPHER_CAMELLIA_256_CCM,
|
|
|
|
MBEDTLS_MODE_CCM,
|
2014-05-13 13:18:17 +02:00
|
|
|
256,
|
|
|
|
"CAMELLIA-256-CCM",
|
|
|
|
12,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
|
2014-05-13 13:18:17 +02:00
|
|
|
16,
|
|
|
|
&ccm_camellia_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CCM_C */
|
2014-05-13 13:18:17 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CAMELLIA_C */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_DES_C)
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static int des_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
|
2013-09-08 23:04:04 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
|
|
|
((void) operation);
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des_crypt_ecb( (mbedtls_des_context *) ctx, input, output );
|
2013-09-08 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static int des3_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
|
2013-09-08 23:04:04 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
|
|
|
((void) operation);
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des3_crypt_ecb( (mbedtls_des3_context *) ctx, input, output );
|
2013-09-08 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static int des_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
|
2011-01-06 16:37:30 +01:00
|
|
|
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des_crypt_cbc( (mbedtls_des_context *) ctx, operation, length, iv, input,
|
2014-05-01 14:18:25 +02:00
|
|
|
output );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t length,
|
2011-01-06 16:37:30 +01:00
|
|
|
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des3_crypt_cbc( (mbedtls_des3_context *) ctx, operation, length, iv, input,
|
2014-05-01 14:18:25 +02:00
|
|
|
output );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2011-01-18 17:17:47 +01:00
|
|
|
((void) key_length);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2011-01-18 17:17:47 +01:00
|
|
|
((void) key_length);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2011-01-18 17:17:47 +01:00
|
|
|
((void) key_length);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2011-01-18 17:17:47 +01:00
|
|
|
((void) key_length);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2011-01-18 17:17:47 +01:00
|
|
|
((void) key_length);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2011-01-06 16:37:30 +01:00
|
|
|
{
|
2011-01-18 17:17:47 +01:00
|
|
|
((void) key_length);
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void * des_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_des_context *des = mbedtls_malloc( sizeof( mbedtls_des_context ) );
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2014-06-18 11:12:03 +02:00
|
|
|
if( des == NULL )
|
|
|
|
return( NULL );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_des_init( des );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
return( des );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void des_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_des_free( (mbedtls_des_context *) ctx );
|
|
|
|
mbedtls_free( ctx );
|
2014-06-13 17:20:13 +02:00
|
|
|
}
|
|
|
|
|
2014-06-18 11:12:03 +02:00
|
|
|
static void * des3_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_des3_context *des3;
|
|
|
|
des3 = mbedtls_malloc( sizeof( mbedtls_des3_context ) );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
if( des3 == NULL )
|
|
|
|
return( NULL );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_des3_init( des3 );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
return( des3 );
|
|
|
|
}
|
|
|
|
|
2014-06-13 17:20:13 +02:00
|
|
|
static void des3_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_des3_free( (mbedtls_des3_context *) ctx );
|
|
|
|
mbedtls_free( ctx );
|
2011-01-06 16:37:30 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t des_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_DES,
|
2013-09-08 23:04:04 +02:00
|
|
|
des_crypt_ecb_wrap,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2011-06-09 16:27:58 +02:00
|
|
|
des_crypt_cbc_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2014-06-13 15:06:59 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-06-13 15:06:59 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2011-06-09 16:27:58 +02:00
|
|
|
des_setkey_enc_wrap,
|
|
|
|
des_setkey_dec_wrap,
|
|
|
|
des_ctx_alloc,
|
|
|
|
des_ctx_free
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t des_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_DES_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
|
|
|
MBEDTLS_KEY_LENGTH_DES,
|
2013-09-08 23:04:04 +02:00
|
|
|
"DES-ECB",
|
|
|
|
8,
|
|
|
|
0,
|
|
|
|
8,
|
|
|
|
&des_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static const mbedtls_cipher_info_t des_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_DES_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
|
|
|
MBEDTLS_KEY_LENGTH_DES,
|
2011-04-24 10:57:21 +02:00
|
|
|
"DES-CBC",
|
|
|
|
8,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
8,
|
2011-06-09 16:27:58 +02:00
|
|
|
&des_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t des_ede_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_DES,
|
2013-09-08 23:04:04 +02:00
|
|
|
des3_crypt_ecb_wrap,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2011-06-09 16:27:58 +02:00
|
|
|
des3_crypt_cbc_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2014-06-13 15:06:59 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-06-13 15:06:59 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2011-06-09 16:27:58 +02:00
|
|
|
des3_set2key_enc_wrap,
|
|
|
|
des3_set2key_dec_wrap,
|
|
|
|
des3_ctx_alloc,
|
2014-06-13 17:20:13 +02:00
|
|
|
des3_ctx_free
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t des_ede_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_DES_EDE_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
|
|
|
MBEDTLS_KEY_LENGTH_DES_EDE,
|
2013-09-08 23:04:04 +02:00
|
|
|
"DES-EDE-ECB",
|
|
|
|
8,
|
|
|
|
0,
|
|
|
|
8,
|
|
|
|
&des_ede_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static const mbedtls_cipher_info_t des_ede_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_DES_EDE_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
|
|
|
MBEDTLS_KEY_LENGTH_DES_EDE,
|
2011-04-24 10:57:21 +02:00
|
|
|
"DES-EDE-CBC",
|
2013-06-24 19:33:02 +02:00
|
|
|
8,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2013-06-24 19:33:02 +02:00
|
|
|
8,
|
2011-06-09 16:27:58 +02:00
|
|
|
&des_ede_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2011-06-09 16:27:58 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t des_ede3_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_DES,
|
2013-09-08 23:04:04 +02:00
|
|
|
des3_crypt_ecb_wrap,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2011-04-24 10:57:21 +02:00
|
|
|
des3_crypt_cbc_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2014-06-13 15:06:59 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-06-13 15:06:59 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2011-06-09 16:27:58 +02:00
|
|
|
des3_set3key_enc_wrap,
|
|
|
|
des3_set3key_dec_wrap,
|
2011-04-24 10:57:21 +02:00
|
|
|
des3_ctx_alloc,
|
2014-06-13 17:20:13 +02:00
|
|
|
des3_ctx_free
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t des_ede3_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_DES_EDE3_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
|
|
|
MBEDTLS_KEY_LENGTH_DES_EDE3,
|
2013-09-08 23:04:04 +02:00
|
|
|
"DES-EDE3-ECB",
|
|
|
|
8,
|
|
|
|
0,
|
|
|
|
8,
|
|
|
|
&des_ede3_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static const mbedtls_cipher_info_t des_ede3_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_DES_EDE3_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
|
|
|
MBEDTLS_KEY_LENGTH_DES_EDE3,
|
2011-04-24 10:57:21 +02:00
|
|
|
"DES-EDE3-CBC",
|
|
|
|
8,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2011-04-24 10:57:21 +02:00
|
|
|
8,
|
2011-06-09 16:27:58 +02:00
|
|
|
&des_ede3_info
|
2011-01-06 16:37:30 +01:00
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
|
|
|
#endif /* MBEDTLS_DES_C */
|
2011-01-06 16:37:30 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_BLOWFISH_C)
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static int blowfish_crypt_ecb_wrap( void *ctx, mbedtls_operation_t operation,
|
2013-09-08 23:04:04 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_blowfish_crypt_ecb( (mbedtls_blowfish_context *) ctx, operation, input,
|
2014-05-01 14:18:25 +02:00
|
|
|
output );
|
2013-09-08 23:04:04 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static int blowfish_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation,
|
2014-05-01 14:18:25 +02:00
|
|
|
size_t length, unsigned char *iv, const unsigned char *input,
|
|
|
|
unsigned char *output )
|
2012-07-04 19:10:40 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_blowfish_crypt_cbc( (mbedtls_blowfish_context *) ctx, operation, length, iv,
|
2014-05-01 14:18:25 +02:00
|
|
|
input, output );
|
2012-07-04 19:10:40 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
static int blowfish_crypt_cfb64_wrap( void *ctx, mbedtls_operation_t operation,
|
2014-05-01 14:18:25 +02:00
|
|
|
size_t length, size_t *iv_off, unsigned char *iv,
|
|
|
|
const unsigned char *input, unsigned char *output )
|
2012-07-04 19:10:40 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_blowfish_crypt_cfb64( (mbedtls_blowfish_context *) ctx, operation, length,
|
2014-05-01 14:18:25 +02:00
|
|
|
iv_off, iv, input, output );
|
2012-07-04 19:10:40 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2014-05-01 14:18:25 +02:00
|
|
|
static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
|
|
|
unsigned char *nonce_counter, unsigned char *stream_block,
|
2012-07-04 19:10:40 +02:00
|
|
|
const unsigned char *input, unsigned char *output )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_blowfish_crypt_ctr( (mbedtls_blowfish_context *) ctx, length, nc_off,
|
2014-05-01 14:18:25 +02:00
|
|
|
nonce_counter, stream_block, input, output );
|
2012-07-04 19:10:40 +02:00
|
|
|
}
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2014-05-01 14:18:25 +02:00
|
|
|
static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
2012-07-04 19:10:40 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_length );
|
2012-07-04 19:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void * blowfish_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_blowfish_context *ctx;
|
|
|
|
ctx = mbedtls_malloc( sizeof( mbedtls_blowfish_context ) );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
if( ctx == NULL )
|
|
|
|
return( NULL );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_blowfish_init( ctx );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
return( ctx );
|
2012-07-04 19:10:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void blowfish_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_blowfish_free( (mbedtls_blowfish_context *) ctx );
|
|
|
|
mbedtls_free( ctx );
|
2012-07-04 19:10:40 +02:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t blowfish_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_BLOWFISH,
|
2013-09-08 23:04:04 +02:00
|
|
|
blowfish_crypt_ecb_wrap,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2012-07-04 19:10:40 +02:00
|
|
|
blowfish_crypt_cbc_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2012-07-04 19:10:40 +02:00
|
|
|
blowfish_crypt_cfb64_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2012-07-04 19:10:40 +02:00
|
|
|
blowfish_crypt_ctr_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2013-08-28 16:36:14 +02:00
|
|
|
blowfish_setkey_wrap,
|
|
|
|
blowfish_setkey_wrap,
|
2012-07-04 19:10:40 +02:00
|
|
|
blowfish_ctx_alloc,
|
|
|
|
blowfish_ctx_free
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t blowfish_ecb_info = {
|
|
|
|
MBEDTLS_CIPHER_BLOWFISH_ECB,
|
|
|
|
MBEDTLS_MODE_ECB,
|
2013-09-08 23:04:04 +02:00
|
|
|
128,
|
|
|
|
"BLOWFISH-ECB",
|
|
|
|
8,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
|
2013-09-08 23:04:04 +02:00
|
|
|
8,
|
|
|
|
&blowfish_info
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
static const mbedtls_cipher_info_t blowfish_cbc_info = {
|
|
|
|
MBEDTLS_CIPHER_BLOWFISH_CBC,
|
|
|
|
MBEDTLS_MODE_CBC,
|
2013-04-07 22:35:44 +02:00
|
|
|
128,
|
2012-07-04 19:10:40 +02:00
|
|
|
"BLOWFISH-CBC",
|
|
|
|
8,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
|
2012-07-04 19:10:40 +02:00
|
|
|
8,
|
|
|
|
&blowfish_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
static const mbedtls_cipher_info_t blowfish_cfb64_info = {
|
|
|
|
MBEDTLS_CIPHER_BLOWFISH_CFB64,
|
|
|
|
MBEDTLS_MODE_CFB,
|
2013-04-07 22:35:44 +02:00
|
|
|
128,
|
2012-07-04 19:10:40 +02:00
|
|
|
"BLOWFISH-CFB64",
|
|
|
|
8,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
|
2012-07-04 19:10:40 +02:00
|
|
|
8,
|
|
|
|
&blowfish_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
static const mbedtls_cipher_info_t blowfish_ctr_info = {
|
|
|
|
MBEDTLS_CIPHER_BLOWFISH_CTR,
|
|
|
|
MBEDTLS_MODE_CTR,
|
2013-04-07 22:35:44 +02:00
|
|
|
128,
|
2012-07-04 19:10:40 +02:00
|
|
|
"BLOWFISH-CTR",
|
|
|
|
8,
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_CIPHER_VARIABLE_KEY_LEN,
|
2012-07-04 19:10:40 +02:00
|
|
|
8,
|
|
|
|
&blowfish_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
|
|
|
#endif /* MBEDTLS_BLOWFISH_C */
|
2012-07-04 19:10:40 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_ARC4_C)
|
2013-08-28 13:50:42 +02:00
|
|
|
static int arc4_crypt_stream_wrap( void *ctx, size_t length,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned char *output )
|
2013-01-07 18:20:04 +01:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
return( mbedtls_arc4_crypt( (mbedtls_arc4_context *) ctx, length, input, output ) );
|
2013-01-07 18:20:04 +01:00
|
|
|
}
|
|
|
|
|
2013-08-28 13:50:42 +02:00
|
|
|
static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
|
|
|
{
|
2013-09-04 12:28:37 +02:00
|
|
|
/* we get key_length in bits, arc4 expects it in bytes */
|
2014-06-17 16:39:18 +02:00
|
|
|
if( key_length % 8 != 0 )
|
2015-04-08 12:49:31 +02:00
|
|
|
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
2013-09-04 12:28:37 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_length / 8 );
|
2013-08-28 13:50:42 +02:00
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void * arc4_ctx_alloc( void )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_arc4_context *ctx;
|
|
|
|
ctx = mbedtls_malloc( sizeof( mbedtls_arc4_context ) );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
if( ctx == NULL )
|
|
|
|
return( NULL );
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_arc4_init( ctx );
|
2014-06-18 11:12:03 +02:00
|
|
|
|
|
|
|
return( ctx );
|
2013-08-28 13:50:42 +02:00
|
|
|
}
|
2013-01-07 18:20:04 +01:00
|
|
|
|
|
|
|
static void arc4_ctx_free( void *ctx )
|
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_arc4_free( (mbedtls_arc4_context *) ctx );
|
|
|
|
mbedtls_free( ctx );
|
2013-01-07 18:20:04 +01:00
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t arc4_base_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_ARC4,
|
2013-01-07 18:20:04 +01:00
|
|
|
NULL,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2013-01-07 18:20:04 +01:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2013-01-07 18:20:04 +01:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2013-09-08 23:04:04 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 13:50:42 +02:00
|
|
|
arc4_crypt_stream_wrap,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2013-08-28 13:50:42 +02:00
|
|
|
arc4_setkey_wrap,
|
|
|
|
arc4_setkey_wrap,
|
2013-01-07 18:20:04 +01:00
|
|
|
arc4_ctx_alloc,
|
|
|
|
arc4_ctx_free
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t arc4_128_info = {
|
|
|
|
MBEDTLS_CIPHER_ARC4_128,
|
|
|
|
MBEDTLS_MODE_STREAM,
|
2013-01-07 18:20:04 +01:00
|
|
|
128,
|
|
|
|
"ARC4-128",
|
|
|
|
0,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2013-01-07 18:20:04 +01:00
|
|
|
1,
|
|
|
|
&arc4_base_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_ARC4_C */
|
2013-01-07 18:20:04 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
2013-08-28 16:36:14 +02:00
|
|
|
static int null_crypt_stream( void *ctx, size_t length,
|
|
|
|
const unsigned char *input,
|
|
|
|
unsigned char *output )
|
|
|
|
{
|
|
|
|
((void) ctx);
|
|
|
|
memmove( output, input, length );
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int null_setkey( void *ctx, const unsigned char *key,
|
|
|
|
unsigned int key_length )
|
|
|
|
{
|
|
|
|
((void) ctx);
|
|
|
|
((void) key);
|
|
|
|
((void) key_length);
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2012-02-06 17:45:10 +01:00
|
|
|
static void * null_ctx_alloc( void )
|
|
|
|
{
|
2014-07-12 02:14:41 +02:00
|
|
|
return( (void *) 1 );
|
2012-02-06 17:45:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void null_ctx_free( void *ctx )
|
|
|
|
{
|
|
|
|
((void) ctx);
|
|
|
|
}
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_base_t null_base_info = {
|
|
|
|
MBEDTLS_CIPHER_ID_NULL,
|
2012-02-06 17:45:10 +01:00
|
|
|
NULL,
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2012-02-06 17:45:10 +01:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2012-02-06 17:45:10 +01:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
2013-09-08 23:04:04 +02:00
|
|
|
NULL,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
2013-08-28 16:36:14 +02:00
|
|
|
null_crypt_stream,
|
2014-12-02 10:09:10 +01:00
|
|
|
#endif
|
2013-08-28 16:36:14 +02:00
|
|
|
null_setkey,
|
|
|
|
null_setkey,
|
2012-02-06 17:45:10 +01:00
|
|
|
null_ctx_alloc,
|
|
|
|
null_ctx_free
|
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
static const mbedtls_cipher_info_t null_cipher_info = {
|
|
|
|
MBEDTLS_CIPHER_NULL,
|
|
|
|
MBEDTLS_MODE_STREAM,
|
2012-02-06 17:45:10 +01:00
|
|
|
0,
|
|
|
|
"NULL",
|
2013-01-07 18:20:04 +01:00
|
|
|
0,
|
2013-09-03 13:25:52 +02:00
|
|
|
0,
|
2012-02-06 17:45:10 +01:00
|
|
|
1,
|
|
|
|
&null_base_info
|
|
|
|
};
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* defined(MBEDTLS_CIPHER_NULL_CIPHER) */
|
2012-02-06 17:45:10 +01:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
|
2013-09-18 15:12:07 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
#if defined(MBEDTLS_AES_C)
|
|
|
|
{ MBEDTLS_CIPHER_AES_128_ECB, &aes_128_ecb_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_192_ECB, &aes_192_ecb_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_256_ECB, &aes_256_ecb_info },
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
{ MBEDTLS_CIPHER_AES_128_CBC, &aes_128_cbc_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_192_CBC, &aes_192_cbc_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_256_CBC, &aes_256_cbc_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
{ MBEDTLS_CIPHER_AES_128_CFB128, &aes_128_cfb128_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_192_CFB128, &aes_192_cfb128_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_256_CFB128, &aes_256_cfb128_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
{ MBEDTLS_CIPHER_AES_128_CTR, &aes_128_ctr_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_192_CTR, &aes_192_ctr_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_256_CTR, &aes_256_ctr_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_GCM_C)
|
|
|
|
{ MBEDTLS_CIPHER_AES_128_GCM, &aes_128_gcm_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_192_GCM, &aes_192_gcm_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_256_GCM, &aes_256_gcm_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CCM_C)
|
|
|
|
{ MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
|
|
|
|
{ MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
|
|
|
|
#endif
|
|
|
|
#endif /* MBEDTLS_AES_C */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_ARC4_C)
|
|
|
|
{ MBEDTLS_CIPHER_ARC4_128, &arc4_128_info },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_BLOWFISH_C)
|
|
|
|
{ MBEDTLS_CIPHER_BLOWFISH_ECB, &blowfish_ecb_info },
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
{ MBEDTLS_CIPHER_BLOWFISH_CBC, &blowfish_cbc_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
{ MBEDTLS_CIPHER_BLOWFISH_CFB64, &blowfish_cfb64_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
{ MBEDTLS_CIPHER_BLOWFISH_CTR, &blowfish_ctr_info },
|
|
|
|
#endif
|
|
|
|
#endif /* MBEDTLS_BLOWFISH_C */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CAMELLIA_C)
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_128_ECB, &camellia_128_ecb_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_192_ECB, &camellia_192_ecb_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_256_ECB, &camellia_256_ecb_info },
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_128_CBC, &camellia_128_cbc_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_192_CBC, &camellia_192_cbc_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_256_CBC, &camellia_256_cbc_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_128_CFB128, &camellia_128_cfb128_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_192_CFB128, &camellia_192_cfb128_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_256_CFB128, &camellia_256_cfb128_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_128_CTR, &camellia_128_ctr_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_192_CTR, &camellia_192_ctr_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_256_CTR, &camellia_256_ctr_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_GCM_C)
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_128_GCM, &camellia_128_gcm_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
|
|
|
|
#endif
|
|
|
|
#if defined(MBEDTLS_CCM_C)
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
|
|
|
|
{ MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
|
|
|
|
#endif
|
|
|
|
#endif /* MBEDTLS_CAMELLIA_C */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_DES_C)
|
|
|
|
{ MBEDTLS_CIPHER_DES_ECB, &des_ecb_info },
|
|
|
|
{ MBEDTLS_CIPHER_DES_EDE_ECB, &des_ede_ecb_info },
|
|
|
|
{ MBEDTLS_CIPHER_DES_EDE3_ECB, &des_ede3_ecb_info },
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
{ MBEDTLS_CIPHER_DES_CBC, &des_cbc_info },
|
|
|
|
{ MBEDTLS_CIPHER_DES_EDE_CBC, &des_ede_cbc_info },
|
|
|
|
{ MBEDTLS_CIPHER_DES_EDE3_CBC, &des_ede3_cbc_info },
|
|
|
|
#endif
|
|
|
|
#endif /* MBEDTLS_DES_C */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
|
|
|
{ MBEDTLS_CIPHER_NULL, &null_cipher_info },
|
|
|
|
#endif /* MBEDTLS_CIPHER_NULL_CIPHER */
|
|
|
|
|
|
|
|
{ MBEDTLS_CIPHER_NONE, NULL }
|
2013-09-18 15:12:07 +02:00
|
|
|
};
|
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#define NUM_CIPHERS sizeof mbedtls_cipher_definitions / sizeof mbedtls_cipher_definitions[0]
|
|
|
|
int mbedtls_cipher_supported[NUM_CIPHERS];
|
2013-09-18 15:12:07 +02:00
|
|
|
|
2015-04-08 12:49:31 +02:00
|
|
|
#endif /* MBEDTLS_CIPHER_C */
|