Search-Space Reduction for S-Boxes Resilient to Power Attacks

: The search of bijective n × n S-boxes resilient to power attacks in the space of dimension ( 2 n ) ! is a controversial topic in the cryptology community nowadays. This paper proposes partitioning the space of ( 2 n ) ! S-boxes into equivalence classes using the hypothetical power leakage according to the Hamming weights model, which ensures a homogeneous theoretical resistance within the class against power attacks. We developed a fast algorithm to generate these S-boxes by class. It was mathematically demonstrated that the theoretical metric confusion coefﬁcient variance takes constant values within each class. A new search strategy—jumping over the class space—is justiﬁed to ﬁnd S-boxes with high confusion coefﬁcient variance in the space partitioned by Hamming weight classes. In addition, a decision criterion is proposed to move quickly between or within classes. The number of classes and the number of S-boxes within each class are calculated, showing that, as n increases, the class space dimension is an ever-smaller fraction of the space of S-boxes, which signiﬁcantly reduces the space of search of S-boxes resilient to power attacks, when the search is performed from class to class.


Introduction
Technology has taken an important role in modern society, increasing the amount of transmitted information. The methods for data encryption protect the access to such information and ensure its confidentiality. In particular, in symmetric cryptography, in block cipher design, particularly, S-boxes are essential components that provide the confusion on encryption and decryption processes [1].
Traditional S-box design criteria focus on the resistance to differential and linear attacks [2,3]. Some S-box transformations, equivalences and classes have been proposed to address this goal. In [4], Biryukov et al. presented algorithms to detect linear and affine equivalences between two S-boxes. They solved the affine equivalence problem by finding unique representatives for the linear equivalence classes. Leander et al. [5] classified all optimal 4-bit S-boxes into 16 different affine equivalence classes, given a representative for each class. The classification criteria were the optimal values for S-boxes concerning linear and differential cryptanalysis, known as values for dimension four. Such a result is remarkable and relevant because exhaustively checking all permutations to find good S-boxes is not a feasible option; the number of mappings from n-bit to n-bit is large; and the classification into optimal classes reduces the work and helps find the most area-efficient S-box.
Despite the encouraging results in traditional S-box design [6], some other interesting approaches from combinatorial optimization have arisen [7,8]. The rising number of cyber-The paper is structured as follows. Section 2 includes the necessary basics concepts. Section 3 presents the contributions about the new equivalence relationship; the Hamming weight equivalence classes and their representatives; the algorithm to generate the S-boxes into each class; and the theoretical demonstration and experimental verification that random S-boxes of a class have the same resistance to power attacks. The number of classes and the number of S-boxes within each class are calculated, showing that, as n increases, the class space dimension is an ever-smaller fraction of the space of S-boxes, which significantly reduces the space of search of S-boxes resilient to power attacks, when the search is performed from class to class. Finally, Section 4 provides concluding remarks.

