Next Article in Journal
Global Low-Complexity Fault-Tolerant Control for Pure-Feedback Systems with Sensor Faults
Previous Article in Journal
Formation of Vibration Fields for a Mechatronic Platform Driven by Dual Asynchronous Motors
Previous Article in Special Issue
Adjusting Optical Polarization with Machine Learning for Enhancing Practical Security of Continuous-Variable Quantum Key Distribution
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Grover on Scrypt

Information Computer Engineering, Hansung University, Seoul 02876, Republic of Korea
*
Author to whom correspondence should be addressed.
Electronics 2024, 13(16), 3167; https://doi.org/10.3390/electronics13163167
Submission received: 15 July 2024 / Revised: 1 August 2024 / Accepted: 8 August 2024 / Published: 10 August 2024
(This article belongs to the Special Issue Quantum Computation and Its Applications)

Abstract

:
This paper presents an optimized quantum circuit for the s c r y p t cryptographic algorithm. We applied various optimization techniques to reduce the DW cost, which is the product of the time and space complexity of quantum circuits. In our proposed method, the number of ancilla qubits was significantly reduced through the use of optimized inverse operations, while the depth was minimized by implementing parallel structures. For the SHA-256, we devised a structure that achieves a substantial reduction in the number of ancilla qubits with only a slight increase in quantum circuit depth. By cleaning the dirty ancilla qubits used in the previous round through inverse operations, we enabled their reuse in each subsequent round. Specifically, we reduced the number of 8128 ancilla qubits, achieving this with an increase of only 6 in the full depth of the quantum circuit. Additionally, within Salsa20/8 in SMix, we reused qubits through inverse operations and performed some operations in parallel to reduce both the number of qubits and the overall quantum circuit depth. Finally, our quantum circuit for s c r y p t demonstrates a significant reduction in the width (the number of qubits) with only a minimal increase in the full quantum circuit depth.

1. Introduction

Quantum computers leverage the properties of quantum mechanics to utilize qubits that can exist in both 0 and 1 states simultaneously, providing powerful computational capabilities for specific problems. Shor’s algorithm efficiently solves the integer factorization problem for large numbers [1], threatening the security of public-key cryptography such as RSA. Grover’s algorithm efficiently addresses the problem of finding a desired item in an unsorted database. While classical algorithms take O ( N ) time complexity, Grover’s algorithm solves it in O ( N ) time complexity [2]. This greatly accelerates brute force attacks for finding keys in symmetric key algorithms (e.g., AES). The advent of quantum computers significantly threatens existing cryptographic systems, including public-key cryptography and symmetric-key cryptography. In response, NIST has launched the Post-Quantum Cryptography Standardization competition to find replacements for current cryptographic standards. NIST has also proposed the cost of Grover’s algorithm attack, using the maximum depth (MAXDEPTH) of AES as a metric to assess the quantum security strength of block ciphers. To estimate Grover’s algorithm attack cost for a target cipher and verify the post-quantum security levels proposed by NIST, it is necessary to implement the cipher as a quantum circuit. Quantum circuits are required inside the oracle of Grover’s algorithm. Optimized quantum circuits allow for a more accurate determination of post-quantum security levels. Motivated by this, many prior studies have conducted optimized implementations of various ciphers as quantum circuits, such as LSH [3,4], PIPO [5], SPEEDY [6], and so on [7,8,9,10,11,12,13,14,15,16,17,18].
This paper presents the implementation of a quantum circuit for s c r y p t . We implement the s c r y p t algorithm on a quantum computer with low circuit complexity and provide a detailed explanation of the various optimization techniques applied to achieve this. We propose a method to ancilla qubits to clean | 0 through inverse operations and to reuse them in the next iteration. During this process, we perform inverse operations in parallel with subsequent operations to minimize the increase in depth. Additionally, we follow a qubit update method, where if the pre-update value of an updated qubit is needed, we use the updated value in the next operation and then apply the inverse operation to restore the pre-update value. Using this method, we significantly reduce the number of ancilla qubits while only slightly increasing the overall depth. Consequently, we reduce the circuit complexity, calculated as the product of time and space complexity (DW-cost = qubit × T-depth), for  s c r y p t . We provide the estimated resources for the optimized quantum circuit. To the best of our knowledge, this is the first quantum circuit implementation for s c r y p t . Therefore, it is difficult to compare the optimization results of our quantum circuit with previous s c r y p t results. We perform quantum circuit optimization based on the original reference implementation of s c r y p t . This s c r y p t quantum circuit can be used to operate Grover’s algorithm to estimate resources. Therefore, this paper will serve as the foundation for future implementations of the s c r y p t algorithm in quantum circuits. Further optimization of future s c r y p t quantum circuits will help us more accurately assess the post-quantum security of the algorithm. The structure of this paper is as follows: in Section 2, related research on NIST’s PQC Standards Competition and quantum computing is written to help understand the paper. Section 3 explains the implementation of the proposed s c r y p t quantum circuit. This section describes the optimization techniques applied to each s c r y p t function in detail. Section 4 estimates and analyzes the resources required for the proposed quantum circuit. We use the projectQ [19] tool to analyze resources and verify implementation results. The DW cost is calculated and written based on the estimated resources. Finally, Section 5 concludes the paper.

