Search code examples
encryptioncryptographyaes

Substitution box for AES


I need to implement AES (Advanced Encryption Standard). According to standard, in each round I substitute bytes using s-box (ex.: 4F -> 84). My question is do I need to store s-box in my c++ source code as variable or can I compute it for each byte?


Solution

  • The idea behind the S-Box is that it is revertible during decryption. As such the values in the S-box are constant. Computing the S-box for each byte is redundant and unnecessarily repetitive.

    You should either copy and paste an existing table or compute it once in the beginning. This site has an explanation and some examples of initialization of the S-box.