Basic Concepts
We begin by stating some basic definitions. Bijective S-boxes are vector functions used in most block ciphers, represented as a mapping F : {0, 1} n → {0, 1} n , n ∈ N. For each binary vector x ∈ {0, 1} n , HW(x) represents the Hamming weight of x [10]. Its objective is to cause the greatest possible confusion by masking the relationship between the plain text and the ciphertext [2,19].
The correlation power attack (CPA) [20] uses the linear correlation coefficient as a distinction to quantify the statistical dependence between the real power leak Y k,p generated from the K key and the hypothetical leak X j,p calculated with the model from the assumed key J.
In the Hamming weight model [2], the hypothetical leakage X j,p of the power consumption evaluating an S-box is represented by the value X j,p = HW(F(j ⊕ p)), where F is the S-box, p represents the clear text and j is the assumed subkey to encrypt the plain text.
S-boxes have a set of properties that allow for the evaluation of their cryptographic quality, such as the high degree of nonlinearity (NL) that protects against linear attacks. The coefficient of confusion (CC) and the confusion coefficient variance (CCV) are two of the used metrics to measure resistance to differential power attacks (DPA). The coefficient of confusion (CC) theoretical metric was introduced by Y. Fei et al. in 2012 [21], who defined the confusion coefficient κ over two keys (k i , k j ) as: where N t is the total number of values for the relevant cipher-text bits and N (L|k i ) =(L|k j ) is the number of occurrences for which different key hypotheses k i and k j result in different L values. In the DPA model, L has only two possible outcomes 0 and 1, but, in other power attack models, L can take more than two values. Then, in [22], the authors defined a general confusion coefficient as: Particularly, under the DPA model, In [15], Picek et al. considered κ(k i , k j ) equal to the expected value E P (among all the possible p plain texts) of the distance between the power leaks L(F(k i ⊕ p)) and L(F(k j ⊕ p)), using the pair of keys k i and k j , i.e., and proposed to take a new theoretical metric as the variance (σ 2 ) of the CC vector over all possible pairs of keys: When using the Hamming weight leakage model as the L function, the CCV is: We expect that arbitrary keys, different from a real key, will look the same for the DPA attack at a higher value of variance. It increases the DPA resistance of the S-box [22,23]. Next, we recall the Stirling formula for factorial calculation. The value of n! grows extremely quickly, but, for large values of n, it can be estimated using the well-known Stirling formula (see Table 1), the full proof of which appears in [24], which, using base 10 logarithm, can be expressed equivalently as: n! = 10 1 2 log(2π)+ 1 2 log(n)+n log(n)−n log(e) .
A refinement of the Stirling formula, in terms of lower and upper bounds is given by

Our Contributions: Reduction of the S-Boxes Search-Space into a Hamming Weight Class SEARCH-Space
In this work, we only work with bijective S-boxes.

S-Boxes HW Equivalent
Definition 1. Two bijective S-boxes F 1 , F 2 of order n × n are called HW equivalent if they have the same leakage of power according to the Hamming weight model, i.e., F 1 , F 2 are HW equivalent if and only if HW(F 1 (x)) = HW(F 2 (x)), for all x ∈ {0, . . . , 2 n − 1}.

Proposition 1.
The HW equivalence relationship defined in the space of all S-boxes F of order n × n, is an equivalence relationship.
Proof. It is immediate from the definition that the S-boxes meet the properties of reflexivity, symmetry and transitivity. It proves the HW equivalent relation between the S-boxes. The HW equivalence class < F a > associated with any S-box, F a can be expressed as: This equivalence relation is used to partition the space of bijective S-boxes into Hamming weight classes. The cardinality of the class space is much smaller than the cardinality of the S-box space. According to the confusion coefficient variance, the theoretical resistance to power attacks is constant within each class and can be different between classes. It is proposed to replace the search in the space of S-boxes by the search in the class space Hamming weight (when trying to search for S-boxes resistant to Power attacks). Now, we discuss the representation of the HW classes using the vector of weights of the S-boxes outputs that compose it. Considering that the vector of weights of outputs of the S-boxes that belong to a class is the same for all S-class boxes. This vector of weights is used to represent any class: < F a >= (HW(F a (0)), . . . , HW(F a (2 n − 1))).
Example 1 (PRINT cipher). The following example represents the PRINT S-box F Print (x) and its HW class < F Print >= (0, 1, 2, 2, 3, 1, 2, 1) using its vector of output weights. This S-box has a variance of the CCV confusion coefficient of 0.275510 (see Table 2).
Example 2 (PRESENT). The representation of the PRESENT S-box class < F PRESENT >, through its weight vector, is given in the Appendix A (see Tables A1 and A2).