1.1. Our Contribution

1.1.1. First Quantum Circuit for S c r y p t

To the best of our knowledge, this is the first quantum circuit for s c r y p t . The s c r y p t algorithm has been implemented in various optimized implementations across different hardware and software environments [20,21,22]. However, there has been no quantum circuit result suitable for a quantum computer environment. Although optimizations such as memory optimization have been studied for s c r y p t  [23], we implemented the quantum circuit based on the original reference code. We present an optimization direction for the s c r y p t quantum circuit and establish a basis for assessing initial post-quantum security. These research results will serve as a foundation for future implementations of s c r y p t quantum circuits.

1.1.2. Qubit Reuse through Inverse Computation

We propose a method where, after using ancilla qubits in a clean | 0 state, the dirty qubit is returned to a clean | 0 state through inverse operations, allowing them to be reused in subsequent iterations. In SHA-256, dirty ancilla qubits that have been used can be reset to a clean | 0 state through inverse operations, enabling reuse in all loops. Using this method, we reduced the number of qubits by 8128 in SHA-256 within P B K D F 2 S H A 256 with a slight increase in depth (approximately depth 6). In the Salsa function within SMix, we avoided using ancilla qubits for intermediate value storage during the ‘Operation on columns’ and ‘Operate on rows’ steps. Instead, we updated the intermediate values directly into the inputs. When the pre-update values of the updated qubits were needed for subsequent operations, we used the updated values in the following operations and then applied inverse operations to restore the pre-update values.

1.1.3. Parallel Structures in SHA-256 and Salsa20/8

We designed the internal operations to be as parallel as possible to reduce the depth of the quantum circuit. In SHA-256, we reset the used ancilla qubits to a clean state | 0 through inverse operations and designed the circuit to reuse them in all loops. However, adding inverse operations increases the depth of the quantum circuit. To minimize the impact of these inverse operations on the circuit depth, we implemented them to operate in parallel with subsequent operations. Similarly, within the salsa function, the inverse operations that restore the updated qubits to their pre-update state and the internal additions operate partially in parallel with subsequent operations. Therefore, while inverse operations were added to reduce the number of qubits, they do not significantly affect the overall depth.

1.1.4. Optimized Quantum Circuit with Low Complexity

We significantly reduced the number of ancilla qubits. To achieve this, we implemented additional operations in parallel so that the quantum circuit depth is minimally affected. We efficiently implemented s c r y p t into a quantum circuit by reducing the ancilla qubits and depth. These results demonstrate an optimized circuit complexity (DW cost) calculated as the product of time and space complexity.

2. Background

2.1. NIST’s PQC Standards Competition

The National Institute of Standards and Technology (NIST) initiated the Post-Quantum Cryptography (PQC) Standards competition to address the imminent threat quantum computing poses to classical cryptographic systems. This project, officially announced in 2016, aims to identify and standardize cryptographic algorithms resistant to quantum attacks. As part of this competition, NIST established the post-quantum security level categories shown in Table 1 to classify algorithms [24,25,26]. These categories are defined based on the complexity of the Grover attack that can be quantified in terms of circuit size. The three proposed security levels (security level 1, 3, and 5) are defined based on the security of different variants of AES, considering attacks on quantum computers. Considering that NIST established security categories based on the depth of quantum circuits, optimizing the depth is crucial in quantum cryptographic implementations to determine the security level of the cryptographic algorithm accurately.

2.2. Quantum Computing

Quantum computing is a technology that performs calculations by leveraging the principles of quantum mechanics [27]. Unlike classical computers, which process information using bits, quantum computers use qubits. Qubits can exist in a superposition state, allowing them to represent both 0 and 1 simultaneously, thereby enabling parallel computation. Additionally, through the phenomenon of entanglement, interactions between distant qubits can be maximized. These characteristics enable quantum computers to solve certain computational problems much faster than classical computers.
Grover’s quantum algorithm  [2] can significantly speed up database searches by a factor of a square root, drastically reducing the time required to find keys in symmetric-key cryptographic systems (e.g., AES). This implies that quantum computers could easily attack many current symmetric-key cryptographic systems. Consequently, advancements in quantum computing are driving the development of new cryptography, such as post-quantum cryptography (PQC)  [28].

Quantum Circuit

