4

I would like to know, how to calculate the inverse S-box. I followed this link (with affine transformation first, then multiplicative inverse), but the result is wrong. For example, if I use the value 0x52 (01010010 in binary), reverse of this value would be 01001010. The inverse matrix (for inverse S-Box) is:

Input = 0  1  0  0  1  0  1  0 (LSB First)
Row 0 = 0  0  1  0  0  1  0  1
Bit 0 = 0  0  0  0  0  0  0  0 = 0

Row 1 = 1  0  0  1  0  0  1  0
Bit 1 = 0  0  0  0  0  0  1  0 = 1

Row 2 = 0  1  0  0  1  0  0  1
Bit 2 = 0  1  0  0  1  0  0  0 = 0

Row 3 = 1  0  1  0  0  1  0  0
Bit 3 = 0  0  0  0  0  0  0  0 = 0

Row 4 = 0  1  0  1  0  0  1  0
Bit 4 = 0  1  0  0  0  0  1  0 = 0

Row 5 = 0  0  1  0  1  0  0  1
Bit 5 = 0  0  0  0  1  0  0  0 = 1

Row 6 = 1  0  0  1  0  1  0  0
Bit 6 = 0  0  0  0  0  0  0  0 = 0

Row 7 = 0  1  0  0  1  0  1  0
Bit 7 = 0  1  0  0  1  0  1  0 = 1

The result is 01000101, MSB first that would be 10100010, XOR-ed with final vector 0x52 is 0xf0. The inverse of 0xf0 is 0x5b, which is wrong. It should be 0x48. Where did I make a mistake?

osemec
  • 247
  • 3
  • 7

1 Answers1

4

You performed the matrix component of the affine tranformation correctly, what you did wrong was the addition of the vector prior to field inversion.

The value 10100010 (0xA2) is the correct result of the inverse affine matrix. The final vector of the inverse affine transform however is 00000101 (0x05).

The resultant 0xA7 is then inverted, which is 0x48, the correct inverse s-box value.

Richie Frame
  • 13,278
  • 1
  • 26
  • 42