side-channel attack against rsa key generation algorithms · rsa key generation algorithms ches...

45
Side-Channel Attack against RSA Key Generation Algorithms CHES 2014 AurØlie Bauer, Eliane Jaulmes, Victor LomnØ , Emmanuel Prouff and Thomas Roche Agence Nationale de la SØcuritØ des SystLmes d’Information (French Network and Information Security Agency) Thursday, September 25 th , 2014

Upload: others

Post on 22-Aug-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Side-Channel Attack againstRSA Key Generation AlgorithmsCHES 2014

Aurélie Bauer, Eliane Jaulmes, Victor Lomné,

Emmanuel Prouff and Thomas Roche

Agence Nationale de la Sécurité des Systèmes d’Information

(French Network and Information Security Agency)

Thursday, September 25th, 2014

Page 2: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Outline

1 Introductiona. Side-Channel Attacksb. RSAc. SCA on RSA

2 Prime Generationa. State of the Artb. Prime Gen. Algo. v1c. Attack on Algo. v1d. Prime Gen. Algo. v2

3 Our Attacka. Descriptionb. Attack Analysisc. Experiments on a Toy Implem.d. Attack in Practice

4 Possible Countermeasures

1/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 3: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Outline

1 Introductiona. Side-Channel Attacksb. RSAc. SCA on RSA

2 Prime Generationa. State of the Artb. Prime Gen. Algo. v1c. Attack on Algo. v1d. Prime Gen. Algo. v2

3 Our Attacka. Descriptionb. Attack Analysisc. Experiments on a Toy Implem.d. Attack in Practice

4 Possible Countermeasures

2/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 4: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Side-Channel Attacks| RSA| SCA on RSA|

SCA: Principle

SCA consist in measuring a physical leakage of a devicewhen it handles sensitive information

I e.g. cryptographic keys

Handled info. is correlated with the physical leakageI e.g. a register leaking as the Hamming Weight of its value

The attacker can then apply statistical methods toextract the secret from the measurements

I Simple Side-Channel Attacks (SSCA)I Differential Side-Channel Attacks (DSCA)I Template Attacks (TA)I Collision-based Side-Channel AttacksI : : :

3/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 5: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Side-Channel Attacks| RSA| SCA on RSA|

RSA (Rivest - Shamir - Adelman)

RSA: the most used public-key cryptosystem

Key Generation

I Generate p, q two prime numbers of same size

I Compute n = p � q, and �(n) = (p � 1) � (q � 1)I Choose an integer e such that e and �(n) are coprime

I Compute d, the multiplicative inverse of e modulo �(n)) Public Key: (e ;n) / Private Key: d

Encryption-Decryption / Signature-Verification

I Encryption / Verification: c = me (mod n)I Decryption / Signature: m = cd (mod n)

4/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 6: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Side-Channel Attacks| RSA| SCA on RSA|

SCA on RSA 1=2

Attacking during the Key Generation

Key Generation

I Generate p, q two prime numbers of same size

I Compute n = p � q, and �(n) = (p � 1) � (q � 1)I Choose an integer e such that e and �(n) are coprime

I Compute d, the multiplicative inverse of e modulo �(n)) Public Key: (e ;n) / Private Key: d

Encryption-Decryption / Signature-Verification

I Encryption / Verification: c = me (mod n)I Decryption / Signature: m = cd (mod n)

5/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 7: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Side-Channel Attacks| RSA| SCA on RSA|

SCA on RSA 2=2

Attacking during the Decryption / Signature

Key Generation

I Generate p, q two prime numbers of same size

I Compute n = p � q, and �(n) = (p � 1) � (q � 1)I Choose an integer e such that e and �(n) are coprime

I Compute d, the multiplicative inverse of e modulo �(n)) Public Key: (e ;n) / Private Key: d

Encryption-Decryption / Signature-Verification

I Encryption / Verification: c = me (mod n)I Decryption / Signature: m = cd (mod n)

6/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 8: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Side-Channel Attacks| RSA| SCA on RSA|

RSA Key Generation exposed ?

Most of the works about Physical Cryptanalysis on RSAfocus on attacking during Decryption / Signature

Until recent years, RSA Key Generation was performedduring device personalisation

This is no longer the case, due to new security services(mobile payment, e-ticketing, OTP generations, : : :)

Some devices can perform RSA Key generation during theirlife cycle

7/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 9: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Side-Channel Attacks| RSA| SCA on RSA|

This Work ) case 1=2

Attacking during the Prime Number Generation

Key Generation

I Generate p, q two prime numbers of same size