A quantum circuit performs quantum operations using qubits, transforming and interacting with qubit states through quantum gates. The depth of a circuit refers to the maximum number of computational steps involving quantum gates, while the width of a circuit indicates the number of qubits being processed. Thus, a quantum circuit is composed of width, depth, and quantum gates. Major quantum gates include the X gate, CNOT gate, and Toffoli gate, as shown in Figure 1:

2.3. Scrypt

S c r y p t is a password-based key derivation function developed by Colin Percival in 2009 [29]. It was designed to be computationally intensive and memory-hard, making it resistant to hardware attacks, particularly those using ASICs (application-specific integrated circuits) and GPUs (graphics processing units). This makes s c r y p t an ideal choice for highly secure applications such as password hashing and cryptocurrencies. The detailed parameters of s c r y p t are available in Table 2.
Algorithm 1 presents the pseudocode for the operation of s c r y p t . The PBKDF2 function generates an initial derived key B using a password (passwd) and a salt. This function typically uses the SHA-256 hash function internally. The SMix function is a core component of the s c r y p t algorithm, responsible for performing memory-hard operations to enhance security against brute-force attacks. The function takes the following parameters: B, the input, which is the initial derived key block and must be 128 r bytes, and N, which determines the computational cost and must be to the power of 2.
Algorithm 2 illustrates the B L O C K M I X s a l s a 8 and SMix functions used in the s c r y p t algorithm. The P B K D F 2 S H A 256 function generates a 128 r p byte string. This generated string is divided into p blocks of equal length, and the SMix function is called for each block. The results from the SMix function are then concatenated and used as the salt in the final P B K D F 2 S H A 256 operation. In this final P B K D F 2 S H A 256 operation, the original password and the new salt are used to generate the final dkLen byte output key.
The SMix function is a core component of the s c r y p t algorithm responsible for its memory-hard properties. According to the s c r y p t RFC [29], the recommended block size parameter is r = 8 . With this parameter, the initial input block for SMix is only 1 kB, making it suitable for the cache. However, the SMix function expands this 1 kB block into an array of N blocks. These blocks are then accessed iteratively in a pseudorandom order determined by the contents of previously accessed blocks. If N is sufficiently large, the SMix function becomes memory-bound, resulting in significant computational costs for running s c r y p t .
Algorithm 1  S c r y p t algorithm
Input: passwd, passwdlen, salt, saltlen, N, r, p
 
       / / ( B 0 B p 1 ) P B K D F 2 ( P , S , 1 , p × M F L e n )
1:
PBKDF 2 SHA 256 (passwd, passwdlen, salt, saltlen, 1, B, p × 128 × r)
 
2:
for (i = 0 to i < p) :
3:
   SMix( B i , N )     / / B i M F ( B i , N )
 
/ / D K P B K D F 2 ( P , B , 1 , d k L e n )
4:
PBKDF 2 SHA 256 (passwd, passwdlen, B, p × 128 × r, 1, buf, buflen)
Algorithm 2  B L O C K M I X s a l s a 8 and SMix algorithms
1:
function SMix(B, N)
2:
X B
3:
for (i = 0 to i < N) :
4:
    V i X
5:
    X B L O C K M I X s a l s a 8 ( X )
 
6:
for (i = 0 to i < N) :
7:
    j I n t e g e r i f y ( X ) mod N
8:
    X B L O C K M I X s a l s a 8 ( X V j )
 
9:
function B L O C K M I X s a l s a 8
10:
X B 2 r 1
11:
for (i = 0 to i < 2 × r ) :
12:
X s a l s a 20 8 ( X B i )
13:
Y i X

3. Quantum Circuit on Scrypt

In this section, we describe the implementation of s c r y p t in a quantum circuit. The key operations of s c r y p t include SMix and PBKDF2SHA256. Within the SMix function, the Salsa20/8 (Salsa20/8 is the 8-round version of Salsa20 [30]) algorithm is utilized, and the SHA-256 algorithm is employed within the PBKDF2SHA256 function.
The ultimate goal of our s c r y p t quantum circuit implementation is to reduce the circuit complexity, i.e., the product of time and space complexity (DW cost; width × T-depth), by adjusting the depth-width balance of the s c r y p t quantum circuit to be used in the Grover Oracle. To achieve this, we introduced parallel structures and optimization methods into the s c r y p t quantum circuit. We designed a structure for SHA-256 that significantly reduces the number of ancilla qubits with only a slight increase in depth. To minimize the number of ancilla qubits used in each round, we cleaned and reused the dirty ancilla qubits from the previous round through inverse operations, allowing their continuous use in each round. In the salsa20/8 function within SMix, we avoided using ancilla qubits for storing intermediate values during the ‘Operation on columns’ and ‘Operate on rows’ steps. Instead, we updated the intermediate values directly in the inputs. When the pre-update values were needed for subsequent operations, we used the updated values and then applied inverse operations to restore the pre-update values. Thus, we did not use ancilla qubits to store the updated results. This approach allowed the inverse operations to restore the updated qubits to their pre-update state, and the internal additions operated partially in parallel with subsequent operations, thereby reducing the overall depth. As a result, we added the inverse operation to reduce the number of qubits, but it did not significantly affect the full depth.

