Efficient Regular Modular Exponentiation Using
Total Page:16
File Type:pdf, Size:1020Kb
J Cryptogr Eng (2017) 7:245–253 DOI 10.1007/s13389-016-0134-5 SHORT COMMUNICATION Efficient regular modular exponentiation using multiplicative half-size splitting Christophe Negre1,2 · Thomas Plantard3,4 Received: 14 August 2015 / Accepted: 23 June 2016 / Published online: 13 July 2016 © Springer-Verlag Berlin Heidelberg 2016 Abstract In this paper, we consider efficient RSA modular x K mod N where N = pq with p and q prime. The private exponentiations x K mod N which are regular and con- data are the two prime factors of N and the private exponent stant time. We first review the multiplicative splitting of an K used to decrypt or sign a message. In order to insure a integer x modulo N into two half-size integers. We then sufficient security level, N and K are chosen large enough take advantage of this splitting to modify the square-and- to render the factorization of N infeasible: they are typically multiply exponentiation as a regular sequence of squarings 2048-bit integers. The basic approach to efficiently perform always followed by a multiplication by a half-size inte- the modular exponentiation is the square-and-multiply algo- ger. The proposed method requires around 16% less word rithm which scans the bits ki of the exponent K and perform operations compared to Montgomery-ladder, square-always a sequence of squarings followed by a multiplication when and square-and-multiply-always exponentiations. These the- ki is equal to one. oretical results are validated by our implementation results When the cryptographic computations are performed on which show an improvement by more than 12% compared an embedded device, an adversary can monitor power con- approaches which are both regular and constant time. sumption [2] or electronic emanation [3]. If the power or electromagnetic traces of a multiplication and a squaring Keywords RSA · Regular exponentiation · Constant time differ sufficiently, an adversary can read the sequence of exponentiation · Multiplicative splitting squarings and multiplications directly on a single power or electromagnetic trace of a modular exponentiation. In the lit- erature these attacks are referred to as simple power analysis 1 Introduction (SPA) and simple electromagnetic analysis (SEMA), respec- tively. Currently, RSA [1] is the most used public key cryptosystem. Consequently, modular exponentiations have to be imple- The main operation in RSA protocols is an exponentiation mented in order to prevent such side channel analysis. The first direct approach which prevents this attack is the B Christophe Negre multiply-always exponentiation which performs all squar- [email protected] ings as multiplications. But, unfortunately, it has been shown Thomas Plantard in [4] that this multiply-always strategy is still weak against [email protected] an SPA or SEMA: an operation r × r and r × r have dif- 1 DALI, Universite de Perpignan, Perpignan, France ferent output Hamming weight. The authors in [5] proposed a square-always approach which performs a multiplication 2 LIRMM, Université de Montpellier and National Center for Scientific Research (CNRS), 161 Rue Ada, 34090 as the combination of two squarings. They then noticed Montpellier, France that in this case the attack of [4] does not apply. But both 3 Centre for Computer and Information Security Research multiply-always and square-always approaches still leak (CCISR), University of Wollongong, Wollongong, Australia some information about the exponent: the computation time 4 School of Computer Science and Software Engineering is correlated with the Hamming weight of the exponent, (SCSSE), University of Wollongong, Wollongong, Australia which is then leaked out. 123 246 J Cryptogr Eng (2017) 7:245–253 Table 1 Complexity in terms of word operations per iteration of loop body for a modular exponentiation Algorithm Regular Constant time Complexity per loop body for t-word integers # Word add. # Word mult. ✗✗ 2 + ( ) 5 2 + ( ) Square-and-multiply 5t O t 2 t O t Multiply-always [5] ✗ 6t2 + O(t) 3t2 + O(t) Square-always [5] ✗ 6t2 + O(t) 3t2 + O(t) 2 + ( ) 7 2 + ( ) Square-and-multiply-always [6] 7t O t 2 t O t 2 + ( ) 7 2 + ( ) Montgomery-ladder [7] 7t O t 2 t O t Montgomery-ladder with CM [9] 6t2 + O(t) 3t2 + O(t) 2 + ( ) 5 2 + ( ) Proposed approach 5t O t 2 t O t A prerequisite to be SPA resistant is then to be regu- 2 Review of regular modular exponentiation lar and constant time. A first method which satisfies both of these properties is the square-and-multiply-always expo- We review in this section several methods for performing an nentiation proposed by Coron [6]. Its principle is to always exponentiation x K mod N. The simplest and most popular perform a multiplication after a squaring, i.e., if the bit ki = 0 method is the square-and-multiply exponentiation [10]. The then a dummy multiplication is performed. Another popular bits of the exponent K are scanned from left to right, for each strategy is the Montgomery-ladder [7] which also performs bit a squaring is performed and is followed by a multiplica- an exponentiation through a regular sequence of squarings tion by x if the bit is equal to 1. This method is detailed in always followed by a multiplication. Algorithm 1. We present in this paper an alternative approach for regular K and constant time exponentiation x mod N. Our method Algorithm 1 Square-and-multiply uses a multiplicative splitting of x into two halves. We mod- Require: x ∈{0,...,N − 1} and K = (k−1,...,k0)2 ify the square-and-multiply algorithm as a regular sequence 1: r ← 1 of squarings always followed by a multiplication with a 2: for i from − 1 downto 0 do ← 2 half-size integer. The half-size multiplications and squarings 3: r r mod N 4: if ki = 1 then modulo N are computed with the method of Montgomery [8], 5: r ← r × x mod N and we then also provide a version of the proposed exponen- 6: end if tiation with Montgomery modular multiplications adapted 7: end for to the size of the operands. We provide a complexity analy- 8: return r sis when modular operations are computed with word-level algorithm: computer words are w-bit long and considered The sequence of squarings and multiplications in the integers modulo N haveasizeoft computer words. The square-and-multiply method has some irregularities due to complexity of the proposed approach is given in Table 1 the irregular sequence of bits ki equal to 1. This can be which contains the costs of the loop bodies of the consid- used to mount a side channel attack by monitoring the power ered exponentiation algorithms. We notice that the proposed consumption or the electromagnetic emanation of the circuit approach always reaches the best complexity while having performing the computations. Indeed, if the monitored sig- the higher security level compared to best known methods of nal of a multiplication and a squaring have a different shape, the literature. then we can directly read on the power trace the sequence of The remainder of the paper is organized as follows. Sec- squarings and multiplications. If a trace of a multiplication tion 2 summarizes state of the art methods for regular modular appears between two subsequent squarings, then we deduce exponentiation. In Sect. 2.1 we review techniques to com- that the corresponding bit is 1, otherwise it is 0. pute a multiplicative splitting of an integer modulo N.In This means that a secure implementation of modular expo- Sect. 3 we present a new modular exponentiation algorithm nentiation must be computed through a regular sequence of which uses this splitting to render regular the square-and- squarings and multiplications uncorrelated with the key bits. multiply exponentiation. In Sect. 4, we present a version In the literature the following strategies were proposed to of the proposed exponentiation which incorporates Mont- prevent SPA: gomery modular multiplications. Finally, in Sect. 5,we evaluate the complexity of the proposed algorithm and pro- • Multiply-always [5]. This approach performs all the vide implementation results. squarings of the square-and-multiply exponentiation as 123 J Cryptogr Eng (2017) 7:245–253 247 3 multiplications. This leads to a sequence of 2 multipli- 2.1 Multiplicative splitting of an integer x modulo N cations on average. Unfortunately, this multiply-always approach can be threatened by the attack of [4]: this attack We consider an RSA modulus N and an integer x ∈[0, N] differentiates a power trace of a multiplication r × r (i.e. that corresponds to the message we want to decrypt or sign a hidden squaring) by a multiplication r × x with x = r by computing x K mod N. We will show in this section that based on a difference of the Hamming weight of the out- x can be split into two parts as follows put bits. • = −1 × | |, | |≤ 1/2. Square-always [5]. This approach is an improvement of x x0 x1 mod N with x0 x1 N (2) the Multiply-always and prevents the attack of [4]. The authors in [5] use the fact that a multiplication can be The idea to split multiplicatively is not new, we can find it in performed with two squarings: a number of references of the literature: for example in [14] the authors use it to randomize an RSA exponent. (r + x)2 − (r − x)2 In order to get a multiplicative splitting of x modulo N, r × x = . (1) 4 we use the method presented in [15] which consists in a partial execution of the extended Euclidean algorithm. The They re-express all the multiplications of the square- Euclidean algorithm computes the greatest common divisor and-multiply exponentiation in order to get a square- of x and N through a sequence of reductions: we start with always exponentiation.