RSA and Power Analysis
RSA and Power Analysis
Abstract. RSA is probably the most famous and the most used public
key cryptosystem. It is implemented in many smart cards with crypto
functionality. Due to its popularity it is also one of the most attacked
(with the DES). Since the first article on power analysis against RSA has
been published by Paul Kocher, many attacks and countermeasures have
been proposed. In this paper we expose an analysis of several attacks.
We will then present several countermeasures and some ideas about a
”secure” implementation with reasonable performance of RSA.
1 Introduction
Protecting a card against power analysis on PKC1 is perhaps one of
the most simple and difficult things to do. Indeed it looks simple because
of numerous mathematical properties the underlying structure allows to
use; several countermeasures do exactly that, blinding methods being the
perfect example. But on the other hand the mathematical computations
require a lot of operations and, therefore, many smart cards integrate a
crypto-processor implementing the basic modular operations. Of course,
the programmer cannot change or bypass these operations and, in many
cases, there are restrictions on the usage of those hardwired instructions.
That’s why, as usual, when dealing with security problems, the program-
mer has to carefully study the detail of the execution of these operations.
In this paper, we will first present some general results on RSA and
the way it is implemented in many smart cards. Next, we will discuss
about several attacks and their (practical) feasibility. And finally, we will
present some countermeasures against these attacks.
?
Research done while at Oberthur Card Systems.
1
Public Key Cryptosystems
2 RSA and the smart card
3 Attacks
0.6
0.4
0.2
−0.2
−0.4
1 2 3 4 5 6 7 8 9 10
4
x 10
Fig. 1. Each high peak is the beginning of one operation. A large peak is a multiply,
a thin peak is a square.
Often, what the attacker gets is not exactly the d exponent but the
reduced exponent dP (or dQ ). By elementary equations, we get
e ∗ dP − 1
P =1+ 1≤k≤e
k
So, if e is small (often 3 or 65537), it is very easy to recover P and Q by
exhaustive search on the value of k. Unfortunately, when e is random, it
is impossible to proceed like this; however another method is applicable
in the general case. The idea2 is the following:
0.1
0.05
−0.05
0.05
−0.05
0.05
−0.05
Fig. 2. The hacker subtract the upper curve (real card) with the middle curve (his
card) to obtain the last curve. A difference indicates him that he didn’t guess the good
exponent.
2
Original idea by Jacques Stern.
3.2 Attack on the initial message reduction
SPA attacks The first -and the most employed- method is to try to
directly distinguish the square and the multiply steps, or, when both
are always executed, to distinguish between the real and the dummy
multiplications. Some time ago, in most cases it was possible to distinguish
the difference just by looking the consumption curves: the timings or the
shape (the bump...) of the two operations was so different than one could
distinguish immediately the two steps. In more recent implementations,
the programmers write very carefully the exponentiation and a visual
analysis is no longer possible (cf. fig.3).
0.3
0.25
0.2
0.15
0.1
0.05
−0.05
−0.1
−0.15
Fig. 3. Each high peak is the beginning of one operation, but it is very difficult to
distinguish a difference between the square and multiply.
The case 1 corresponds to a zero bit exponent where, during the mul-
tiplication by C (which is dummy in this case) the add and shift algorithm
uses C to add and not the result of the square4 ; indeed there is a cor-
relation between the two squares because the output of the first is the
input of the second. There is a correlation between the beginning of the
multiply and the square 2 because the input of the multiply is the input
of the squaring 2. There is no correlation between the other part of the
multiply and the squaring because just after the beginning of the multi-
ply the value just squared is modified because it is the value C which is
added at each elementary step of the multiplication.
The case 2 corresponds to a zero bit, where the multiplication step uses
the squared value for the elementary addition step in the multiplication.
The case 3 is a 1 bit exponent with C value for elementary addition.
The case 4, a 1 bit exponent with squared value for elementary addition.
Set(buffer1,1)
for(i=0;i<n/8;i++)
for(j=0;j<8;k++)
{
Square(buffer2,buffer1);
if(bit(i,j,d)==1)
{
Multiply(buffer1,buffer2,C);
}
else
{
Copy(buffer1,buffer2);
}
}
Example (better)
Set(buffer1,1)
p1 = &buffer1;
p2 = &buffer2;
for(i=0;i<n;i++)
{
waitrdm();
BeginSquare(p2,p1);
waitrdm();
WaitEndSquare();
waitrdm();
BeginMultiply(p1,p2,C);
waitrdm();
bit = bit(i,n);
p1 = bit*p1 + (1-bit)*p2;
p2 = bit*p2 + (1-bit)*p1;
waitrdm();
WaitEndMultiply();
waitrdm();
}
4.2 Blinding ideas
– Ñ = rdm1 × N
– M̃ = M + rdm2 × N with preferably gcd(rdm1, rdm2) = 1
– d˜ = d + rdm3 × (P − 1)(Q − 1)
Another idea is to modify the message before and after the exponen-
tiation:
Now the smart card world seems to go towards powerful 32 bits core
processor without crypto-processor, but with some efficient useful basic
instructions (multiplier 32x32 to 64 bits, ...). The advantage of those
processors is that the programmer fully controls his implementation and
countermeasures can be implanted deep in the heart of algorithm; such a
thing is impossible with crypto-processors.
5
Even if the adversary does not get the real secret exponent d, he gets a working
decrypting exponent.
Most of these attacks can easily be adapted to other finite field algo-
rithms and to elliptic curves; moreover concerning the latter, there are
specific technics using the structure of ECC (see [2, 6]).
5 Conclusion
References
1. M.-L. Akkar, R. Bévan, P. Dischamp, and D. Moyart. Power analysis, what is now
possible. Asiacrypt’00, 2000.
2. J.-S. Coron. Resistance against differential power analysis for elliptic curve cryp-
tosystems. CHES, 1999.
3. D.E. Knuth. The Art of Computer Programming, volume 2. Addison Wesley, third
edition, 1988.
4. P. Kocher, J. Jaffe, and B. Jun. Differential power analysis. Web Site:
www.cryptography.com/dpa, 1998.
6
I am still optimistic for the term ”some”, because right now, the considered solution
imply to solve a hard -a special case of the DPL- problem on the card at each
signature!!
5. P. C. Kocher. Timing attacks on implementations of Diffie-Hellman, RSA, DSS,
and other systems. Crypto ’96, pages 104–113, 1996.
6. J. López and R. Dahab. Fast multiplication on elliptic curve over gf (2m ) without
precomputation. CHES, 1999.
7. A.J. Menezes, P.C. van Oorschot, and S.A. Vanstone. Handbook of Applied Cryp-
tography. CRC Press, 1997.
8. T.S. Messerges, E.A. Dabbish, and R.H. Sloan. Power analysis attacks of modular
exponentiation in smartcards. CHES, 1999.
9. P.L. Montgomery. Modular multiplication without trial division. Mathematics of
Computation, 54, pages 839–854, 1990.