On Rijndael ByteSub Transformation
Author(s) W. Eltayeb Ahmed1,2
ABSTRACT
The first step in converting a plaintext to ciphertext by the famous Advanced Encryption Standard (AES), which is called Rijndael ByteSub Transformation, involves some operations: computing a multiplicative inverse, multiplying this multiplicative inverse by a specific matrix, and adding the result to a specific vector. The purpose of this research is to simplify these operations. This paper gives elegant techniques and presents the matrices multiplication as simple XOR operations, and the result is a simple, straightforward way finding the transformation.

1. Introduction

Rijndael ByteSub transformation (or AES substitution byte)  transforms an input byte into another byte by two operations:

1) Finding a multiplicative inverse of an input byte $\left({a}_{7}{a}_{6}{a}_{5}{a}_{4}{a}_{3}{a}_{2}{a}_{1}{a}_{0}\right)$ in the finite field GF (28).

2) Applying the following affine transform:

$\begin{array}{l}{c}_{i}={b}_{i}+{b}_{\left(i+4\right)\mathrm{mod}\left(8\right)}+{b}_{\left(i+5\right)\mathrm{mod}\left(8\right)}+{b}_{\left(i+6\right)\mathrm{mod}\left(8\right)}\\ \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}+{b}_{\left(i+7\right)\mathrm{mod}\left(8\right)}+{d}_{i},\text{\hspace{0.17em}}\text{\hspace{0.17em}}0\le i\le 7\end{array}$ (1)

where $\left({b}_{7}{b}_{6}{b}_{5}{b}_{4}{b}_{3}{b}_{2}{b}_{1}{b}_{0}\right)$ is resulting from the first operation, $\left({d}_{7}{d}_{6}{d}_{5}{d}_{4}{d}_{3}{d}_{2}{d}_{1}{d}_{0}\right)=01100011$ .

In general, the multiplicative inverse is found by using the extended Euclidean algorithm  , instead of using it, we use an elegant technique which finds the multiplicative inverse in clear steps.

The transform of the second operation can be expressed in the matrix form as:

$\left[\begin{array}{c}{c}_{0}\\ {c}_{1}\\ {c}_{2}\\ {c}_{3}\\ {c}_{4}\\ {c}_{5}\\ {c}_{6}\\ {c}_{7}\end{array}\right]=\left[\begin{array}{cccccccc}1& 0& 0& 0& 1& 1& 1& 1\\ 1& 1& 0& 0& 0& 1& 1& 1\\ 1& 1& 1& 0& 0& 0& 1& 1\\ 1& 1& 1& 1& 0& 0& 0& 1\\ 1& 1& 1& 1& 1& 0& 0& 0\\ 0& 1& 1& 1& 1& 1& 0& 0\\ 0& 0& 1& 1& 1& 1& 1& 0\\ 0& 0& 0& 1& 1& 1& 1& 1\end{array}\right]\left[\begin{array}{c}{b}_{0}\\ {b}_{1}\\ {b}_{2}\\ {b}_{3}\\ {b}_{4}\\ {b}_{5}\\ {b}_{6}\\ {b}_{7}\end{array}\right]+\left[\begin{array}{c}1\\ 1\\ 0\\ 0\\ 0\\ 1\\ 1\\ 0\end{array}\right]$ (2)

To solve this system, we use an unusual and more suitable technique which shows this multiplication of matrix (8 × 8) and matrix (8 × 1) as simple XOR operations, and we can find it directly from $\left({b}_{7}{b}_{6}{b}_{5}{b}_{4}{b}_{3}{b}_{2}{b}_{1}{b}_{0}\right)$ .

2. The Methodology

For an input byte $\left({a}_{7}{a}_{6}{a}_{5}{a}_{4}{a}_{3}{a}_{2}{a}_{1}{a}_{0}\right)$ , we find its multiplicative inverse $\left({b}_{7}{b}_{6}{b}_{5}{b}_{4}{b}_{3}{b}_{2}{b}_{1}{b}_{0}\right)$ , and find $\left({e}_{7}{e}_{6}{e}_{5}{e}_{4}{e}_{3}{e}_{2}{e}_{1}{e}_{0}\right)$ such that:

