mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 05:40:01 -06:00
Update external polarssl to 1.3.8
There were some fixes back on March 13th, 2014 for fixing compiling on MIPS64. Also some fixes on June 25th, 2014 for SPARC64 fixes. Probably more things, but those are what I care about.
This commit is contained in:
450
Externals/polarssl/library/cipher_wrap.c
vendored
450
Externals/polarssl/library/cipher_wrap.c
vendored
@ -1,11 +1,11 @@
|
||||
/**
|
||||
* \file cipher_wrap.c
|
||||
*
|
||||
*
|
||||
* \brief Generic cipher wrapper for PolarSSL
|
||||
*
|
||||
* \author Adriaan de Jong <dejong@fox-it.com>
|
||||
*
|
||||
* Copyright (C) 2006-2013, Brainspark B.V.
|
||||
* Copyright (C) 2006-2014, Brainspark B.V.
|
||||
*
|
||||
* This file is part of PolarSSL (http://www.polarssl.org)
|
||||
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
||||
@ -27,7 +27,11 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#if !defined(POLARSSL_CONFIG_FILE)
|
||||
#include "polarssl/config.h"
|
||||
#else
|
||||
#include POLARSSL_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_CIPHER_C)
|
||||
|
||||
@ -57,8 +61,12 @@
|
||||
#include "polarssl/gcm.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_C)
|
||||
#include "polarssl/memory.h"
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
#include "polarssl/ccm.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_free free
|
||||
@ -78,7 +86,21 @@ static void gcm_ctx_free( void *ctx )
|
||||
gcm_free( ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
#endif
|
||||
#endif /* POLARSSL_GCM_C */
|
||||
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
/* shared by all CCM ciphers */
|
||||
static void *ccm_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( ccm_context ) );
|
||||
}
|
||||
|
||||
static void ccm_ctx_free( void *ctx )
|
||||
{
|
||||
ccm_free( ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
#endif /* POLARSSL_CCM_C */
|
||||
|
||||
#if defined(POLARSSL_AES_C)
|
||||
|
||||
@ -92,7 +114,8 @@ static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input, output );
|
||||
return aes_crypt_cbc( (aes_context *) ctx, operation, length, iv, input,
|
||||
output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -101,15 +124,17 @@ static int aes_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
}
|
||||
|
||||
static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
|
||||
size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation,
|
||||
size_t length, size_t *iv_off, unsigned char *iv,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CFB)
|
||||
return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv, input, output );
|
||||
return aes_crypt_cfb128( (aes_context *) ctx, operation, length, iv_off, iv,
|
||||
input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -119,12 +144,12 @@ static int aes_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t lengt
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CFB */
|
||||
}
|
||||
|
||||
static int aes_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
||||
unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CTR)
|
||||
@ -139,27 +164,37 @@ static int aes_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
}
|
||||
|
||||
static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return aes_setkey_dec( (aes_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return aes_setkey_enc( (aes_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static void * aes_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( aes_context ) );
|
||||
aes_context *aes = (aes_context *) polarssl_malloc( sizeof( aes_context ) );
|
||||
|
||||
if( aes == NULL )
|
||||
return( NULL );
|
||||
|
||||
aes_init( aes );
|
||||
|
||||
return( aes );
|
||||
}
|
||||
|
||||
static void aes_ctx_free( void *ctx )
|
||||
{
|
||||
aes_free( (aes_context *) ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
@ -315,7 +350,8 @@ const cipher_info_t aes_256_ctr_info = {
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
|
||||
#if defined(POLARSSL_GCM_C)
|
||||
static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_AES,
|
||||
key, key_length );
|
||||
@ -340,7 +376,7 @@ const cipher_info_t aes_128_gcm_info = {
|
||||
128,
|
||||
"AES-128-GCM",
|
||||
12,
|
||||
1,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&gcm_aes_info
|
||||
};
|
||||
@ -351,7 +387,7 @@ const cipher_info_t aes_192_gcm_info = {
|
||||
192,
|
||||
"AES-192-GCM",
|
||||
12,
|
||||
1,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&gcm_aes_info
|
||||
};
|
||||
@ -362,27 +398,85 @@ const cipher_info_t aes_256_gcm_info = {
|
||||
256,
|
||||
"AES-256-GCM",
|
||||
12,
|
||||
1,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&gcm_aes_info
|
||||
};
|
||||
#endif /* POLARSSL_GCM_C */
|
||||
|
||||
#endif
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_AES,
|
||||
key, key_length );
|
||||
}
|
||||
|
||||
const cipher_base_t ccm_aes_info = {
|
||||
POLARSSL_CIPHER_ID_AES,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ccm_aes_setkey_wrap,
|
||||
ccm_aes_setkey_wrap,
|
||||
ccm_ctx_alloc,
|
||||
ccm_ctx_free,
|
||||
};
|
||||
|
||||
const cipher_info_t aes_128_ccm_info = {
|
||||
POLARSSL_CIPHER_AES_128_CCM,
|
||||
POLARSSL_MODE_CCM,
|
||||
128,
|
||||
"AES-128-CCM",
|
||||
12,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&ccm_aes_info
|
||||
};
|
||||
|
||||
const cipher_info_t aes_192_ccm_info = {
|
||||
POLARSSL_CIPHER_AES_192_CCM,
|
||||
POLARSSL_MODE_CCM,
|
||||
192,
|
||||
"AES-192-CCM",
|
||||
12,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&ccm_aes_info
|
||||
};
|
||||
|
||||
const cipher_info_t aes_256_ccm_info = {
|
||||
POLARSSL_CIPHER_AES_256_CCM,
|
||||
POLARSSL_MODE_CCM,
|
||||
256,
|
||||
"AES-256-CCM",
|
||||
12,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&ccm_aes_info
|
||||
};
|
||||
#endif /* POLARSSL_CCM_C */
|
||||
|
||||
#endif /* POLARSSL_AES_C */
|
||||
|
||||
#if defined(POLARSSL_CAMELLIA_C)
|
||||
|
||||
static int camellia_crypt_ecb_wrap( void *ctx, operation_t operation,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
return camellia_crypt_ecb( (camellia_context *) ctx, operation, input, output );
|
||||
return camellia_crypt_ecb( (camellia_context *) ctx, operation, input,
|
||||
output );
|
||||
}
|
||||
|
||||
static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation,
|
||||
size_t length, unsigned char *iv,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv, input, output );
|
||||
return camellia_crypt_cbc( (camellia_context *) ctx, operation, length, iv,
|
||||
input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -391,15 +485,17 @@ static int camellia_crypt_cbc_wrap( void *ctx, operation_t operation, size_t len
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
}
|
||||
|
||||
static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
|
||||
size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation,
|
||||
size_t length, size_t *iv_off, unsigned char *iv,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CFB)
|
||||
return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length, iv_off, iv, input, output );
|
||||
return camellia_crypt_cfb128( (camellia_context *) ctx, operation, length,
|
||||
iv_off, iv, input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -409,17 +505,17 @@ static int camellia_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CFB */
|
||||
}
|
||||
|
||||
static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
||||
unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CTR)
|
||||
return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off, nonce_counter,
|
||||
stream_block, input, output );
|
||||
return camellia_crypt_ctr( (camellia_context *) ctx, length, nc_off,
|
||||
nonce_counter, stream_block, input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) length);
|
||||
@ -429,27 +525,38 @@ static int camellia_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
}
|
||||
|
||||
static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return camellia_setkey_dec( (camellia_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return camellia_setkey_enc( (camellia_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static void * camellia_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( camellia_context ) );
|
||||
camellia_context *ctx;
|
||||
ctx = (camellia_context *) polarssl_malloc( sizeof( camellia_context ) );
|
||||
|
||||
if( ctx == NULL )
|
||||
return( NULL );
|
||||
|
||||
camellia_init( ctx );
|
||||
|
||||
return( ctx );
|
||||
}
|
||||
|
||||
static void camellia_ctx_free( void *ctx )
|
||||
{
|
||||
camellia_free( (camellia_context *) ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
@ -605,7 +712,8 @@ const cipher_info_t camellia_256_ctr_info = {
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
|
||||
#if defined(POLARSSL_GCM_C)
|
||||
static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return gcm_init( (gcm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
key, key_length );
|
||||
@ -630,7 +738,7 @@ const cipher_info_t camellia_128_gcm_info = {
|
||||
128,
|
||||
"CAMELLIA-128-GCM",
|
||||
12,
|
||||
1,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&gcm_camellia_info
|
||||
};
|
||||
@ -641,7 +749,7 @@ const cipher_info_t camellia_192_gcm_info = {
|
||||
192,
|
||||
"CAMELLIA-192-GCM",
|
||||
12,
|
||||
1,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&gcm_camellia_info
|
||||
};
|
||||
@ -652,12 +760,67 @@ const cipher_info_t camellia_256_gcm_info = {
|
||||
256,
|
||||
"CAMELLIA-256-GCM",
|
||||
12,
|
||||
1,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&gcm_camellia_info
|
||||
};
|
||||
#endif /* POLARSSL_GCM_C */
|
||||
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return ccm_init( (ccm_context *) ctx, POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
key, key_length );
|
||||
}
|
||||
|
||||
const cipher_base_t ccm_camellia_info = {
|
||||
POLARSSL_CIPHER_ID_CAMELLIA,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ccm_camellia_setkey_wrap,
|
||||
ccm_camellia_setkey_wrap,
|
||||
ccm_ctx_alloc,
|
||||
ccm_ctx_free,
|
||||
};
|
||||
|
||||
const cipher_info_t camellia_128_ccm_info = {
|
||||
POLARSSL_CIPHER_CAMELLIA_128_CCM,
|
||||
POLARSSL_MODE_CCM,
|
||||
128,
|
||||
"CAMELLIA-128-CCM",
|
||||
12,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&ccm_camellia_info
|
||||
};
|
||||
|
||||
const cipher_info_t camellia_192_ccm_info = {
|
||||
POLARSSL_CIPHER_CAMELLIA_192_CCM,
|
||||
POLARSSL_MODE_CCM,
|
||||
192,
|
||||
"CAMELLIA-192-CCM",
|
||||
12,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&ccm_camellia_info
|
||||
};
|
||||
|
||||
const cipher_info_t camellia_256_ccm_info = {
|
||||
POLARSSL_CIPHER_CAMELLIA_256_CCM,
|
||||
POLARSSL_MODE_CCM,
|
||||
256,
|
||||
"CAMELLIA-256-CCM",
|
||||
12,
|
||||
POLARSSL_CIPHER_VARIABLE_IV_LEN,
|
||||
16,
|
||||
&ccm_camellia_info
|
||||
};
|
||||
#endif /* POLARSSL_CCM_C */
|
||||
|
||||
#endif /* POLARSSL_CAMELLIA_C */
|
||||
|
||||
#if defined(POLARSSL_DES_C)
|
||||
@ -680,7 +843,8 @@ static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input, output );
|
||||
return des_crypt_cbc( (des_context *) ctx, operation, length, iv, input,
|
||||
output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -689,7 +853,7 @@ static int des_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
}
|
||||
|
||||
@ -697,7 +861,8 @@ static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input, output );
|
||||
return des3_crypt_cbc( (des3_context *) ctx, operation, length, iv, input,
|
||||
output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -706,75 +871,52 @@ static int des3_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
}
|
||||
|
||||
static int des_crypt_cfb128_wrap( void *ctx, operation_t operation, size_t length,
|
||||
size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
((void) length);
|
||||
((void) iv_off);
|
||||
((void) iv);
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
static int des_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
((void) ctx);
|
||||
((void) length);
|
||||
((void) nc_off);
|
||||
((void) nonce_counter);
|
||||
((void) stream_block);
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
}
|
||||
|
||||
static int des_setkey_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
((void) key_length);
|
||||
|
||||
return des_setkey_dec( (des_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des_setkey_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
((void) key_length);
|
||||
|
||||
return des_setkey_enc( (des_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
((void) key_length);
|
||||
|
||||
return des3_set2key_dec( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
((void) key_length);
|
||||
|
||||
return des3_set2key_enc( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
((void) key_length);
|
||||
|
||||
return des3_set3key_dec( (des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
((void) key_length);
|
||||
|
||||
@ -783,16 +925,38 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key, unsigned
|
||||
|
||||
static void * des_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( des_context ) );
|
||||
}
|
||||
des_context *des = (des_context *) polarssl_malloc( sizeof( des_context ) );
|
||||
|
||||
static void * des3_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( des3_context ) );
|
||||
if( des == NULL )
|
||||
return( NULL );
|
||||
|
||||
des_init( des );
|
||||
|
||||
return( des );
|
||||
}
|
||||
|
||||
static void des_ctx_free( void *ctx )
|
||||
{
|
||||
des_free( (des_context *) ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
static void * des3_ctx_alloc( void )
|
||||
{
|
||||
des3_context *des3;
|
||||
des3 = (des3_context *) polarssl_malloc( sizeof( des3_context ) );
|
||||
|
||||
if( des3 == NULL )
|
||||
return( NULL );
|
||||
|
||||
des3_init( des3 );
|
||||
|
||||
return( des3 );
|
||||
}
|
||||
|
||||
static void des3_ctx_free( void *ctx )
|
||||
{
|
||||
des3_free( (des3_context *) ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
@ -800,8 +964,8 @@ const cipher_base_t des_info = {
|
||||
POLARSSL_CIPHER_ID_DES,
|
||||
des_crypt_ecb_wrap,
|
||||
des_crypt_cbc_wrap,
|
||||
des_crypt_cfb128_wrap,
|
||||
des_crypt_ctr_wrap,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
des_setkey_enc_wrap,
|
||||
des_setkey_dec_wrap,
|
||||
@ -837,13 +1001,13 @@ const cipher_base_t des_ede_info = {
|
||||
POLARSSL_CIPHER_ID_DES,
|
||||
des3_crypt_ecb_wrap,
|
||||
des3_crypt_cbc_wrap,
|
||||
des_crypt_cfb128_wrap,
|
||||
des_crypt_ctr_wrap,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
des3_set2key_enc_wrap,
|
||||
des3_set2key_dec_wrap,
|
||||
des3_ctx_alloc,
|
||||
des_ctx_free
|
||||
des3_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t des_ede_ecb_info = {
|
||||
@ -874,13 +1038,13 @@ const cipher_base_t des_ede3_info = {
|
||||
POLARSSL_CIPHER_ID_DES,
|
||||
des3_crypt_ecb_wrap,
|
||||
des3_crypt_cbc_wrap,
|
||||
des_crypt_cfb128_wrap,
|
||||
des_crypt_ctr_wrap,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
des3_set3key_enc_wrap,
|
||||
des3_set3key_dec_wrap,
|
||||
des3_ctx_alloc,
|
||||
des_ctx_free
|
||||
des3_ctx_free
|
||||
};
|
||||
|
||||
const cipher_info_t des_ede3_ecb_info = {
|
||||
@ -905,21 +1069,24 @@ const cipher_info_t des_ede3_cbc_info = {
|
||||
&des_ede3_info
|
||||
};
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
#endif
|
||||
#endif /* POLARSSL_DES_C */
|
||||
|
||||
#if defined(POLARSSL_BLOWFISH_C)
|
||||
|
||||
static int blowfish_crypt_ecb_wrap( void *ctx, operation_t operation,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input, output );
|
||||
return blowfish_crypt_ecb( (blowfish_context *) ctx, operation, input,
|
||||
output );
|
||||
}
|
||||
|
||||
static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t length,
|
||||
unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation,
|
||||
size_t length, unsigned char *iv, const unsigned char *input,
|
||||
unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
||||
return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv, input, output );
|
||||
return blowfish_crypt_cbc( (blowfish_context *) ctx, operation, length, iv,
|
||||
input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -928,15 +1095,17 @@ static int blowfish_crypt_cbc_wrap( void *ctx, operation_t operation, size_t len
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
||||
}
|
||||
|
||||
static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t length,
|
||||
size_t *iv_off, unsigned char *iv, const unsigned char *input, unsigned char *output )
|
||||
static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation,
|
||||
size_t length, size_t *iv_off, unsigned char *iv,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CFB)
|
||||
return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length, iv_off, iv, input, output );
|
||||
return blowfish_crypt_cfb64( (blowfish_context *) ctx, operation, length,
|
||||
iv_off, iv, input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) operation);
|
||||
@ -946,17 +1115,17 @@ static int blowfish_crypt_cfb64_wrap( void *ctx, operation_t operation, size_t l
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CFB */
|
||||
}
|
||||
|
||||
static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
size_t *nc_off, unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
||||
unsigned char *nonce_counter, unsigned char *stream_block,
|
||||
const unsigned char *input, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_CIPHER_MODE_CTR)
|
||||
return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off, nonce_counter,
|
||||
stream_block, input, output );
|
||||
return blowfish_crypt_ctr( (blowfish_context *) ctx, length, nc_off,
|
||||
nonce_counter, stream_block, input, output );
|
||||
#else
|
||||
((void) ctx);
|
||||
((void) length);
|
||||
@ -966,22 +1135,32 @@ static int blowfish_crypt_ctr_wrap( void *ctx, size_t length,
|
||||
((void) input);
|
||||
((void) output);
|
||||
|
||||
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
||||
#endif /* POLARSSL_CIPHER_MODE_CTR */
|
||||
}
|
||||
|
||||
static int blowfish_setkey_wrap( void *ctx, const unsigned char *key, unsigned int key_length )
|
||||
static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
return blowfish_setkey( (blowfish_context *) ctx, key, key_length );
|
||||
}
|
||||
|
||||
static void * blowfish_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( blowfish_context ) );
|
||||
blowfish_context *ctx;
|
||||
ctx = (blowfish_context *) polarssl_malloc( sizeof( blowfish_context ) );
|
||||
|
||||
if( ctx == NULL )
|
||||
return( NULL );
|
||||
|
||||
blowfish_init( ctx );
|
||||
|
||||
return( ctx );
|
||||
}
|
||||
|
||||
static void blowfish_ctx_free( void *ctx )
|
||||
{
|
||||
blowfish_free( (blowfish_context *) ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
@ -1004,7 +1183,7 @@ const cipher_info_t blowfish_ecb_info = {
|
||||
128,
|
||||
"BLOWFISH-ECB",
|
||||
8,
|
||||
0,
|
||||
POLARSSL_CIPHER_VARIABLE_KEY_LEN,
|
||||
8,
|
||||
&blowfish_info
|
||||
};
|
||||
@ -1016,7 +1195,7 @@ const cipher_info_t blowfish_cbc_info = {
|
||||
128,
|
||||
"BLOWFISH-CBC",
|
||||
8,
|
||||
0,
|
||||
POLARSSL_CIPHER_VARIABLE_KEY_LEN,
|
||||
8,
|
||||
&blowfish_info
|
||||
};
|
||||
@ -1029,7 +1208,7 @@ const cipher_info_t blowfish_cfb64_info = {
|
||||
128,
|
||||
"BLOWFISH-CFB64",
|
||||
8,
|
||||
0,
|
||||
POLARSSL_CIPHER_VARIABLE_KEY_LEN,
|
||||
8,
|
||||
&blowfish_info
|
||||
};
|
||||
@ -1042,7 +1221,7 @@ const cipher_info_t blowfish_ctr_info = {
|
||||
128,
|
||||
"BLOWFISH-CTR",
|
||||
8,
|
||||
0,
|
||||
POLARSSL_CIPHER_VARIABLE_KEY_LEN,
|
||||
8,
|
||||
&blowfish_info
|
||||
};
|
||||
@ -1061,7 +1240,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
{
|
||||
/* we get key_length in bits, arc4 expects it in bytes */
|
||||
if( key_length % 8 != 0)
|
||||
if( key_length % 8 != 0 )
|
||||
return( POLARSSL_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
|
||||
arc4_setup( (arc4_context *) ctx, key, key_length / 8 );
|
||||
@ -1070,11 +1249,20 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
|
||||
static void * arc4_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( arc4_context ) );
|
||||
arc4_context *ctx;
|
||||
ctx = (arc4_context *) polarssl_malloc( sizeof( arc4_context ) );
|
||||
|
||||
if( ctx == NULL )
|
||||
return( NULL );
|
||||
|
||||
arc4_init( ctx );
|
||||
|
||||
return( ctx );
|
||||
}
|
||||
|
||||
static void arc4_ctx_free( void *ctx )
|
||||
{
|
||||
arc4_free( (arc4_context *) ctx );
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
@ -1125,7 +1313,7 @@ static int null_setkey( void *ctx, const unsigned char *key,
|
||||
|
||||
static void * null_ctx_alloc( void )
|
||||
{
|
||||
return (void *) 1;
|
||||
return( (void *) 1 )
|
||||
}
|
||||
|
||||
static void null_ctx_free( void *ctx )
|
||||
@ -1184,6 +1372,11 @@ const cipher_definition_t cipher_definitions[] =
|
||||
{ POLARSSL_CIPHER_AES_192_GCM, &aes_192_gcm_info },
|
||||
{ POLARSSL_CIPHER_AES_256_GCM, &aes_256_gcm_info },
|
||||
#endif
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
{ POLARSSL_CIPHER_AES_128_CCM, &aes_128_ccm_info },
|
||||
{ POLARSSL_CIPHER_AES_192_CCM, &aes_192_ccm_info },
|
||||
{ POLARSSL_CIPHER_AES_256_CCM, &aes_256_ccm_info },
|
||||
#endif
|
||||
#endif /* POLARSSL_AES_C */
|
||||
|
||||
#if defined(POLARSSL_ARC4_C)
|
||||
@ -1227,6 +1420,11 @@ const cipher_definition_t cipher_definitions[] =
|
||||
{ POLARSSL_CIPHER_CAMELLIA_192_GCM, &camellia_192_gcm_info },
|
||||
{ POLARSSL_CIPHER_CAMELLIA_256_GCM, &camellia_256_gcm_info },
|
||||
#endif
|
||||
#if defined(POLARSSL_CCM_C)
|
||||
{ POLARSSL_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
|
||||
{ POLARSSL_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
|
||||
{ POLARSSL_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
|
||||
#endif
|
||||
#endif /* POLARSSL_CAMELLIA_C */
|
||||
|
||||
#if defined(POLARSSL_DES_C)
|
||||
@ -1250,4 +1448,4 @@ const cipher_definition_t cipher_definitions[] =
|
||||
#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
|
||||
int supported_ciphers[NUM_CIPHERS];
|
||||
|
||||
#endif
|
||||
#endif /* POLARSSL_CIPHER_C */
|
||||
|
Reference in New Issue
Block a user