3.1. Notation

In this paper, qubits are represented as arrays. For example, a 32-length qubit x is written as x [ i ] , where 0 i 31 . An array declared with a certain data type, such as an unsigned 32-bit integer array X [ n ] , is represented as an n × 32 array. To avoid confusion, we distinguish between one-dimensional and two-dimensional qubit arrays using lowercase and uppercase letters, respectively (lowercase: one-dimensional qubit arrays, uppercase: two-dimensional qubit arrays). We use mixing-XOR (hereafter called m-XOR) in the internal optimization process. m-XOR, introduced in [13], is a method that transforms the creating operations of CNOT gates into updating operations to minimize qubit usage. Here, a creating operation refers to an out-of-place operation that stores the result of a b in c ( c = a b ), while an updating operation refers to an in-place operation that stores the result of a b in qubit b ( b = a b ).

3.2. Addition in Scrypt

SHA-256 in PBKDF2 and Salsa20/8 in the SMix function use the ( 2 n + 3 ) -depth quantum adder proposed in [31]. The quantum adder uses n-bit a and b as inputs along with a 1-bit ancilla c, performing an in-place addition: A D D ( a , b , c ) = ( a , a b , c ) . Here, a retains its original value, while b is updated to a⊕b. The ancilla c is input in a clean | 0 state and remains clean after the operation, allowing it to be reused in subsequent addition operations. Consequently, this quantum circuit allows for addition using only a single qubit as the ancilla.

3.3. SHA-256 in P B K D F 2 S H A 256

Within the password-based key derivation function 2 ( P B K D F 2 S H A 256 ), SHA-256 operates. We implemented the SHA-256 quantum circuit in P B K D F 2 by significantly reducing ancilla qubits while slightly increasing the depth. The operations performed in SHA-256 are as follows:
  • Ch ( x , y , z ) = ( ( x & ( y   ^ z ) )   ^ z ) ;
  • Maj ( x , y , z ) = ( ( x & ( y | z ) ) | ( y & z ) ) ;
  • SHR ( x , n ) = ( x n ) ;
  • ROTR ( x , n ) = ( ( x n ) | ( x ( 32 n ) ) )
  • S 0 ( x ) = ( R O T R ( x , 2 )   ^ R O T R ( x , 13 )   ^ R O T R ( x , 22 ) ) ;
  • S 1 ( x ) = ( R O T R ( x , 6 )   ^ R O T R ( x , 11 )   ^ R O T R ( x , 25 ) ) ;
  • s 0 ( x ) = ( R O T R ( x , 7 )   ^ R O T R ( x , 18 )   ^ S H R ( x , 3 ) ) ;
  • s 1 ( x ) = ( R O T R ( x , 17 )   ^ R O T R ( x , 19 )   ^ S H R ( x , 10 ) ) .
Algorithms 3–5 illustrate the quantum circuits for S 0 , S 1 , and  M a j functions in P B K D F 2 S H A 256 , respectively. We propose a method to reuse ancilla qubits ( S 0 a n c , S 1 a n c , and M a j a n c 1 , 3 in the algorithms) by returning them to a clean | 0 state through inverse operations, allowing them to be reused in each iteration of the functions. Thus, inverse operations can reset ancilla qubits to | 0 , enabling their reuse in all loops.
We reduce the full depth of the quantum circuit by ensuring that the S 1 , S 0 , and  M a j operations run in parallel with subsequent operations. Figure 2 illustrates the parallel processing of the RND operations within SHA-256. S 1 and S 0 run in parallel with the subsequent operations C h and M a j , respectively, while M a j operates in parallel with the Add operation of the next RNDr function. Using this method, we reduced the number of qubits by 8128 with only a slight increase in depth (approximately 6) when SHA-256 operates once. As a result, the  S 0 a n c , S 1 a n c , and M a j a n c 1 , 3 qubits can continue to be reused in the next round of the RNDr function in P B K D F 2 S H A 256 .
Algorithm 3  S 0 quantum circuit in SHA-256
Input: x, h, S 0 a n c
1:
⋄Point 1: Start inverse operation
2:
for (i = 0 to 32) :
3:
    S 0 a n c [ i ] C N O T ( x [ ( i + 2 ) % 32 ] , S 0 a n c [ i ] )
4:
    S 0 a n c [ i ] C N O T ( x [ ( i + 13 ) % 32 ] , S 0 a n c [ i ] )
5:
    S 0 a n c [ i ] C N O T ( x [ ( i + 22 ) % 32 ] , S 0 a n c [ i ] )
6:
⋄Point 2: End inverse operation
 
7:
h A d d ( S 0 a n c , h )
 
