scieee AI-readable full text Open interactive document viewer

Performance Analysis of Rainbow on ARM Cortex-M4

Moya Riera, Joan

Abstract

The risk posed by a fully operational quantum computer has anticipated a revolution in the way to approach the level of security provided by a cryptographic algorithm. Public keybased solutions such as RSA or ECC will be easily broken once we enter the post-quantum era. Multivariate quadratic cryptosystems are a promising candidate for the need of quantum resistant digital signature schemes. In order to estimate if these approach will someday be able to replace current standards, it is necessary to determine how ef?ciently can they operate on diverse platforms and at which level of security can they do it. This aspects are particularly relevant for reduced size devices with restricted energy, memory or computational power. In this work, a theoretical description of the so-called Rainbow multivariate signature algorithm is given, which is later implemented on a memory-constrained environment. An optimization approach is proposed in order to improve the ef?ciency of the scheme, in terms of message signature and veri?cation speed. A performance comparison is also presented between various state-of-the-art post-quantum signature cryptosystems and the optimized instances of Rainbow, in order to study its characteristics from a wider perspective.

Full text

Performance Analysis of Rainbow on ARM Cortex-M4 Evaluation of a Post-Quantum Multivariate Signature Scheme on a Resource-Constrained Device Wissenschaftliche Arbeit zur Erlangung des Grades B.Sc. an der Fakultät für Elektrotechnik und Informationstechnik der Technischen Universität München. Betreut von Prof. Dr.-Ing. Georg Sigl Thomas Schamberger, M.Sc. Lehrstuhl für Sicherheit in der Informationstechnik Eingereicht von Joan Moya Riera Josep Trueta 10 08970 Sant Joan Despi, Barcelona +34 680 31 85 87 Eingereicht am München, den 30.7.2019 The risk posed by a fully operational quantum computer has anticipated a revolution in the way to approach the level of security provided by a cryptographic algorithm. Public keybased solutions such as RSA or ECC will be easily broken once we enter the post-quantum era. Multivariate quadratic cryptosystems are a promising candidate for the need of quantum resistant digital signature schemes. In order to estimate if these approach will someday be able to replace current standards, it is necessary to determine how efficiently can they operate on diverse platforms and at which level of security can they do it. This aspects are particularly relevant for reduced size devices with restricted energy, memory or computational power. In this work, a theoretical description of the so-called Rainbow multivariate signature algorithm is given, which is later implemented on a memory-constrained environment. An optimization approach is proposed in order to improve the efficiency of the scheme, in terms of message signature and verification speed. A performance comparison is also presented between various state-of-the-art post-quantum signature cryptosystems and the optimized instances of Rainbow, in order to study its characteristics from a wider perspective. 2 Contents 1 Introduction 5 2 Post-Quantum Cryptography 7 2.1 Introduction to PQ-Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 Multivariate Public Key Cryptosystems (MPKC’s) . . . . . . . . . . . . . . . . 9 2.2.1 Construction of MPKC’s . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.2.2 Security Principles (Underlying Problems) . . . . . . . . . . . . . . . . 13 2.2.3 Strengths and Limitations . . . . . . . . . . . . . . . . . . . . . . . . . 14 3 Finite Field Theory 16 3.1 Finite Field Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.2 Tower Field Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.3 Karatsuba-Ofman Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4 Rainbow Signature Scheme 19 4.1 Unbalanced Oil & Vinegar Polynomials . . . . . . . . . . . . . . . . . . . . . 19 4.2 Rainbow Construction Principle . . . . . . . . . . . . . . . . . . . . . . . . . 20 4.3 Parameter Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.4 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.4.1 Key Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4.4.2 Message Signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.4.3 Signature Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 5 Rainbow in ARM Cortex-M4 27 5.1 Description of the Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 27 5.2 Implementation Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 5.2.1 Representation of Finite Field Elements . . . . . . . . . . . . . . . . . 29 5.2.2 Key Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 5.2.3 Finite Field Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 5.2.4 Comparison between Rainbow Variants . . . . . . . . . . . . . . . . . 32 5.3 Modifications to the Reference Implementation . . . . . . . . . . . . . . . . . 34 5.4 Rainbow Embedded Application . . . . . . . . . . . . . . . . . . . . . . . . . 35 5.5 Performance Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.5.1 Data Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.5.2 Optimization Approach . . . . . . . . . . . . . . . . . . . . . . . . . . 39 5.5.3 Reference Implementation Performance . . . . . . . . . . . . . . . . . 42 3 5.5.4 Optimized Implementation Performance . . . . . . . . . . . . . . . . . 44 6 Results Analysis 46 6.1 Key Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 6.2 Signature Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 6.3 Signature Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 6.4 Comparison with other Cryptosystems . . . . . . . . . . . . . . . . . . . . . . 48 7 Conclusions 52 7.1 Further Improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 4 1 Introduction Cryptography is essential for providing security over the exchange of data between two or more communicating parties. In modern society, we have become frequent users of cryptographic techniques, in tasks such as online shopping, mail accessing, website visiting or file downloading. Not only for private usage, but also institutions like banks, governments or the military protect their data by making use of cryptographic solutions. Furthermore, given the growth in the number of services offered on the cloud, it is expected that the number of secure algorithms keeps increasing in the future. Most asymmetric key cryptosystems currently used in practice are based on large integer factorization and discrete logarithm calculation. Cryptographic approaches that base their security on these mathematical operations are considered to be unbreakable using current computing systems. However, since the invention of Peter Shor’s algorithm [Sho99] in 1997 for efficiently solving both problems, the security community has been forced to develop new cryptographic solutions to anticipate a post-quantum cryptography standarization process, before the appearance of a sufficiently large quantum computer. Post-quantum candidate algorithms are based in mathematical problems that are supposedly resilient against classical, as well as post-quantum cryptanalysis. These quantum immune techniques also need to be feasible for all kind of systems, including small embedded micro controllers. Due to the limited amount of resources on such platforms, the implementation of these solutions to provide post-quantum security on such devices does sometimes lack of feasibility. Current research related to post-quantum cryptography has been mainly focused on the security provided by the different post-quantum cryptographic solutions. The feasibility of these approaches can be validated by studying the computational complexity of the algorithms and testing their efficiency experimentally. This work is based on a practical study of the performance concerning the Rainbow multivariate signature cryptosystem on an ARM Cortex-M4 microcontroller. The efficiency is characterized in terms of execution speed and the memory consumption of the scheme, as well as the reachable security levels in the constrained device where the analysis is performed. 5 The contribution of this thesis is concluded as follows: 1. We present an implementation of the Rainbow multivariate signature scheme, which provides post-quantum security on a suitable device for the Internet of Things. 2. We evaluate the feasibility of the different parameter sets available to provide a specific level of security on our platform. 3. We analyze the performance in terms of execution time and memory consumption of the scheme’s different functionalities, considering different compiler optimizations. 4. We propose an optimized solution with increased efficiency on our target device. 5. Based on the observations, we compare the behaviour on the same computing architecture of various Rainbow instances with different state-of-the-art quantum secure digital signature cryptosystems. Organization. The research and experimental work that has been carried out in the thesis is organized as follows. In Section 2, we introduce post-quantum cryptography and describe the characteristic features of the multivariate approach. In Section 3, we give an overview on finite field algebra, focusing on two aspects that are later exploited during the optimization procedure. In Section 4, we present the construction methodology and the different algorithms provided by the Rainbow signature scheme. Section 5 gathers all the aspects related with the experimental part of the project. The obtained benchmarks are evaluated and discussed in Section 6. Finally, we conclude with some remarks in Section 7, based on the observed results. 6 2 Post-Quantum Cryptography 2.1 Introduction to PQ-Cryptography Quantum computers are high-speed parallel computing systems, whose properties and operation principles are based on the behaviour of subatomic particles ruled by quantum mechanics. This systems use qubits instead of bits, which can exist in any superposition of the 0 and 1 states in a conventional device. This principle grants the ability to perform calculations simultaneously, solving problems that require an enormous amount of computing power in current available computers. With operational tasks being drastically accelerated, quantum computers offer promising solutions to complex problems in different fields such as generating sophisticated market models, creating new medicines or exponentially increasing database search speed, among others. Current quantum computers are far from their capabilities in terms of efficiency, as they operate at temperatures close to the absolute zero. Nevertheless, there are tasks that quantum computers can fulfill in a more efficient way than classical computers do. One of the prominent applications for quantum computers is decoding traditional cryptographic protocols in polynomial time. In particular, there exist two main algorithms that executed in a quantum computing system would be able to break the security of most asymmetric cryptography approaches employed nowadays. Shor’s Algorithm was invented by Peter Shor in 1994. It is a method [Sho99] capable of efficiently solving some of the problems that back up the security of the most popular and currently used public key cryptosystems, based on integer factorization and (elliptic curve) discrete logarithm. All these mathematical trapdoor functions are considered to be hard to solve by classical computing systems, even though a quantum computer with sufficiently powerful resources could break them in polynomial time. Grover’s algorithm consists in another quantum approach [Gro96] that can invert functions in O(√n)time. This algorithm reduces the security of a symmetric key cryptosystem by a root factor when being executed in a quantum computer. However, it is not considered a major threat as doubling the level of security of the scheme can mitigate these attacks. The future construction of a quantum computer capable of executing these algorithms is quite unknown as only speculations have been made about the moment when such systems 7 could be brought to light. Nevertheless, in 2006, NIST proposed a competition1in order to enhance the development of new candidates to replace RSA and ECC and implement postquantum cryptography as the standard security model. Post-quantum cryptography is the study of cryptosystems that can be implemented in a classical computing systems while being able to protect against quantum computer attacks. Post-quantum schemes provide confidentiality, integrity, authenticity, and non-repudiation, as well as traditional cryptosytems do. There exists 6 different types of approaches [LSY+16], which are briefly described below. •Lattice-based Lattices are considered the most flexible approach among the others because they provide strong security reductions and are also capable of performing key exchange as well as generating digital signatures. The trapdoor of this scheme is based on solving a system of linear equations that contains an error variable which gets bigger at each step of the Gaussian Elimination algorithm in order to solve the system, until the point where any useful information about the secret key gets hidden. This is called the Learning With Errors problem (LWE), based on finding the shortest vector in a lattice, which is considered to be NP-hard. •Multivariate Such schemes base their security both on the NP-hardness of solving systems of multivariate equations over finite fields and the Extended Isomorphism of Polynomials. The size and the speed at which the signatures are generated by this approach, place multivariate cryptosystems as a potential candidate for post-quantum authentication schemes. However, the length of the public and secret keys generated notably reduce the feasibility of this approach, specially on low-resource embedded platforms. •Elliptic curves / Isogenies Elliptic curve cryptography relies on the hardness that involves finding the discrete logarithm of a random elliptic curve element with respect to a publicly known base point. The size of the elliptic curve determines how much difficult the problem turns out to be. The main advantage is the small size of the keys generated, respect to other cryptosystems that employ finite fields (discrete mathematics), providing the same level of security. Elliptic curve cryptosystems can be broken by quantum computers by performing discrete logarithm operations. In order to provide a secure approach, a supersingular isogeny-based scheme is developed. In this case, the security is based on supersingular elliptic curves in order to create a modified Diffie-Hellman key exchange that can be used as a replacement for the Diffie-Hellman and elliptic curve Diffie–Hellman methods used nowadays. This scheme provides extremely small key sizes even though it is the slowest algorithm for key generation and shared secret acquisition. 1https://csrc.nist.gov/Projects/Post-Quantum-Cryptography 8 •Hash-based Hash-based signature techniques use the input to a hash function as the secret key and the output as the public key. The generated digital signatures by this approach have been studied ever since as an interesting alternative to other authentication approaches, like RSA and DSA, that are based on number theory. For any hash-based public key, there exists a limit that constrains the number of signatures that can be generated using a single set of private keys. This fact reduced the interest on this cryptographic technique until post-quantum cryptography was introduced, given the resistance that they oppose against quantum computer-based attacks. Hash signatures are not memory efficient. However, approach is considered to be fast and the security relies on the underlying hash function •Code-based During the transmission of binary messages, there is a certain probability that errors occur by getting the bit flips. Error-correction codes provide the possibility to detect and revert a certain number of bit flips at the expense of message compactness. The most prominent type is called linear codes, represented by matrices, whose size depends on the length of the original message and the length of the encoded message. It is computationally expensive to decode a message without information about the underlying linear code. This problem backs up the security of the so-called McEliece public key cryptosystem. The secret key of this cryptosystem is a random code from a class called Goppa codes. The public key consists of an invertible matrix with binary entries. Like lattices, code-based cryptographic schemes suffer because of the size of the matrices that are used to represent the public and secret keys. Altough, various modifications have been done to the original scheme to improve this aspect. 2.2 Multivariate Public Key Cryptosystems (MPKC’s) Multivariate cryptography is a post-quantum asymmetric key approach based on multivariate polynomials over a finite field. The security of this cryptographic technique relies on both the MQ-problem and the Extended Isomorphism of Polynomials (EIP). The former has been proven to be NP-complete [GJ90] and doubly exponential, even in the simplest case, using a finite field composed by two elements. The latter is related to the construction principle of multivariate schemes. Unfortunately, there is no security proof regarding the problem regarding the followed procedure to build MQcryptosystems. For this reason, most MPKC’s have been broken except the Unbalanced Oil and Vinegar signature scheme [KPG99] and its variants Rainbow [DS05] and enTTS [YC05]. 9 3 Finite Field Theory 3.1 Finite Field Algebra A field is an abstraction of a set of elements with mathematical operations defined over them, so that calculations can be made between the numbers so that the result stays always inside the field. These operations should satisfy the field axioms, such as associativity, commutativity and distributivity. It is also needed to have both an additive and multiplicative inverse. When the field has a finite number of elements is called Finite Field or Galois Fields, in honor of Évariste Galois, creator of the concept. The order of a the field is the number of elements that compose the field. A Galois field Fof order qexists, if and only if qis a prime power, such as q=pmwhere p is a prime number known as the characteristic of F, and mis a positive integer. The name of the fields changes according to the value that takes m. It can be distinguished between prime fields when m= 1 and extension fields when m≥2. Finite fields are unique for a characteristic q, meaning that despite the possibility of having a different representation of its elements, they will be structurally the same. For this reason, two finite fields with characteristic qare called isomorphic and denoted as Fq. •Prime Fields Being pa prime number, integers modulo pconsisting of the integers {0,1,2, ..., p−1} with addition and multiplication operations performed modulo p, form a finite field of order p. •Binary Fields Finite fields of order 2mare called binary fields. One way to construct them is using a polynomial basis representation, where the elements of F2mare the polynomials of degree at most m−1, whose coefficients belong to F2={0,1}. F2m={am−1zm−1+am−2zm−2+···+a1z+a0:ak∈ {0,1}}. Addition of field elements is computed as the usual addition of polynomials, with coefficient arithmetic performed modulo 2. Multiplication is performed modulo an irreducible polynomial f(z)degree m. The structure of the irreducible polynomial has a direct impact on the efficiency of the arithmetic opeartions where reduction is needed. In fact, 16 choosing third and fifth degree polynomials are the best alternative for this purpose. Some reasons why finite fields are employed in many cryptographic algorithms is because GF(2m) all the operations carry-less, there are is no rounding performed and the word length is constant [BDKR03]. Moreover, the structure of the field can be reformulated where we can consider displaying a k-bit input as mcontiguous n-bit groups which corresponds to instructions in SIMD architectures. These principles offer the possibility to efficiently implement finite field arithmetic operations. •Extension Fields The polynomial basis representation can be generalized to any extension field. Let p be a prime and m≥2. With Fp[z]denoting the set of all polynomials in the variable z whose coefficients belong to Fp. The irreducible polynomial f(z)is chosen to be of degree min Fp[z]. The coefficients that compose Fpmare the polynomials in Fp[z]of degree at most m−1. Fpm={am−1zm−1+am−2zm−2+···+a1z+a0:ak∈Fp} 3.2 Tower Field Representation If it is possible to decompose an integer Nas the product of land m, it is possible to derive a representation of GF(2N) over GF(2l). This is because, even though the form of the elements differs between GF((2l)m)and GF(2N), they define the same finite field. The elements of GF(2N) are polynomials of degree at most N−1whose coefficients are in GF(2) = {0, 1}, and the elements of GF((2l)m)) are polynomials whose coefficients are in GF(2l) of degree at most m−1. The tower field can be constructed with as much layers as possible, depending on the power representation of the order. Modelling a field following this approach receives the name of tower (or composite) field representation. Instead of using a base B1={1, α, α2, ..., αN−1}and generating the coefficients of the field as A=PN−1 i=0 aiαi, where aiare the elements from GF(2), we use the alternative base B2={1, β, β2, ..., βm−1}and the generation equation turns into B=Pm−1 i=0 biβiwith bias the elements of GF(2l). Employing this technique provides the capability of modelling the coefficients of a finite field, using a lower amount of elements equal to the order of the field below in the tower structure. Moreover, downgrading the order of the field translates into a fewer quantity of bits to represent the coefficients. 17 3.3 Karatsuba-Ofman Method The efficient implementation of finite field arithmetic is key to the development of cryptosystems whose underlying mathematical principles are based on arithmetic operations between the elements of a field with a finite number of elements. The Karatsuba-Ofman methodology provides an alternative representation to multiplications in order to reduce the number of computations needed to obtain the final result [GCL92]. The algorithm relies on the "divide-and-conquer" principle. It consists in solving partial problems separately and combining the solutions to obtain a joint result. In order to multiply two n-bit integers using the "schoolbook" method, considered the slowest, m2 multiplications and (m−1)2additions are required. By means of Karatsuba-Ofman algorithm applied recursively, the number of operations is reduced to nlog23multiplications and 6nlog23−8n+ 2 additions [Eyu15]. Since the complexity of addition and subtraction is linear (O(n)), this reformulation is justifiable. In order to employ this approach, the number of bits of each element has to be a power of 2. Otherwise, they are padded with zeros. Two integers from a given finite field are represented as polynomials A(x)and B(x)of degree n−1. The goal is to obtain a resulting polynomial of degree at most 2n−2given by C(x) = A(x)B(x). The Karatsuba-Ofman alternative model is shown in the next equations. Every step halves the number of bits required to represent the integers in the equations by using the upper and lower parts of each of the operands (A1, A0, B1, B0): A(x) = A1xn 2+A0= (xn 2−1an−1+···+an 2)xn 2+ (xn 2−1an 2−1+···+a0) B(x) = B1xn 2+B0= (xn 2−1bn−1+···+bn 2)xn 2+ (xn 2−1bn 2−1+···+b0) Multiplying the two polynomials A(x)and B(x)expressed in this form, gives the following result C(x) = A(x)B(x) = A0B0+xn 2[(A0+A1)(B0+B1)−A0B0−A1B1] + xnA1B1 This methodology terminates after log2nsteps when is applied recursively, until the point where only constant monomials compose the polynomial equations. 18 4 Rainbow Signature Scheme 4.1 Unbalanced Oil & Vinegar Polynomials The Oil and Vinegar and later Unbalanced Oil and Vinegar are schemes employed in multivariate cryptosystems for generating digital signatures. The trapdoor is achieved not by using field extensions but giving the polynomials a special algebraic structure. The name of this approach comes from the distinction of the variables that is made over two different groups, the Oil and the Vinegar. The unknowns of each group are mixed in the polynomials of the central map. Having a balanced or unbalanced scheme, depends on the number of variables from each group present in the equations. The unbalanced case was born after the balanced approach was broken, after exploiting the possibility of building oil and vinegar polynomials independently, because of the number of variables from each group in the construction (v=o). To prevent this attack, the unbalanced approach was developed where a different number of unknowns is chosen from each group (v > o) [KPG99]. The number of unknowns is defined by n=o+v. The variable sets are divided into vinegar V={x1, ..., xv}and oil O={xv+1, ..., xn}. The number of polynomials in the central map equals the number of oil variables m=o=n−v. The structure of a UOV polynomial equation is given by f(m)(x1, ...xn) := v X i=1 v X j=1 α(m) i,j xixj+ v X i=1 n X j=v+1 β(m) i,j xixj+ n X i=1 γ(m) ixi+δ(m) where α(m) i,j ,β(m) i,j ,γ(m) i,j and δ(m) i,j are chosen from a finite field of size q(Fq). The most significant algebraic property of this scheme is that the oil and vinegar variables are not fully mixed, which means that there will not exist quadratic terms between two variables from the oil set in the equations of the central map. This principle makes the central map Qeasily invertible. This is not the case for the public map P, as the affine transformation Sfully mixes all the variables. 19 In order to sign a given message x = (x1, ..., xo), a vector w = (w1, ..., xn) that satisfies x=P(w)the public key polynomial equation system has to be inverted, which is a possible task if information about the secret key is available. To invert the central map, random values are chosen for the vinegar variables x1, ..., xv, obtaining olinear equations in the oil variables xv+1, ..., xn. This linear system is, with high probability, solvable by Gaussian Elimination [Laz83]. In case that the system has no solution, different random vinegar variables are chosen and the process is restarted. To generate the public key of a cryptosystem based on UOV polynomials, only one affine map is needed to obfuscate the polynomials of the central map. The reason that explains this practice comes from the fact that the trapdoor remains unaltered after composing Swith Q, and thus does not contribute to the security of the scheme. Therefore, Sis dropped and the public key is constructed as P=Q◦T :Fn→Fo. The main drawback of the Unbalanced Oil & Vinegar approach is the size of the keys and signatures generated, which becomes infeasible for some practical applications. In order to reduce the size of the keys without degrading the security level of the scheme, Rainbow was first proposed in 2005 by J. Ding and D. Schmidt in [DS05]. 4.2 Rainbow Construction Principle Rainbow is a signature scheme based on multivariate cryptography whose central map is constructed stacking various Unbalanced Oil & Vinegar-based layers [DS05, DYC+08]. The multi-layered structure is designed hierarchically, in order to reuse already computed coefficients in upcoming layers and create dependencies between them, to improve the overall efficiency of the algorithm. An exhaustive analysis of Rainbow’s security can be found in [DYC+08]. Let V be the set of integers {1, v1, v2, ..., vu, n}. For a Rainbow signature scheme with u stacked layers, two variable sets are defined to design the polynomials of the central map, where l= 1, ..., u −1; In the one hand, Vl= {1, ..., vl} with vlelements and in the other hand Ol=Vl+1 \Vl=vl+ 1, ..., vl+1 with ol=vl+1 −vlelements, as it shown in Figure 4.1 for a 2-layer Rainbow construction. Following this construction manner, the vinegar variable set for each layer satisfies V1⊂V2⊂... ⊂Vu=V. The central map Qis represented as a set of m=n−v1polynomial equations f(v1+1), ..., f(n) that present the following form: 20 f(k)(x1, ...xn) := X i,j∈Vl α(k) i,j xixj+X i∈Vl,j∈Ol β(k) i,j xixj+X i∈VlSOl γ(k) ixi+δ(k) where α(k) i,j ,β(k) i,j ,γ(k) i,j and δ(k) i,j are chosen from Fqand lis an integer such that k∈Ol. The polynomials of the central map are distributed between the different layers. As in UOV, there are no crossed terms between xixjwhere i, j ∈Ol. Figure 4.1: Quadratic distribution of the central map in each of the two-layer Rainbow scheme. Green parts correspond the v×vvariables, mixed yellow-green to v×ocrossed variables and white to zero entries. The public key Pof the Rainbow scheme consists in a system of n−v1polynomial equations, composed by a central map Qwith the described form in 4.1, and two affine transformations Sand T. In order to mix the variables from the polynomials of the central map, we compute S ◦Q◦T :Fn→Fm. The central map Qcan be displayed as a matrix-vector product. Q=x1··· xn           x11 ··· x1vx1(v+1) ··· x1n . . .. . .. . .. . . xv1··· xnv xn(v+1) ··· xvn x(v+1)1 ··· x(v+1)v0··· 0 . . .. . .. . .. . . xn1··· xnv 0··· 0              x1 . . . xn    The private key consists of the three mappings S,Q,T. In this case, it is required a second affine transformation to mix the polynomials from S ◦Q between them, unlike the UOV approach, as the trapdoor Qdoes not get altered when it is composed with T, and therefore its contribution to the scheme’s security is null. 21 Rainbow is considered a booster stage to the Unbalanced Oil & Vinegar approach, where the size of the keys and signatures is notably shortened. Because of the hierarchical stack building manner, the parameters that define the scheme (v1, o1, o2, ...)can be chosen smaller than in the simple UOV construction, leading to shorter keys and smaller message to signature ratios. The number of coefficients from Fqthat compose the public and the private keys of an u-layered Rainbow scheme is given by the following equations. sizepk=m·(n+ 1) ·(n+ 2) 2 sizesk=m·(m+ 1) + n·(n+ 1) + u X i=1 ol·(vl·(vl+ 1) 2+vl·ol+vl+1 + 1) Signing Methodology. To sign a message, the trapdoor function has to be inverted, which is an easy task if there is information available about the mappings that compose the secret key. Reverting the affine transformations Sand Tis simple, while performing this task for the central map is slightly more complex. Below is explained the signing procedure for a two-layer Rainbow scheme. In Figure 4.2, it is shown the polynomial structure of the central map. The steps followed to sign a message are described in the following lines and illustrated in 4.3 and 4.4. The colors employed in the plots are organized as follows : blue for quadratic terms, green for linear terms in V1, yellow for linear terms in O1, red for linear terms in O2and white for constant terms. Figure 4.2: Central map of the Rainbow scheme • Random values for the vinegar variables x1, ..., xv1are chosen and substituted into the central map polynomials (f(v1+1), ..., f(n)) obtaining a system of o1linear equations, given by the polynomials of the first layer k∈O1. • Oil variables xv1+1, ..., xv2are found by solving the o1linear equations from the first layer. After that, these are substituted into the equations of the second layer. • The central map turns into an equation system of o2linear polynomials of the second layer k∈O2over the oil variables xv2+1, ..., xvnwhich can be solved with Gaussian Elimination. 22 Figure 4.3: First step of the Rainbow signature procedure Figure 4.4: Second step of the Rainbow signature procedure In case that one of the linear equation systems does not have a solution, new vinegar variables x1, ..., xv1from the first layer are chosen and the process is repeated again. 4.3 Parameter Sets Choosing a certain set of parameters to build a cryptographic scheme defines its level of security as well as the capacity to implement it efficiently. Rainbow offers two degrees of freedom to build its structure. In the one hand, the size qof the finite field (Fq) where the numerical units used in this approach are selected from. On the other hand, the parameters corresponding to the number of layers uand the size of both the oil and vinegar variables sets of each layer (v1, o1,··· , ou). Regarding the choice of the field’s size, it is a common practice to select 28as its size given the efficient implementations that can be implemented when working with 8-bit variables. Multiples of this size are also chosen, even though further processing of the elements of the field, like splitting or merging is required, for implementing fast arithmetic operations. About the choice of this parameters in order to design the structure of each layer, it can be claimed that, even though Rainbow can be defined for an arbitrary number of stages u, choosing u= 2 offers a more efficient scheme that generates shorter keys at the same level of security offered by a scheme designed with other values of u. Choosing u > 2leads to a small improvement in performance terms while increasing notably the size of the keys to reach the same level of security. It is a common practice to choose the size of the layers to be equal (o1=o2=··· =ou) due to implementation ease and efficiency-related reasons. 23 Furthermore, the number of vinegar variables is chosen to be two (v= 2o) or three (v= 3o) times the number of oil variables, given that v≤oand v >> o compromises the security of the cryptosystem. All these principles are presented and justified in [DS05]. Diverse research has been made to determine the suitable parameters depending on the user’s interest by studying the correlation between the selection of values and the level of security offered by the scheme. In fact, on the supporting documentation of Rainbow [DPSY19], the authors claim four statements that relate the choice of concrete parameter sets with the vulnerabilities that are generated over the security of the cryptosystem which can be exploited by different cryptanalysis techniques. These remarks are listed below. • If the number of equations (o1+o2) that form the public key mapping is not large enough, the scheme becomes vulnerable to direct attacks. • The value of v1, corresponding to the number of vinegar variables of the first layer, has to be large enough to prevent the Rainbow-Band-Separation attack. • Choosing the number of oil variables in the second layer o2too high will make the scheme vulnerable to the UOV attack. • A small value of o2can get the security of the scheme compromised when facing the HighRank attack. 4.4 Algorithms The Rainbow signature scheme provides three different available cryptographic functionalities. The first is Key Generation, which returns a duple composed by the public and the secret key whose size will depend on the parameters chosen to design the structure of the cryptosystem. The second is Signature Generation, which implies the encryption, with the secret key, of the hash value generated from the message to sign, in order to obtain its digest. The last procedure is Signature Verification, which authenticates the actual sender of the signature to verify, by comparing both the hash of the message and the hash of the decrypted signature using the public key. Along the following pseudo-code description of the algorithms, different functions are being called. Instead of also showing their whole implementation, we directly provide a brief description for each of them in Table 4.1. 24 Functions Output isInvertible(M)True or False if the input matrix has an inverse Aff(M, c)Affine transformation M·x+c Matrix(q, s1, s2) s1×s2matrix with random coefficients from Fq CentralMap(q, v1, o1, o2)Rainbow central map according to the input parameters Aff−1(b f(v1+1), ..., b f(n))Affine inverse of the system (b f(v1+1), ..., b f(n)) Gauss(b f(v2+1,...,n)= (xv2+1, ..., xn)Random solution of the input equation system Table 4.1: Description of the functions implicitly called in the KeyGen, Sign and Verify algorithms pseudo-code. 4.4.1 Key Generation The private key consists in two invertible affine maps S(MS, cS) : Fm→Fmand T(MT, cT) : Fn→Fn, as well as a quadratic central map Q:Fn→Fm. Random values from a given finite field of size qare selected to fill the coefficient matrices and vectors of each mapping. The public key is generated by computing the composition P=S ◦Q◦T :Fn→Fm. The affine transformation Smixes the variables of in the polynomials of the central map. Otherwise, the mapping Tis responsible for mixing the polynomials of the composition between them. As mentioned in 4.2, after this process the public map Plooks like a random polynomial system. Algorithm 1 Rainbow Key Generation Input: Rainbow parameters (q, v1, o1, o2), length of salt l Output: Rainbow key pair (pk, sk) 1: m←o1+o2 2: n←m+v1 3: while isInvertible(Ms) == FALSE do 4: MS←Matrix(q, m, n) 5: cS←rand(Fn) 6: S ← Aff(MS, cS) 7: while isInvertible(MT) == FALSE do 8: MT←Matrix(q, n, n) 9: cT←rand(Fn) 10: T ← Aff(MT, cT) 11: Q ← CentralMap(q, v1, o1, o2) 12: P ← S ◦Q◦T 13: pk←pk, l 14: sk←sk, l 15: return (pk, sk) 25 The o-linear group of coefficients is stored in the form of a row-major matrix, as shown in the following sequence [γ(v1+1) v1+1 , γ(v1+1) v1+2 ,··· , γ(v1+1) v2, γ(v1+2) v1+1 ,··· , γ(v2) v2] 5.2.3 Finite Field Arithmetic Galois Field Arithmetic plays a key role in the performance of cryptographic schemes. For this reason, it is important to look for efficient software implementations, given that only in a few fields of concrete size is possible to perform hardware-supported operations. •Addition The reference implementation performs additions and subtractions with 8-bit integers, corresponding to elements from GF(256), so no merging or splitting of has to be performed. It is the most efficient way to exploit the size of the smallest variable type provided by the integer standard library of the C language. For this reason, numbers from GF(16) have to be arranged in pairs before being added to another pair of GF(16) coefficients. In case of additions between GF(256) integers, the operation is performed directly. The addition performed modulo 2, as an XOR binary function. •Multiplication In the reference algorithm of both rounds, the multiplication is implemented to be timeconstant, taking advantage of the tower field representation. The methodology used is the so-called Karatsuba-Ofman, which is recursively employed until the terms of the multiplication are expressed with coefficients from GF(2), where the operation is entirely performed at hardware level as an AND function. Multiplications between GF(16) elements are faster than GF(256), as in the latter case, one more decomposition stage of the tower representation has to be undergone. 5.2.4 Comparison between Rainbow Variants Up to this point, we have described the most relevant details in the implementation that are shared between the two submissions of Rainbow to the NIST post-quantum competition. The following lines describe the differing parts between both rounds and the impact they have over the general behaviour of the scheme. The second round submission of the algorithm is basically a variant of the first submission, that yields three different algorithms for each parameter set provided, with improved performance in terms of execution time and memory called after Classic, Cyclic and Compressed Rainbow. 32 •Improved Key Generation The three proposed schemes in Round 2 generate the pair of keys much faster, given that the interpolation method, used in Round 1, is substituted by a matrix multiplication approach, which reduces drastically the number of instructions to perform the task. The mappings that describe the private key S,Qand Tare restricted to an homogeneous composition which results into an homogeneous public key P. A polynomial is called to be homegenous when its non-zero terms have the same degree. Therefore, all the Rainbow mappings are composed only by second degree polynomials, leaving out the linear and the constant terms. The security level of Rainbow is not compromised by this modification, given that the non-homogeneous part of the matrices does not provide further resilience to the scheme. Furthermore, the linear maps Sand Tare arranged in a special form, as shown below. S=1o1×o1S0 o1×o2 0o1×o21o2×o2T=   1v1×v1T(1) v1×o1T(2) v1×o2 0o1×v11o1×o1T(3) o1×o2 0o2×v10o2×o11o2×o2    •Parameter Sets From the 9 parameter sets that are proposed in Round 1 by combining GF (16), GF(31) or GF(256) and the different options to choose from SHA-2, Round 2 reduces the number of sets available to 3. The roman numbers indicate the NIST security category that the scheme aims at. Moreover, I and II employ SHA256, III and IV SHA384 and V and VI SHA512. The letter indicates the finite field used (a for GF(16), b for GF(31) and c for GF(256)). Set Parameters #Equations #Variables Ia (F, v1, o1, o2)GF(16),32,32,32 64 96 Ib (F, v1, o1, o2)GF(31),36,28,28 56 92 Ic (F, v1, o1, o2)GF(256),40,24,24 48 88 IIIb (F, v1, o1, o2)GF(31),64,32,48 80 144 IIIc (F, v1, o1, o2)GF(256),68,36,36 72 140 IVa (F, v1, o1, o2)GF(16),56,48,48 96 152 Vc (F, v1, o1, o2)GF(256),92,48,48 96 188 VIa (F, v1, o1, o2)GF(16),76,64,64 128 204 VIb (F, v1, o1, o2)GF(31),84,56,56 112 196 Table 5.1: List of the proposed parameter sets for the Round 1 submission of the Rainbow algorithm 33 Set Parameters #Equations #Variables Ia (F, v1, o1, o2)GF(16),32,32,32 64 96 IIIc (F, v1, o1, o2)GF(256),68,36,36 72 140 Vc (F, v1, o1, o2)GF(256),92,48,48 96 188 Table 5.2: List of the proposed parameter sets for the Round 2 submission of the Rainbow algorithm •Memory-Speed Trade-Off Cyclic and compressed Rainbow variants are characterized by drastically reducing the memory usage while losing efficiency during execution. In the one hand, cyclic Rainbow is based on Petzoldt’s cyclic scheme [PBB10], which allows, not only to insert cyclic matrices into the public key map but also to generate most of its parts by using a stored seed [DBM12]. This approach saves up to the 70% of the memory space employed in Round 1. In the other hand, the compressed version stores the secret key as two 256 bit seeds. The loss of efficiency is given by the fact that every time the public or secret keys have to be used in either verification or signing routines respectively, they have to be decompressed from the stored seed that generates them, leading to a slower execution. 5.3 Modifications to the Reference Implementation In order to implement the Rainbow algorithm in the Cortex-M4, we have to get rid of most of the libraries used in the reference implementation due to the huge overhead that is generated. The strict memory constraints imposed by the MCU and the incompatibilities in the code between x86_64 and ARM compilers are the reasons that explain this practice. Fortunately, only the OpenSSL library is employed, both for document hashing and generating random bytes. We replaced the OpenSSL library used in the given reference implementation with the mbedTLS2, a cryptographic library with SSL and TLS capabilities for ARM microprocessors. Even though we managed to compile the mbedTLS library for our architecture, a huge amount of memory was consumed in order to handle the storage of this library, without leaving enough space for implementing the algorithm on the device. After discussing which could be the best option for omitting the use of libraries without downgrading the overall performance, we decided to 2https://tls.mbed.org 34 •Hash Functions Employ the hashing functions for SHA256, SHA384 and SHA512 based on Daniel Bernstein’s public domain implementation. •RNGeneration Use the Pseudo-Random Number Generator (PRNG) integrated in the Nucleo L4R5ZI board, which uses hardware noise as the source to obtain a seed for generating aleatory numbers. Therefore, all the functions and structures related to seed generation and PRNG configuration are dismissed. To take advantage of the integrated PRNG, we use the HAL driver available for this purpose. More specifically, we call the function HAL_RNG_GenerateRandomNumber, that returns a 32-bit random number. As the original function from the reference implementation returns nrandom bytes, we had to adapt our method to return the demanded number of bytes correctly by performing 8-bit splits over the output of the HAL PRNG function. •Memory Allocation Instead of using aligned_alloc() for dynamically allocating memory, we directly use malloc(), given that the C standard library for the cross-compiler arm-none-eabi-gcc does not provide this function. This change is only applied in Round 2. 5.4 Rainbow Embedded Application For visualizing and evaluating the way key generation, signature and verification algorithms work, we embedded the Rainbow scheme in a real application. The MCU is flashed with three different instances of the Rainbow scheme constructed from the parameter sets Ia and Ic from Round 1 and Ia from Round 2. The security provided by these parameter sets corresponds to level 1 of the NIST security categories for the Ia and level 2 for the Ic. The parameter sets that we evaluate in this thesis use SHA256 to generate hash values. Because of the limitations imposed by the memory of our device, we could not fit any of the other parameter set alternatives proposed. From round 2 we only select the Ia_Classic approach, leaving out the cyclic and compressed variants from the evaluation. Furthermore, We have not included the set Ib, which uses GF(31) as the underlying finite field, given that most part of the research papers tend to dismiss its use due to the efficiency loss that it generates. The application we have implemented is based on a finite state machine to communicate the PC and the microprocessor. The methodology is quite straightforward, given the simplicity of our MCU which does not have neither an OS nor a file system. The program runs over an infinite loop and listens to the PC that through UART until a command is received. Once at this point, the MCU processes the message and executes 35 a callback function, according to the content of the command that has been received. The microprocessor can be interpreted as a server, while a python script on the PC side performs the task of a client. The client application is capable of sending commands and documents to the MCU, as well as receiving results, like keys, signatures, performance metrics... We designed a simple transmission protocol in order to communicate both ends and have a synchronous functioning of the whole system. In a certain time instant, the application finds himself in a concrete state, where a handler function is executed. The next state is determined by the return value of this function. This methodology is followed indefinitely during the execution of the program. The starting point is the IDLE state, which waits for the client to send a SPACE character (0x20) to launch the application. Once received, the application jumps to the D_IN state, where the the program waits for the commands corresponding to the algorithm that user demands to execute. The characters that refer to Key Generation, Signature and Verification are 0x00, 0x01 and 0x02 respectively. The D_RX state is responsible for checking the command received. The KEY (keygen_Handler()), SIGN (signature_Handler()) or VERIF (verification_Handler()) states correspond to the three functions provided by the cryptosystem. After the program has returned from the handler of any of the mentioned states above, the application jumps back to the REST state, which allows the user to keep the application running or to terminate it. As the MCU does not have a file system, the keys and signatures Figure 5.1: States diagram of the Rainbow embedded application 36 are stored in arrays of 8-bit integers that are declared as global variables in the code. Within the states SIGN and VERIF, the application waits for the client to send the entire message that has to be signed or verified before calling the corresponding handler, which implies that two more buffers are required to store this data. These arrays are allocated dynamically, once the whole messages have been received in the microprocessor side. Every time the application is terminated, all the buffers are freed from memory. 5.5 Performance Optimization Regarding the performance of the Rainbow instances from Round 1 and Round 2 in our platform, we made the decision to optimize the execution time for the key generation, message signature and verification, in order to further increase the speed of the algorithm. The number of clock cycles elapsed to execute these functions is higher than in various post-quantum digital signature approaches. We want to prove that taking advantage of the scheme’s construction features, the execution speed can be accelerated in order to get a modified Rainbow that processes the basic functions faster than other state-of-the-art digital signature alternatives in our platform. It is important to notice that the implementation runs slower in our MCU than in other platforms with higher complexity, not only because of the faster clock but also because of the different instructions that are employed. The microprocessor that is used is a reduced instruction set computing (RISC), resulting into smaller and simpler instructions fetched to the core. Therefore, in order to perform a specific task, the number of instructions needed is bigger in a RISC than in a CISC (complex instruction set computing) architecture, where longer and more complex instructions are executed. The instructions of the last ISA mentioned usually require various clock cycles to be executed. This is why CISC architectures are usually implemented in systems with a high frequency clock in the order of GHz. In our case, we have a lower frequency system clock combined with a huge amount of 1-cycle instructions, which ends up in a slower execution. 5.5.1 Data Collection To quantify the performance of the optimized version of the algorithms that have been implemented, we analyze two different features: execution speed and stack memory usage. Below is described the methodology followed for obtaining these metrics. •Stack Memory Usage The stack usage is obtained by first filling the stack memory from a known address, given by the declaration of a variable, down to a concrete amount of bytes with known 37 dummy values. After that, we check the values stored from the lowest memory address storing a dummy value as starting point, to the first appearance of a different value. We claim the amount of stack used by subtracting the address corresponding to the first non-dummy value and the address of the declared variable before calling the function to evaluate. The stack usage is given in Bytes among all the tables that are exposed in this work. This sequential procedure is shown from left to right in 5.2. Figure 5.2: Stack usage measurement. The first picture shows the sectioned structure of the RAM. The second picture presents the memory with filled dummy values. The third picture illustrates the RAM layout before returning from a function. •Execution Time For measuring the number of clock cycles spent in each function, we take advantage of the DWT_CYCCNT internal register of the Cortex-M4 3. This register increments by one the current stored value, every time a clock cycle elapses during the execution of a program. The number of cycles that can be represented range from 0to 232 −1. When the register overflows it is wrapped around 0. Therefore, in case that the function takes longer than 232 clock cycles, we must know the number of times that the register overflows to obtain the total time. For this purpose, we use the internal SysTick timer. Using the HAL drivers functionalities, we can set a concrete number of elapsed ticks before the MCU throws an interruption calling HAL_SYSTICK_Config. In our case, we set this value to the maximum number that can be stored in the 24-bit SYST_CVR register4. 3http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0439c/BABJFFGJ.html 4http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0552a/Bhccbfia.html 38 This register stores the current value of the SysTick Timer. The interruption handler is implemented to add one to uwTick, which is the global variable storing the number of times that the register has been overflowed. Finally, we can compute the total number of clock cycles elapsed making use of both measurements with the following equation: Clock_Cycles =numIRQ *maxTicks_Counter +current_Counter 5.5.2 Optimization Approach The first step of the optimization process consists in evaluating the different factors that characterize the algorithms so that we can exploit them in order to achieve an optimized version. The fact that all the parameter sets evaluated are using the same hash function (SHA256), we can assume that no difference in performance between them will come from the hashing procedure, but from the size difference of the finite fields employed, as well as the parameters chosen to design the scheme. As the latter factor is fixed to achieve a established level of security, we decide to focus on finite field arithmetic in order to increase the efficiency of the cryptographic functions provided by the Rainbow scheme. The second step is based on exploring alternatives to the multiplication reference implementation, so that we can reduce the number of clock cycles to compute the operation. In order to do so, we took advantage of the following principles: • Arithmetic in GF (2N)for large Ncan sometimes be too expensive in terms of computation, specially when using traditional multiplication methodologies. The use of the composite field representation can speed up the opeartions since the coefficients are represented by n-bit words, which is advantageous for the implementation of on microprocessors, specially when nis selected properly. However, this property can not be fully exploited as the size of the fields is relatively small. • The use of look up tables allows us to substitute the reference implementation log2n- step Karatsuba-Ofman algorithm called every time a multiplication is performed, where ncorresponds to the degree of the polynomials, for memory accesses to a precomputed table, containing the multiplications between every combination of elements from the underlying field. The construction time of the tables can be reduced if the degree of the irreducible polynomial in the tower structure equals 3or 5[SK10]. The look up table for multiplying GF(2N)elements is initialized once when the application is launched, so no overhead is generated. It is constructed using the Karatsuba-Ofman al- 39 gorithm to reduce the number of submultiplications to obtain the results. For generating the GF(16) table, we used logarithmic look-up tables to speed up the execution of this suboperations obtained after applying the Karatsuba decomposition method. The log-antilog tables compute the multiplications in the ground field. Therefore, we only used them to compute multiplications in GF(4). The GF(16) look up table is reused to tabulate the products from GF(256). The motivation to use log-antilog tables is given by the fact that a multiplication between two integers from a finite field a·bcan be alternatively written as log−1(log(a) + log(b)), which allows the user to compute the operation by simply performing three memory accesses to tables which size equals the number of elements of the field, and a modulo computation. Furthermore, the clock cycles can be reduced even more, by using an inverse logarithmic table twice the size of the original approach instead of the modulo. This methodology fits perfectly in small field multiplications, where doubling their size does not increase too much the number of elements in the antilog table. It is required to ensure that after the modifications made to improve the efficiency, the scheme remains immune against timing attacks. As mentioned in 5.2.3, the tower field representation provides time-constant arithmetic opeartions between the components of the private key. Therefore it can be ensured that no side-channel information is leaked . The use of look up tables can be exploited by performing cache-timing attacks, such as PRIME+PROBE and its variant FLUSH+RELOAD, which take advantage of the shared lastlevel cache [DHF+10]. The time difference between the cache hits or misses to the look up tables leaks information about the structure of the secret key. This attacks consist in three stages. Firstly, the attacker flushes a cache line from the cache hierarchy. Secondly, he waits until the victim accesses that line. Then, the attacker reloads the content on that line and measures the access time. If the line has been stored in the cache (hit), the number of clock cycles to perform the task will be lower. Otherwise, it will take significantly longer, as the data will have to be brought from memory. This reveals the positions on the look up table that were accessed, and thus, the location where the elements are stored. In our case, although using the look-up table approach, the security of our scheme will not get compromised, as the Cortex-M4 microprocessor does not have a cache memory structure. Round 1 We compute the elements for the table of GF(16) and GF (256) using GF(4) and GF(16) look-up tables respectively, as it has been mentioned above. Algorithms 4 and 5 describe the generation procedure of these tables in pseudo code. The functions gf16_mul_lookupTable and gf4_mul_lookupTable perform the memory accesses in order to get the result of the multiplications. 40 Therefore, we need to store a table of 256 (28) elements for Ia and 65536 (216) elements for Ic. Algorithm 4 GF(16)Look-up Table Generation Input: GF(4) look-up table gf4_tab Output: GF(16) look-up table gf16_tab 1: size ←1<< 4 2: for i≤size do 3: for j≤size do 4: a0b0←gf4_mul_lookupTable(x0, y0, gf4_tab); 5: a1b1←gf4_mul_lookupTable(x1, y1, gf4_tab); 6: abx←gf4_mul_lookupTable(x0Lx1, y0Ly1, gf4_tab)La0b0La1b1; 7: a1b1_2←gf4_mul_lookupTable(a1b1,2, gf4_tab); 8: gf16_tab[16i+j]←(abxLa1b1)<< 2) La0b0+a1b1_2; 9: return (gf16_tab) Algorithm 5 Look-up GF(256) Table Generation Input: GF(16) look-up table gf16_tab Output: GF(256) look-up table gf256_tab 1: size ←1<< 8 2: for i≤size do 3: for j≤size do 4: a0b0←gf16_mul_lookupTable(x0, y0, gf16_tab); 5: a1b1←gf16_mul_lookupTable(x1, y1, gf16_tab); 6: abx←gf16_mul_lookupTable(x0Lx1, y0Ly1, gf16_tab)La0b0La1b1; 7: a1b1_8←gf16_mul_lookupTable(a1b1,8, gf16_tab); 8: gf256_tab[256i+j]←(abx+a1b1)<< 4) La0b0La1b1_8; 9: return (gf256_tab) There is an alternative for GF (256) multiplications to save space in the SRAM, given that the size of the table used of size 216 in addition to the public and secret key buffers, constrain drastically the amount of memory available left for the execution of the cryptographic procedures of key generation, signing and verification. Given that the Karatsuba-Ofman decomposition of the GF(256) multiplication consists in 4 GF(16) multiplications, we can perform 4 memory accesses to the GF(16) table instead of 1 access to the GF(256). Choosing between the two variants depends on the user’s interest. The GF(256) table option is faster but needs a huge table to store all the values. Even though accessing a bigger table is slower than checking entries in a smaller table, it is still faster than the second option, where 4 accesses are required. In this case, the table’s size used is very small compared to the other alternative, thus saving a great amount of memory space. In this case, the difference in size between the tables of both methods is 65280 bytes, given by 216 −28. 41 in comparison to the 32-bit multiplication approach implemented in the reference version. We are able to improve the speed of this set only with -O2 and -Ofast optimization flags. Otherwise, for the sets from Round 1, the execution time is reduced by the same factor as the achieved in the signature procedure. Og O1 O2 Ofast Og O1 O2 Ofast Og O1 O2 Ofast 106 107 108 Number of Clock Cycles Optimized Reference Ia Ic Ia_Classic Figure 6.3: Optimized and Reference Rainbow Performance for Signature Verification on Ia, Ic and Ia_Classic. 6.4 Comparison with other Cryptosystems To evaluate the functioning of the Rainbow cryptosystem in a global scene, we provide a quantitative comparison of the performance achieved during the signature and verification functions, with timing benchmarks for various state-of-the-art post-quantum signature schemes [KRSS]. These algorithms are the Lattice-based DilithiumIII[DKL+17] and qTesla- II [BAA+19], the Hash-based SPHINCS+sha256-128f[BDE+19], and the multivariate LUOVII [BPSV19]. In order to give a fair comparison, we have selected concrete versions of the post-quantum techniques whose security level [BBB+12] is equal to the achieved by the Rainbow parameter sets that are evaluated in this thesis: 128-bit post quantum security (levels 1 and 2 of the NIST requirements). The Rainbow metrics shown in the plots correspond to the best result achieved, in terms of speed, for each of the parameter sets. Although, many aspects should be taken into account to offer an exact comparison, such as computational assumptions, implementation details or constant-time against non-constant- time approaches, we intend to give a precise differentiation between different algorithms that compete to become the quantum secure digital signature standard. 48 Methodology. The timings for Rainbow Ia, Ic and Ia_Classic sets are obtained with the core running at 16MHz, while the measurements for the other algorithms are acquired at 24MHz. However, the benchmarks have been generated in the same exact platform (Cortex- M4). Even though the times are obtained using different clock frequencies, the fact that the instruction set architecture of the MCU’s is the same in all cases (ARMv7-M), allows the scaling of the time to give a highly precise approximation of the milliseconds elapsed in a common clock frequency basis. The measurements are taken at a certain frequency where the wait cycles due to the speed of the memory controller are not added to the elapsed time. Algorithm Sign Time (ms) Verif Time (ms) Pk (KB) Sk (KB) Signature (B) Ia 0.028 0.026 152.097 100.209 64 Ic 0.026 0.024 192.241 143.385 104 Ia_Classic 0.015 0.013 148.992 92.960 64 qTesla-II 0.156 0.027 2.336 1.600 2144 LUOV-II 1.133 0.898 12.100 0.032 311 Dilithium-III 0.077 0.019 1.472 -2701 SPHINCS+ 128 4.349 0.174 0.032 0.064 16976 Table 6.1: List of the algorithms evaluated their corresponding performance metrics in terms of execution time and size. (1) (2) (3) (4) (5) (6) (7) (1) (2) (3) (4) (5) (6) (7) 0.01 0.1 1 10 Elapsed Time (ms) Signature Verification qTesla-II LUOV-II Ia Ic IaClassic Dilithium-III SPHINCS+ Figure 6.4: Execution time comparison between different public key algorithms during signature and message verification. 49 (1) (2) (3) (4) (5) (6) (7) (1) (2) (3) (4) (5) (6) (7) 0.1 1 10 100 Size (KB) Keys (Pk/Sk) Signature qTesla-II LUOV-II Ia Ic IaClassic Dilithium-III SPHINCS+ Figure 6.5: Size of the public key and secret key on the left and signature on the right. The measurements are expressed in Kbytes. Analyzing the bar plot in Figure 6.4, we can claim that during the signature procedure, all the different versions of Rainbow are faster than any of the other post-quantum approaches presented, concretely by 0.062 ms in case of Ia_Classic and 0.049 ms and 0.051 ms in case of Ia and Ic respectively, compared to the signing speed of Dilithium-III, which is the fastest algorithm right after the Rainbow schemes. The Ia_Classic Rainbow is still the fastest in verification speed, although in this case, Dilithium- III overcomes by 0.015 ms the sets Ia and Ic. The lattice-based qTesla is quite fast during verification speed unlike in the signature case. It is interesting also to compare the different behaviour between Rainbow and the multivariate approach LUOV-II, which is a single layer version of the former, that employs a different representation of its keys to drastically reduce the amount of memory needed for their storage. This has a huge impact over the speed of both the signature and verification cases. Regarding the size of the keys and signatures generated by the cryptographic techniques in Figure 6.5, we can affirm that Rainbow generates the smallest signatures, although the size of its keys its about hundreds of kilobytes, which are very big compared to the ones provided by the other algorithms. The SPHINCS+sha256-128f cryptosystem needs the smallest amount of space to store the pair of public and private keys (96 Bytes). The biggest signatures are generated by the the lattice-based Dilithium-III (2.7KBytes) and the hashbased SPHINCS+sha256-128f (16.9KBytes). 50 Based on the observations, we can conclude that there clearly exists a trade-off between the execution time of the different procedures and the memory needed to store the key pair and the signature. The bar plots show that there is not any approach from the ones analyzed, that actually has a good balance between the aspects evaluated. We can hold that the Rainbow cryptosystem offers the fastest signature and message verification among the approaches compared. It also has the shortest signatures even though the size of its keys is very large in contrast to the other authentication cryptographic solutions. This results are based on the fact that all cryptosystems share the same level of security. It would be interesting to evaluate how the speed and the memory amount required vary depending on the security level of the scheme as the choice of the parameters is not done equal in all the algorithms but according to its own structure. There are still a few other signature schemes submitted to the NIST competition that have not been included in this comparison: Falcon [PFH+19], GeMSS [CFMR+19], MQDSS [SCH+19] and Picnic [ZCD+19]. The reason why we dismissed this approaches is because they are unable to fit in the memory of our target device, due to the large keys generated and the extensive use of the stack that they perform. 51 7 Conclusions In this thesis, we evaluated the efficiency of the Rainbow multivariate scheme in an ARM Cortex-M4 microprocessor, in order to study the feasibility of its implementation on a constrained device. It has been shown that the level of security that Rainbow can provide is notably constrained due to the memory limitations of our platform, even though the parameter sets according to the two first security categories proposed by NIST, are still suitable options. Rainbow has been proven to be the fastest in both signature generation and verification, compared to a group of several state-of-the-art post-quantum digital signature techniques, sharing the same security level (category 1). We also manifested the limitation that implies the size of the keys generated by this MQ-based algorithm, which is the main obstacle faced during the implementation in limited-resource platforms. We proposed an optimized version of the Rainbow reference constructions that were able to fit in our MCU, by implementing a look-up table-based approach, exploiting the characteristic architecture of our platform and the construction principles of the scheme. The modifications resulted in the reduction of the signing and verifying times by a factor of 17.5and 19 respectively, in two out of three cases. In consequence of the optimization approach followed, we implemented a more efficient Rainbow instance, providing category 2 security, with a faster signature generation than all the different post-quantum cryptographic solutions analyzed. 7.1 Further Improvements Rainbow provides notably short signatures due to its construction principle, even though the public and private keys are too big to fit all the possible parameter sets available in a constrained device. Once known that this approach provides short signatures which are generated at a relatively high speed compared to other post-quantum families, the next step would consist in reducing the amount memory required to store the keys. Below are some options that have already been proposed for this purpose. •Private Key : The affine transformations and the central map from the secret key are composed by random values from the same finite field generated by a PRNG. Instead of storing all the bytes corresponding to the coefficients of the polynomials, we can simply store a n-bit seed, which is enough to always generate the same random num- 52 bers. The drawback of this technique is the efficiency reduction during the signature generation, as all the elements that constitute the private key have to be generated every time that the key has to be employed. •Public Key : The size of the Rainbow construction is tightly related to the parameter set that is chosen to build the scheme. Exhaustive research has been made on the optimized selection of parameters, in order to find combinations between them that are able to reduce the size of the keys without downgrading the level of security. Another option to efficiently store the key is based on Macauley matrices. The technique consists in inserting a structured submatrix into the public map coefficient Macauley matrix. This construction provides the possibility to the user to fix most part of the public key so the central map of the scheme is computed out of it. Partially circulant matrices or linear recurring sequences are two alternatives for choosing the composition of the structured matrix. Furthermore, depending on the submatrix structure, the verification process of the scheme can be speed up. As mentioned several times along the thesis and further proven in Section 6.4, there exists trade-off that has to be respected between the memory needed for storing the keys and the speed at which the key generation, message signature and verification are executed. Employing the techniques proposed in different research papers for reducing the memory footprint, it is shown that the execution time elapsed for signing and verifying messages gets always longer. Given the advantage that has Rainbow in terms of speed, in front of other post-quantum approaches, this algorithm has still margin to improve the memory efficiency while still being one of the fastest cryptographic solutions among quantum secure digital signature proposals. 53 Bibliography [BAA+19] Nina Bindel, Sedat Akleylek, Erdem Alkim, Paulo S. L. M. Barreto, Johannes Buchmann, Edward Eaton, Gus Gutoski, Juliane Kramer, Patrick Longa, Harun Polat, Jefferson E. Ricardini, and Gustavo Zanon. Lattice-based digital signature scheme qtesla, 2019. https://github.com/qtesla/qTesla. [BBB+12] E B Barker, W C Barker, W E Burr, W T Polk, and M E Smid. Recommendation for key management, part 1 :. Technical report, 2012. [BDE+19] Daniel J. Bernstein, Christoph Dobraunig, Maria Eichlseder, Scott Fluhrer, Stefan-Lukas Gazdag, Andreas Hülsing, Panos Kampanakis, Stefan Kölbl, Tanja Lange, Martin M. Lauridsen, Florian Mendel, Christian Rechberger Ruben Niederhagen, Joost Rijneveld, and Peter Schwabe. Sphincs+ – submission to the nist post-quantum project, 2019. https://sphincs.org/ resources.html. [BDKR03] Raghav Bhaskar, Pradeep Dubey, Vijay Kumar, and Atri Rudra. Efficient galois field arithmetic on simd architectures. pages 256–257, 01 2003. [BPSV19] Ward Beullens, Bart Preneel, Alan Szepieniec, and Frederik Vercauteren. Submission of the luov signature scheme to the nist pqc project, 2019. https: //github.com/WardBeullens/LUOV. [CDF02] Nicolas T. Courtois, Magnus Daum, and Patrick Felke. On the security of hfe, hfev- and quartz. Cryptology ePrint Archive, Report 2002/138, 2002. https: //eprint.iacr.org/2002/138. [CFMR+19] A. Casanova, J.-C. Faugère, G. Macario-Rat, J. Patarin, L. Perret, and J. Ryckeghem. Gemss. technical report, 2019. https://csrc.nist.gov/projects/ post-quantum-cryptography/round-2-submissions. [Che06] Y Chen. An implementation of pmi+ on low-cost smartcard. Master’s thesis, National Taiwan University, 2006. [DBM12] Philippe Dreesen, Kim Batselier, and Bart De Moor. Structured matrices and solving multivariate polynomial equations, 2012. 54 [DHF+10] Jean-Luc Danger, Youssef El Housni, Adrien Facon, Cheikh T. Gueye, Sylvain Guilley, and Sylvie Herbel. On the performance and security of multiplication in gf(2N). 2010. [DKL+17] Léo Ducas, Eike Kiltz, Tancrède Lepoint, Vadim Lyubashevsky, Peter Schwabe, Gregor Seiler, and Damien Stehlé. Crystals-dilithium – submission to the nist post-quantum project, 2017. https://pq-crystals.org/dilithium/index. shtml. [DPSY19] Jintai Ding, Ming-Shing Chen Albrecht Petzoldt, Dieter Schmidt, and Bo-Yin Yang. Rainbow. technical report, 2019. https://csrc.nist.gov/projects/ post-quantum-cryptography/round-2-submissions. [DS05] Jintai Ding and Dieter Schmidt. Rainbow, a new multivariable polynomial signature scheme. In John Ioannidis, Angelos Keromytis, and Moti Yung, editors, Applied Cryptography and Network Security, pages 164–175, Berlin, Heidelberg, 2005. Springer Berlin Heidelberg. [DYC+08] Jintai Ding, Bo-Yin Yang, Owen Chen, Ming-Shing Chen, and Doug Cheng. New differential-algebraic attacks and reparametrization of rainbow. Cryptology ePrint Archive, Report 2008/108, 2008. https://eprint.iacr.org/2008/ 108. [Eyu15] Can Eyupoglu. Performance analysis of karatsuba multiplication algorithm for different bit lengths. Procedia - Social and Behavioral Sciences, 195:1860– 1864, July 2015. [GCL92] Keith O Geddes, Stephen R Czapor, and George Labahn. Algorithms for computer algebra. Springer Science & Business Media, 1992. [GJ90] Michael R. Garey and David S. Johnson. Computers and Intractability; A Guide to the Theory of NP-Completeness. W. H. Freeman & Co., New York, NY, USA, 1990. [Gro96] Lov K Grover. A fast quantum mechanical algorithm for database search. arXiv preprint quant-ph/9605043, 1996. [KPG99] Aviad Kipnis, Jacques Patarin, and Louis Goubin. Unbalanced oil and vinegar signature schemes. In Jacques Stern, editor, Advances in Cryptology — EUROCRYPT ’99, pages 206–222, Berlin, Heidelberg, 1999. Springer Berlin Heidelberg. [KRSS] Matthias J. Kannwischer, Joost Rijneveld, Peter Schwabe, and Ko Stof- 55 felen. PQM4: Post-quantum crypto library for the ARM Cortex-M4. https: //github.com/mupq/pqm4. [Laz83] D. Lazard. Gröbner bases, gaussian elimination and resolution of systems of algebraic equations. In J. A. van Hulzen, editor, Computer Algebra, pages 146–156, Berlin, Heidelberg, 1983. Springer Berlin Heidelberg. [LSY+16] L.Chen, S.Jordan, Y.K.Liu, D.Moody, R.Peralta, R.Perlner, and D.Smith-Tone. Report on post-quantum cryptography. 2016. [Pat96] Jacques Patarin. Hidden fields equations (hfe) and isomorphisms of polynomials (ip): Two new families of asymmetric algorithms. In Ueli Maurer, editor, Advances in Cryptology — EUROCRYPT ’96, pages 33–48, Berlin, Heidelberg, 1996. Springer Berlin Heidelberg. [PBB10] Albrecht Petzoldt, Stanislav Bulygin, and Johannes Buchmann. Cyclicrainbow – a multivariate signature scheme with a partially cyclic public key. In Guang Gong and Kishan Chand Gupta, editors, Progress in Cryptology - INDOCRYPT 2010, pages 33–48, Berlin, Heidelberg, 2010. Springer Berlin Heidelberg. [PBD14] Jaiberth Porras, John Baena, and Jintai Ding. Zhfe, a new multivariate public key encryption scheme. In Michele Mosca, editor, Post-Quantum Cryptography, pages 229–245, Cham, 2014. Springer International Publishing. [PCG01] Jacques Patarin, Nicolas Courtois, and Louis Goubin. Flash, a fast multivariate signature algorithm. In David Naccache, editor, Topics in Cryptology — CTRSA 2001, pages 298–307, Berlin, Heidelberg, 2001. Springer Berlin Heidelberg. [PFH+19] Thomas Prest, Pierre-Alain Fouque, Jeffrey Hoffstein, Paul Kirchner, Vadim Lyubashevsky, ThomasPornin, Thomas Ricosset, Gregor Seiler, William Whyte, and Zhenfei Zhang. Falcon. technical report, 2019. https://csrc.nist.gov/ projects/post-quantum-cryptography/round-2-submissions. [rou17] Post-quantum cryptography: Round 1 submissions, 2017. https://csrc.nist.gov/projects/post-quantum-cryptography/ round-1-submissions. [rou19] Post-quantum cryptography: Round 2 submissions, 2019. https://csrc.nist.gov/projects/post-quantum-cryptography/ round-2-submissions. [SCH+19] Simona Samardjiska, Ming-Shing Chen, Andreas Hulsing, Joost Rijneveld, 56 and Peter Schwa. Mqdss. technical report, 2019. https://csrc.nist.gov/ projects/post-quantum-cryptography/round-2-submissions. [Sho99] Peter W. Shor. Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM Review, 41(2):303–332, January 1999. [SK10] Erkay Savas and Cetin Koc. Finite field arithmetic for cryptography. IEEE Circuits and Systems Magazine, 10(2):40–56, 2010. [TC01] T.Moh and Jiun-Ming Chen. On the goubin-courtois attack on ttm. Cryptology ePrint Archive, Report 2001/072, 2001. https://eprint.iacr.org/2001/ 072. [WYHL06] Lih-Chung Wang, Bo-Yin Yang, Yuh-Hua Hu, and Feipei Lai. A “medium-field” multivariate public-key encryption scheme. In David Pointcheval, editor, Topics in Cryptology – CT-RSA 2006, pages 132–149, Berlin, Heidelberg, 2006. Springer Berlin Heidelberg. [YC05] Bo-Yin Yang and Jiun-Ming Chen. Building secure tame-like multivariate publickey cryptosystems: The new tts. In Colin Boyd and Juan Manuel González Nieto, editors, Information Security and Privacy, pages 518–531, Berlin, Heidelberg, 2005. Springer Berlin Heidelberg. [YDH+13] Takanori Yasuda, Xavier Dahan, Yun-Ju Huang, Tsuyoshi Takagi, and Kouichi Sakurai. Mq challenge: Hardness evaluation of solving multivariate quadratic problems. https://eprint.iacr.org/2015/275.pdf, 2013. [ZCD+19] Greg Zaverucha, Melissa Chase, David Derler, Steven Goldfeder, Claudio Orlandi, Sebastian Ramacher, Christian Rechberger, Daniel Slamanig, Jonathan Katz, Xiao Wang, and Vladmir Kolesnik. Picnic. technical report, 2019. https://csrc.nist.gov/projects/post-quantum-cryptography/ round-2-submissions. 57