tiny-AES-c icon indicating copy to clipboard operation
tiny-AES-c copied to clipboard

Some smaller AES implementations

Open akdjka opened this issue 10 years ago • 12 comments

You asked for smaller AES implementations, here you are: http://www.ti.com/tool/aes-128 http://dominik.cc/projekty/avr-aes/

Warning: They have the same timing vulnerability in GF multiplication.

akdjka avatar Mar 26 '15 14:03 akdjka

See also my cmcqueen/aes-min.

cmcqueen avatar Nov 10 '15 05:11 cmcqueen

You might like to look at opentrv/OTAESGCM also.

DamonHD avatar Nov 10 '15 09:11 DamonHD

Thank you both very much for your links :)

I tried compiling one of these libraries a few weeks back, and it was considerably smaller than this one! I will read the code ASAP and try to see if I can learn some tricks to slim down this library :)

I'll keep this issue open for further additions. I will see if I can link directly to this issue in the readme text, so it can be used as a way for people to contribute knowledge of smaller implementations :)

kokke avatar Jun 15 '16 18:06 kokke

dont' suppose you have a 256 version anywhere?

NateZimmer avatar Aug 08 '16 19:08 NateZimmer

@NateZimmer this project now supports AES192 and AES256 FYI

EDIT: Whoops, didn't mean to close this issue. I think it's informative enough to stay until I get my sh*t together and move it into a wiki.

kokke avatar Jul 13 '17 08:07 kokke

You might like to look at opentrv/OTAESGCM also.

Link, for convenience :) https://github.com/opentrv/OTAESGCM

waldyrious avatar Aug 07 '17 13:08 waldyrious

TI version does not support streaming modes and does not support different key sizes .. this trims the code a lot.. we can do it here also, I think, if we're compiling for 128 bit keys, but I think we should keep the streaming modes as they are basically few function calls in a loop, also we can provide flags for encrypt/decrypt version only which will reduce the size if only one operation is desired. Also we can remove decryption for CTR only situation as decrypt is not used

sdrsdr avatar Dec 06 '17 13:12 sdrsdr

Hi @sdrsdr

I think the other mentioned libraries may be slightly smaller for CBC-mode and ECB, but not by much. It's been a few years since I compiled and compared binary sizes, but to the best of my knowledge, only aes-min is significantly smaller than this library.

I am not sure what the current status is because it's been so long since I compared last. aes-min doesn't output a single object-file, so it isn't immediately obvious to me how to compare the binary sizes.

As far as I remember aes-min has an option to only use a single key. This means the key-.expansion can be pre-computed, hard-coded and placed in ROM. This trick does a big difference.

For this library, when only using CTR-mode, GCC will automatically remove the code used for decryption, because it is unused. That is why CTR-mode takes up less than 1KB when compiled for the ARM Thumb ISA :)

kokke avatar Dec 06 '17 14:12 kokke

If we can provide the options we probably should. Relying on the compiler/linker to clean up the code is optimistic at best :-)

sdrsdr avatar Dec 06 '17 21:12 sdrsdr

aes-min does not provide code for any of the encryption modes, only the basic encryption/decryption block operation. And, it is 128-bit key size only. It does provide for using a pre-computed key schedule (with a function to compute the key schedule if needed) as well as on-the-fly calculation of the key schedule. aes-min is intended to be a "bare bones" AES-128 building block for tiny embedded systems.

cmcqueen avatar Dec 07 '17 01:12 cmcqueen

@sdrsdr I agree with you that it is optimistic to rely on the compiler. I have had the "pleasure" of using some old shitty KEIL compilers that could not remove dead code like this function.

InvCipher and friends should be wrapped in

#if (defined(CBC) && (CBC == 1)) || (defined(ECB) && (ECB == 1))
...
#endif

kokke avatar Dec 11 '17 20:12 kokke

I made key length determine AES variant, and it became larger: https://github.com/monolifed/tiny-AES-c

monolifed avatar Sep 17 '18 00:09 monolifed