0

I have a program that can encrypt and decrypt a text with Boneh-Franklin encryption. This works great on a PC, but for some reason causes a constant reboot on ESP32 with the following error message:

setup2
setup2.2
setup2.3
Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception)
Debug exception reason: Stack canary watchpoint triggered (loopTask) 
Core 1 register dump:
PC      : 0x40083774  PS      : 0x00060b36  A0      : 0x3ffb0120  A1      : 0x3ffb0060  
A2      : 0x68efa751  A3      : 0x3ffb0938  A4      : 0x3ffb0720  A5      : 0xfb879c5c  
A6      : 0x61b36b71  A7      : 0x0006970f  A8      : 0x01709af4  A9      : 0x01709af4  
A10     : 0xfaa5dfed  A11     : 0x01a3ff3b  A12     : 0x76651dec  A13     : 0x00000001  
A14     : 0x00000000  A15     : 0x04adbe74  SAR     : 0x0000001e  EXCCAUSE: 0x00000001  
EXCVADDR: 0x00000000  LBEG    : 0x400f1cc5  LEND    : 0x400f1cc9  LCOUNT  : 0x00000000  

ELF file SHA256: 0000000000000000

I use an Arduino ESP32 environment, CONFIG_ARDUINO_LOOP_STACK_SIZE is set to 8192 in main.cpp, 8k stack should be enough to run it. It works perfectly on PC, it’s a mystery to me why not on ESP32. Can anyone help? I absolutely ran out of ideas. For the Boneh-Franklin implementation I used this library: https://github.com/miracl/core My own code is ~200 lines, I have uploaded it to Google Drive: https://drive.google.com/file/d/1EY0mGC2UiVNhE68b5Q0VB9JIY2Owbpxg/view?usp=sharing

mtamas
  • 15
  • 1
  • 5

2 Answers2

1

Looking at the code, it isn't unreasonable that the stack will require more than 8192 bytes as a lot of big objects are allocated on the stack, both in your code and in the library, e.g.:

loop()

  • csprng RNG – 128 bytes
  • ECP2 pPublic – 264 bytes
  • ECP2 cipherPointU – 264 bytes
  • ECP privateKey – 132 bytes

encrypt(...)

  • ECP pointQId – 132 bytes
  • char[] dst – 256 bytes
  • BIG l – 40 bytes
  • FP12 theta – 532 bytes

PAIR_fexp()

  • FP2 X – 88 bytes
  • BIG x – 40 bytes
  • FP a, b – 2 * 44 = 88 bytes
  • FP12 t0, y0, y1, y2, y3 – 5 * 532 = 2660 bytes

Increase your stack size. It will likely help.

Codo
  • 75,595
  • 17
  • 168
  • 206
  • Thank you. I have increased the stack size to 64k. ESP32 still keeps rebooting but the error message is different now: setup2 setup2.2 setup2.3 setup2.4 kkkk encrypt Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled. Core 1 register dump: PC : 0x400d964b PS : 0x00060930 A0 : 0x800d1048 A1 : 0x3ffcfe40 A2 : 0x3ffd04a4 A3 : 0x0000000b A4 : 0x3ffb855c A5 : 0x3ffb858c Etc. – mtamas May 17 '21 at 13:01
  • 1
    Use a backtrace analyzer (such as https://github.com/tve/esp32-backtrace) to decode where exactly the code crashes. – Codo May 17 '21 at 14:05
1

I got to this page by googling my own troubles so thought I would add my solution here

I experienced this error recently and by using a series of Serial.println's was able to trace to an infinite loop created in the code