Electrónica
New S-box calculation for Rijndael-AES based on an artificial neural network
Nuevo enfoque para el calculo de la Caja-S para Rijndael-AES basado en una red neuronal artificial
New S-box calculation for Rijndael-AES based on an artificial neural network
ReCIBE. Revista electrónica de Computación, Informática, Biomédica y Electrónica, vol. 6, no. 2, pp. 49-69, 2017
Universidad de Guadalajara
Received: 14 September 2017
Accepted: 05 October 2017
Abstract: The S-box is a basic important component in symmetric key encryption, used in block ciphers to confuse or hide the relationship between the plaintext and the ciphertext. In this paper a way to develop the transformation of an input of the S-box specified in AES encryption system through an artificial neural network and the multiplicative inverse in Galois Field is presented. With this implementation more security is achieved since the values of the S-box remain hidden and the inverse table serves as a distractor since it would appear to be the complete S-box. This is implemented on MATLAB and HSPICE using a network of perceptron neurons with a hidden layer and null error.
Keywords: Artificial Neural Network, Cryptography, Circuits, SPICE.
Resumen: La Caja-S es un componente básico en el cifrado de clave simétrica, usado en los cifradores por bloques para confundir o esconder la relación entre el texto plano y el texto cifrado. Este trabajo presenta una manera de desarrollar la transformación de los valores de entrada de la Caja-S especificada en el sistema de cifrado AES por medio de una red neuronal y los valores del inverso multiplicativo en el campo de Galois. Con esta implementación se logra mayor seguridad debido a que los valores de la Caja-S permanecen ocultos mientras que la tabla de los valores inversos en el dominio de Galois sirve de distractor pareciendo ser la verdadera Caja-s. Este trabajo fue implementado en MATLAB y HSPICE utilizando una red con neuronas del tipo Perceptron con una capa oculta, obteniendo los valores esperados por la Caja-S original sin error.
Palabras clave: Circuitos, Criptografia, Red Neuronal Artificial, SPICE.
1. Introdution
In cryptography, an S-box consists of a look up table with the corresponding 8-bit word for each possible input in a non-linear transformation, in which the input byte is considered the address of the table (Rodriguez-Henriquez, Saqib, Díaz & Koc 2007). The S-box represents a bricklayer non-linear function that can be decomposed in several boolean functions operating independently on a subset of bits from the input vector (Daemen & Rijmen, 2002). If the functions are linear they are called D-boxes.
The operation of an S-box is as follows: when a transformation is required for a certain input, this input enters the S-box and points, or directs to the previously calculated output of its transformation and then the input is replaced, as shown in fig.1, where the value ai,j is substituted for the value bi,j as it passes through the S-box.

