1 Introduction
Classical cryptography are divided into asymmetric cryptography and symmetric cryptography [
1]. RSA cryptography [
2] is a typical asymmetric cipher, whose security relies on our inability to effectively factor large integers. However, RSA cryptography will be broken in the face of quantum computer. Shor’s algorithm [
3] can effectively solve the problem in
O((log
N)
3) time, where
N is the large integer to be factorized. AES is a typical symmetric cryptography [
4]. Grover’s quantum algorithm [
5,
6], finding a marked item from an unsorted database with square-root speedup, can attack the AES cryptography. Fortunately, the AES is not fully broken. By doubling the length of the key in AES, its security can be maintained. However, it is vital to study the level of influence of quantum computer on the AES.
Yamamura
et al. [
7] studied the impact of quantum algorithms on symmetric cryptography. Such as the AES cryptography, which can be decrypted in
O(2
n/2) time using Grover’s algorithm, where
n is the key length. Kaplan proposed a quantum version [
8] of the classical Meet-inthe-middle attack [
9] using the Ambainis quantum algorithm [
10]. The time complexity and qubits complexity of Kaplen’s algorithm both are
O(2
2n/3). In 2014, Roetteler
et al. proposed the quantum related key attack [
11] by using Simon’s algorithm [
12]. Grassl
et al. [
13] presented a quantum implementation of AES in 2015 and analyzed the consumption of quantum resources. This is the first time that the “zig-zag” method is used to reduce the number of qubits. In the “zig-zag” method, the qubits that are used to encode the cipher in the front rounds of encryption can be released and reused to encode later rounds of cipher. Later on, Kim
et al. [
14] made an improvement on SubBytes operation, one of the four operations in AES, in Grassl
et al.’s work, which saves one multiplication operation. In 2018, Almazrooie
et al. [
15] proposed a quantum circuit that uses Grover’s algorithm to attack S-AES cryptography. Owing to the small size, this is the most likely case to implement in the near-term quantum computing systems [
16,
17]. Recently, Langenberg
et al. designed a quantum circuit [
18] for SubBytes based on Boyar
et al.’s classical algorithm [
19]. It reduced the number of Toffoli gates by 88% compared to Grassl
et al.’s work.
In this paper, we design an improved key expansion quantum circuit. The SubBytes quantum circuit in [
18] is modified firstly, which eliminates the effect that the output qubits in SubBytes are not in |0〉
⊗8. Then, we construct the quantum circuit to encode the new round sub-key on the qubits encoding previous round sub-key. This can reduce the cost of qubits by 224 compared to Langenberg
et al.’s work [
18]. Employing the lowest possible number of qubits, we optimize the quantum circuit of S-AES using the methods used in AES-128. Compared with Almazrooie
et al.’s work [
15], it saves 71% of Toffoli gates, over 66% C-NOT gates and one third(24) for qubits.
This paper is organized as follows: the first part briefly reviews the structure of AES algorithm and the quantum circuit. Then an improved key expansion quantum circuit is proposed, and the SubBytes quantum circuit from Ref. [
18] is modified. The quantum circuit of S-AES is optimized using the same methods as in AES. Next, we analyze the complexity of AES-128 and S-AES quantum circuits and compared with the results in Ref. [
18] and Ref. [
15] respectively. Finally, discussion and conclusion are presented.
2 Introduction to AES-128
As a symmetric block cipher, AES-128 uses the same 128-bit key each time to encrypt 128-bit plain-text. Both the key and the plain-text are arranged into a rectangular array of 4×4 bytes. The entire encryption process contains 4 encryption operations, namely AddRoundKey, SubBytes, ShiftRows and MixColumns. In the first nine rounds of encryption, the above 4 encryption operations are executed in order, and the tenth round of encryption contains two AddRoundKey operations but without MixColumns operation. Therefore, in addition to the 128-bit initial key, 10 rounds sub-key are needed to be generated for AddRoundKey. The specific flow chart is shown in Fig. 1. In the key expansion operation, transposition and SubBytes are mainly used. Below we briefly introduce the 4 kinds of encryption operations.
AddRoundKey implements the bit-wise XOR of the round keys, and it needs 128 C-NOT gates each time and can be executed in parallel.
ShiftRows is a particular permutation of the current AES state. For the first row in the plain-text array of 4 × 4 bytes, we do nothing; for the second row, rotate one unit (a byte) to the left; for the third row, rotate two units to the left; for the last row, rotate three units to the left. All of the above operations are equivalent to adjust the position of the bytes, so no additional operations are required.
MixColumns operates on an entire column of the plaintext array at a time as an affine transformation, so Mix-Columns is equivalent to a 32 × 32 matrix acting on every column. A MixColumns requires 277 C-NOT gates.
SubBytes is the most important and complex part of the entire algorithm which prevents linear correspondence between the plain-text and the cipher-text. The main function of SubBytes is to map one byte to another through the S-box. SubBytes can be achieved by performing the inverse operation for each byte in the 4 × 4 bytes array on the finite field, and then performing an affine transformation for every byte.
Next, we briefly introduce the key expansion algorithm. The 16-byte initial key is arranged into a 4×4 array, which is divided into k0, k1, k2, and k3 according to the row, and each part has 4 bytes. First, for the 4 bytes of k3, we loop them to the left by one unit (a byte) and do SubBytes operation for each of the byte, followed by performing XOR operations with a known 32-bit string. Finally, XOR operations between k0 and the above results are performed to get k4. k5 can be obtained by making XOR operations between k1 and k4. Then, k6 and k7 can be gained. A round key expansion is finished. The last 9-round sub-key can be gained by repeating the above process. The 32 known bits that perform XOR operations with the 4-byte key are different in each round, a total of 16 Pauli-X gates are required for 10 rounds. In Langenberg et al.’s work, the key expansion quantum circuit needs 224 qubits to generate the 10-round sub-key.
In the last part of this section, the quantum circuit of AES-128 is shown in Fig. 2. Round n (n = 1, 2, ..., 10) represents the encryption round and Inverse n represents the inverse operation for the corresponding encryption round. The plain-text is encoded on the qubits that encodes the initial key, which can save 128 qubits used to encode plaintext. We denote the XOR operations between the plaintext and the initial key as P.
3 Improvements in quantum implementation of AES-128
We propose an improved design for key expansion, which does not need the extra qubits for saving the sub-key. It is shown in Fig. 3.
The new design saves 224 qubits compared with Langenberg
et al.’s work because we generate the sub-key in the qubits that encode the previous key, instead of using another 224 qubits in |0〉 state in the first 7 rounds totally. The quantum circuit for SubBytes in Ref. [
18], requiring 16 auxiliary qubits, 55 Toffoli gates, 314 C-NOT gates and 4 NOT gates, can be used in the 10-round encryption but cannot be applied in the key expansion since the initial state of the output qubits in SubBytes are not |0〉
⊗8. In order to use this quantum circuit of SubBytes, an affine transformation shown in Fig. 4 operates on the output qubits which eliminates the effect that the output qubits are not in |0〉
⊗8 state, and the final result is the same as the output of SubBytes and the initial state of the output qubits to do XOR operations. It is denoted as SB
*. Suppose the input is
X and the initial state of output qubits is
Y in this step, this process can be written as a function:
This affine transformation contains 8 C-NOT gates but does not increase the depth of the entire quantum circuit of SubBytes. So the overall cost of SubBytes in key expansion is 16 auxiliary qubits, 55 Toffoli gates, 322 C-NOT gates and 4 NOT gates.
4 An improved quantum implementation of S-AES
Here, the same method is used in S-AES. It saves 16 qubits without increasing the gate complexity. Figure 5 shows the quantum circuit of S-AES.
For S-AES, we design a SubBytes quantum circuit by using the Boolean functions corresponding to the inverse in finite field
GF(2
4). The inverse representation in
GF(2
4) based on the normal basis [
19] is as follows:
where xi represents the input qubit and yi represents the output qubit (i = 1, 2, 3, 4). The derivation of the equation is based on the representation in the finite field, in which an element of GF(24) can be written as ∆ = (x1W + x2W2)Z2 + (x3W + x4W2)Z8, where W is a root of x2 + x + 1 over GF (2) and Z is a root of x2 + x + W2 over GF(22). The inverse of this element can be represented as ∆′ = (y1W + y2W2)Z2 + (y3W + y4W2)Z8. There are 4 mapping matrices between this normal basis and polynomial basis, the simplest of which is as follow:
This matrix transforms the polynomial basis to the normal basis, and the inverse matrix transforms the normal basis to the polynomial basis. Figure 6 is the corresponding quantum circuit. It requires 4 C-NOT gates to implement the basis transformation.
We design a quantum circuit in Fig. 7 based on the Eq. (2), which does not require auxiliary qubits or the initial state of the output qubits in |0〉⊗4. If the initial state of the output qubits are not in |0〉⊗4, the results are equal to performing XOR operations with the initial state of the output qubits. This process requires 14 Toffoli gates and 11 C-NOT gates.
In addition, the affine transformation and the mapping matrix can be merged. The quantum circuit is shown in Fig. 8, which only requires 8 C-NOT gates and 2 NOT gates. So the SubBytes in S-AES requires 14 Toffoli gates, 23 C-NOT gates and 2 NOT gates.
5 Complexity analysis
In AES-128, there are 256 SubBytes in 10-round encryption and 72 SubBytes in key expansion, where the first, second, third and sixth rounds sub-key need to be generated twice and elimination once. So performing the XOR operations with the known 32-bit string in key expansion requires 24 C-NOT gates. In addition, the operation P, its gate complexity at most 128 X gates, is performed four times. The number of times each operation needs to be performed and the gates required per operation are shown in Table 1. In S-AES, there are 12 SubBytes. The number of times each operation needs to be performed and the gates required per operation are shown in Table 2.
The cost of quantum resources can be calculated by the data in Table 1 and Table 2. Table 3 compares the resource usage between Langenberg et al. ’s work and this work in quantum implementation of AES-128. Table 4 compares the resource usage between Almazrooie et al.’s work and this work in quantum implementation of S-AES.
A comparison in Table 3 shows that the gate complexity between Langenberg et al.’work and our work is basically the same, but 224 qubits are saved. Table 4 shows that the quantum circuits we proposed for S-AES can save 71% Toffoli gates, over 66% C-NOT gates, and one third of the qubits usage compared to Almazrooie et al.’s work.
6 Discussion and conclusion
In this work, we proposed an improved key expansion algorithm and modified the SubBytes circuit in Langenberg et al.’s work. The design for the key expansion algorithm was structured to utilize the lowest possible number of qubits, which cuts the number of qubits by 224 for AES-128. All of which advance the quantum implementation of AES. We applied the same methods to S-AES and got a similar result. The reduction of the number of qubits makes S-AES algorithm possible to be implemented on quantum computers in the near future, while the cost of 48 qubits also allows classical computers to do the full amplitude quantum simulation.
At present, the quantum attack on AES algorithm is mainly based on Grover’s algorithm, while the quantum implementation of AES algorithm, as an Oracle, is the most important part in Grover attack. We have constructed a simpler Oracle that will accelerate the process of quantum Grover attack.
After our work was done, we noted that a similar paper was published [
20]. There are also two main improvements compared with Langenberg
et al.’s work. One improvement is in sub-key expansion. They solved the problem that the initial state of the output qubits in SubBytes is not in |0〉
⊗8 state by introducing an auxiliary qubit, while ours is making an affine transformation. The other improvement is proposing a new zig-zag method which can reduce 256 qubits in the encryption process compared with Grassl
et al.’s work. If the new zig-zag method was used in our work, the quantum resource usage can be further reduced. Table 5 shows the number of times each operation needs to be performed and the gates required per operation using the new zig-zag method. The resource usage in using new zig-zag method is shown in Table 6.
Table 6 shows that our work is slightly prior to Zou et al.’s work in gate complexity and reduces the qubits used by 112.