kokke/tiny-AES-c

How to implement Rijndael 256-bit block size and 256-bit key size

bettafish15 opened this issue · 5 comments

First of all, thanks so much for your open source code tiny AES. you made my life so much easier when dealing with it in C.
My knowledge in C/C++ is bad so i have to find open source code like this
I know this is not the best place to ask questions but i dont know how to do this. My problem at work is that they are not using AES but rather a Rijndael 256-bit block size and 256-bit key size. how can i implement Rijndael 256-bit block size in your code? what variable or constant that i have to change in order to do that?
Thanks so much for your work

kokke commented

Hi @bettafish15 and thanks for the compliments :)

AES is a version of Rijndael with 128-bit block size and 128/192/256 bit key size.

Unfortunately that means it won't easily convert to 256-bit Rijndael. You could hack the code if you are up for the task - but there is not a single flag or something similar you could change.

Over the years, the code has been improved for efficiency and smaller code size. Sometimes that has meant specializing some operations or unrolling a loop. The earliest versions of this project may be an easier fit for a conversion to 256-bit block size, at least compared to the current HEAD.

Sorry to disappoint you :(

If you decide to attempt the conversion, feel free to ask follow-up questions here.

Hi @kokke thanks for your response! i am having no others choice but hacking your code. Can i have the earliest version of this project?

kokke commented

Hi @bettafish15 - sure you can :)

I just checked the commit-history, and the code is a lot simpler in the first versions.
Check the files from around 2014, about here or so https://github.com/kokke/tiny-AES-c/commits/master?after=3f69a5899e58e2e398e8c32ce7b3a954dd593ed4+244&branch=master

The code from 2014 is easier to read and understand, but with fewer modes of operation available (initially ECB only) and much fewer optimizations.

A major change should be something about changing from working on a 16 byte / 128 bit state -> 32 byte / 256 bit state.

If you are comfortable with the maths involved in Rijndael, the wiki page for the Rijndael algorithm might be helpful.

Thanks @kokke for your response! Luckily i am familiar with the operation in encrypting of Rijndael. It's just C/C++ coding. I will try out with your suggestions and hope that performance is not an issue :D

kokke commented

It definitely helps if you understand Galois-fields and how the arithmetic works there. Then you "only" have to struggle with the C/C++ implementation 👍

If performance gets problematic, there are other much faster implementations of AES you could look into. A typical trick is to use lookup-tables, which takes up RAM but speeds up calculations (e.g. this section of the Rijndael-article on wikipedia).

Good luck @bettafish15 and let me know if you need help debugging the C/C++ code you end up with :)