Topic: 'Not enought memory' Arduino

Hi, I'm doing an example exercise for encryption and decryption in Arduino.

#include <wolfssl.h>
#include <wolfssl/wolfcrypt/aes.h>

 
void setup(void){

}
 
void loop(void){


Aes enc;

int ret = 0;

byte key[] = {"0123456789abcdef"};

byte iv[]  = {"1234567890abcdef"};

String plain = "hola mundo";


if (ret = wc_AesSetKey(&enc, key, AES_BLOCK_SIZE, iv, AES_ENCRYPTION) != 0) {

// failed to set aes key

}

}

The trouble is the call to the function 'wc_AesSetKey' produces a 'not enought memory' arduino error.

If I comment function, it gets the message: "Global variables use 35 bytes (1%) of dynamic memory, leaving 2,013 bytes for Local variables Maximum is 2,048 bytes.."

But if the code is complete, I get: "Global variables use 2,137 bytes (104%) of dynamic memory, leaving -89 Maximum bytes for the local variables is 2,048 bytes..
processing.app.debug.RunnerException: Not enough memory; http://www.arduino.cc/en/Guide/Troubleshooting#size see for tips on Reducing your footprint.
at cc.arduino.Compiler.size (Compiler.java:338)
at cc.arduino.Compiler.build (Compiler.java:158)
at processing.app.Sketch.build (Sketch.java:1111)
at processing.app.Sketch.exportApplet (Sketch.java:1146)
at processing.app.Sketch.exportApplet (Sketch.java:1132)
processing.app.Editor at $ DefaultExportHandler.run (Editor.java:2409)
at java.lang.Thread.run (Thread.java:745)
Not enough memory; http://www.arduino.cc/en/Guide/Troubleshooting#size see for tips on Reducing your footprint. "

Any suggestion for fix it? Thanks for your replies in advance.

Share

Re: 'Not enought memory' Arduino

Hi jesussotofan,

Could you tell me which board you are working with and what your available RAM and FLASH is?

For the AES algorithm to work unfortunately requires very large static tables (10280 bytes of RO or 10k). These can be viewed in <wolfssl-root>/wolfcrypt/src/aes.c under the define NEED_AES_TABLES. The only to get around using the tables in software is to have an AES hardware module on the board you're working with. It is very likely your board does not have that feature but it would not hurt to check.

If you do not have a hardware AES module and the tables will not fit into the available memory space... since this is a research project and you're probably not extremely concerned with bit-strength of the algorithm chosen... might I suggest instead using one of the following ciphers as alternates to AES:

wc_AesSetKey             [4338 bytes code size | 10280 bytes RO data] Very Big footprint

Non-Stream cipher:
wc_Des3_SetKey           [1560 bytes code size | 2200 bytes RO data]  Medium footprint

Stream ciphers:

wc_Chacha_SetKey         [1160 bytes code size | 32 bytes RO data  ] smaller footprint
wc_Arc4SetKey            [184  bytes code size | 0 bytes RO data   ] tiny footprint

All of these work fine on the Intel Gallileo, however if you platform is truely limited to 2k RAM as your error would indicate you will have to go with a much smaller algorithm.


Kind Regards,

Kaleb (AKA kalsheraut on pi forums)