I Compute n = p � q, and �(n) = (p � 1) � (q � 1)I Choose an integer e such that e and �(n) are coprime

I Compute d, the multiplicative inverse of e modulo �(n)) Public Key: (e ;n) / Private Key: d

Encryption-Decryption / Signature-Verification

I Encryption / Verification: c = me (mod n)I Decryption / Signature: m = cd (mod n)

8/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 10: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Outline1 Introduction

a. Side-Channel Attacksb. RSAc. SCA on RSA

2 Prime Generationa. State of the Artb. Prime Gen. Algo. v1c. Attack on Algo. v1d. Prime Gen. Algo. v2

3 Our Attacka. Descriptionb. Attack Analysisc. Experiments on a Toy Implem.d. Attack in Practice

4 Possible Countermeasures

9/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 11: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

How to generate a prime number ?

Two methods to generate a prime number:

I Provable prime generation algorithms

1. pick up a random odd value

2. perform a provable primality test

3. if test fails, increment the random value and go to step 2

I Probable prime generation algorithms

1. pick up a random odd value

2. perform a probable primality test

3. if test fails, increment the random value and go to step 2

Probable algorithms generally used for embedded systemsdue to timing constraints

10/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 12: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v1Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output : A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Prime Sieve */2 v v03 s s04 i = 05 while (v mod s 6= 0) and (i < 53) do6 i = i + 17 s si

8 if (i 6= 53) then9 v = v + 2

10 goto Step 3

/* Probabilistic primality tests */11 else12 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */13 while (Miller-Rabin(v) = ok) and (i < t) do14 i = i + 1

/* Process one Lucas’ test */15 if (i = t) and (Lucas(v) = ok) then16 return v

17 else18 v = v + 219 goto Step 3

11/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 13: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v1Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Prime Sieve */2 v v03 s s04 i = 05 while (v mod s 6= 0) and (i < 53) do6 i = i + 17 s si

8 if (i 6= 53) then9 v = v + 2

10 goto Step 3

/* Probabilistic primality tests */11 else12 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */13 while (Miller-Rabin(v) = ok) and (i < t) do14 i = i + 1

/* Process one Lucas’ test */15 if (i = t) and (Lucas(v) = ok) then16 return v

17 else18 v = v + 219 goto Step 3

11/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 14: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v1Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Prime Sieve */2 v v03 s s04 i = 05 while (v mod s 6= 0) and (i < 53) do6 i = i + 17 s si

8 if (i 6= 53) then9 v = v + 2

10 goto Step 3

/* Probabilistic primality tests */11 else12 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */13 while (Miller-Rabin(v) = ok) and (i < t) do14 i = i + 1

/* Process one Lucas’ test */15 if (i = t) and (Lucas(v) = ok) then16 return v

17 else18 v = v + 219 goto Step 3

11/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 15: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v1Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Prime Sieve */2 v v03 s s04 i = 05 while (v mod s 6= 0) and (i < 53) do6 i = i + 17 s si

8 if (i 6= 53) then9 v = v + 2

10 goto Step 3

/* Probabilistic primality tests */11 else12 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */13 while (Miller-Rabin(v) = ok) and (i < t) do14 i = i + 1

/* Process one Lucas’ test */15 if (i = t) and (Lucas(v) = ok) then16 return v

17 else18 v = v + 219 goto Step 3

11/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 16: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v1Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Prime Sieve */2 v v03 s s04 i = 05 while (v mod s 6= 0) and (i < 53) do6 i = i + 17 s si

8 if (i 6= 53) then9 v = v + 2

10 goto Step 3

/* Probabilistic primality tests */11 else12 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */13 while (Miller-Rabin(v) = ok) and (i < t) do14 i = i + 1

/* Process one Lucas’ test */15 if (i = t) and (Lucas(v) = ok) then16 return v

17 else18 v = v + 219 goto Step 3

11/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 17: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Attack on Probable Prime Generation Algorithm v1

Attack of [Finke+09]:I Each prime sieve execution ends as soon as v mod si = 0

I Each prime sieve execution leaks through SPA

I Allows to construct equation system with v0 as unknown:

v0 mod si0 = 0v0 + 2 mod si1 = 0

...v0 + k � 2 mod sik = 0

9>>>=>>>;() v0 = x mod si0�si1�: : :�sik (1)

I Chinese Reminder Theorem allows to deduce equation (1)) v0 mod si0 � si1 � : : :� sik) p mod si0 � si1 � : : :� sik