Example 3 (AES).
The representation of the AES S-box class < F AES >, through its weight vector, is given in the Appendix B (see Tables A3 and A4).
Considering that all S-boxes in a class have the same hypothetical power leakage according to the Hamming weight model, it is theoretically expected that all S-boxes in a class have the same resistance to power attacks. We also look forward in the direction of having some invariant theoretical metric. Proof. In the CCV expression under the Hamming weight leakage model, It can be seen that two HW equivalent S-boxes have the same CCV value because, for all x, HW(F a (x)) = HW(F b (x)), the Hamming weights of the outputs of each S-box are equal to each other for all possible inputs, and therefore the expected value and the variance that define the CCV are equal.
The proposition ensures that two S-boxes of the same class have the same CCV value, but the CCV values of different HW classes could be the same or different. This is a problem that will be investigated in future works.

Redefining the Equivalence Relation and the HW Classes.
For the generation of the elements of each class < F a >, it is convenient to redefine it, representing it from the following (n + 1) subsets: Thus, C(F) k is the set of inputs of the S-box F whose outputs have weight k.
If it is assumed that x exists such that x ∈ C(F 1 ) k and x / ∈ C(F 2 ) k , then the hypothesis contradicts. On the other hand, assuming that C(F 1 ) k = C(F 2 ) k , ∀k ∈ {0, 1, 2, . . . , n}, if there exists an x ∈ C(F 1 ) k , then x ∈ C(F 2 ) k , and therefore HW(F 1 (x)) = HW(F 2 (x)) = k. By redefining the equivalence relationship, the class associated with the S-box F a can be expressed as: From the redefinition of the class, it is easy to see that it is determined by the (n + 1) sets C(F a ) k , ∀k ∈ {0, . . . , n}.

Generation of HW Equivalent S-Boxes. ESboxG Algorithm
We present an equivalent S-box Generator (ESboxG) (Algorithm 1) to generate S-boxes belonging to a class by permuting elements of C(F a ) k sets.  The complexity of this algorithm is determined by the permutations it performs within the subsets C(F a ) k (Lines 5-10), in particular by the values of the two parameters (nss, mnos). Three possible cases of different complexity are highlighted: • The maximum complexity is reached when all elements of all sub-assemblies are exchanged (maximum values of nss and mnos).

•
The complexity can be reduced by exchanging only elements of a single subset C(F a ) k , (nss = 1). • The minimum complexity is reached when only two elements are permuted within a single subset (nss = 1, mnos = 2).
Proposition 4 (Necessary condition of belonging to the same class). If two S-boxes F a (x) and F b (x) belong to the same class, then C(F a ) 0 = C(F b ) 0 and C(F a ) n = C(F b ) n , or equivalently: Proof. The proof is straightforward and is essentially based on two conditions: 1. The S-boxes of a class are generated by permuting the elements inside the sets C(F a ) k , k = 1, . . . n − 1 2. The sets C(F a ) 0 and C(F a ) n have a single element.
By Condition 2, for each of the sets C(F a ) 0 and C(F a ) n , it is not possible to permute elements of equal weight within the same class.
If an element of one of these sets is permuted, it will necessarily be permuted with an element of a different weight, which immediately leads to another HW class through Condition 1.

Experimental Verification That all S-Boxes of a Class Have the Same Resistance to Power Attacks
SILK is a high level of abstraction simulator that builds a leakage trace based on a source code of an algorithm and several user-defined parameters. As source code, we used the AES cipher, which is executed using a plain text and a key. We also used the default SILK consumption power noise.
The objective of this experiment was to verify that all the S-boxes of a Hamming weight class have the same resistance to power attacks since they all have the same hypothetical power leakage, according to the Hamming weight leakage model. In particular, it was verified that, with the power leakage traces of an arbitrary S-box F a (x), the power attack can be performed on all the S-boxes of its class < F a >. The S-box of the AES cryptographic algorithm was selected as S-box F a (x), taking into account that this S-box is vulnerable to this type of attack. The SILK simulator was used only once to generate the power drain traces of the AES S-box. The proposed HW equivalent relationship theoretically ensure homogeneous DPA resistance within each class. To verify it practically, the following experiment was carried out in two steps: Step 1. With the ESboxG algorithm, 1000 S-boxes belonging to the < F AES > class were generated. The SILK simulator [25] was used to generate the energy leak traces of the AES S-box, using 200 plain texts and the key 00112233445566778899aabbccddeeff. We also used the default SILK consumption power noise. Subsequently, the power attack (CPA) was carried out on the 1000 S-boxes, but, in all cases, the energy leakage generated with the SILK Simulator was used for the first S-box.
It was found that, for each of the 1000 S-boxes generated, the same results were obtained (the correct 16 bytes of the key) as for the first S-box. It is important to note that, in all cases (the 1000 S-boxes), the traces of the first S-box were used. This experimental result confirms that, in practice, HW classes fulfill the theoretically expected property of Section 3.1.
Step 2. The objective of this second step was to illustrate in practice that Step 1 is not obtained with S-boxes that do not belong to the < F AES > class. First, 1000 S-boxes not belonging to the < F AES > class were randomly generated, and the attack was carried out again with the same energy leak traces from step one. Unsurprisingly, no byte was obtained correctly from the key, and the results were different for each S-box.