Due to their importance, S-boxes are chosen and designed to be resistant to cryptanalysis, in literature several proposals with different characteristics are found, some of them based on neural networks, like the framework for the design of S-boxes used in ciphers based on neural networks by Noughabi (Noughabi & Sadeghiyan, 2010) and “a new scheme for implementing s-box based on neural network” by X. Zhang (Zhang, Chen, Chen, & Cao, 2015), others that optimize existing boxes such as the high speed implementation of S. Oukili for the AES S-box (Oukili, Bri & Kumar, 2016) and low-area S-box implementation of Thomson (Thomson, Siva, & Priya, 2014); even new proposals such as the evolutionary design of S-Box of M. Yang (Yang, Wang, Meng & Han, 2011) and the based on chaotics maps of C. I. Rı̂ncu (Rı̂ncu & Iana, 2014).
This article presents a substitution of the S-box for another module that calculates the AES S-box outputs with the use of a neural network and the multiplicative inverse on Galois field 28 (GF (28)) of the input value to transform, or S-box input value.
Section 2 introduces the AES algorithm giving a brief introduction to history and a complete description of the Rijndael-AES algorithm, in this section under the subsection “The Round Transformation” highlights the sub-Bytes function that describe how the values of the S-box are calculated. Section 3 describes the proposed method, this includes the neural network topology and the approach for hardware implementation. The simulations are presented in section 4, this section is an explanation of the implementation, behavior and results in MATLAB and HSPICE. Finally conclusions are given in section 5.
2. AES, Advance Encryption Standard
Developed by Joan Daemen and Vincent Rijimen, Rijndael was finally chosen on October 2000 by the National Institute of Standards and Technology (NIST) among other encryption algorithms in an open process organized by the same institute on January 1997 to become the new Advanced Encryption Standard (AES) to replace Data Encryption Standard (DES) and triple-DES as encryption standard (Daemen & Rijmen, 2002). Following NIST specifications, AES is a symmetric block cipher algorithm with variable length of 128 bits, 192 bits and 256 bits, with a variable length key of 128 bits, 192 bits y 256 bits and easy on hardware and software implementation (Daemen & Rijmen, 2002).
Although it is common to talk about AES and Rijndael indistinctly, being Rijndael the selected algorithm for AES, there is a difference among them in the range of values supported by the block length and key length to use. In Rijndael, the block length and key length can be independently specified to any multiple of 32 bits, with a minimum of 128 bits and a maximum of 256 bits. AES fixes the length block and the length key to 128, 192 o 256 bits only (Daemen & Rijmen, 1999).
Independently of technical differences in the length of block and key permitted, when talking about Rijndael or AES, we are talking about the same iterative block cipher algorithm. Inputs and outputs of Rijndael-AES are considered to be one-dimensional arrays of 8-bits. For encryption the input is a Plaintext block and a cipher key, and the output is a ciphertext block. For decryption the inputs is a ciphertext block and a cipher key, and the output is a Plaintext block (Daemen & Rijmen, 2002).
The cipher can be divided in two parts with different functionality: the transformation or encoding of the message, function called “The Round transformation” and denoted as “Round” and “FinalRound”, this encryption function is described in fig. 2 along with the functions that make it up, called steps; and the transformation of the key called “Key schedule” given by the function “KeyExpansion”.

The different transformation operates on an intermediate result called State which is represented as a rectangular array of bytes, with four rows and Nb number of columns

Similarly, the cipher key is represented as a rectangular array with four rows and Nk number of columns (Daemen & Rijmen, 1999), (Rodriguez-Henriquez et al., 2007), (Daemen & Rijmen, 2002), (Katz & Lindell, 2008), where

The number of rounds Nr depends on the values of Nband Nk as presented in the table 1. (Error 11: La referencia: Nk está ligada a un elemento que ya no existe)

2.1. The Round Transformation
As shown in the fig. 2, the round transformation is divided in Round and FinalRound. Round is formed by a sequence of four different and invertible mathematical transformations on GF(28) which are called steps: 1) SubBytes, 2) ShiftRows, 3) MixColumn, 4) AddRoundKey (Daemen & Rijmen, 1999), (Rodriguez-Henriquez et al., 2007), (Daemen & Rijmen, 2002). The FinalRound is similar to round but without the MixColumns function.
2.1.1. subBytes.
It is a non-linear transformation where each input byte of the state matrix is replaced by another byte produced by the transformation. This Transformation is defined in two steps (Daemen & Rijmen, 1999):
Multiplicative inverse:
The input byte a is replaced by its multiplicative inverse x = a-¹ , with x = 0 for a = 0.
Affine transformation:
Defined by y = M × x ⊕ b, where M is a constant matrix of 8 × 8 bits, x represents the value to transform while b is a constant byte equal to 6316 (011000112 ) (Daemen & Rijmen, 2002).
The matrix representation of the transformation is shown in (3), where M is replaced by the constant matrix of 8×8 bits, x is expanded to the polynomial representation of a byte, starting with the most significant bit; and b the binary constant.

Another way to implement this transformation is to use the corresponding S-Box shown in fig. 3 replacing the input value (row, column) by the value that crosses them.

The inverse operation, called InvSubBytes, consists of the use of the inverse S-Box of fig. 4 for each byte of the state.

The inverse S-box is obtained by the applying the inverse of the affine transformation, shown in ec. 3 followed by taking the multiplicative inverse in GF(28). The inverse of (3) is represented in (4) (Daemen & Rijmen, 2002).

