Skip to content

Commit

Permalink
Merge pull request #9588 from Staars/MI32
Browse files Browse the repository at this point in the history
MI_ESP32: use BEARSSL for decryption, revert to old TELEPERIOD style as default
  • Loading branch information
arendst committed Oct 20, 2020
2 parents 83a090b + e3d3e76 commit 9a21dc8
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 70 deletions.
2 changes: 2 additions & 0 deletions lib/bearssl-esp8266/src/pgmspace_bearssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
extern "C" {
#endif

#ifndef ESP32
#ifndef ICACHE_RODATA_ATTR
#define ICACHE_RODATA_ATTR __attribute__((section(".irom.text")))
#endif
Expand All @@ -29,6 +30,7 @@ extern "C" {
// Place each progmem object into its own named section, avoiding conflicts
#define PROGMEM __attribute__((section( "\".irom.text." __FILE__ "." __STRINGIZE(__LINE__) "." __STRINGIZE(__COUNTER__) "\"")))
#endif
#endif //ESP32
#ifndef PGM_P
#define PGM_P const char *
#endif
Expand Down
19 changes: 19 additions & 0 deletions lib/bearssl-esp8266/src/rand/sysrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<sizeof(tmp)/sizeof(tmp[0]); i++) {
tmp[i] = esp_random();
}

(*ctx)->update(ctx, tmp, sizeof tmp);

return 1;
}
#else
extern uint32_t phy_get_rand(void); // From the ESP8266 SDK

static int
Expand All @@ -157,6 +175,7 @@ seeder_esp8266(const br_prng_class **ctx)
return 1;
}
#endif
#endif

/* see bearssl_rand.h */

Expand Down
4 changes: 4 additions & 0 deletions lib/bearssl-esp8266/src/symcipher/chacha20_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
12 changes: 9 additions & 3 deletions lib/bearssl-esp8266/src/t_bearssl_tasmota_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
#define __ets__
#endif

#ifndef ESP32
#ifndef ICACHE_FLASH
#define ICACHE_FLASH
#endif

#ifndef ESP8266
#define ESP8266
#else
#ifndef PROGMEM
#define PROGMEM
#endif
#endif

// #ifndef ESP8266
// #define ESP8266
// #endif

#ifndef BR_SLOW_MUL15
#define BR_SLOW_MUL15 1 // shrinks EC code by 8.5k
Expand Down
8 changes: 4 additions & 4 deletions lib/bearssl-esp8266/src/t_inner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand Down
Loading

0 comments on commit 9a21dc8

Please sign in to comment.