arduino-libraries / ArduinoBearSSL

Port of BearSSL to Arduino
MIT License
86 stars 49 forks source link

How to shrink the library to a minimal IoT version #46

Closed CKFFMGH closed 3 years ago

CKFFMGH commented 3 years ago

Hello,

First of all Thanks for your work! As this is my first ever comment on GitHub I'm not quite sure whether I am right here but anyways..

I do need to make my UNO WiFi Rev 2 an AWS "Thing". So I followed the instructions given here: https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365 Which went fine until compiling, as the Flash of the UNO is only 48kB which I overshot by 400%.

Searching the internet gave me no solution, only other people with the same problem. On https://www.bearssl.org/sizes.html I found a size calculator and some information making me guess, that it should be possible to shrink the library for that specific use case to a compiled size of less than 20kB. Alone - I don't know how and commenting out section by section is not .... efficient.

So: Is there a way to have that exact functionality as given in the first link but with no more than 30kB of compiled size? And if so, how would I do that?

Thank you! Chris

P.S. Reducing the buffer size helped, but still > 100% of the available memory blocked and I can't assess how low I can go

aentinger commented 3 years ago

Hi :wave: Flash isn't your only problem. RAM exhaustion is far worse. The Uno WiFi Rev. 2's ATMEGA4809 packs 6 kB of SRAM but BearSSL recommends 32 kB (split in 16 kB IN-Buffer and 16 kB OUT-Buffer). You can do with less, but you really can't do with a total of 6 kB where you also need space for your application.

PS: The tutorial you are referencing uses an MKR WiFi 1010 which has a ATSAMD21G18 on board - this one packs at least 48 kB of SRAM (and 256 kB of flash vs. 48 kB for the Uno).