[NUC472/M487] Remove AES alter. dead code

pull/4925/head
ccli8 2017-09-14 14:26:54 +08:00
parent 5665247d4a
commit 2dcc1e9e27
3 changed files with 10 additions and 49 deletions

View File

@ -61,19 +61,6 @@ static void swapInitVector(unsigned char iv[16])
} }
} }
/* IRQHandler: To share CRYPTO_IRQHandler() with TRNG & other crypto IPs
For ex:
volatile void CRYPTO_IRQHandler()
{
...
if (AES_GET_INT_FLAG()) {
g_AES_done = 1;
AES_CLR_INT_FLAG();
}
...
}
*/
/* AES available channel 0~3 */ /* AES available channel 0~3 */
static unsigned char channel_flag[4]= {0x00,0x00,0x00,0x00}; // 0: idle, 1: busy static unsigned char channel_flag[4]= {0x00,0x00,0x00,0x00}; // 0: idle, 1: busy

View File

@ -27,17 +27,20 @@
#if defined(MBEDTLS_AES_ALT) #if defined(MBEDTLS_AES_ALT)
#include <string.h> #include <string.h>
#include "NUC472_442.h" #include "NUC472_442.h"
#include "mbed_toolchain.h" #include "mbed_toolchain.h"
#include "mbed_assert.h" #include "mbed_assert.h"
/* Implementation that should never be optimized out by the compiler */ /* Implementation that should never be optimized out by the compiler */
static void mbedtls_zeroize( void *v, size_t n ) static void mbedtls_zeroize( void *v, size_t n )
{ {
volatile unsigned char *p = (unsigned char*)v; volatile unsigned char *p = (unsigned char*)v;
while( n-- ) *p++ = 0; while( n-- ) *p++ = 0;
} }
extern volatile int g_AES_done; extern volatile int g_AES_done;
// Must be a multiple of 16 bytes block size // Must be a multiple of 16 bytes block size
@ -58,15 +61,8 @@ static void swapInitVector(unsigned char iv[16])
} }
} }
//volatile void CRYPTO_IRQHandler()
//{
// if (AES_GET_INT_FLAG()) {
// g_AES_done = 1;
// AES_CLR_INT_FLAG();
// }
//}
// AES available channel 0~3 /* AES available channel 0~3 */
static unsigned char channel_flag[4]= {0x00,0x00,0x00,0x00}; // 0: idle, 1: busy static unsigned char channel_flag[4]= {0x00,0x00,0x00,0x00}; // 0: idle, 1: busy
static int channel_alloc() static int channel_alloc()
{ {
@ -91,15 +87,11 @@ void mbedtls_aes_init( mbedtls_aes_context *ctx )
{ {
int i =-1; int i =-1;
// sw_mbedtls_aes_init(ctx);
// return;
memset( ctx, 0, sizeof( mbedtls_aes_context ) ); memset( ctx, 0, sizeof( mbedtls_aes_context ) );
ctx->swapType = AES_IN_OUT_SWAP; ctx->swapType = AES_IN_OUT_SWAP;
while( (i = channel_alloc()) < 0 ) { while( (i = channel_alloc()) < 0 ) {
mbed_assert_internal("No available AES channel", __FILE__, __LINE__); mbed_assert_internal("No available AES channel", __FILE__, __LINE__);
//osDelay(300);
} }
ctx->channel = i; ctx->channel = i;
memset(ctx->iv, 0, sizeof (ctx->iv)); memset(ctx->iv, 0, sizeof (ctx->iv));
@ -121,14 +113,6 @@ void mbedtls_aes_free( mbedtls_aes_context *ctx )
if( ctx == NULL ) if( ctx == NULL )
return; return;
/* Unlock protected registers */
// SYS_UnlockReg();
// CLK_DisableModuleClock(CRPT_MODULE);
/* Lock protected registers */
// SYS_LockReg();
// NVIC_DisableIRQ(CRPT_IRQn);
// AES_DISABLE_INT();
channel_free(ctx->channel); channel_free(ctx->channel);
mbedtls_zeroize( ctx, sizeof( mbedtls_aes_context ) ); mbedtls_zeroize( ctx, sizeof( mbedtls_aes_context ) );
} }
@ -231,11 +215,8 @@ void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
const unsigned char input[16], const unsigned char input[16],
unsigned char output[16] ) unsigned char output[16] )
{ {
ctx->encDec = 1; ctx->encDec = 1;
__nvt_aes_crypt(ctx, input, output, 16); __nvt_aes_crypt(ctx, input, output, 16);
} }
/* /*
@ -245,12 +226,8 @@ void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
const unsigned char input[16], const unsigned char input[16],
unsigned char output[16] ) unsigned char output[16] )
{ {
ctx->encDec = 0; ctx->encDec = 0;
__nvt_aes_crypt(ctx, input, output, 16); __nvt_aes_crypt(ctx, input, output, 16);
} }
/* /*
@ -261,8 +238,6 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
const unsigned char input[16], const unsigned char input[16],
unsigned char output[16] ) unsigned char output[16] )
{ {
ctx->opMode = AES_MODE_ECB; ctx->opMode = AES_MODE_ECB;
if( mode == MBEDTLS_AES_ENCRYPT ) if( mode == MBEDTLS_AES_ENCRYPT )
mbedtls_aes_encrypt( ctx, input, output ); mbedtls_aes_encrypt( ctx, input, output );
@ -287,6 +262,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
unsigned char temp[16]; unsigned char temp[16];
int length = len; int length = len;
int blockChainLen; int blockChainLen;
if( length % 16 ) if( length % 16 )
return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH ); return( MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH );
@ -316,7 +292,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
length -= blockChainLen; length -= blockChainLen;
input += blockChainLen; input += blockChainLen;
output += blockChainLen; output += blockChainLen;
if(length < MAX_DMA_CHAIN_SIZE ) blockChainLen = length; // For last remainder block chain if(length < MAX_DMA_CHAIN_SIZE ) blockChainLen = length; // For last remainder block chain
} }
@ -340,11 +316,12 @@ static int __nvt_aes_crypt_partial_block_cfb128( mbedtls_aes_context *ctx,
int c; int c;
size_t n = *iv_off; size_t n = *iv_off;
unsigned char iv_tmp[16]; unsigned char iv_tmp[16];
if( mode == MBEDTLS_AES_DECRYPT ) { if( mode == MBEDTLS_AES_DECRYPT ) {
while( length-- ) { while( length-- ) {
if( n == 0) if( n == 0)
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
else if( ctx->opMode == AES_MODE_CFB) { // For previous cryption is CFB mode else if( ctx->opMode == AES_MODE_CFB) { // For previous cryption is CFB mode
memcpy(iv_tmp, iv, n); memcpy(iv_tmp, iv, n);
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, ctx->prv_iv, iv ); mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, ctx->prv_iv, iv );
memcpy(iv, iv_tmp, n); memcpy(iv, iv_tmp, n);
@ -436,7 +413,7 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
length -= blockChainLen; length -= blockChainLen;
input += blockChainLen; input += blockChainLen;
output += blockChainLen; output += blockChainLen;
if(length < MAX_DMA_CHAIN_SIZE ) blockChainLen = length; // For last remainder block chain if(length < MAX_DMA_CHAIN_SIZE ) blockChainLen = length; // For last remainder block chain
} }
*iv_off = remLen; *iv_off = remLen;

View File

@ -20,12 +20,9 @@
* *
* This file is part of mbed TLS (https://tls.mbed.org) * This file is part of mbed TLS (https://tls.mbed.org)
*/ */
#ifndef MBEDTLS_AES_ALT_H #ifndef MBEDTLS_AES_ALT_H
#define MBEDTLS_AES_ALT_H #define MBEDTLS_AES_ALT_H
#include "mbedtls/aes.h"
#if defined(MBEDTLS_AES_C) #if defined(MBEDTLS_AES_C)
#if defined(MBEDTLS_AES_ALT) #if defined(MBEDTLS_AES_ALT)
// Regular implementation // Regular implementation