From 968fda65caf19d32a9996f35073f327e3f36abb1 Mon Sep 17 00:00:00 2001 From: Staars Date: Mon, 19 Oct 2020 19:07:22 +0200 Subject: [PATCH] adapt bearsll-esp8266 to ESP32 --- lib/bearssl-esp8266/src/rand/sysrng.c | 19 +++++++++++++++++++ .../src/symcipher/chacha20_ct.c | 4 ++++ lib/bearssl-esp8266/src/t_inner.h | 8 ++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/bearssl-esp8266/src/rand/sysrng.c b/lib/bearssl-esp8266/src/rand/sysrng.c index c8268de72..8fa4f3403 100644 --- a/lib/bearssl-esp8266/src/rand/sysrng.c +++ b/lib/bearssl-esp8266/src/rand/sysrng.c @@ -140,6 +140,24 @@ seeder_win32(const br_prng_class **ctx) #endif #if BR_USE_ESP8266_RAND +#ifdef ESP32 +extern uint32_t esp_random(void); + +static int +seeder_esp8266(const br_prng_class **ctx) //TODO: rename/refactor it to ESP32 +{ + uint32_t tmp[32 / sizeof(uint32_t)]; + size_t i; + + for (i=0; iupdate(ctx, tmp, sizeof tmp); + + return 1; +} +#else extern uint32_t phy_get_rand(void); // From the ESP8266 SDK static int @@ -157,6 +175,7 @@ seeder_esp8266(const br_prng_class **ctx) return 1; } #endif +#endif /* see bearssl_rand.h */ diff --git a/lib/bearssl-esp8266/src/symcipher/chacha20_ct.c b/lib/bearssl-esp8266/src/symcipher/chacha20_ct.c index 84ea79a1e..da4024cd1 100644 --- a/lib/bearssl-esp8266/src/symcipher/chacha20_ct.c +++ b/lib/bearssl-esp8266/src/symcipher/chacha20_ct.c @@ -33,7 +33,11 @@ br_chacha20_ct_run(const void *key, uint32_t kw[8], ivw[3]; size_t u; +#ifdef ESP32 + static const uint32_t CW[] = { +#else static const uint32_t CW[] PROGMEM = { +#endif 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 }; diff --git a/lib/bearssl-esp8266/src/t_inner.h b/lib/bearssl-esp8266/src/t_inner.h index 8dca0c09b..435c67c49 100644 --- a/lib/bearssl-esp8266/src/t_inner.h +++ b/lib/bearssl-esp8266/src/t_inner.h @@ -132,7 +132,7 @@ * Set BR_LOMUL on platforms where it makes sense. */ #ifndef BR_LOMUL -#if BR_ARMEL_CORTEXM_GCC || (defined(ESP8266) && !defined(ESP8266M32)) +#if BR_ARMEL_CORTEXM_GCC || ((defined(ESP8266) || defined(ESP32)) && !defined(ESP8266M32)) #define BR_LOMUL 1 #endif #endif @@ -315,7 +315,7 @@ * Use ESP8266 hardware random generator when possible. */ #ifndef BR_USE_ESP8266_RAND -#if defined(ESP8266) +#if (defined(ESP8266) || defined(ESP32)) #define BR_USE_ESP8266_RAND 1 #endif #endif @@ -433,7 +433,7 @@ */ #ifndef BR_USE_UNIX_TIME -#if defined __unix__ || defined __linux__ || defined ESP8266 \ +#if defined __unix__ || defined __linux__ || defined ESP8266 || defined ESP32\ || defined _POSIX_SOURCE || defined _POSIX_C_SOURCE \ || (defined __APPLE__ && defined __MACH__) #define BR_USE_UNIX_TIME 1 @@ -2568,7 +2568,7 @@ br_cpuid(uint32_t mask_eax, uint32_t mask_ebx, #endif -#ifdef ESP8266 +#if (defined(ESP8266)|| defined(ESP32)) #ifdef __cplusplus extern "C" {