From a2be7590d15efdec3c0743cefdd0bdc610d549ed Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 7 Sep 2018 17:02:34 -0700 Subject: [PATCH] Fixes for NXP LTC support with K82. Fix for SHA384/512. Fix for AES CBC not storing previous IV. Fix for `wc_AesSetKey` arg check. Fix for AES GCM IV != 12 test. Changed LTC default in settings.h to not enable SHA512 and Ed/Curve25519. Tested using Rowley Crossworks v4.2.0 on a FRDM-K82F. There is an initial stack pointer issue with the arm-startup code here for Rowley still outstanding, but these fixes are valid as-is. --- IDE/ROWLEY-CROSSWORKS-ARM/arm_startup.c | 2 +- IDE/ROWLEY-CROSSWORKS-ARM/benchmark_main.c | 4 ++++ IDE/ROWLEY-CROSSWORKS-ARM/test_main.c | 4 ++++ IDE/ROWLEY-CROSSWORKS-ARM/user_settings.h | 9 ++++++--- IDE/ROWLEY-CROSSWORKS-ARM/wolfssl_ltc.hzp | 6 +++--- wolfcrypt/src/aes.c | 20 +++++++++++++++++++- wolfcrypt/src/memory.c | 4 ++++ wolfcrypt/src/sha512.c | 5 ++--- wolfcrypt/test/test.c | 9 +++++---- wolfssl/wolfcrypt/settings.h | 10 +--------- 10 files changed, 49 insertions(+), 24 deletions(-) diff --git a/IDE/ROWLEY-CROSSWORKS-ARM/arm_startup.c b/IDE/ROWLEY-CROSSWORKS-ARM/arm_startup.c index 0faae8ecd..45c796705 100644 --- a/IDE/ROWLEY-CROSSWORKS-ARM/arm_startup.c +++ b/IDE/ROWLEY-CROSSWORKS-ARM/arm_startup.c @@ -155,7 +155,7 @@ void HardFault_HandlerC( uint32_t *hardfault_args ) printf ("BFAR = %x\n", _BFAR); // Break into the debugger - __asm("BKPT #0\n"); + __asm("BKPT #0\n"); } __attribute__( ( naked ) ) diff --git a/IDE/ROWLEY-CROSSWORKS-ARM/benchmark_main.c b/IDE/ROWLEY-CROSSWORKS-ARM/benchmark_main.c index 25f50ae7e..e205f2cb5 100644 --- a/IDE/ROWLEY-CROSSWORKS-ARM/benchmark_main.c +++ b/IDE/ROWLEY-CROSSWORKS-ARM/benchmark_main.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include @@ -42,6 +43,7 @@ void main(void) { int test_num = 0; + wolfCrypt_Init(); /* required for ksdk_port_init */ do { /* Used for testing, must have a delay so no data is missed while serial is initializing */ @@ -68,6 +70,8 @@ void main(void) printf("\n&&&&&&&&&&&&&& done &&&&&&&&&&&&&\n"); delay_us(1000000); #endif + + wolfCrypt_Cleanup(); } /* diff --git a/IDE/ROWLEY-CROSSWORKS-ARM/test_main.c b/IDE/ROWLEY-CROSSWORKS-ARM/test_main.c index 2b1e76fde..bb483aa01 100644 --- a/IDE/ROWLEY-CROSSWORKS-ARM/test_main.c +++ b/IDE/ROWLEY-CROSSWORKS-ARM/test_main.c @@ -26,6 +26,7 @@ #endif #include +#include #include #include #include "hw.h" @@ -43,6 +44,7 @@ void main(void) { int test_num = 0; + wolfCrypt_Init(); /* required for ksdk_port_init */ do { /* Used for testing, must have a delay so no data is missed while serial is initializing */ @@ -68,6 +70,8 @@ void main(void) printf("\n&&&&&&&&&&&&&& done &&&&&&&&&&&&&\n"); delay_us(1000000); #endif + + wolfCrypt_Cleanup(); } diff --git a/IDE/ROWLEY-CROSSWORKS-ARM/user_settings.h b/IDE/ROWLEY-CROSSWORKS-ARM/user_settings.h index b9f3ae150..63279511e 100644 --- a/IDE/ROWLEY-CROSSWORKS-ARM/user_settings.h +++ b/IDE/ROWLEY-CROSSWORKS-ARM/user_settings.h @@ -19,7 +19,10 @@ extern "C" { #define SINGLE_THREADED #undef WOLFSSL_SMALL_STACK -#define WOLFSSL_SMALL_STACK +//#define WOLFSSL_SMALL_STACK + +#undef WOLFSSL_SMALL_STACK_CACHE +//#define WOLFSSL_SMALL_STACK_CACHE /* ------------------------------------------------------------------------- */ @@ -58,7 +61,7 @@ extern "C" { #define HAVE_ECC224 #undef NO_ECC256 #define HAVE_ECC384 - #ifndef USE_NXP_LTC /* NXP LTC HW supports up to 512 */ + #ifndef USE_NXP_LTC /* NXP LTC HW supports up to 384 */ #define HAVE_ECC521 #endif @@ -221,7 +224,7 @@ extern "C" { #endif #ifdef USE_NXP_LTC #define FREESCALE_USE_LTC - #define LTC_MAX_ECC_BITS (512) + #define LTC_MAX_ECC_BITS (384) #define LTC_MAX_INT_BYTES (256) //#define FREESCALE_LTC_TFM_RSA_4096_ENABLE diff --git a/IDE/ROWLEY-CROSSWORKS-ARM/wolfssl_ltc.hzp b/IDE/ROWLEY-CROSSWORKS-ARM/wolfssl_ltc.hzp index f9be95d06..5a474b301 100644 --- a/IDE/ROWLEY-CROSSWORKS-ARM/wolfssl_ltc.hzp +++ b/IDE/ROWLEY-CROSSWORKS-ARM/wolfssl_ltc.hzp @@ -4,7 +4,7 @@ @@ -338,7 +338,7 @@ arm_simulator_memory_simulation_parameter="MK82FN256xxx15;0x40000;0x0;0x0;0x40000;4" arm_target_loader_applicable_loaders="Flash" arm_target_loader_default_loader="Flash" - c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS" + c_preprocessor_definitions="WOLFSSL_ROWLEY_ARM;WOLFSSL_USER_SETTINGS;USE_NXP_MMCAU;USE_NXP_LTC" c_user_include_directories=".;./drivers;./mmcau_2.0.0;./CMSIS/Include;../;../../;$(TargetsDir);$(TargetsDir)/Kinetis;$(TargetsDir)/Kinetis/CMSIS;$(TargetsDir)/Kinetis/CMSIS/include;$(TargetsDir)/CMSIS_3/CMSIS/include" debug_register_definition_file="$(TargetsDir)/Kinetis/MK82F25615_Peripherals.xml" linker_memory_map_file="$(TargetsDir)/Kinetis/MK82FN256xxx15_MemoryMap.xml" @@ -511,7 +511,7 @@