I Coppersmith technique ) p12/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 18: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v2Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output : A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Costly Prime Sieve for v0 */2 for j = 0 to 52 do3 R[j ] v0 mod sj /* costly modular reduction over `-bit integers */4

/* Efficient Prime Sieve for vi with i > 0 */5 v v06 while (R contains a null remainder) do7 v = v + 28 for j = 0 to 52 do9 R[j ] R[j ] + 2 mod sj /* efficient modular reduction over 8-bit integers */

10

/* Probabilistic primality tests */11 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */12 while (Miller-Rabin(v) = ok) and (i < t) do13 i = i + 1

/* Process one Lucas’ test */14 if (i = t) and (Lucas(v) = ok) then15 return v

16 else17 v = v + 218 goto Step 6

13/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 19: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v2Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Costly Prime Sieve for v0 */2 for j = 0 to 52 do3 R[j ] v0 mod sj /* costly modular reduction over `-bit integers */4

/* Efficient Prime Sieve for vi with i > 0 */5 v v06 while (R contains a null remainder) do7 v = v + 28 for j = 0 to 52 do9 R[j ] R[j ] + 2 mod sj /* efficient modular reduction over 8-bit integers */

10

/* Probabilistic primality tests */11 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */12 while (Miller-Rabin(v) = ok) and (i < t) do13 i = i + 1

/* Process one Lucas’ test */14 if (i = t) and (Lucas(v) = ok) then15 return v

16 else17 v = v + 218 goto Step 6

13/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 20: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v2Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Costly Prime Sieve for v0 */2 for j = 0 to 52 do3 R[j ] v0 mod sj /* costly modular reduction over `-bit integers */4

/* Efficient Prime Sieve for vi with i > 0 */5 v v06 while (R contains a null remainder) do7 v = v + 28 for j = 0 to 52 do9 R[j ] R[j ] + 2 mod sj /* efficient modular reduction over 8-bit integers */

10

/* Probabilistic primality tests */11 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */12 while (Miller-Rabin(v) = ok) and (i < t) do13 i = i + 1

/* Process one Lucas’ test */14 if (i = t) and (Lucas(v) = ok) then15 return v

16 else17 v = v + 218 goto Step 6

13/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 21: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v2Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Costly Prime Sieve for v0 */2 for j = 0 to 52 do3 R[j ] v0 mod sj /* costly modular reduction over `-bit integers */4

/* Efficient Prime Sieve for vi with i > 0 */5 v v06 while (R contains a null remainder) do7 v = v + 28 for j = 0 to 52 do9 R[j ] R[j ] + 2 mod sj /* efficient modular reduction over 8-bit integers */

10

/* Probabilistic primality tests */11 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */12 while (Miller-Rabin(v) = ok) and (i < t) do13 i = i + 1

/* Process one Lucas’ test */14 if (i = t) and (Lucas(v) = ok) then15 return v

16 else17 v = v + 218 goto Step 6

13/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 22: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v2Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Costly Prime Sieve for v0 */2 for j = 0 to 52 do3 R[j ] v0 mod sj /* costly modular reduction over `-bit integers */4

/* Efficient Prime Sieve for vi with i > 0 */5 v v06 while (R contains a null remainder) do7 v = v + 28 for j = 0 to 52 do9 R[j ] R[j ] + 2 mod sj /* efficient modular reduction over 8-bit integers */

10

/* Probabilistic primality tests */11 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */12 while (Miller-Rabin(v) = ok) and (i < t) do13 i = i + 1

/* Process one Lucas’ test */14 if (i = t) and (Lucas(v) = ok) then15 return v

16 else17 v = v + 218 goto Step 6

13/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 23: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Algorithm: Probable Prime Generation Algorithm v2Input : A bit-length `, the set S = fs0; � � � ; s52g of all odd primes lower than 256Output: A probable prime p

/* Generate a seed */1 Randomly generate an odd `-bit integer v0

/* Costly Prime Sieve for v0 */2 for j = 0 to 52 do3 R[j ] v0 mod sj /* costly modular reduction over `-bit integers */4

/* Efficient Prime Sieve for vi with i > 0 */5 v v06 while (R contains a null remainder) do7 v = v + 28 for j = 0 to 52 do9 R[j ] R[j ] + 2 mod sj /* efficient modular reduction over 8-bit integers */

10

/* Probabilistic primality tests */11 i = 0

/* Process t Miller-Rabin’s tests (stop if one fails) */12 while (Miller-Rabin(v) = ok) and (i < t) do13 i = i + 1

/* Process one Lucas’ test */14 if (i = t) and (Lucas(v) = ok) then15 return v

16 else17 v = v + 218 goto Step 6

