From 0a56b34d0eb8ffe3f0ef7cb291e611a6097c175f Mon Sep 17 00:00:00 2001 From: ccli8 Date: Wed, 27 Sep 2017 18:42:12 +0800 Subject: [PATCH] Refine AES alter. key endianness code --- .../targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c | 7 ++----- .../targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c b/features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c index faca8ca3b8..fca7ce9026 100644 --- a/features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c +++ b/features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c @@ -87,12 +87,9 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); } - // key swap + /* Fetch key byte data in big-endian */ for( i = 0; i < ( keybits >> 5 ); i++ ) { - ctx->keys[i] = (*(key+i*4) << 24) | - (*(key+1+i*4) << 16) | - (*(key+2+i*4) << 8) | - (*(key+3+i*4) ); + ctx->keys[i] = nu_get32_be(key + i * 4); } return( 0 ); diff --git a/features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c b/features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c index dcddf1da74..50f41fd4a6 100644 --- a/features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c +++ b/features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c @@ -87,12 +87,9 @@ int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key, return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH ); } - // key swap + /* Fetch key byte data in big-endian */ for( i = 0; i < ( keybits >> 5 ); i++ ) { - ctx->keys[i] = (*(key+i*4) << 24) | - (*(key+1+i*4) << 16) | - (*(key+2+i*4) << 8) | - (*(key+3+i*4) ); + ctx->keys[i] = nu_get32_be(key + i * 4); } return( 0 );