Thanks! I took some inspiration from discussion on that page, however my solution differs because instead of hard coding everything it instead calculates the multiplicative inverse and affine transformation separately. This is worse in terms of space but it lets you more clearly represent the two s-boxes as those two operations composed applied element wise to [0, 256]. You can also use this code to do multiplicative inverses over any field GF(2^n), just change the parameters and supply a new irreducible polynomial. I implement the totality of binary finite field arithmetic here: https://gist.github.com/juliusgeo/9e4eff4c0519f7f7b9af122d59...
The rijndael S-box unlike some other ciphers I've read about, does not use "nothing up my sleeve" numbers but uses numbers with specific mathematical properties. I don't think that means anything nefarious was intended but I've always wondered if replacing that with something like "digits of pi starting from a random offset" would be workable?
To some extent the purpose of this code is to demonstrate that while the s-box seems like 256 values in random order, it is actually the composition of multiple operations in finite field arithmetic. The values in the S-box I would argue are also based on "nothing up my sleeve numbers". The values all depend on the irreducible polynomial and the field size, as well as the specific affine transformation. Knowing the field size and irreducible polynomial, you can then make guarantees about the properties of numbers when transformed using an S-box.
6 comments
[ 2.7 ms ] story [ 22.2 ms ] threadPardon the ignorance, I know little about crypto.