13/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 24: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

State of the Art| Prime Gen. Algo. v1| Attack on Algo. v1| Prime Gen. Algo. v2|

Probable Prime Generation Algorithm v2

Prime sieve of algorithm v2 is regular

Attack of [Finke+09] becomes ineffective

Algorithm v2 is more efficient than algorithm v1

Algorithm v2 recommended in:

I ANSI X9:31

I FIPS 186-4

14/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 25: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Outline1 Introduction

a. Side-Channel Attacksb. RSAc. SCA on RSA

2 Prime Generationa. State of the Artb. Prime Gen. Algo. v1c. Attack on Algo. v1d. Prime Gen. Algo. v2

3 Our Attacka. Descriptionb. Attack Analysisc. Experiments on a Toy Implem.d. Attack in Practice

4 Possible Countermeasures

15/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 26: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

Attacker records side-channels of following computations:(each line corresponds to a prime sieve execution)

8>>>>>><>>>>>>:

r0;0 = v0 mod 3 r0;1 = v0 mod 5 : : : r0;52 = v0 mod 251

r1;0 = v1 mod 3 r1;1 = v1 mod 5 : : : r1;52 = v1 mod 251

......

...

rn;0 = vn mod 3 rn;1 = vn mod 5 : : : rn;52 = vn mod 251

16/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 27: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

As vi = v0 + i � 2, one gets:

8>>>>>><>>>>>>:

r0;0 = v0 mod 3 r0;1 = v0 mod 5 : : : r0;52 = v0 mod 251

r1;0 = v0 + 2 mod 3 r1;1 = v0 + 2 mod 5 : : : r1;52 = v0 + 2 mod 251

......

...

rn;0 = v0 + n � 2 mod 3 rn;1 = v0 + n � 2 mod 5 : : : rn;52 = v0 + n � 2 mod 251

17/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 28: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

As n can be guessed by SPA, the attacker can then performpartial DPA for each small prime number:

8>>>>>><>>>>>>:

r0;0 = v0 mod 3 r0;1 = v0 mod 5 : : : r0;52 = v0 mod 251

r1;0 = v0 + 2 mod 3 r1;1 = v0 + 2 mod 5 : : : r1;52 = v0 + 2 mod 251

......

...

rn;0 = v0 + n � 2 mod 3 rn;1 = v0 + n � 2 mod 5 : : : rn;52 = v0 + n � 2 mod 251

) allows to get v0 mod 3

18/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 29: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

As n can be guessed by SPA, the attacker can then performpartial DPA for each small prime number:

8>>>>>><>>>>>>:

r0;0 = v0 mod 3 r0;1 = v0 mod 5 : : : r0;52 = v0 mod 251

r1;0 = v0 + 2 mod 3 r1;1 = v0 + 2 mod 5 : : : r1;52 = v0 + 2 mod 251

......

...

rn;0 = v0 + n � 2 mod 3 rn;1 = v0 + n � 2 mod 5 : : : rn;52 = v0 + n � 2 mod 251

) allows to get v0 mod 5

19/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 30: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

As n can be guessed by SPA, the attacker can then performpartial DPA for each small prime number:

8>>>>>><>>>>>>:

r0;0 = v0 mod 3 r0;1 = v0 mod 5 : : : r0;52 = v0 mod 251

r1;0 = v0 + 2 mod 3 r1;1 = v0 + 2 mod 5 : : : r1;52 = v0 + 2 mod 251

......

...

rn;0 = v0 + n � 2 mod 3 rn;1 = v0 + n � 2 mod 5 : : : rn;52 = v0 + n � 2 mod 251

) : : :

20/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 31: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

As n can be guessed by SPA, the attacker can then performpartial DPA for each small prime number:

8>>>>>><>>>>>>:

r0;0 = v0 mod 3 r0;1 = v0 mod 5 : : : r0;52 = v0 mod 251

r1;0 = v0 + 2 mod 3 r1;1 = v0 + 2 mod 5 : : : r1;52 = v0 + 2 mod 251

......

...

rn;0 = v0 + n � 2 mod 3 rn;1 = v0 + n � 2 mod 5 : : : rn;52 = v0 + n � 2 mod 251

) allows to get v0 mod 251

21/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 32: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack on Probable Prime Generation Algorithm v2

Similarly to [Finke+09], one constructs an equationsystem with v0 as unknown:

v0 mod 3v0 mod 5...v0 mod 251

9>>>>=>>>>;() v0 = x mod 3� 5� : : :� 251 (2)