8:
⋄Start inverse operation from Point 1 to Point 2.
Algorithm 4  S 1 quantum circuit in SHA-256
Input: x, h, S 1 a n c
1:
⋄Point 1: Start inverse operation
2:
for (i = 0 to 32) :
3:
    S 1 a n c [ i ] C N O T ( x [ ( i + 6 ) % 32 ] , S 1 a n c [ i ] )
4:
    S 1 a n c [ i ] C N O T ( x [ ( i + 11 ) % 32 ] , S 1 a n c [ i ] )
5:
    S 1 a n c [ i ] C N O T ( x [ ( i + 25 ) % 32 ] , S 1 a n c [ i ] )
6:
⋄Point 2: End inverse operation
7:
h A d d ( S 1 a n c , h )
 
8:
/ / Reset S 1 a n c to clean | 0
 
9:
⋄Start inverse operation from Point 1 to Point 2.
The quantum circuits of s 0 and s 1 are shown in Algorithms 6 and 7. In s 0 and s 1 , the SHR operation performs an n-bit right shift, filling the n-bit portion with zeros, so CNOT does not operate in this n-bit region. Consequently, we omitted the shift operation by not applying CNOT in the n-bit portion. To exclude the CNOT operation for n bits, the number of loop iterations is set to 32 n (where n = 3 , 10 ) in line 4 of Algorithms 6 and 7. This approach can reduce the use of CNOT gates. Additionally, through the m-XOR method, we modified the result of C N O T ( R O T R ( x , 17 ) , a n c i l l a ) and C N O T ( R O T R ( x , 18 ) , a n c i l l a ) for subsequent unused h to C N O T ( R O T R ( x , 17 ) , h ) and C N O T ( R O T R ( x , 19 ) , h ) , thereby reducing the number of ancilla qubits. ROTR performs an n-bit right rotation, but in a quantum computer that executes bitwise operations, the rotation operation can be omitted by adjusting the indices of the control qubits.
Algorithm 5  M a j quantum circuit in SHA-256
Input: x, h, M a j a n c 1 , M a j a n c 2 , M a j a n c 3
1:
for (i = 0 to 32) :
2:
    M a j a n c 1 [ i ] T o f f o l i ( y [ i ] , z [ i ] , M a j a n c 1 [ i ] )
 
3:
/ / OR-gate operation
4:
for (i = 0 to 32) :
5:
    y [ i ] X ( y [ i ] )
6:
    z [ i ] X ( z [ i ] )
7:
    M a j a n c 2 [ i ] T o f f o l i ( y [ i ] , z [ i ] , M a j a n c 2 [ i ] )
8:
    y [ i ] X ( y [ i ] )
9:
    z [ i ] X ( z [ i ] )
10:
    M a j a n c 2 [ i ] X ( M a j a n c 2 [ i ] )
 
11:
for (i = 0 to 32) :
12:
    M a j a n c 3 [ i ] T o f f o l i ( x [ i ] , M a j a n c 2 [ i ] , M a j a n c 3 [ i ] )
 
13:
/ / OR-gate operation (Reset M a j a n c 2 )
14:
for (i = 0 to 32) :
15:
    y [ i ] X ( y [ i ] )
16:
    z [ i ] X ( z [ i ] )
17:
    M a j a n c 2 [ i ] T o f f o l i ( y [ i ] , z [ i ] , M a j a n c 2 [ i ] )
18:
    y [ i ] X ( y [ i ] )
19:
    z [ i ] X ( z [ i ] )
20:
    M a j a n c 2 [ i ] X ( M a j a n c 2 [ i ] )
 
21:
/ / OR-gate operation.
22:
for (i = 0 to 32) :
23:
    M a j a n c 1 [ i ] X ( M a j a n c 1 [ i ] )
24:
    M a j a n c 3 [ i ] X ( z [ i ] )
25:
    M a j a n c 2 [ i ] T o f f o l i ( M a j a n c 1 [ i ] , M a j a n c 3 [ i ] , M a j a n c 2 [ i ] )
26:
    M a j a n c 1 [ i ] X ( M a j a n c 1 [ i ] )
27:
    M a j a n c 3 [ i ] X ( M a j a n c 3 [ i ] )
28:
    M a j a n c 2 [ i ] X ( M a j a n c 2 [ i ] )
 
29:
h A d d ( M a j a n c 2 , h )
 
30:
for (i = 0 to 32) :
31:
    M a j a n c 3 [ i ] T o f f o l i ( y [ i ] , z [ i ] , M a j a n c 3 [ i ] ) / / Reset M a j a n c 3
32:
    M a j a n c 1 [ i ] T o f f o l i ( y [ i ] , z [ i ] , M a j a n c 1 [ i ] ) / / Reset M a j a n c 1
Algorithm 6  s 0 quantum circuit in SHA-256
Input: x, h
1:
for (i = 0 to 32) :
2:
    h [ i ] C N O T ( x [ ( i + 7 ) % 32 ] , h [ i ] )