$\left[\begin{array}{c}{e}_{0}\\ {e}_{1}\\ {e}_{2}\\ {e}_{3}\\ {e}_{4}\\ {e}_{5}\\ {e}_{6}\\ {e}_{7}\end{array}\right]=\left[\begin{array}{cccccccc}1& 0& 0& 0& 1& 1& 1& 1\\ 1& 1& 0& 0& 0& 1& 1& 1\\ 1& 1& 1& 0& 0& 0& 1& 1\\ 1& 1& 1& 1& 0& 0& 0& 1\\ 1& 1& 1& 1& 1& 0& 0& 0\\ 0& 1& 1& 1& 1& 1& 0& 0\\ 0& 0& 1& 1& 1& 1& 1& 0\\ 0& 0& 0& 1& 1& 1& 1& 1\end{array}\right]\left[\begin{array}{c}{b}_{0}\\ {b}_{1}\\ {b}_{2}\\ {b}_{3}\\ {b}_{4}\\ {b}_{5}\\ {b}_{6}\\ {b}_{7}\end{array}\right]$ (3)

Then, we find the output $\left({c}_{7}{c}_{6}{c}_{5}{c}_{4}{c}_{3}{c}_{2}{c}_{1}{c}_{0}\right)$ as:

$\left[\begin{array}{c}{c}_{0}\\ {c}_{1}\\ {c}_{2}\\ {c}_{3}\\ {c}_{4}\\ {c}_{5}\\ {c}_{6}\\ {c}_{7}\end{array}\right]=\left[\begin{array}{c}{e}_{0}\\ {e}_{1}\\ {e}_{2}\\ {e}_{3}\\ {e}_{4}\\ {e}_{5}\\ {e}_{6}\\ {e}_{7}\end{array}\right]+\left[\begin{array}{c}1\\ 1\\ 0\\ 0\\ 0\\ 1\\ 1\\ 0\end{array}\right]$ (4)

First, we find a multiplicative inverse of ${a}_{7}{x}^{7}+{a}_{6}{x}^{6}+{a}_{5}{x}^{5}+{a}_{4}{x}^{4}+{a}_{3}{x}^{3}+{a}_{2}{x}^{2}+{a}_{1}x+{a}_{0}\mathrm{mod}\left({x}^{8}+{x}^{4}+{x}^{3}+x+1\right)$ .

Let ${M}_{1}={a}_{7}{x}^{7}+{a}_{6}{x}^{6}+{a}_{5}{x}^{5}+{a}_{4}{x}^{4}+{a}_{3}{x}^{3}+{a}_{2}{x}^{2}+{a}_{1}x+{a}_{0}$ , $P={x}^{8}+{x}^{4}+{x}^{3}+x+1$ , and represent the multiplicative inverse by T.

We seek for ${q}_{1}$ and ${r}_{1}$ satisfying:

${M}_{1}{q}_{1}+{r}_{1}={Q}_{1}$ (5)

where ${Q}_{1}=P+1$  , (look at Table 1).

If ${r}_{1}=0$ , then $T={q}_{1}$ .

If ${r}_{1}\ne 0$ , we let ${M}_{2}={r}_{1}+1$ and seek for ${q}_{i}$ and ${r}_{i}$ satisfying:

${M}_{i}{q}_{i}+{r}_{i}={Q}_{i},\text{\hspace{0.17em}}\text{\hspace{0.17em}}2\le i\le 7$ (6)

where ${Q}_{i}={M}_{i-1}$ , and ${M}_{i+1}={r}_{i}$ (look at Table 2).

Whenever ${r}_{i}=1$ , then

$T={T}_{i}={q}_{i}{T}_{i-1}+{T}_{i-2}$ (7)

where ${T}_{0}=1$ , and ${T}_{1}={q}_{1}$ .

Then, to find $\left({e}_{7}{e}_{6}{e}_{5}{e}_{4}{e}_{3}{e}_{2}{e}_{1}{e}_{0}\right)$ , we write the system (3), as follows:

$\left[e\right]=\left[\begin{array}{cc}X& Y\\ Y& X\end{array}\right]\left[b\right]$ (8)

${e}_{i}=X{b}_{i}+Y{b}_{j}$ (9)

${e}_{j}=Y{b}_{i}+X{b}_{j}$ (10)

where $0\le i\le 3$ , $4\le j\le 7$ , and

$X=\left[\begin{array}{cc}1& \begin{array}{ccc}0& 0& 0\end{array}\\ \begin{array}{c}1\\ 1\\ 1\end{array}& \begin{array}{ccc}\begin{array}{c}1\\ 1\\ 1\end{array}& \begin{array}{c}0\\ 1\\ 1\end{array}& \begin{array}{c}0\\ 0\\ 1\end{array}\end{array}\end{array}\right]$ (11)