Experimental Verification of the Constant Value of Confusion Coefficient Variance CCV within HW Classes
To experimentally confirm that the CCV metric has a constant value within each HW class, a sample of 4 HW classes were taken: < F AESCC >, < F SCREAM >, < F AES > and < F STRIBOG >. In each class, 10,000 S-boxes were generated by the ESboxG algorithm, and its CCV value was calculated. The results after experimenting were as expected. For the 10,000 S-boxes, the same constant value of CCV was obtained within the class in each class.
There are differences between the CCV values of the four analyzed classes.
By decreasing these CCV values, the S-boxes are decreased by their theoretical resistance to power attacks as follows: AESCC, SCREAM, AES and STRIBOG (as in [26]).

New Search Strategy for S-Boxes Resistant to Power Attacks Based on HW Classes
This section proposes a new search strategy for S-boxes resistant to power attacks based on the HW classes. It reduces the search space avoiding unnecessary operations. We suggest moving between HW classes and avoiding analyzing all S-boxes in the same class because they have the same DPA resistance. This new partition in classes allows us to define a new approach to search S-boxes with high CCV, and that also satisfies other desirable properties such as high nonlinearity. The proposed new strategy consists of two steps: Step 1. As long as the S-box evaluated has a CCV value less than the desired one, the HW class must be changed.
Step 2. When a high CCV value is reached, it is necessary to search within that class the S-boxes that meet the other cryptographic properties, such as high nonlinearity.
The practical application of this strategy supports two aspects. First, changing classes is enough to swap at least two elements of the input whose outputs have different weights, and, second, the generation algorithm of S-boxes within the class (ESboxG algorithm) is easy to use and not complicated to implement. It is enough to permute two elements within one of the subsets C(F) k defined in Section 3.2.
Different meta-heuristics can be used to perform movement between classes and within classes. The objective function used for the search within the classes will depend on the remaining cryptographic properties of the S-box to be optimized.

Comparison between the Partition of the Space of S-Boxes in Related Classes and Hamming Weight Classes
Properties of the Partition of the space of S-boxes in Affine Classes. 1. Constant cryptographic properties within classes.

-
The nonlinearity is constant within each class: the classes, by way of construction, fulfill the property that all the S-boxes of a class have the same nonlinearity value. This ensures that all S-boxes in a class have the same resistance against linear attacks.

-
Other cryptographic properties are not constant within each class since they were not taken into account for the definition of these classes. For example, the resistance to power attacks is not constant within the class; if measured with the theoretical metric of the confusion coefficient variance (CCV), this metric can take different values for S-boxes that belong to the same class.
2. Movement between classes and within classes.
-Movement within each class: Given an S-box F a , to obtain another S-box F b of the same class, transformations related to F a are performed.

-
Movement between different classes: Given an S-box F a , to obtain another S-box F b belonging to a different class, it is enough that affine transformations do not relate the two S-boxes.
3. Number of classes.