2.1.2. ShiftRows
In ShiftRows, the rows of the state are shifted cyclically to the left in different proportions. Row 0 does not changes, but the remaining rows follow an offset of C1 , C2 and C3 bytes respectively, this proportion depends only of the block length Nb (Daemen & Rijmen, 2002). The inverse operation, called InvShiftRows, consists in a cyclic shift of the three bottom rows over Nb − C1 , Nb − C2 y Nb − C3 bytes respectively. The table 2 shows the value of Cn pereach possible Nb.

2.1.3. MixColumns
The MixColumns step is a bricklayer permutation operating on the state column by column. In Mixcolumns the state columns are considered as polynomials in GF (28) and multiplied modulo x4 + 1 with the fixed polynomial c(x) given by c(x) = (0316 )x3 + (0116)x2 + (0116)x + 0216 . This operation can be written as a matrix multiplication, let b(x) = c(x) a(x) mod x4 +1 as is show in (5)

The inverse of MixColumns is called InvMixColumns. It is similar to MixColumns. The transformation is performed by multiplying each column by the polynomial d(x) = (0B16)x3 + (0D16)x2 + (0916)x + 0E16, represented in (6) as a matrix multiplication (Daemen & Rijmen, 1999), (Daemen & Rijmen, 2002), (Parikh & Narkhede, 2016).

2.1.4. AddRoundKey
In this transformation the state is modified with the bitwise XOR operation with the round key derived from the cipher key and the function Key Schedule. The length of round key is equal to the block length Nb (Daemen & Rijmen, 1999). The inverse of AddRoundKey is called InvAddRoundKey, and is applied in the same way as AddRoundKey applying the keys in reverse order (Rodriguez-Henriquez et al., 2007).
2.2. Key Schedule
Consists in the expansion of the key and in the key selection round (Daemen & Rijmen, 2002). The key expansion specifies how the expanded key is calculated from the cipher key. The number of bits in the expanded key is equal to the block length multiplied by the number of rounds Nr plus one, generating a total of Nb × (Nr + 1) words, or Nr + 1 subkeys, one per each round (Bonadero, Liberatori, Bria & Villagarcı́a, 2005).
The cipher key is expanded inside of the Expanded key. Round keys are taken from Expanded key as follows: the first round key consists on the initial Nb words, the second on the subsequent Nb words, and so on (Daemen & Rijmen, 1999).
2.2.1 KeyExpansion.
Expanded Key is a four byte linear array denoted by W [Nb × (Nr + 1)]. The first Nk words contain the cipher key, while all other words are defined recursively. KeyExpansion depends of the Nk value and is calculated as in fig. 5, employing the functions subBytes, Rotbyte and Rcon (Daemen & Rijmen, 1999), (Daemen & Rijmen, 2002).
RotByte returns a word that results from a cyclical permutation from the input word, e.g., for an input {a,b,c,d} the output is {b,c,d,a}.
The constant Rcon is independent of N k and is defined in (7) as:

where RC[i] represents an element in GF (28) with value x(i-1) such that:


3. Proposed Method
The modification consists in substituting the AES S-box for an Artificial Neural Network (ANN) that solves the transformation using as input the corresponding multiplicative inverse value GF (28) of the original S-box input value. To obtain the corresponding inverse a lookup table is used. The S-box is substituted for a module formed by a table with the inverse values obtained from (Pelzl & Paar, 2010), (Srebrny, Kościelny & Kurkowski, 2013) and a neural network as is shown in fig. 6. With this method two advantages are obtained, the first one is that the values of the S-box are hidden, and the second one is that it’s possible to change the values of the S-box just by a simply changing the weights.

The neural network topology was proposed by means of observation. The transformation is performed bitwise, nevertheless another arrangement is also acceptable. The neural network consists of eight subnetworks, one per bit, each one as illustrated in fig. 7 is composed by seven perceptron neurons in three layers: input layer, hidden layer and output layer. Based on neural networks that perform AND and XOR behaviors each neuron has two inputs and a pulse activation function given by (11).


