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 );