{'fraction_non_alphanumeric': 0.03882847421442391, 'fraction_numerical': 0.037560877977183264, 'mean_word_length': 3.9455625206202574, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Algebraic Fault Analysis of SHA-256 Compression Function and Its Application

: Cryptographic hash functions play an essential role in various aspects of cryptography, such as message authentication codes, pseudorandom number generation, digital signatures, and so on. Thus, the security of their hardware implementations is an important research topic. Hao et al. proposed an algebraic fault analysis (AFA) for the SHA-256 compression function in 2014. They showed that one could recover the whole of an unknown input of the SHA-256 compression function by injecting 65 faults and analyzing the outputs under normal and fault injection conditions. They also presented an almost universal forgery attack on HMAC-SHA-256 using this result. In our work, we conducted computer experiments for various fault-injection conditions in the AFA for the SHA-256 compression function. As a result, we found that one can recover the whole of an unknown input of the SHA-256 compression function by injecting an average of only 18 faults on average. We also conducted an AFA for the SHACAL-2 block cipher and an AFA for the SHA-256 compression function, enabling almost universal forgery of the chopMD-MAC function.


Background
Side-channel attacks are severe threats to hardware implementations of cryptographic algorithms. Fault attacks (FAs) are side-channel attacks that intentionally cause faults in the cryptographic process on a hardware device and try to recover the secret information from internal information that is not usually output. They can cause faults, for example, by irradiating electromagnetic waves, such as lasers, or by manipulating the device's voltage. Fault attacks were first proposed by Boneh et al. in 1996 [1,2], and then Biham and Shamir proposed a differential fault analysis (DFA) for DES in 1997 [3]. The basic principle of DFAs is to recover the secret key by using the output difference between normal and fault-injected executions and the cryptographic algorithm from the point of fault injection to the output. DFAs were also applied to other ciphers [4][5][6]. In addition, DFAs on the compression functions of cryptographic hash functions were studied. Hemme et al. proposed a DFA against the SHA-1 compression function using a 32-bit random fault model [7]. Based on this attack, DFAs were also applied to the HAS-160 [8] and MD5 [9] compression functions. On the other hand, Courtois et al. proposed an algebraic fault analysis (AFA) for DES [10]. An AFA can analyze more information than a DFA and recover secret information with fewer fault injections. AFAs were also applied to other ciphers [11,12].
When performing an AFA, a SAT solver and an SMT solver are used to solve algebraic equations. A SAT solver is a program that judges whether a given problem is satisfiable or not and outputs a solution if it is satisfiable. The problem is given in the form of a CNF formula. An SMT solver is an extension of the SAT solver for propositional logic and deals with predicate logic satisfiability problems. STP [13] is a kind of SMT solver, which solves bit-vector theory. STP converts a given problem into a CNF equation and then calls a SAT solver to solve it. The SAT solver we used was CryptoMiniSat 5 [14], which is capable of processing cryptographic problems quickly.

Related Work
SHA-2 is a family of cryptographic hash functions standardized by NIST in FIPS PUB 180-4 [15]. SHA-256 is included in the family. It is widely deployed and is one of the most important cryptographic hash functions. HMAC is a MAC function standardized by NIST in FIPS PUB 198-1 [16].
Jeong et al. [17] recovered the secret key of HMAC/NMAC-SHA-2 by injecting a fault during the computation of HMAC/NMAC and reducing the number of steps in the SHA-2 compression function. Their fault model assumes that an attacker can change the number of steps in the SHA-2 compression function. Hao et al. [18] proposed an AFA for the SHA-256 compression function using a 32-bit random fault model. They recovered the whole of an unknown input of the SHA-256 compression function by injecting 65 faults. They also presented an almost universal forgery attack on HMAC-SHA-256 based on this result. Nejati et al. [19] assumed an advanced fault injection device and improved the AFA by Hao et al. [18] in 2018. They recovered the whole of an unknown input message block of the SHA-256 compression function with fewer fault injections.

Our Contribution
We first conducted computer experiments on various fault injection conditions and showed that one can recover the whole of an unknown input of the SHA-256 compression function by injecting about 18 faults on average. While our AFA reduces the number of fault injections compared to that of Hao et al., it requires more time to solve algebraic equations. However, a standard PC can solve them in less than an hour, and it still seems practical. Next, we performed an AFA for the block cipher SHACAL-2 [20]. It can recover the secret key with 12 fault injections by using a standard PC to solve algebraic equations in less than an hour. Finally, we performed an AFA for the SHA-256 compression function, which enabled almost universal forgery of the chopMD-MAC function [21].

Organization
In Section 2, we describe the SHA-256 compression function, the block cipher SHACAL-2, and the chopMD-MAC function. We also review the AFA for the SHA-256 compression function of Hao et al. In Section 3, we first describe the results of computer experiments on the AFA of Hao et al. and show that the number of injected faults can be greatly reduced. Next, we present the results of the AFA for SHACAL-2 and the AFA for the SHA-256 compression function, which enables almost universal forgery of the chopMD-MAC function. Section 4 is the conclusion.

Materials and Methods
This section describes the SHA-256 compression function [15], the SHACAL-2 block cipher [20], and the chopMD-MAC function [21]. We also review the AFA for the SHA-256 compression function of Hao et al. [18]. The algorithm of the SHA-256 compression function is described below. It is also depicted in Figure 1. In the following description, the operation + denotes addition modulo 2 32 , ⊕ denotes bitwise XOR, ∧ denotes bitwise AND, ¬ denotes bitwise NOT, and denotes the concatenation of bit strings. The SHA-256 compression function first divides a given 512-bit message block M as follows:
Next, it assigns an input intermediate hash value to (a 0 , b 0 , . . . , h 0 ) and calculates the following steps for i = 0, 1, . . . , 63 ( Figure 2). a i , b i , . . . , h i are called chaining values, α i , β i are called auxiliary values, and k i is called a step constant.

SHACAL-2
SHACAL-2 [20] is a block cipher based on the SHA-256 compression function. A plain text is given as an intermediate hash value, and a secret key as a message block. The ciphertext is (a 64 , b 64 , . . . , h 64 ). The key length is recommended to be at least 128 bits.

ChopMD-MAC
The chopMD-MAC function [21] adds a chop function to the output of the MD hash function, whose initial value is the secret key. The chop function truncates an n-bit input and outputs an s-bit output ( Figure 3). In this work, we assume that chopMD-MAC uses the SHA-256 compression function (n = 256) and s = 128.

Algebraic Fault Analysis for the SHA-256 Compression Function by Hao et al.
This section reviews the AFA procedure for the SHA-256 compression function in the study by Hao et al. [18]. It assumes that a 32-bit fault is injected into a specified chaining value among a i , b i , . . . , h i (i = 0, 1, . . . , 63). When a fault is injected, the chaining value is changed to a random value unknown to the attacker, and a faulty output is obtained after the cryptographic operation. With the faulty output and the normal output, an algebraic equation is constructed for the operations from the injected fault location to the output. Through repeated fault injection into the same chaining value, multiple algebraic equations are obtained for the same operations. STP is used to solve the algebraic equations.
The process of the AFA for the SHA-256 compression function can be divided into two phases. Phase 1 recovers the chaining value p 63 = (a 63 , b 63 , . . . , h 63 ). Phase 2 recovers the whole input to the SHA-256 compression function.

Phase 1
In this phase, 14 faults are injected into c 60 , and the 14 corresponding faulty outputs are obtained. Next, the algebraic equations are constructed based on the normal and faulty outputs and the operations (including feed-forward operations) for the four steps from 60 to 63. STP solves the algebraic equations and returns a solution for p 63 . Hao et al. reported that they succeeded in recovering p 63 in all of the 100 trials of the procedure above. They also reported that they always succeeded in recovering p 63 in the same way by injecting 13 faults into c 58 or c 59 .
In addition, they examined the number of chaining values p i 's recovered at the same time and the computation time for the cases where 13 faults were injected into one of a 59 , b 59 , . . . , h 59 . The results showed that there was a positive correlation between the number of recovered chaining values and the percentage of computation time larger than 200 s.
Phase 2 proceeds as follows. First, 13 faults are injected into c 56 , and faulty outputs are obtained. For each faulty output Y * , the corresponding faulty chaining value p * 63 is calculated. Based on these values, the algebraic equations for the seven steps from 56 to 62 are constructed. Subsequently, STP solves them and finds the values of w 59 , w 60 , w 61 , w 61 , w 62 . Hao et al. claimed that they were successful in all of their 100 trials.
Second, 13 faults are injected into c 52 . For each faulty output Y * , the faulty chaining value p * 63 is calculated in the same way as above. For faulty p * 63 and non-faulty p 63 , p * 59 and p 59 are calculated, respectively, with recovered w 59 , w 60 , w 61 , w 62 . Then, based on p * 59 and p 59 , algebraic equations for the seven steps from 52 to 58 are constructed. STP solves them and finds the values of w 55 , w 56 , w 57 , w 58 .
In a similar way, by injecting faults into c 48 and c 44 , w 51 , w 52 , w 53 , w 54 and w 47 , w 48 , w 49 , w 50 are recovered. The input message block m 0 m 1 · · · m 15 can be calculated from the recovered w 47 , . . . , w 62 according to the message schedule. Once the input message block is recovered, w 63 can be calculated. Next, p 64 can be calculated from p 63 and w 63 , and the input intermediate hash value p 0 = H − p 64 is recovered.
In summary, by injecting 65 32-bit random faults in total (13 faults are injected five times), the whole input of the SHA-256 compression function can be recovered.

Detailed Examination of AFA
We conducted computer experiments on various fault-injection conditions in the AFA for the SHA-256 compression function described in Section 2. In the experiments, we implemented the SHA-256 compression function in the C language and simulated fault injections. STP was used as an automatic tool, and CryptoMiniSat5 was used as a SAT solver. The experiments were performed on a PC with Intel(R) Xeon(R) Silver 4110 CPU @ 2.10 GHz, 32 G memory, and Ubuntu 18.04.3 LTS.
For Phase 1, we first injected 13 faults into each of the chaining values from a 60 to h 60 , and tried to recover as many chaining values p i = (a i , b i , . . . , h i ) as possible. The results are shown in Table 1. The computation time is the average of 100 trials. The results show that the fault injections into e 60 can recover more chaining values than the fault injections into other positions. Next, we changed the number of faults injected into c 60 or e 60 in Phase1 and c 56 or e 56 in Phase 2 and measured the number of times the correct chaining values were recovered out of 100 trials. The results are shown in Tables 2 and 3 for Phase 1 and Phase 2, respectively. For Phase 1, except for the cases where four or fewer faults were injected, the correct chaining values were recovered with higher probabilities when faults were injected into e 60 than when faults were injected into c 60 . For Phase 2, even when only three faults were injected into e 56 , all 100 trials were successful. Table 2. Success rate and average time for each number of faults (Phase 1). "-" indicates that the result was not output within 72 h.

Phase 1 Fault Position c 60
Fault Position e 60  From the experimental results described above, the procedure of AFA with the smallest expected number of faults (with the cases of the colored parts in Tables 2 and 3) is given below.

Number of Faults
Phase 1: Inject five faults into e 60 and recover the chaining value p 63 . Phase 2: (1) Inject three faults into e 56 and recover w 59 , w 60 , w 61 , and w 62 .

AFA for SHACAL-2
Since SHACAL-2 feeds the key to the message input of the SHA-256 compression function, the goal of the AFA is to recover the message input of the SHA-256 compression function. SHACAL-2 outputs the chaining value (a 64 , b 64 , . . . , h 64 ) as a ciphertext without the feed-forward operation of the SHA-256 compression function. Thus, we can start the AFA with Phase 2 in Section 2. The procedure is shown below: (1) Inject three faults into e 57 and recover w 60 , w 61 , w 62 , and w 63 .
For the procedure with 12 fault injections in total, all of 100 trials were successful. The total computation time was about 33 min.

AFA for Almost Universal Forgery of chopMD-MAC
For almost universal forgery of the chopMD-MAC function, we recover the hash value input (a 0 , b 0 , . . . , h 0 ) of the SHA-256 compression function under the condition that the message input and only 128 bits of the 256-bit output are known. Since (a 0 , b 0 , . . . , h 0 ) can be calculated from p 63 and the message input, only p 63 has to be recovered.
We assumed that the chop function outputs four words among the eight-word output (Y a , Y b , . . . , Y h ) of the SHA-256 compression function. We injected 14 faults into c 60 and analyzed the SHA-256 compression function under the condition mentioned above. Since we found that the SHA-256 compression function does not propagate the faults to Y h , we excluded the cases that the chop function outputs Y h . We verified all the other 35 cases. Table 4 shows all the successful cases (p 63 was recovered). The success rate is for 10 trials.

Conclusions
In this study, we changed the fault-injection condition of the AFA for the SHA-256 compression function in the study by Hao et al. and conducted computer experiments. We found that the whole input of the SHA-256 compression function can be recovered with a smaller number of faults. We also demonstrated the results of computer experiments on the AFA for SHACAL-2 and the AFA for the SHA-256 compression, which enabled almost universal forgery of chopMD-MAC. Future work should include an AFA for the SHA-512 compression function.