3:
    h [ i ] C N O T ( x [ ( i + 18 ) % 32 ] , h [ i ] )
 
4:
/ / h update
5:
for (i = 0 to 32 − 3) :
6:
    h [ i ] C N O T ( x [ i + 3 ] , h [ i ] )
Algorithm 7  s 1 quantum circuit in SHA-256
Input: x, h
1:
for (i = 0 to 32) :
2:
    h [ i ] C N O T ( x [ ( i + 17 ) % 32 ] , h [ i ] )
3:
    h [ i ] C N O T ( x [ ( i + 19 ) % 32 ] , h [ i ] )
 
4:
/ / h update
5:
for (i = 0 to 32 − 10) :
6:
    h [ i ] C N O T ( x [ i + 10 ] , h [ i ] )

3.4. Salsa20/8 in SMix

Salsa20/8 is the eight-round version of Salsa20 and is used within the SMix function of s c r y p t . Figure 3 and Figure 4 illustrate the operations in the columns and rows of Salsa20/8, respectively. In the Figure, + represents the in-place addition of two qubits, while + performs the inverse addition. Each CNOT operation performs a right shift of n bits (⋘n) on the control qubit. Instead of separately performing the shift operation on the control qubit, we adjusted the index to operate. We will refer to this method as index-rotating, which allows us to omit the shift operation on the qubits. X is a 16 × 32 array of qubits and is denoted as X [ i ] [ j ] (where 0 i 16 and 0 j 32 ). Therefore, X [ 0 ] , X [ 1 ] , , X [ 15 ] represent an array of 32 qubits. The CNOT gate for a two-dimensional array X, i.e., CNOT( X [ i 1 ] , X [ i 2 ] ), involves XOR operations between X [ i 1 ] [ j ] and X [ i 2 ] [ j ] , where j ranges from 0 to 31. Thus, 32 CNOT gates are used. The Add operation utilizes the adder described in Section 3.2.

4. Evaluation

In this paper, we optimized the quantum circuit for s c r y p t by adjusting the width–depth balance. To operate Grover’s algorithm, the quantum circuit of the target cipher, s c r y p t in this case, must be placed inside the oracle. This allows us to estimate the quantum resources needed for Grover’s key search. We presented a quantum circuit for s c r y p t . Table 3 and Table 4 show the estimated quantum resources for the internal functions of s c r y p t . The quantum resources needed for these quantum circuits were estimated using the ProjectQ tool [19]. We designed a structure for SHA-256 that significantly reduces the number of ancilla qubits with only a slight increase in depth. To minimize the number of ancilla qubits allocated in each round, we cleaned the dirty ancilla qubits used in the previous round through inverse operations, allowing continuous use in each round. In the S0 function, 2048 ancilla qubits were used (64 loops × 32), and in the S1 function, 2048 ancilla qubits were used (64 loops × 32). In the Maj function, 6144 ancilla qubits were used (64 loops × 96). However, through inverse operations, we reduced the number of ancilla qubits to 32 in the S0 function, 32 in the S1 function, and 2048 in the Maj function (64 loops × 32), reducing a total of 8128 qubits. The inverse operations were designed to run in parallel with subsequent operations, resulting in an increase of only 6 in the total depth of the quantum circuit used for inverse operations. Furthermore, in Salsa20/8 within SMix, we reused qubits through inverse operations and performed some parallel operations to reduce both the number of qubits and the full depth, while the m-XOR and index-rotating techniques were used to reduce the number of quantum gates. As a result, our quantum circuit ultimately showed a significant reduction in width (number of qubits) with almost no increase in full depth.

5. Conclusions

In this paper, we applied optimization techniques to reduce the DW cost in a s c r y p t quantum circuit. By implementing inverse operations, we reduced the number of qubits used, and by designing a parallel structure, we minimized the circuit’s depth. We also estimated the quantum resources required for this implementation. To the best of our knowledge, this is the first quantum circuit implementation of s c r y p t . Therefore, these findings will serve as a foundation for future s c r y p t quantum circuit implementations and can be used to assess the quantum security level.

Author Contributions

Software, G.S.; Investigation, G.S.; Writing—original draft, G.S.; Writing—review & editing, H.S.; Supervision, H.S. All authors have read and agreed to the published version of the manuscript.

Funding

This research was financially supported by Hansung University.

Data Availability Statement

