From 5837c70e99c9992ccf73c7a5f520c4a9be03fb9f Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 3 Jun 2020 11:38:56 -0700 Subject: [PATCH] Support for STM32L5 PKA ECC sign/verify acceleration. --- IDE/OPENSTM32/Inc/user_settings.h | 1 + wolfcrypt/src/port/st/stm32.c | 7 ++++++- wolfssl/wolfcrypt/port/st/stm32.h | 28 ++++++++++++++++++---------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/IDE/OPENSTM32/Inc/user_settings.h b/IDE/OPENSTM32/Inc/user_settings.h index 7ff0e7e43..1c4282fb0 100644 --- a/IDE/OPENSTM32/Inc/user_settings.h +++ b/IDE/OPENSTM32/Inc/user_settings.h @@ -64,6 +64,7 @@ extern "C" { //#define NO_STM32_HASH //#define NO_STM32_RNG //#define NO_STM32_CRYPTO +//#define WOLFSSL_STM32_PKA /* WB55 and L5 only */ /* ------------------------------------------------------------------------- */ diff --git a/wolfcrypt/src/port/st/stm32.c b/wolfcrypt/src/port/st/stm32.c index bb20a14d7..2c3aac27d 100644 --- a/wolfcrypt/src/port/st/stm32.c +++ b/wolfcrypt/src/port/st/stm32.c @@ -363,9 +363,14 @@ int wc_Stm32_Aes_Init(Aes* aes, CRYP_InitTypeDef* cryptInit, #ifdef WOLFSSL_STM32_PKA #include + +#if defined(WOLFSSL_STM32L5) +#include +#include +#else #include #include - +#endif extern PKA_HandleTypeDef hpka; /* Reverse array in memory (in place) */ diff --git a/wolfssl/wolfcrypt/port/st/stm32.h b/wolfssl/wolfcrypt/port/st/stm32.h index 25e59e1da..24de1c183 100644 --- a/wolfssl/wolfcrypt/port/st/stm32.h +++ b/wolfssl/wolfcrypt/port/st/stm32.h @@ -28,11 +28,6 @@ #include #include -#if defined(WOLFSSL_STM32_PKA) && defined(HAVE_ECC) - #include - #include -#endif - #ifdef STM32_HASH #define WOLFSSL_NO_HASH_RAW @@ -139,12 +134,25 @@ int wc_Stm32_Hash_Final(STM32_HASH_Context* stmCtx, word32 algo, #endif /* STM32_CRYPTO */ #if defined(WOLFSSL_STM32_PKA) && defined(HAVE_ECC) -int stm32_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, - word32 hashlen, int* res, ecc_key* key); - -int stm32_ecc_sign_hash_ex(const byte* hash, word32 hashlen, WC_RNG* rng, - ecc_key* key, mp_int *r, mp_int *s); +#ifdef WOLFSSL_SP_MATH + struct sp_int; + #define MATH_INT_T struct sp_int +#elif defined(USE_FAST_MATH) + struct fp_int; + #define MATH_INT_T struct fp_int +#else + struct mp_int; + #define MATH_INT_T struct mp_int #endif +struct ecc_key; +struct WC_RNG; + +int stm32_ecc_verify_hash_ex(MATH_INT_T *r, MATH_INT_T *s, const byte* hash, + word32 hashlen, int* res, struct ecc_key* key); + +int stm32_ecc_sign_hash_ex(const byte* hash, word32 hashlen, struct WC_RNG* rng, + struct ecc_key* key, MATH_INT_T *r, MATH_INT_T *s); +#endif /* WOLFSSL_STM32_PKA && HAVE_ECC */ #endif /* _WOLFPORT_STM32_H_ */