-
The number of affine classes is approximately (2 n )!/|G| 2 , where |G| is the linear or affine group size, as estimated in [27].
Properties of the S-box Space Partition in Hamming Weight Classes (HW) Based on the Theoretical Resistance to Power Attacks According to the Metric of the Confusion Coefficient Variance (CCV).

-
The variance of the confusion coefficient variance (CCV) is constant within each class: the "theoretical" resistance to power attacks is constant within the class. The HW classes, by the way of construction, fulfill the property that all the S-boxes of a class have the same value of the confusion coefficient variance (CCV). This ensures that all S-boxes in a class have the same "theoretical" resistance against power attacks, based on this metric.

-
None of the known theoretical metrics of resistance against Power Attacks is exact, nor is the confusion coefficient variance (CCV), therefore, the actual resistance against these attacks is "approximately" constant within the class.

-
Other cryptographic properties are not constant within each class, since they were not taken into account for the definition of these classes. For example, nonlinearity can take different values for S-boxes that belong to the same Hamming weight class.

Movement between classes and within classes.
-Movement within each class: Given an S-box F a , to obtain another S-box F b of the same class, it is necessary and sufficient to swap between two elements of the output of F a that have the same Hamming weight. The swap can be generalized between several pairs of elements, as long as the two elements of each pair have the same weight, which can be different between the pairs. -Movement between different classes: Given an S-box F a , to obtain another S-box F b belonging to a different class, it is necessary and sufficient to perform the swap between two elements of the output that have different Hamming weights.
3. Number of classes.

-
The number of classes and the number of S-boxes in each class are estimated in this work (by two different ways) for any n, by means of Propositions 5 and 6.

-
The number of classes is exponentially less than the number of S-boxes. -For n = 3, in Partition of the 3 × 3 S-box space into equivalence classes, the list of the 1120 HW classes is given.

Quantifying the Search-Space Reduction Achieved Using the Partition into HW Classes Instead of Searching by S-Boxes
In previous sections, a new partition in equivalence classes is proposed for the S-boxes of n × n, denoted as a partition in Hamming weight (HW) classes. According to the Hamming weight model, all S-boxes in an HW class have the same hypothetical power leakage. According to the CCV metric, we experimentally verified that all S-boxes of a class have the same theoretical resistance to power attacks. Based on this result, we propose a new strategy consisting of going through the class space and not the S-box space, and we argue that this reduces the search space, when the search is performed from class to class.
In this section, for the S-boxes of n × n, we obtain the expression of the exact number of Hamming weight classes and the number of S-boxes within each class. Using this expression, we quantify the reduction in the search space associated with this new strategy. In particular, it is shown that, as n increases, the number of classes represents an increasingly smaller proportion of the number of S-boxes. For n = 3, 4, 5, 6, 7, 8, we calculate the total number of classes, the number of S-boxes per class and the reduction achieved in the search space when going through the class space HW and not the space of S-boxes.