The circuit implementation was developed in HSPICE which is an electric circuit simulator (synopsys, 2003), (Piuri, 1991). In hardware implementation, Operational Transconductance Amplifiers (OTA) are used as proposed in (Kawaguchi, Umeno & Ishii, 2014), (Ghosh, LaCour & Jackson, 1994) in order to manage current signals and simplify the sum of the synaptic weights.
The OTA is a voltage controlled current source (VCCS). Its main characteristics are high input impedance and high output impedance (Barclay & Wood, 1994), (Qing-Lin, Jian-You & Mei-Lun, 1991). The OTA macromodel is shown in fig. 8, where Vin1 and Vin2 are the voltage inputs, the voltage difference of these sources is reflected in nodes a and b.

The output current Iout is proportional to the difference between these voltages as in eqn. 12.

where gm is the transconductance gain, Vin1 the positive input voltage, Vin2 the negative input voltage and Iout the output current.
The OTA is used to represent the neuron inputs, converting (in the input layer) or keeping (in the remaining layers) the input signal into a current signal and using the amplifiers gain (gm) as the corresponding synaptic weight. The signals are summed by simply connecting the OTAs outputs to a wire line which is then the input to the activation function.
4. Simulations
The proposed network was simulated in Matlab, where it was tested and the expected operation for the S-box specified for AES was verified. An implementation using OTAs in HSPICE was performed, where the gain is equivalent to the corresponding weights. Simulating the electric behavior of the system. In the next subsections details of its implementation and results are given.
4.1. Simulation and Results in MATLAB
In the simulation the inverse value in GF(28) was used as input of the system and the results were compared and verified with its corresponding S-box values. For a better visualization of the results, the binary values were converted to decimal and are presented in fig. 9 highlighting that the values obtained correspond to those expected with an error of 0%.

The synaptic weights used are shown in table 3, these values were obtained from neural networks with AND and XOR behaviors, hence there was no previous training of the network.

4.2. HSPICE Implementation and Results
According to the structure proposed in fig. 7 the architecture shown in fig. 10 is implemented in HSPICE, where V1 through V8 represent the input signals, the weight, W, are represented by the transconductance of the OTAs, the sums are represented by linking the OTAs outputs, and finally the activation function described in (11) is applied (Error 7: La referencia: (11) está ligada a un elemento que ya no existe)
The structure in fig. 10 has one bit output, hence it’s necessary to replicate the structure in order to have an eight bit output. It should be noted that it is not necessary to replicate the voltage sources and their resistance, i.e. the inputs, only the current source, their resistance and the activation functions.

OTA1 output and OTA2 output are linked in Irl1
OTA3 output and OTA4 output are linked in Irl2
OTA5 output and OTA6 output are linked in Irl3
OTA7 output and OTA8 output are linked in Irl4
As mentioned previously, the structure is replicated to obtain the eight output bits, therefore the same steps are repeated to obtain bit1 to bit7.
To verify the circuit operation, tests were performed with the input values shown in table IV, the table displays some of the values found in the S-box and the result to those inputs, the next two columns show the input value for the proposed network which corresponds to the multiplicative inverse in GF(28) and the result obtained from that input. The results obtained from the network are identical, thus the operation of the network is validated.
In figs. 11 and 12 the results obtained from the circuit for four inputs of the table are shown.


e.g. On the left side in fig. 11 the obtained result from the circuit to input 00 16 in GF(28) is 6316 , the result is verified in table 4. Similarly on the left side the result EC16 is obtained for an input 8016 in GF(28).