$Y=\left[\begin{array}{cc}\begin{array}{cc}1& 1\\ 0& 1\end{array}& \begin{array}{cc}1& 1\\ 1& 1\end{array}\\ \begin{array}{cc}0& 0\\ 0& 0\end{array}& \begin{array}{cc}1& 1\\ 0& 1\end{array}\end{array}\right]$ (12)

${b}_{i}=\left[\begin{array}{c}{b}_{0}\\ {b}_{1}\\ {b}_{2}\\ {b}_{3}\end{array}\right],\text{\hspace{0.17em}}\text{\hspace{0.17em}}{b}_{j}=\left[\begin{array}{c}{b}_{4}\\ {b}_{5}\\ {b}_{6}\\ {b}_{7}\end{array}\right]$ (13)

Table 1. First step to find the multiplicative inverse.

Table 2. All steps to find the multiplicative inverse.

Then we compute

$X{b}_{i}=\left[\begin{array}{cc}1& \begin{array}{ccc}0& 0& 0\end{array}\\ \begin{array}{c}1\\ 1\\ 1\end{array}& \begin{array}{ccc}\begin{array}{c}1\\ 1\\ 1\end{array}& \begin{array}{c}0\\ 1\\ 1\end{array}& \begin{array}{c}0\\ 0\\ 1\end{array}\end{array}\end{array}\right]\left[\begin{array}{c}{b}_{0}\\ {b}_{1}\\ {b}_{2}\\ {b}_{3}\end{array}\right]=\left[\begin{array}{c}{b}_{0}\\ {b}_{0}+{b}_{1}\\ {b}_{0}+{b}_{1}+{b}_{2}\\ {b}_{0}+{b}_{1}+{b}_{2}+{b}_{3}\end{array}\right]$ (14)

$Y{b}_{j}=\left[\begin{array}{cc}\begin{array}{cc}1& 1\\ 0& 1\end{array}& \begin{array}{cc}1& 1\\ 1& 1\end{array}\\ \begin{array}{cc}0& 0\\ 0& 0\end{array}& \begin{array}{cc}1& 1\\ 0& 1\end{array}\end{array}\right]\left[\begin{array}{c}{b}_{4}\\ {b}_{5}\\ {b}_{6}\\ {b}_{7}\end{array}\right]=\left[\begin{array}{c}{b}_{7}+{b}_{6}+{b}_{5}+{b}_{4}\\ {b}_{7}+{b}_{6}+{b}_{5}\\ {b}_{7}+{b}_{6}\\ {b}_{7}\end{array}\right]$ (15)

$Y{b}_{i}=\left[\begin{array}{cc}\begin{array}{cc}1& 1\\ 0& 1\end{array}& \begin{array}{cc}1& 1\\ 1& 1\end{array}\\ \begin{array}{cc}0& 0\\ 0& 0\end{array}& \begin{array}{cc}1& 1\\ 0& 1\end{array}\end{array}\right]\left[\begin{array}{c}{b}_{0}\\ {b}_{1}\\ {b}_{2}\\ {b}_{3}\end{array}\right]=\left[\begin{array}{c}{b}_{3}+{b}_{2}+{b}_{1}+{b}_{0}\\ {b}_{3}+{b}_{2}+{b}_{1}\\ {b}_{3}+{b}_{2}\\ {b}_{3}\end{array}\right]$ (16)

$X{b}_{j}=\left[\begin{array}{cc}1& \begin{array}{ccc}0& 0& 0\end{array}\\ \begin{array}{c}1\\ 1\\ 1\end{array}& \begin{array}{ccc}\begin{array}{c}1\\ 1\\ 1\end{array}& \begin{array}{c}0\\ 1\\ 1\end{array}& \begin{array}{c}0\\ 0\\ 1\end{array}\end{array}\end{array}\right]\left[\begin{array}{c}{b}_{4}\\ {b}_{5}\\ {b}_{6}\\ {b}_{7}\end{array}\right]=\left[\begin{array}{c}{b}_{4}\\ {b}_{4}+{b}_{5}\\ {b}_{4}+{b}_{5}+{b}_{6}\\ {b}_{4}+{b}_{5}+{b}_{6}+{b}_{7}\end{array}\right]$ (17)