Data are contained within the article.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Shor, P.W. Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Rev. 1999, 41, 303–332. [Google Scholar] [CrossRef]
  2. Grover, L.K. A fast quantum mechanical algorithm for database search. In Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing, Philadelphia, PA, USA, 22–24 May 1996; pp. 212–219. [Google Scholar]
  3. Song, G.J.; Jang, K.B.; Seo, H.J. Resource Estimation of Grover Algorithm through Hash Function LSH Quantum Circuit Optimization. J. Korea Inst. Inf. Secur. Cryptol. 2021, 31, 323–330. [Google Scholar]
  4. Song, G.; Jang, K.; Kim, H.; Seo, H. A Parallel Quantum Circuit Implementations of LSH Hash Function for Use with Grover’s Algorithm. Appl. Sci. 2022, 12, 10891. [Google Scholar] [CrossRef]
  5. Jang, K.; Song, G.; Kwon, H.; Uhm, S.; Kim, H.; Lee, W.K.; Seo, H. Grover on PIPO. Electronics 2021, 10, 1194. [Google Scholar] [CrossRef]
  6. Song, G.; Jang, K.; Kim, H.; Eum, S.; Sim, M.; Kim, H.; Lee, W.; Seo, H. SPEEDY quantum circuit for Grover’s algorithm. Appl. Sci. 2022, 12, 6870. [Google Scholar] [CrossRef]
  7. Song, G.; Jang, K.; Seo, H. Improved Low-Depth SHA3 Quantum Circuit for Fault-Tolerant Quantum Computers. Appl. Sci. 2023, 13, 3558. [Google Scholar] [CrossRef]
  8. Jang, K.; Baksi, A.; Breier, J.; Seo, H.; Chattopadhyay, A. Quantum implementation and analysis of default. Cryptogr. Commun. 2023, 1–17. [Google Scholar] [CrossRef]
  9. Chauhan, A.K.; Sanadhya, S.K. Quantum resource estimates of grover’s key search on aria. In Proceedings 10, Proceedings of the Security, Privacy, and Applied Cryptography Engineering: 10th International Conference, SPACE 2020, Kolkata, India, 17–21 December 2020; Springer: Berlin/Heidelberg, Germany, 2020; pp. 238–258. [Google Scholar]
  10. Anand, R.; Maitra, A.; Mukhopadhyay, S. Grover on SIMON. Quantum Inf. Process. 2020, 19, 340. [Google Scholar] [CrossRef]
  11. Rahman, M.; Paul, G. Grover on KATAN: Quantum resource estimation. IEEE Trans. Quantum Eng. 2022, 3, 1–9. [Google Scholar] [CrossRef]
  12. Jang, K.; Song, G.; Kim, H.; Kwon, H.; Kim, H.; Seo, H. Parallel quantum addition for Korean block ciphers. Quantum Inf. Process. 2022, 21, 373. [Google Scholar] [CrossRef]
  13. Liu, Q.; Preneel, B.; Zhao, Z.; Wang, M. Improved Quantum Circuits for AES: Reducing the Depth and the Number of Qubits. In Proceedings of the International Conference on the Theory and Application of Cryptology and Information Security; Springer: Singapore, 2023; pp. 67–98. [Google Scholar]
  14. Zou, J.; Li, L.; Wei, Z.; Luo, Y.; Liu, Q.; Wu, W. New quantum circuit implementations of SM4 and SM3. Quantum Inf. Process. 2022, 21, 181. [Google Scholar] [CrossRef]
  15. Song, G.; Jang, K.; Kim, H.; Lee, W.K.; Hu, Z.; Seo, H. Grover on SM3. In Proceedings of the Information Security and Cryptology–ICISC 2021: 24th International Conference, Seoul, Republic of Korea, 1–3 December 2021; Revised Selected Papers. Springer: Cham, Switzerland, 2022; pp. 421–433. [Google Scholar]
  16. Grassl, M.; Langenberg, B.; Roetteler, M.; Steinwandt, R. Applying Grover’s algorithm to AES: Quantum resource estimates. In Proceedings of the International Workshop on Post-Quantum Cryptography; Springer: Cham, Switzerland, 2016; pp. 29–43. [Google Scholar]
  17. Huang, Z.; Sun, S. Synthesizing quantum circuits of AES with lower t-depth and less qubits. In Proceedings of the International Conference on the Theory and Application of Cryptology and Information Security; Springer: Cham, Switzerland, 2022; pp. 614–644. [Google Scholar]
  18. Shi, H.; Feng, X. Quantum Circuits of AES with a Low-depth Linear Layer and a New Structure. Cryptol. ePrint Arch. 2024. [Google Scholar]
  19. Steiger, D.S.; Häner, T.; Troyer, M. ProjectQ: An open source software framework for quantum computing. Quantum 2018, 2, 49. [Google Scholar] [CrossRef]
  20. Rollmeister. veriumMiner: Further Aarch64/Armv8 Optimizations. 2023. Available online: https://github.com/rollmeister/veriumMiner (accessed on 31 July 2024).
  21. Novators. EnScrypt: EnScrypt, a Scrypt Based Password Hashing Library. 2023. Available online: https://github.com/Novators/EnScrypt (accessed on 31 July 2024).
  22. Daninet. Hash-Wasm: Lightning Fast Hash Functions Using Hand-Tuned WebAssembly Binaries. 2023. Available online: https://github.com/Daninet/hash-wasm (accessed on 31 July 2024).
  23. Watkins, D. Scrypt mining with ASICS. arXiv 2022, arXiv:2208.02160. [Google Scholar]
  24. National Institute of Standards and Technology. Module-Lattice-Based Key-Encapsulation Mechanism Standard; Federal Information Processing Standards Publication 203; National Institute of Standards and Technology: Gaithersburg, MD, USA, 2023. [Google Scholar]
  25. National Institute of Standards and Technology. Module-Lattice-Based Digital Signature Standard; Federal Information Processing Standards Publication 204; National Institute of Standards and Technology: Gaithersburg, MD, USA, 2023. [Google Scholar]
  26. National Institute of Standards and Technology. Stateless Hash-Based Digital Signature Standard; Federal Information Processing Standards Publication 205; National Institute of Standards and Technology: Gaithersburg, MD, USA, 2023. [Google Scholar]
  27. Nielsen, M.A.; Chuang, I.L. Quantum Computation and Quantum Information; Cambridge University Press: Cambridge, UK, 2010. [Google Scholar]
  28. Bernstein, D.J.; Lange, T. Post-quantum cryptography. Nature 2017, 549, 188–194. [Google Scholar] [CrossRef] [PubMed]
  29. Percival, C. Stronger Key Derivation via Sequential Memory-Hard Functions. 2009. Available online: https://www.bsdcan.org/2009/schedule/attachments/87_scrypt.pdf (accessed on 10 August 2024.).
  30. Bernstein, D.J. The Salsa20 family of stream ciphers. In New Stream Cipher Designs: The eSTREAM Finalists; Springer: Berlin/Heidelberg, Germany, 2008; pp. 84–97. [Google Scholar]
  31. Cuccaro, S.A.; Draper, T.G.; Kutin, S.A.; Moulton, D.P. A new quantum ripple-carry addition circuit. arXiv 2004, arXiv:quant-ph/0410184. [Google Scholar]