Chinese Reminder Theorem allows to deduce equation (2)) v0 mod 3� 5� : : :� 251) p mod 3� 5� : : :� 251

Coppersmith technique ) p

22/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 33: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack Analysis

Attack success depends on number n of prime sieveexecutions

Unlike classical SCA, n cannot be chosen by attacker

In the sequel, we focus on 512-bit case

When all the 53 partial DPA succeed, one gets roughly 350bits of p

If at least 256 consecutive bits of p are retrived,Coppersmith technique can allow to get the others

23/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 34: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack Analysis

Figure : Cumulative distrib. fct. of n for diff. prime bit-lengths `

512-bit prime number generation imply at least:(estimations over 2000 generations)

I 53 prime sieve executions in 75% of the cases (Q1)I 126 prime sieve executions in 50% of the cases (Q2)I 246 prime sieve executions in 25% of the cases (Q3)

24/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 35: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack Analysis

1

1 1

1 1

1

1 1

10.990

0 0.08 1

0 0 0.7

0.46

Q2 Q3Q1

0

2

3

4

5

1

Figure : Success rates for different noise levels to recover 256bits of p depending on the number of prime sieve executions

25/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 36: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Toy Implementation

8-bit ATMega128 micro-controller at 8MHz

Implementation of 300 prime sieve executions from arandom seed v0

EM measurements with sampling rate at 1GSa/s

Partial DPA performed with Pearson correlation asdistinguisher

Experiment repeated 200 times

26/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 37: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attacking the Toy Implementation

0 10 20 30 40 50 600

20

40

60

80

100

Index of the prime residue within the 53 tests

Su

cce

ss r

ate

in

%

10 prime sieves50 prime sieves250 prime sieves300 prime sieves

Figure : Success rates for each prime sieve elements

27/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 38: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attacking the Toy Implementation

0 50 100 150 200 250 300 350 400 450 5000

20

40

60

80

100

Number of bits recovered

Su

cce

ss r

ate

in

%

10 prime sieves50 prime sieves250 prime sieves300 prime sieves

Figure : Success rates for recovering x bits of information on thegenerated prime

28/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 39: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Improving the Attack Success

Unsuccessful partial DPA can be discarded thanks to KeyEnumeration Algorithm

The attacker can attack both p and q generations and usethe RSA public modulus n to increase the success of theattack

The initial costly prime sieve can also be used to getmore information on p

29/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 40: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Practical Issues

Record long side-channel trace corr. to full primegeneration

I use high-end oscilloscope w. huge memory depth

I use several cascaded oscilloscopes

Find patterns corr. to n prime sieve executions

I located between patterns corr. to Miller-Rabin tests

I once one is found, use pattern matching techniques

Find sub-patterns corr. to trial divisions

I use classical peak extraction techniques used in SCA

30/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 41: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack Flow in Practice

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

Figure : EM radiations measured during a prime number generationcomputation on a commercial smartcard

Pattern 1 ) initial costly prime sievePatterns 2 to 28 ) Miller-Rabin tests

31/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 42: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Description| Attack Analysis| Experiments on a Toy Implem.| Attack in Practice|

Attack Flow in Practice

1 2 3

Figure : Zoom on the two first patterns of previous figure

Pattern 1 ) initial costly prime sievePattern 2 ) efficient prime sieve executionsPattern 3 ) first Miller-Rabin test

32/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 43: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Outline1 Introduction

a. Side-Channel Attacksb. RSAc. SCA on RSA

2 Prime Generationa. State of the Artb. Prime Gen. Algo. v1c. Attack on Algo. v1d. Prime Gen. Algo. v2

3 Our Attacka. Descriptionb. Attack Analysisc. Experiments on a Toy Implem.d. Attack in Practice

4 Possible Countermeasures

33/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 44: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Possible Countermeasures

Our attack exploits two features:

I use of a prime sieve

I deterministic candidate generation

Approaches to thwart our attack:

I Add randomly dummy trial divisions in each prime sievecomputation

I Perform prime sieve computation in pseudo-random order

I Prime generation w. non-deterministic generation) [Fouque+11]

I Efficient provable prime generation algorithm) [Clavier+12]

34/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms

Page 45: Side-Channel Attack against RSA Key Generation Algorithms · RSA Key Generation Algorithms CHES 2014 Aurélie Bauer, Eliane Jaulmes, Victor Lomné, Emmanuel Prouff and Thomas Roche

Introduction| Prime Generation| Our Attack| Possible Countermeasures|

Thanks for your attention !

Questions ?

35/35 Victor LOMNE - ANSSI / SCA against RSA Key Generation Algorithms