$X{b}_{i}+Y{b}_{j}=\left[\begin{array}{c}{b}_{0}\\ {b}_{0}+{b}_{1}\\ {b}_{0}+{b}_{1}+{b}_{2}\\ {b}_{0}+{b}_{1}+{b}_{2}+{b}_{3}\end{array}\right]+\left[\begin{array}{c}{b}_{7}+{b}_{6}+{b}_{5}+{b}_{4}\\ {b}_{7}+{b}_{6}+{b}_{5}\\ {b}_{7}+{b}_{6}\\ {b}_{7}\end{array}\right]=\left[\begin{array}{c}{b}_{0}+{b}_{7}+{b}_{6}+{b}_{5}+{b}_{4}\\ {b}_{0}+{b}_{1}+{b}_{7}+{b}_{6}+{b}_{5}\\ {b}_{0}+{b}_{1}+{b}_{2}+{b}_{7}+{b}_{6}\\ {b}_{0}+{b}_{1}+{b}_{2}+{b}_{3}+{b}_{7}\end{array}\right]$ (18)

$Y{b}_{i}+X{b}_{j}=\left[\begin{array}{c}{b}_{3}+{b}_{2}+{b}_{1}+{b}_{0}\\ {b}_{3}+{b}_{2}+{b}_{1}\\ {b}_{3}+{b}_{2}\\ {b}_{3}\end{array}\right]+\left[\begin{array}{c}{b}_{4}\\ {b}_{4}+{b}_{5}\\ {b}_{4}+{b}_{5}+{b}_{6}\\ {b}_{4}+{b}_{5}+{b}_{6}+{b}_{7}\end{array}\right]=\left[\begin{array}{c}{b}_{3}+{b}_{2}+{b}_{1}+{b}_{0}+{b}_{4}\\ {b}_{3}+{b}_{2}+{b}_{1}+{b}_{4}+{b}_{5}\\ {b}_{3}+{b}_{2}+{b}_{4}+{b}_{5}+{b}_{6}\\ {b}_{3}+{b}_{4}+{b}_{5}+{b}_{6}+{b}_{7}\end{array}\right]$ (19)

The result is

$\left[\begin{array}{c}{e}_{0}\\ {e}_{1}\\ {e}_{2}\\ {e}_{3}\\ {e}_{4}\\ {e}_{5}\\ {e}_{6}\\ {e}_{7}\end{array}\right]=\left[\begin{array}{c}{b}_{0}+{b}_{7}+{b}_{6}+{b}_{5}+{b}_{4}\\ {b}_{0}+{b}_{1}+{b}_{7}+{b}_{6}+{b}_{5}\\ {b}_{0}+{b}_{1}+{b}_{2}+{b}_{7}+{b}_{6}\\ {b}_{0}+{b}_{1}+{b}_{2}+{b}_{3}+{b}_{7}\\ {b}_{3}+{b}_{2}+{b}_{1}+{b}_{0}+{b}_{4}\\ {b}_{3}+{b}_{2}+{b}_{1}+{b}_{4}+{b}_{5}\\ {b}_{3}+{b}_{2}+{b}_{4}+{b}_{5}+{b}_{6}\\ {b}_{3}+{b}_{4}+{b}_{5}+{b}_{6}+{b}_{7}\end{array}\right]$ (20)

and this satisfies:

${e}_{i}={b}_{i}+{b}_{\left(i+4\right)\mathrm{mod}\left(8\right)}+{b}_{\left(i+5\right)\mathrm{mod}\left(8\right)}+{b}_{\left(i+6\right)\mathrm{mod}\left(8\right)}+{b}_{\left(i+7\right)\mathrm{mod}\left(8\right)},\text{\hspace{0.17em}}\text{\hspace{0.17em}}0\le i\le 7$ (21)

At the last, to find $\left({c}_{7}{c}_{6}{c}_{5}{c}_{4}{c}_{3}{c}_{2}{c}_{1}{c}_{0}\right)$ , we add $\left({e}_{7}{e}_{6}{e}_{5}{e}_{4}{e}_{3}{e}_{2}{e}_{1}{e}_{0}\right)$ to $01100011$ .

3. Results

The matrices: $X{b}_{i},Y{b}_{j},Y{b}_{i}$ and $X{b}_{j}$ are just $\left({b}_{7}{b}_{6}{b}_{5}{b}_{4}{b}_{3}{b}_{2}{b}_{1}{b}_{0}\right)$ with some XOR operations. When multiplying X by ${b}_{i}$ or ${b}_{j}$ , the result will be:

(first element, first + second, first + second + third, first + second + third+ fourth) of ${b}_{i}$ or ${b}_{j}$ , and when multiplying Y by ${b}_{i}$ or ${b}_{j}$ , starting from the fourth element, the result will be:

(First + second + third + fourth, second + third + fourth, third + fourth, fourth) of ${b}_{i}$ or ${b}_{j}$ .