Figure 1. Quantum gates.
Figure 1. Quantum gates.
Electronics 13 03167 g001
Figure 2. RNDr function of P B K D F 2 S H A 256 with inverse functions ( S 1 , S 0 , M a j ) operating in parallel.
Figure 2. RNDr function of P B K D F 2 S H A 256 with inverse functions ( S 1 , S 0 , M a j ) operating in parallel.
Electronics 13 03167 g002
Figure 3. Operation on columns in Salsa20/8.
Figure 3. Operation on columns in Salsa20/8.
Electronics 13 03167 g003
Figure 4. Operation on rows in Salsa20/8.
Figure 4. Operation on rows in Salsa20/8.
Electronics 13 03167 g004
Table 1. NIST post-quantum security level categories.
Table 1. NIST post-quantum security level categories.
LevelCipherCategory
1AES 128 2 157 / MAXDEPTH quantum gates
3AES 192 2 221 / MAXDEPTH quantum gates
5AES 256 2 285 / MAXDEPTH quantum gates
Table 2. Parameters in s c r y p t .
Table 2. Parameters in s c r y p t .
ParametersMeaningRemarks
passwdPassword entered by user-
passwdlen; len (pwd)Length of the password-
saltA unique, randomly generated valueA positive integer
saltlen; len (salt)Length of the salt-
NCPU/memory cost parameterA power of two
rBlock size parameterA positive integer
pParallelization parameterA positive integer satisfying
Table 3. Quantum resource estimation for the s c r y p t quantum circuit.
Table 3. Quantum resource estimation for the s c r y p t quantum circuit.
FunctionQubitQuantum Gates
ToffoliCNOTX
SHA-256 in PBKDF217,10058,448137,88863,231
Salsa20/8 in SMix104016,592145,77616,060
Table 4. Quantum resource (decomposed quantum gate) estimation for the s c r y p t quantum circuit and DW cost.
Table 4. Quantum resource (decomposed quantum gate) estimation for the s c r y p t quantum circuit and DW cost.
FunctionQuantum GatesT-DepthFull DepthDW-Cost
TT
SHA-256 in PBKDF2179,230225,774292,240138,358 1.1 × 2 31
Salsa20/8 in SMix57,44858,42482,96035,050 1.28 × 2 26
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Song, G.; Seo, H. Grover on Scrypt. Electronics 2024, 13, 3167. https://doi.org/10.3390/electronics13163167

AMA Style

Song G, Seo H. Grover on Scrypt. Electronics. 2024; 13(16):3167. https://doi.org/10.3390/electronics13163167

Chicago/Turabian Style

Song, Gyeongju, and Hwajeong Seo. 2024. "Grover on Scrypt" Electronics 13, no. 16: 3167. https://doi.org/10.3390/electronics13163167

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop