Comments (4)
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.
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:
- Clone the project in a working directory
- 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.
- 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.
- (on or around line 41) Edit aes.c and #include <avr/pgmspace.h>
- (on or around line 95) Change static const uint8_t sbox[256] to const PROGMEM uint8_t sbox[256]
- (on or around line 114) Change static const uint8_t rsbox[256] to const PROGMEM uint8_t rsbox[256]
- (on or around line 134) Change static const uint8_t Rcon[11] to const PROGMEM uint8_t Rcon[11]
- (on or around line 173) Change return sbox[num]; to return pgm_read_byte_near(sbox + num);
- (on or around line 178) Change return rsbox[num]; to return pgm_read_byte_near(rsbox + num);
- (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);
- 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.
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.
from tiny-aes-c.
Related Issues (20)
- How to pass the data type as string for key and plain_test varibles in test_encrypt_ecb_verbose method HOT 5
- AES256 mode HOT 1
- Add AES-CFB.. HOT 1
- aes.h comment error
- AES reversing HOT 3
- Zenner default AES keys would be needed HOT 3
- Uninitialized AES key HOT 2
- Change bitrate at runtime, via Init ?
- USML or ECCN number? HOT 2
- openssl 1.1.1t support TLSv1 and TLSv1_1? or how to enable TLSv1 and TLSv1_1 on openssl 1.1.1t? HOT 1
- HOW TO IMPLEMENT IN STM32 MICROCONTROLLERS HOT 1
- tiny-AES-c AES256 CTR interoperability HOT 3
- heap overflow while decrypting HOT 1
- Different values in x64 and x32 HOT 1
- Issues with Include HOT 1
- Request for AES128_CBC Encryption Help HOT 1
- Maybe you want replace INT to UINT8_T here.
- Does tiny-AES-c support GCM mode?
- Reduce size even more: generate s-box table? HOT 7
- aes256-ctr encrypt result differ from openssl lib HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tiny-aes-c.