So, we can find $\left({e}_{7}{e}_{6}{e}_{5}{e}_{4}{e}_{3}{e}_{2}{e}_{1}{e}_{0}\right)$ from $\left({b}_{7}{b}_{6}{b}_{5}{b}_{4}{b}_{3}{b}_{2}{b}_{1}{b}_{0}\right)$ directly.

4. Example

To encrypt:

Input: 32 43 F6 A8 88 5A 30 8D 31 31 98 A2 E0 37 07 34

Key: 2B 7E 15 16 28 AE D2 A6 AB F7 15 88 09 CF 4F 3C

using AES  .

Let us do the first step (Rijndael ByteSub transformation).

$\left[\begin{array}{cc}32& \begin{array}{ccc}88& 31& E0\end{array}\\ \begin{array}{c}43\\ F6\\ A8\end{array}& \begin{array}{ccc}\begin{array}{c}5A\\ 30\\ 8D\end{array}& \begin{array}{c}31\\ 98\\ A2\end{array}& \begin{array}{c}37\\ 07\\ 34\end{array}\end{array}\end{array}\right]+\left[\begin{array}{cc}2B& \begin{array}{ccc}28& AB& 09\end{array}\\ \begin{array}{c}7E\\ 15\\ 16\end{array}& \begin{array}{ccc}\begin{array}{c}AE\\ D2\\ A6\end{array}& \begin{array}{c}F7\\ 15\\ 88\end{array}& \begin{array}{c}CF\\ 4F\\ 3C\end{array}\end{array}\end{array}\right]=\left[\begin{array}{cc}19& \begin{array}{ccc}..& ..& ..\end{array}\\ \begin{array}{c}..\\ ..\\ ..\end{array}& \begin{array}{ccc}\begin{array}{c}..\\ ..\\ ..\end{array}& \begin{array}{c}..\\ ..\\ ..\end{array}& \begin{array}{c}..\\ ..\\ ..\end{array}\end{array}\end{array}\right]$

We just transform the element {19},

$19=00011001={x}^{4}+{x}^{3}+1$

Computing the multiplicative inverse, (look at Table 3).

Since ${r}_{2}=1$ ,

$\begin{array}{c}T={T}_{2}\\ ={q}_{2}{T}_{1}+{T}_{0}\\ =x\left({x}^{4}+{x}^{3}+{x}^{2}+x+1\right)+1\\ ={x}^{5}+{x}^{4}+{x}^{3}+{x}^{2}+x+1\\ =00111111\end{array}$

Now, we take $\left(00111111\right)$ , to do the second operation.

$\left[\begin{array}{c}1\\ 1\\ 1\\ 1\\ 1\\ 1\\ 0\\ 0\end{array}\right]\to \frac{\left[\begin{array}{c}1\\ 0\\ 1\\ 0\end{array}\right]+\left[\begin{array}{c}0\\ 1\\ 0\\ 0\end{array}\right]}{\left[\begin{array}{c}0\\ 1\\ 0\\ 1\end{array}\right]+\left[\begin{array}{c}1\\ 0\\ 0\\ 0\end{array}\right]}\to \left[\begin{array}{c}1\\ 1\\ 1\\ 0\\ 1\\ 1\\ 0\\ 1\end{array}\right]$

Then we add the result to $\left(01100011\right)$

Table 3. Steps finish when ${r}_{2}=1$ .

$\left[\begin{array}{c}1\\ 1\\ 1\\ 0\\ 1\\ 1\\ 0\\ 1\end{array}\right]+\left[\begin{array}{c}1\\ 1\\ 0\\ 0\\ 0\\ 1\\ 1\\ 0\end{array}\right]=\left[\begin{array}{c}0\\ 0\\ 1\\ 0\\ 1\\ 0\\ 1\\ 1\end{array}\right]$

So,

$19\to 11010100=D4$

5. Conclusion

The modern technique proposed in this work equivalently finds the Rijndael byte substitute transformation without a need to compute multiplicative inverses and matrices multiplication by traditional methods.

Cite this paper
Ahmed, W. (2019) On Rijndael ByteSub Transformation. Applied Mathematics, 10, 113-118. doi: 10.4236/am.2019.103010.
References
   Advanced Encryption Standard (AES), FIPS Publication 197, National Institute of Standards and Technology (NIST), November 26, 2001.

   Menezes, A., van Oorschot, P. and Vanstone, S. (1997) Handbook of Applied Cryptography. CRC Press, New York.

   Ahmed, W. (2019) Some Techniques to Compute Multiplicative Inverses for Advanced Encryption Standard. Journal of Advances in Mathematics, 16, 8208-8212.
https://doi.org/10.24297/jam.v16i0.8016

Top