This article introduces MDSECheck method — a novel approach to checking square MDS matrices for unconditional security as the components of affine permutation layers of P-SP-networks.
Introduction
Maximum distance separable (MDS) matrices play a significant role in algebraic coding theory and symmetric cryptography. In particular, square MDS matrices are commonly used in affine permutation layers of partial substitution-permutation networks (P-SPNs). These are widespread designs of the modern symmetric ciphers and hash functions. A classic example of the latter is Poseidon [1], a well-known hash function used in zk-SNARK proving systems.
Square MDS matrices differ in terms of security that they are able to provide for P-SPNs. The use of some such matrices in certain P-SPNs may result in existence of infinitely long subspace trails of small period for the latter, which make them vulnerable to differential cryptanalysis [2].
Two methods for security checking of square MDS matrices for P-SPNs have been proposed in [2]. The first one, which is referred to as the three tests method in the rest of the article, is aimed at security checking for a specified structure of the substitution layer of a P-SPN. The second method, which is referred here as the sufficient test method, has been designed to determine whether a square MDS matrix satisfies a sufficient condition of being secure regardless of the structure of a P-SPN substitution layer, i.e. to check whether the matrix belongs to the class of square MDS matrices, which are referred to as unconditionally secure in the current article.
This article aims to introduce MDSECheck method — a novel approach to checking square MDS matrices for unconditional security, which has already been implemented in the Rust programming language as the library crate [3]. The next sections explain the notions mentioned above, describe the MDSECheck method as well as its mathematical foundations, provide a brief overview of the MDSECheck library crate and outline possible future research directions.
MDS matrix: how to define and construct
An x matrix over a finite field is called MDS, if and only if for distinct -dimensional column vectors and the column vectors and , where stands for vertical concatenation, do not coincide in or more components. The set of all possible column vectors for some fixed matrix is a systematic MDS code, i.e. a linear code, which contains input symbols on their original positions and achieves the Singleton bound. The latter property results in good error-correction capability.
There are several equivalent definitions of MDS matrices, but the next one is especially useful for constructing them directly by means of algebraic methods. A matrix over a finite field is called MDS, if and only if all its square submatrices are nonsingular. The matrix entries and the matrix itself are also considered submatrices.
One of the most efficient and straightforward methods to directly construct an MDS matrix is generating a Cauchy matrix [4]. Such an x matrix is defined using -dimensional vector and -dimensional vector , for which all entries in the concatenation of and are distinct. The entries of the Cauchy matrix are described by the formula . It is obvious that any submatrix of a Cauchy matrix is also a Cauchy matrix. The Cauchy determinant formula [5] implies that every square Cauchy matrix is nonsingular. Thus, Cauchy matrices satisfy the second definition of MDS matrices.
Partial substitution-permutation networks
Describing SPNs in algebraic terms is convenient, so this approach has been chosen for this article. SPNs are designs of the symmetric cryptoprimitives, which operate on an internal state, which is represented as an -dimensional vector over some finite field, and update this state iteratively by means of the round transformations described below.
Each round begins with an optional update of the internal state by adding to its components some input data or extraction of some of these components as the output data. This optional step depends on the specific cryptoprimitive and the current round number. The next step is called the nonlinear substitution layer and lies in replacing the -th component of the internal state with for each , where is the component value and is a nonlinear invertible function over the finite field. The function is specific to the cryptoprimitive and called an S-Box. The final step, which is known as the affine permutation layer, replaces the internal state with , where is the current internal state, is a nonsingular square matrix and is the vector of the round constants. The value of is specific to the cryptoprimitive and the current round number, while typically depends only on the cryptoprimitive. The data flow diagram for an SPN is given below.
..................................
│ │ │ │
▼ ▼ ▼ ▼
┌────────────────────────────────┐
│ Optional addition / extraction │ <─────> Input / output
└──┬────────┬────────┬────────┬──┘
▼ ▼ ▼ ▼
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
│S₁(x)│ │S₂(x)│ │ ... │ │Sₙ(x)│
└──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘
▼ ▼ ▼ ▼
┌────────────────────────────────┐
│ Affine permutation │
└──┬────────┬────────┬────────┬──┘
▼ ▼ ▼ ▼
┌────────────────────────────────┐
│ Optional addition / extraction │ <─────> Input / output
└──┬────────┬────────┬────────┬──┘
▼ ▼ ▼ ▼
┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐
│S₁(x)│ │S₂(x)│ │ ... │ │Sₙ(x)│
└──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘
▼ ▼ ▼ ▼
┌────────────────────────────────┐
│ Affine permutation │
└──┬────────┬────────┬────────┬──┘
▼ ▼ ▼ ▼
..................................
Partial SPNs are modifications of SPNs, where for certain rounds some S-Boxes are replaced with the identity functions to reduce computational efforts [2]. For example, the nonlinear substitution layers of the partial rounds of Poseidon update only the first internal state component [1]. In the case of P-SPNs, security considerations commonly demand to choose as a square MDS matrix, because these matrices provide perfect diffusion property for the affine permutation layer [6]. Possessing this property means ensuring that any two -dimensional internal states, which differ in exactly components, are mapped by the affine permutation layer to two new internal states that differ in at least components.
Square MDS matrix security check in the context of P-SPNs
Certain square MDS matrices should not be used in certain P-SPNs to avoid making them vulnerable to differential cryptanalysis, since it may exploit the existence of infinitely long subspace trails of small period for vulnerable P-SPNs. [2]. Such matrices are called insecure with respect to particular P-SPNs.
An infinitely long subspace trail of period exists for a P-SPN, if and only if there is a proper subspace of differences of internal state vectors, such that if for a pair of initial internal states the difference belongs to this subspace, then the difference for the new internal states, which are obtained from the initial ones by means of the same -round transformation, also belongs to this subspace [2].
Two methods for checking square MDS matrices for suitability for P-SPNs in terms of existence of infinitely long subspace trails have been proposed in [2]. The three tests method is aimed at checking whether using a specified matrix for a P-SPN with a specified structure of the substitution layer leads to existence of infinitely long subspace trails of period for this P-SPN for all no larger than a given . The sufficient test method has been designed to determine whether a square MDS matrix satisfies a sufficient condition of non-existence of infinitely long subspace trails of period for P-SPNs using this matrix for all no larger than a specified .
The sufficient test method is a direct consequence of Theorem 8 in [2] and consists in checking that the minimal polynomial of the -th power of the tested matrix has maximum degree and is irreducible for all . The aforesaid sufficient non-existence condition is satisfied by the matrix, if and only if all the checks yield positive results.
It is convenient to define the unconditional P-SPN security level of the square MDS matrix as follows: this level is for the matrix , if and only if the minimal polynomials of , , , have maximum degree and are irreducible, but for the minimal polynomial does not have this property. Using this definition, the purpose of the sufficient test method can be described as checking whether the unconditional P-SPN security level of the specified matrix is no less than a given bound.
MDSECheck method: getting rid of the matrix powers
The MDSECheck method, whose name is derived from the words "MDS", "security", "elaborated" and "check", has the same purpose as the sufficient test method, but achieves it differently. The differences of the first method from the latter and approaches to implementing them can be described as follows:
Computation and verification of minimal polynomials of , , , , where is the tested x matrix over and is the security level bound, has been replaced with checks for the corresponding powers of a root of the characteristic polynomial of for non-presence in nontrivial subfields of .
The non-presence check is performed without straightforward consideration of all nontrivial subfields of . The root is checked only for non-presence in the subfields , , , , where , , , are all prime divisors of .
The non-presence check reuses some data computed during the checking for irreducibility the minimal polynomial of , which in this case coincides with designating the characteristic polynomial of . The values of are saved for each during the irreducibility check to replace exponentiations with sequential computations of from as its product with .
The check of the minimal polynomial of for irreducibility and maximum degree is performed without unconditional computation of this polynomial. This computation has been replaced with the Krylov method fragment, which consists in building and solving only one system of linear equations over . If has an irreducible minimal polynomial of maximum degree, then its coefficients are trivially determined from the system solution. If the system is degenerate, then the minimal polynomial of does not have such properties.
The correctness of the first distinctive feature can be proven as follows. Verifying that the minimal polynomial of a matrix is of maximum degree and irreducible is equivalent to verifying that the characteristic polynomial of this matrix is irreducible, because the minimal polynomial divides the characteristic one. Also, it is trivially proven that for a matrix with such a minimal polynomial it is equal to the characteristic polynomial. Thus, the required checks for the matrices , , , can be done by checking their characteristic polynomials for irreducibility.
Let be x matrix over , whose minimal polynomial is of maximum degree and irreducible. The statements in the previous paragraph imply that , which is the -degree characteristic polynomial of , is irreducible. Consider over the extension field , which is the splitting field of . Let be a root of . According to standard results from the Galois field theory, , , , , are distinct roots of [7]. Thus, these powers of are distinct eigenvalues of . Hence, due to matrix similarity properties, there is some matrix such that , where is the diagonal matrix, whose nonzero elements are , , , , . Therefore, , so the roots of the characteristic polynomial of are , , , , . If the minimal polynomial of has degree less than , then the characteristic polynomial of is divisible by this minimal polynomial, while lies in some nontrivial subfield of . One of the fields isomorphic to this subfield is a residue class ring of polynomials modulo the minimal polynomial of [7]. If the minimal polynomial of is of degree , then the characteristic polynomial of equals this minimal polynomial and therefore is irreducible, while does not lie in any nontrivial subfield of . In this case, , , , , are linearly independent as distinct roots of an irreducible polynomial over a finite field [7], so any field containing has at least elements and therefore cannot be a trivial subfield of . Thus, checking the characteristic polynomials of the matrices , , , for irreducibility is equivalent to verifying that , , , do not lie in any nontrivial subfield of .
The last sentences of the two previous paragraphs imply the following: verifying that the minimal polynomials of , , , are of maximum degree and irreducible can be performed by verifying that the corresponding powers of a root of the characteristic polynomial of the x matrix over do not belong to any nontrivial subfield of .
The approaches to implementing the first distinctive feature can be explained and proven to be correct as follows. Since is a nontrivial subfield of if and only if divides and [7], the presence of some in , which is a nontrivial subfield of , implies that for some prime dividing , because divides the quotient of and some of its prime factors. Thus, checking that some value does not belong to subfields , , , , where , , , are all prime divisors of , is equivalent to checking this value for non-presence in nontrivial subfields of .
Checking for irreducibility the minimal polynomial of is performed by means of Algorithm 2.2.9 in [8] and consists in sequential computation of , , , and checking that for each , where is the characteristic polynomial of and coincides with the minimal polynomial in this case. The optimized root non-presence check is performed by checking that for each for each the value of is nonzero. This approach is based on the following standard results from the Galois field theory [7]:
is isomorphic to the residue class ring of univariate polynomials in modulo , because at this point is known to be irreducible, and some root of is mapped by this isomorphism to the residue class the polynomial in this ring.
All elements of a finite field and only they are roots of .
The expression can be rewritten as , which can be computed without exponentiation as the product of and , which has been saved during the irreducibility check.
The second distinctive feature can be explained and proven to be correct in following way. The x matrix does not have a minimal polynomial of maximum degree, if some Krylov subspace of order for it is not -dimensional. Indeed, the minimal polynomial of the matrix is divisible by the minimal polynomial of the restriction of this linear operator to an arbitrary subspace, and in the considered case the latter polynomial has degree less than , because the degree of the minimal polynomial of a linear operator cannot exceed the dimension of the subspace the operator acts on. Thus, an unconditional computation of the minimal polynomial of is not required to determine whether this polynomial is irreducible and has maximum degree. Using this computation has been replaced with the Krylov method fragment, which consists in choosing any nonzero -dimensional column vector and solving the system of linear equations , where is an x matrix, whose columns are , , , , , and is . If is singular, the minimal polynomial of is reducible or does not have maximum degree, so checking has been accomplished; otherwise, , which is the minimal and characteristic polynomial of , can be expressed as .
The steps of MDSECheck method can be summarized as follows:
The square MDS matrix over and the unconditional P-SPN security level bound are received as inputs.
The Krylov method fragment is used to compute the minimal polynomial of . If the computation fails, then is not unconditionally secure, so the check of is complete. If it succeeds, then the minimal polynomial has maximum degree and, therefore, coincides with the characteristic polynomial of .
Algorithm 2.2.9 is used to check for irreducibility the minimal polynomial of , which is also the characteristic polynomial of in this case. Some data computed during this step is saved to be reused at the next one. If the polynomial is reducible, then the check of is complete, because has been found to be not unconditionally secure.
The values of , , , , where is a root of the characteristic polynomial of , are sequentially checked for non-presence in nontrivial subfields of as described above. If belongs to some nontrivial subfield of , then the unconditional P-SPN security level of is , so the check of is complete. If all the values do not belong to such a subfield, then the unconditional P-SPN security level is at least .
MDSECheck library crate: implementation in Rust
The library crate [3] provides tools for generating random square Cauchy MDS matrices over prime finite fields and applying the MDSECheck method to check such matrices for unconditional security. The used data types of field elements and polynomials are provided by the crates ark-ff [9] and ark-poly [10]. The auxiliary tools in the crate modules are accessible as well.
Generating by means of this crate a 10 x 10 MDS matrix, which is defined over the BN254 scalar field [11] and has unconditional P-SPN security level is 1000, takes less than 60 milliseconds on average for the laptop with the processor Intel® Core™ i9-14900HX, whose maximum clock frequency is 5.8 GHz.
Conclusion
The MDSECheck method proposed in this article is a novel approach to checking square MDS matrices for unconditional security as the components of affine permutation layers of P-SPNs. It has been implemented as a practical library crate for generating unconditionally secure square MDS matrices for P-SPNs over prime finite fields.
The future research directions may include theoretical and experimental studies of performance of approaches, which use the MDSECheck method to generate unconditionally secure square MDS matrices for P-SPNs.
References
- L. Grassi, D. Khovratovich, C. Rechberger, A. Roy, M. Schofnegger. "POSEIDON: A New Hash Function for Zero-Knowledge Proof Systems (Updated Version)".
- L. Grassi, C. Rechberger, M. Schofnegger. "Proving Resistance Against Infinitely Long Subspace Trails: How to Choose the Linear Layer".
- The page "mdsecheck" on crates.io.
- Y. Kumar, P. Mishra, S. Samanta, K. Chand Gupta, A. Gaur. "Construction of all MDS and involutory MDS matrices".
- The page "Value of Cauchy Determinant" on proofwiki.org.
- T. Silva, R. Dahab "MDS Matrices for Cryptography".
- S. Huczynska, M. Neunhöffer. "Finite Fields"
- R. Crandall, C. Pomerance. "Prime Numbers: A Computational Perspective" (2nd edition).
- The page "ark-ff" on crates.io.
- The page "ark-poly" on crates.io.
- The page "ark-bn254" on crates.io.