Estimate of the Number of HW Classes and the Number of S-Boxes in Each Class as Permutation with Repetition
Proposition 5 (Calculating the number of HW classes). When the space of (2 n )! S-boxes of dimension n × n is partitioned into Hamming weight (HW) classes: (a) The total number of HW equivalence classes is: PR C(n,0),...,C(n,n) 2 n = (2 n )! ∏ n r=0 C(n,r)! . (b) The total number of S-boxes in each HW equivalence class is: ∏ n r=0 C(n, r)!.
Proof. The demonstration is direct because the HW classes definition meets that each class is equivalent to a permutation with repetition of 2 n elements grouped into (n + 1) groups, where group r has exactly C(n, r) equal elements. Keep in mind that, if the 2 n outputs of the S-boxes {S(X) : X = 0, . . . , 2 n − 1} are grouped by their weights, then the 2 n weights of these outputs { S(X) : S(X) = 0, . . . , 2 n − 1} are divided into (n + 1) groups corresponding to the (n + 1) different values r = 0, . . . , n, which can take their weights { S(X) = r : r = 0, . . . , n}. The essential observation is that classes are defined by the permutations of the positions occupied by the (n + 1) groups. In turn, within a class, the S-boxes are determined by the permutation of the groups' elements. In group r, there are C(n, r) elements (the ways of locating r ones in a binary vector of length n), corresponding to outputs of the S-box whose weights are equal to r. It is important to note that the order is not crucial in each group because all the weights are equal to r (indistinguishable elements). However, the order is essential between groups because they correspond to different weights (distinguishable elements). Therefore, to find the number of HW classes of the S-boxes of n × n, we directly applied the formula PR C(n,0),...,C(n,n) 2 n which calculates the number of permutations with repetition. From here (a) follows.
Given that in group r, there are precise C(n, r) elements equal to r; then, they can be permuted in (C(n, r))! ways. In general, we can permute the elements within the groups in ∏ n r=0 C(n, r)!, which corresponds to the number of S-boxes within a class, demonstrating the statement in (b).
We now dwell in an interpretation of Proposition 5. Notice that the numerator (2 n )! corresponds to the total number of S-boxes of n × n, while the denominator ∏ n r=0 C(n, r)! is the number of S-boxes within a class and its quotient is exactly the number of classes. Although this is an exact expression very appropriate for theoretical analysis, it should be noted that, in practice, for large values of (2 n ) and C(n, r), the calculation of their factorials will be approximate, using the Stirling formula. The following Corollary will be very useful to quantify the reduction of the search space.

Reduced Search-Space
The corollary above provides an inverse measure of the reduction in search space achieved by replacing the S-boxes path with the path over the HW classes. It tells us what fraction of the initial space of S-boxes is reduced by HW's classes space. The lower the value of 1 ∏ n r=0 C(n,r) = 1 ∏ n−1 r=1 C(n,r) , the more significant the reduction achieved when going through the classes and not the S-boxes. Now, we discuss the reduction speed as a function of n. Note that as n increases, the value ∏ n r=0 C(n, r)! grows very quickly and 1 ∏ n r=0 C(n,r)! decreases very rapidly. Note that The above expression shows that as n increases, the class space's dimension becomes an ever-smaller fraction of the S-box space. This fraction decreases very rapidly as n grows.

Examples of the Number of HW Classes, the Number of S-Boxes per Class and the Reduction in Search-Space Achieved with the New Proposed Strategy
In this subsection, we illustrate the previous proposition's application to estimate the search space reduction using some examples (see Table 3).  We next discuss some observations on the data shown in Table 3. With respect to the dimension of the class space, notice how for n = 3, 4, 5, 6, 7, 8 the dimension of the class space is, respectively, equal to 10 −1 , 10 −6 , 10 −17 , 10 −43 , 10 −52 and 10 −316 , i.e., for each part of the initial space of S-boxes, there is a smaller and smaller fraction of the initial space. Note that, for n = 3, 4, 5, 6, 7, the number of classes is greater than the class's cardinal, while, for n = 8, the number of classes is less than the class's cardinal.
On the exponential reduction of space, for n = 8, the dimension of the class space is approximately 10 316 times less than the initial space of S-boxes. Therefore, when applying the proposed strategy of moving from class to class and not from S-box to S-box, the reduction of the search space is of the order 10 316 . Importantly, by rejecting a class for having a low CCV value, one is simultaneously rejecting approximately ∼10 316 S-boxes. On the other hand, accepting a class, due to having a high value of CCV, there are approximately 10 316 S-boxes among which to look for some that meet the remaining cryptographic properties. Now, relating the comparison of S-box space partitions, consider the case n = 4. In [5], for n = 4, the bijective S-box space is partitioned into classes considering the resistance to differential and linear cryptanalysis. In this work, the space of S-boxes is divided into HW classes according to their theoretical resistance to power attacks, according to the CV metric. It would be very interesting to compare both partitions, which is left for future work.
With respect to all S-boxes in a 3 × 3 class, consider the following. For the 3 × 3 S-box of the PRINT cryptographic algorithm [28], the 36 equivalent S-boxes were generated. They are shown in the Appendix. It is observed how the necessary condition given in Proposition 4 is fulfilled. The preimages of 0 and 7 = 2 3 − 1 are constant within the class: The 1120 HW equivalence classes were constructed.