5. Conclusion
An implementation of an S-box using a neural network in MATLAB and HSPICE is presented, this neural network is based on the operations used to obtain the values of the S-box through 8 perceptron subnetworks and a lookup table with the inverse in GF(28). Even if this method of calculating S-box values for AES does not present an advantage reducing resources, since storing the inverse values for each possible input represent hundred percent of the necessary resources to store the original S-box, the values computed by a neural network offers greater security by maintaining the transformation values hidden and using a distractor or an apparently S-box that contains the inverse values in GF(28). The simulation results show that the implementation presents a null error, thereafter if the neural network were applied, it will not show changes in the results expected within the encryption algorithm because it simulates without error the operation of the S-box.
References
Barclay M. & Wood J., (1994) A SPICE macromodel for operational transconductance amplifiers. IEE Colloquium on Analogue Signal Processing, London, 1994, pp. 1/1-1/4.
Bonadero J., Liberatori M., Bria O. & Villagarcı́a-Wanza H. (2005) Expanción de la clave en rijndael: diseño y optimización en vhdl. In XI Workshop IBERSHIP.
Daemen J. & Rijmen V. (1999) AES proposal: Rijndael.
Daemen J. & Rijmen V. (2002) The design of Rijndael: AES - the Advanced Encryption Standard. Springer-Verlag.
Ghosh J., LaCour P. & Jackson S. (1994) Ota based neural network architectures with on-chip tuning of synapses. In Proceedings of 7th International Conference on VLSI Design, pages 71–76.
Katz J. & Lindell Y. (2008) Introduction to Modern Cryptography. Chapman & Hall/CRC cryptography and Network Security.
Kawaguchi M., Umeno M. & Ishii N. (2014) The two-stage analog neural network model and hardware implementation. In 2014 IIAI 3rd International Conference on Advanced Applied Informatics, pages 936–941.
Noughabi M. N. A. & Sadeghiyan B. (2010) Design of s-boxes based on neural networks. In 2010 International Conference on Electronics and Information Engineering, volume 2, pages V2–172–V2–178.
Oukili S., Bri S., & Kumar A. V. S. (2016) High speed efficient fpga implementation of pipelined aes s-box. In 2016 4th IEEE International Colloquium on Information Science and Technology (CiSt), pages 901–905.
Parikh P. & Narkhede S. (2016) High performance implementation of mixing of column and inv mixing of column for aes on fpga. In 2016 International Conference on Computation of Power, Energy Information and Commuincation (ICCPEIC), pages 174–179./
Pelzl J. & Paar C.. (2010) Understanding Cryptography - A Textbook for Students and Practitioners. Springer-Verlag Berlin Heidelberg, 1 edition.
Piuri V. (1991) The use of the electrical simulator spice for behavioral simulation of artificial neural networks. In 1991 Proceedings of the 24th Annual Simulation Symposium, pages 18–29.
Qing-Lin Sun, Jian-You Liu & Mei-Lun Liu, (1991) An improved nonlinear macromodel of OTA, 1991 International Conference on Circuits and Systems, Shenzhen, China. pp. 906-908 vol.2.
Rı̂ncu C. & Iana V. (2014) S-box design based on chaotic maps combination. In 2014 10th International Conference on Communications (COMM), pages 1–4.
Rodriguez-Henriquez F., Saqib N.A., Dı́az A., & Koc CK. (2007) Cryptographic Algorithms on Reconfigurable Hardware. US: Springer.
Srebrny M., Kościelny C. & Kurkowski M. (2013) Modern Cryptography Primer, Theoretical Foundations and Practical Applications. Springer-Verlag Berlin Heidelberg, 1 edition.
synopsys. (2003) HSPICE Simulation and Analysis User Guide.
Thomson K, Siva. N, & Priya S. (2014) Implementation of low-area s-box based on normal basis. In 2014 International Conference on Electronics and Communication Systems (ICECS), pages 1–4.
Yang M., Wang Z., Meng Q., & Han L. (2011) Evolutionary design of s-box with cryptographic properties. In 2011 IEEE Ninth International Symposium on Parallel and Distributed Processing with Applications Workshops, pages 12–15.
Zhang X., Chen F., Chen B., & Cao Z. (2015) A new scheme for implementing s-box based on neural network. In 2015 International Conference on Computational Science and Computational Intelligence (CSCI), pages 571–576.
Author notes




Alternative link
http://recibe.cucei.udg.mx/ojs/index.php/ReCIBE/article/view/77/75 (html)