mirror of https://github.com/ARMmbed/mbed-os.git
Remove debug code in AES alternative
parent
de0db52903
commit
5894775398
|
@ -40,8 +40,6 @@
|
|||
|
||||
|
||||
|
||||
#define mbedtls_trace(...) //printf(__VA_ARGS__)
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
|
||||
|
@ -59,13 +57,6 @@ extern volatile int g_AES_done;
|
|||
MBED_ALIGN(4) static uint8_t au8OutputData[MAX_DMA_CHAIN_SIZE];
|
||||
MBED_ALIGN(4) static uint8_t au8InputData[MAX_DMA_CHAIN_SIZE];
|
||||
|
||||
static void dumpHex(const unsigned char au8Data[], int len)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < len; j++) mbedtls_trace("%02x ", au8Data[j]);
|
||||
mbedtls_trace("\r\n");
|
||||
}
|
||||
|
||||
static void swapInitVector(unsigned char iv[16])
|
||||
{
|
||||
unsigned int* piv;
|
||||
|
@ -123,8 +114,6 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx )
|
|||
{
|
||||
int i =-1;
|
||||
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
memset( ctx, 0, sizeof( mbedtls_aes_context ) );
|
||||
|
||||
ctx->swapType = AES_IN_OUT_SWAP;
|
||||
|
@ -143,13 +132,11 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx )
|
|||
|
||||
NVIC_EnableIRQ(CRPT_IRQn);
|
||||
AES_ENABLE_INT();
|
||||
mbedtls_trace("=== %s channel[%d]\r\n", __FUNCTION__, (int)ctx->channel);
|
||||
}
|
||||
|
||||
void mbedtls_aes_free( mbedtls_aes_context *ctx )
|
||||
{
|
||||
|
||||
mbedtls_trace("=== %s channel[%d]\r\n", __FUNCTION__,(int)ctx->channel);
|
||||
|
||||
if( ctx == NULL )
|
||||
return;
|
||||
|
@ -167,8 +154,6 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
|
|||
{
|
||||
unsigned int i;
|
||||
|
||||
mbedtls_trace("=== %s keybits[%d]\r\n", __FUNCTION__, keybits);
|
||||
dumpHex(key,keybits/8);
|
||||
|
||||
switch( keybits )
|
||||
{
|
||||
|
@ -210,8 +195,6 @@ int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
|
|||
{
|
||||
int ret;
|
||||
|
||||
mbedtls_trace("=== %s keybits[%d]\r\n", __FUNCTION__, keybits);
|
||||
dumpHex((uint8_t *)key,keybits/8);
|
||||
|
||||
/* Also checks keybits */
|
||||
if( ( ret = mbedtls_aes_setkey_enc( ctx, key, keybits ) ) != 0 )
|
||||
|
@ -231,8 +214,6 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
|
|||
unsigned char* pIn;
|
||||
unsigned char* pOut;
|
||||
|
||||
// mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
dumpHex(input,16);
|
||||
|
||||
AES_Open(ctx->channel, ctx->encDec, ctx->opMode, ctx->keySize, ctx->swapType);
|
||||
AES_SetInitVect(ctx->channel, ctx->iv);
|
||||
|
@ -257,7 +238,6 @@ static void __nvt_aes_crypt( mbedtls_aes_context *ctx,
|
|||
while (!g_AES_done);
|
||||
|
||||
if( pOut != output ) memcpy(output, au8OutputData, dataSize);
|
||||
dumpHex(output,16);
|
||||
|
||||
}
|
||||
|
||||
|
@ -269,12 +249,8 @@ void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
|
|||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
|
||||
ctx->encDec = 1;
|
||||
__nvt_aes_crypt(ctx, input, output, 16);
|
||||
|
||||
}
|
||||
#endif /* MBEDTLS_AES_ENCRYPT_ALT */
|
||||
|
||||
|
@ -286,13 +262,8 @@ void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
|
|||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
|
||||
ctx->encDec = 0;
|
||||
__nvt_aes_crypt(ctx, input, output, 16);
|
||||
|
||||
|
||||
}
|
||||
#endif /* MBEDTLS_AES_DECRYPT_ALT */
|
||||
|
||||
|
@ -304,9 +275,6 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
|||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
|
||||
ctx->opMode = AES_MODE_ECB;
|
||||
if( mode == MBEDTLS_AES_ENCRYPT )
|
||||
mbedtls_aes_encrypt( ctx, input, output );
|
||||
|
@ -331,7 +299,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
|||
unsigned char temp[16];
|
||||
int length = len;
|
||||
int blockChainLen;
|
||||
mbedtls_trace("=== %s [0x%x]\r\n", __FUNCTION__,length);
|
||||
|
||||
if( length % 16 )
|
||||
return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
|
||||
|
||||
|
@ -388,7 +356,7 @@ static int __nvt_aes_crypt_partial_block_cfb128( mbedtls_aes_context *ctx,
|
|||
int c;
|
||||
size_t n = *iv_off;
|
||||
unsigned char iv_tmp[16];
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
|
||||
if( mode == MBEDTLS_AES_DECRYPT )
|
||||
{
|
||||
while( length-- )
|
||||
|
@ -448,7 +416,6 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
|||
int remLen=0;
|
||||
int ivLen;
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
|
||||
// proceed: start with partial block by ECB mode first
|
||||
if( n !=0 ) {
|
||||
|
@ -520,7 +487,6 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
|||
unsigned char c;
|
||||
unsigned char ov[17];
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
while( length-- )
|
||||
{
|
||||
memcpy( ov, iv, 16 );
|
||||
|
@ -556,7 +522,6 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
|||
int c, i;
|
||||
size_t n = *nc_off;
|
||||
|
||||
mbedtls_trace("=== %s \r\n", __FUNCTION__);
|
||||
while( length-- )
|
||||
{
|
||||
if( n == 0 ) {
|
||||
|
|
|
@ -54,14 +54,7 @@ typedef struct
|
|||
uint32_t swapType;
|
||||
uint32_t *iv;
|
||||
unsigned char prv_iv[16];
|
||||
#if 1
|
||||
uint32_t buf[8];
|
||||
/* For comparsion with software AES for correctness */
|
||||
#else
|
||||
uint32_t buf[68]; /*!< unaligned data */
|
||||
int nr; /*!< number of rounds */
|
||||
uint32_t *rk; /*!< AES round keys */
|
||||
#endif
|
||||
}
|
||||
mbedtls_aes_context;
|
||||
|
||||
|
|
Loading…
Reference in New Issue