Estimation of the Number of HW classes and the Number of S-boxes in Each Class as an Occupation Problem
The following proposition provides another alternative way of calculating the number of classes and the number of S-boxes per class. Proposition 6 (Calculating the S-box number within each HW class). When we partition the space of (2 n )! S-boxes of dimension n × n, into Hamming weight (HW) classes, then the following hold: (a) The number of "Hamming Weight" equivalence classes is equal to: (b) The number of S-boxes within each HW equivalence class is exactly equal to: Proof. The demonstration of Statement (a) is based on modeling the construction of the classes using an occupation problem, with successive dependent launches. It is taken into account that the 2 n weights { S(X) : S(X) = 0, . . . , 2 n − 1} of the outputs of the S-boxes can be divided into (n + 1) groups corresponding to the (n + 1) different values {r : r = 0, . . . , n} that can take their weights { S(X) = r : r = 0, . . . , n}, where the group r contains exactly C(n, r) equal elements. The essential observation is that each class corresponds to a different location of the (n + 1) weight groups in the 2 n places. Without loss of generality, it can be assumed that the groups are located in increasing order of the value of r.
The first group corresponds to the weight r = 0, containing C(n, 0) = 1, only one element and can be located in any of the C(2 n , 1) = 2 n possible places. For the remaining groups r = 1, . . . , (n − 1), the reduction in the number of available places caused by the location of the previous groups must be taken into account, as discussed below.
In general, to locate the C(n, r) elements of the rth group, for r = 1, . . . , (n − 1), there are exactly 2 n − ∑ r−1 i=0 C(n, i) available places, since the ∑ r−1 i=0 C(n, i) places occupied by the previous groups are subtracted from the 2 n starting places. The selection of those C(n, r) positions among the available 2 n − ∑ r−1 i=0 C(n, i) can be done in C 2 n − ∑ r−1 i=0 C(n, i) , C(n, r) forms. Therefore, the total number of ways to locate the (n + 1) weight groups in the 2 n places is equal to 2 n ∏ n r=1 C(2 n − ∑ r−1 i=0 C(n, i), C(n, r)), which is exactly the number of HW classes. Now, we turn to Statement (b). By dividing the total number (2 n )! of S-boxes of n × n between the number of classes, (2 n ) ∏ n r=1 C( 2 n − ∑ r−1 i=0 C(n, i) , C(n, r)) calculated for Statement (a), it is obtained that the number of S-boxes inside each class is N S = (2 n )! 2 n ∏ n r=1 C(2 n − ∑ r−1 i=0 C(n, i), C(n, r)) .

Examples Using Proposition 6
In this subsection, we present some examples derived from Proposition 6.
Example 6. Let n = 3. The number of classes is equal to This example illustrates the calculation of the number of HW classes by Proposition 6, according to which there are 1120 classes. This statement was tested experimentally and the 1120 classes obtained are shown in the Appendix C (see Table A5).
Example 7. For n = 8, (2 n )! = (256)! ∼ 10 506 by F. Stirling (see Table 4). This example illustrates the difficulty in calculating the number of S-boxes even for small values of n(n = 8) if it is necessary and convenient to use the Stirling formula. Finally, we establish a comparison of the number of classes estimated by Propositions 5 and 6. For n = 3, it is observed that both values coincide (1120 HWclasses o f 3 × 3), as expected since they are exact calculations. For n = 8, the Stirling formula was used in both cases to approximate different factorials, so there may be differences between the two estimates (see Table 5). The difference between both estimates is of the order 10 2 . It can be considered acceptable, given the dimensions of the spaces being estimated. This comparison can be improved using the refinement of the Stirling formula.

