kokke / tiny-AES-c

Small portable AES128/192/256 in C
The Unlicense
4.22k stars 1.29k forks source link

Eliminate Rcon array to save space #43

Open rillig opened 7 years ago

rillig commented 7 years ago

The Rcon array currently takes 255 bytes of ROM, but only its first 11 elements are accessed, since there are only 10 rounds. Therefore the remaining 244 elements should be removed. The first element can also be removed when the array index is adjusted by -1.

The whole array can be replaced by starting a local variable uint8_t rcon = 0x01 and applying xtime after each round, which is a little slower but eliminates the need for fixed constants.

kokke commented 7 years ago

Duly noted, thank you :) I think another issue-opener also comments on this exact issue.

EliotWealth commented 7 years ago

This rom elements can be used to store xtime computed values instead to increase performance which is not the best.

kokke commented 7 years ago

@EliotWealth the performance is definitely not optimal in this module. The main goal of the project is a small code size. There is a lot of potential for performance-optimizations, at the cost of a slightly larger binary size :)

kokke commented 7 years ago

This issue has been addressed after removing some of the elements in the Rcon array, as suggested in PR #12.

I'm keeping the issue open, because I like the description of how to avoid the array. I want to move the architectural comments / suggestions into a wiki. A lot of people have mentioned small changes that affect architecture or performance in a different way. There are usually some tradeoffs to be made, which is why I won't always accept the solution, but will place a comment in the source, suggesting the changes. I would like to put all that info in a wiki some day.

RKTRIP commented 6 years ago

To make better performance at Nano seconds you can replace For loop at multiple place by memset :)