Git Product home page Git Product logo

Comments (4)

kokke avatar kokke commented on September 18, 2024

Are you including the test-files? Because the whole thing should not take up that much RAM.

Try having a look in the memory map / listing, to see what is taking up the RAM.

from tiny-aes-c.

aimass avatar aimass commented on September 18, 2024

Yeah it was the test code, how dumb!

But it was even weirder than that. I am not sure but I think the Arduino IDE was using the Makefile because when I deleted the test.c file the sketch refused to compile. Maybe it was even overriding main() who knows...

Anyway I got the whole thing working and these are the steps and some observations that other Arduino users can follow:

  1. Clone the project in a working directory
  2. Create a new directory in your ~/Arduino/libraries (e.g. tiny-aes) and in it softlink aes.c from your working directory to aes.cpp in your library directory. Do the same with aes.h but do not change the name.
  3. At this point you should be able to compile, run and test the library in your arduino sketch just by including normally as #include "aes.h". Without any mods the library will take up 546 bytes of RAM and it's pretty fast. If you want to reduce this RAM follow the next steps, but note that the code will get slower.
  4. (on or around line 41) Edit aes.c and #include <avr/pgmspace.h>
  5. (on or around line 95) Change static const uint8_t sbox[256] to const PROGMEM uint8_t sbox[256]
  6. (on or around line 114) Change static const uint8_t rsbox[256] to const PROGMEM uint8_t rsbox[256]
  7. (on or around line 134) Change static const uint8_t Rcon[11] to const PROGMEM uint8_t Rcon[11]
  8. (on or around line 173) Change return sbox[num]; to return pgm_read_byte_near(sbox + num);
  9. (on or around line 178) Change return rsbox[num]; to return pgm_read_byte_near(rsbox + num);
  10. (on or around line 232) Change tempa[0] = tempa[0] ^ Rcon[i/Nk]; to tempa[0] = tempa[0] ^ pgm_read_byte_near(Rcon + i/Nk);
  11. Compile and the lib should just use 278 bytes of RAM

There are probably more optmizations that could be done but 278 bytes is amazing for our application so we are happy with these simple and safe changes. Reading from PROGMEM does not seem to affect performance too much.

Here is our fork with the changes for reference and the specific commit:

AgroMe@a640b8c
https://github.com/AgroMe/tiny-AES-c

Really great lib!
Thanks @kokke et al. great job!!

from tiny-aes-c.

kokke avatar kokke commented on September 18, 2024

Hi Alejandro, thanks for the detailed description :)

I could imagine the Arduino IDE getting confused about the Makefile and the extra main()-function.
I have only used the Arduino IDE once or twice, to make an LED blink - I mostly work on custom boards and ARM processors.

Also, thanks a lot for providing a fork that is Arduino compatible :)

from tiny-aes-c.

aimass avatar aimass commented on September 18, 2024

from tiny-aes-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.