Conclusions
The main results of the present work are the proposal of a new equivalence relationship between S-boxes and their application to exponentially reduce the search space for nonlinear S-boxes and resistance to power attacks, when the search is performed from class to class.
This result provides new theoretical knowledge about the internal structure of the bijective S-box space and its partition into equivalence classes according to its resistance to power attacks. As far as we know, there are no previous reports of results of this type New equivalence classes: This paper proposes a new definition of equivalence classes to relate S-boxes according to their power leak following the Hamming weight model (HW equivalence). A new algorithm is presented, which randomly generates an S-box HW equivalent to the initial one, given an initial S-box of input. Three variants of different complexity are proposed to apply this algorithm. It was demonstrated that the metric "variance of the confusion coefficient (CCV)" that theoretically measures the resistance of an S-box against power attacks takes constant values within the HW classes. This result was confirmed experimentally (using the previous algorithm) for four S-boxes classes, corresponding to the S-boxes of the AESCC, SCREAM, AES and STRIBOG algorithms.
Exponential reduction of the search space: Based on these new HW equivalence classes, a new strategy was proposed to search for S-boxes resistant to power attacks, essentially consisting of moving in the class space and not in the S-box space, changing of classes as long as the CCV value is low. When a high CCV class is found, the S-boxes inside the class are scanned to evaluate the remaining cryptographic properties of the S-boxes, such as nonlinearity. An advantage of this strategy is that it is easily applied because, to change classes, it is enough to swap at least two elements of different hamming weights, while, to change S-boxes within the class, it is enough to swap at least two elements of equal weight. The main advantage of this strategy is that it allows an exponential reduction of the search space. The cardinal of the class space was calculated using two different methods. Its comparison with the cardinal of the space of S-boxes shows that, as n increases, the class space represents a smaller and smaller fraction of the space of S-boxes. For n = 8, this reduction reaches the order of 10 316 . This result was confirmed experimentally for n = 3.
In future work, we will investigate the probability distribution of other S-box cryptographic properties within these new HW classes and how to use these distributions to improve the effectiveness or efficiency of searching for S-boxes that are not linear with a high value of CCV. On the other hand, although all S-boxes in a class have the same CCV value, we will investigate different HW classes with the same CCV value and the conditions that these classes must meet. Future studies will investigate whether the increase in the number of permuted elements influences the search's effectiveness. If positive, the optimal number of elements to be exchanged must be determined, considering the compromise between effectiveness and efficiency. In this work, the space of S-boxes was divided into HW classes according to their theoretical resistance to power attacks, according to the CCV metric. For n = 4, it would be interesting to compare with the partition of G. Leander and A. Poschmann [5], which is left proposed.

•
Construction, by columns, of the 36 equivalent S-boxes from the HW class < F Print > of the PRINT cipher's S-box F Print . All of them have CCV = 0.275510. Let the S-box be F Print of the PRINT cipher's (Example 3). The < F Print > class can be represented directly by the output weight vector: < F Print >= (HW(F Print (0)), . . . , HW(F Print (7)) = (0, 1, 2, 2, 3, 1, 2, 1), of the last row; however, for the construction of the class, it is more convenient to use the representation through the sets {C(F Print ) k : k = 0, 1, 2, 3} ={Inputs x whose outputF Print (x) has; weightHW(F Print (x)) = k}. Class construction: -Column 1: C(F Print ) 0 = {0} Input 0 with output 0 of weight 0. Taking into account that, for the weight k = 0, the set C(F Print ) 0 = {0} has cardinal one, its elements cannot be permuted with each other, therefore all the S-boxes F b of the < F Print > class satisfy that F b (0) = 0 (Proposition 4).

-
Column 5: C(F Print ) 3 = {4}. Input 4, with output 7 of weight 3. Analogously for the weight k = 3, the set C(F Print ) 3 = {4} has cardinal one and its elements cannot be permuted with each other; therefore, all S-boxes F b of the < F Print > class satisfy that F b (4) = 7 (Proposition 4).