CACHE-TIMING ATTACKS ON RSA KEY GENERATION Conference on - - PowerPoint PPT Presentation

cache timing attacks on rsa key generation
SMART_READER_LITE
LIVE PREVIEW

CACHE-TIMING ATTACKS ON RSA KEY GENERATION Conference on - - PowerPoint PPT Presentation

CACHE-TIMING ATTACKS ON RSA KEY GENERATION Conference on Cryptographic Hardware and Embedded Systems (CHES) 2019 Alejandro Cabrera Aldaya 1 , Cesar Pereida Garca 2 , Luis Manuel Alvarez Tapia 1 , Billy Bob Brumley 2 , {aldaya,


slide-1
SLIDE 1

CACHE-TIMING ATTACKS ON RSA KEY GENERATION

Conference on Cryptographic Hardware and Embedded Systems (CHES) 2019

Alejandro Cabrera Aldaya1, Cesar Pereida García2, Luis Manuel Alvarez Tapia1, Billy Bob Brumley2,

{aldaya, lalvarezt89}@gmail.com, {billy.brumley, cesar.pereidagarcia}@tuni.fi 1 Universidad Tecnológica de la Habana (CUJAE), Habana, Cuba 2 Network and Information Security Group (NISEC), Tampere University, Tampere, Finland

Aug 25-28, 2019

slide-2
SLIDE 2

default

Contents

Introduction Side-Channel Leakage Finding The BN_FLG_CONSTTIME A New Methodology The Tool Leakage Analysis RSA Key Generation Binary GCD The Attack Conclusion Lessons Learned

2 / 21

slide-3
SLIDE 3

default

Contents

Introduction Side-Channel Leakage Finding The BN_FLG_CONSTTIME A New Methodology The Tool Leakage Analysis RSA Key Generation Binary GCD The Attack Conclusion Lessons Learned

3 / 21

slide-4
SLIDE 4

default

Introduction

◮ What?: A single trace cache-timing attack against the binary Extended

Euclidean (GCD) algorithm used during RSA key generation, leading to complete RSA private key recovery.

◮ Why?: Because we can!.

◮ Cloud services (e.g. AWS, Azure) and automated certificate renewal (e.g. Let’s Encrypt) make RSA key generation a semi-predictable operation. ◮ Micro-architecture attacks. ◮ RSA key generation neglected.

◮ How?: We developed a new methodology to help us detect insecure code

paths in OpenSSL, then we combine FLUSH+RELOAD, signal processing and lattice techniques.

4 / 21

slide-5
SLIDE 5

default

Contents

Introduction Side-Channel Leakage Finding The BN_FLG_CONSTTIME A New Methodology The Tool Leakage Analysis RSA Key Generation Binary GCD The Attack Conclusion Lessons Learned

5 / 21

slide-6
SLIDE 6

default

OpenSSL and the BN_FLG_CONSTTIME

◮ OpenSSL relies on the BN_FLG_CONSTTIME to protect against timing-attacks. ◮ The flag gives a lot of room for mistakes. ◮ Several flaws involving the flag have been identified previously.

◮ CVE-2016-2178 ◮ CVE-2016-7056 ◮ CVE-2018-0734

◮ We have a record of well known side-channel vulnerable functions used in

OpenSSL.

6 / 21

slide-7
SLIDE 7

default

A New Methodology

◮ Create a list of known side-channel

vulnerable functions in a library (e.g. OpenSSL).

◮ Use a debugger to automatically set

breakpoints at lines of code that should be unreachable.

◮ Run several security-critical

commands.

◮ Generate a report if any of the

breakpoints is reached.

◮ Investigate manually the root-cause.

7 / 21

slide-8
SLIDE 8

default

The Tool1

INFO: Parsing source code at: ./openssl-1.0.2k #2 ... in BN_is_prime_fasttest_ex (...) at bn_prime.c:329 ... #3 ... in BN_generate_prime_ex (...) at bn_prime.c:199 INFO: Breakpoints file generated: triggers.gdb #4 ... in rsa_builtin_keygen (...) at rsa_gen.c:150 ... ... INFO: Monitor target command line INFO: Insecure code executed! TOOL: gdb --batch --command=triggers.gdb --args Breakpoint 2, BN_gcd (...) at bn_gcd.c:120

  • penssl-1.0.2k/apps/openssl genpkey -algorithm RSA

120 int ret = 0;

  • out private_key.pem -pkeyopt rsa_keygen_bits:2048

#0 BN_gcd (...) at bn_gcd.c:120 ... #1 ... in rsa_builtin_keygen (...) at rsa_gen.c:154 INFO: Setting breakpoints... ... Breakpoint 1 at ...: file bn_exp.c, line 418. INFO: Insecure code executed! Breakpoint 2 at ...: file bn_gcd.c, line 120. Breakpoint 3, BN_mod_inverse (...) at bn_gcd.c:238 Breakpoint 3 at ...: file bn_gcd.c, line 238. 238 bn_check_top(a); ... #0 BN_mod_inverse (...) at bn_gcd.c:238 INFO: Insecure code executed! #1 ... in BN_MONT_CTX_set (...) at bn_mont.c:450 Breakpoint 1, BN_mod_exp_mont (...) at bn_exp.c:418 #2 ... in BN_is_prime_fasttest_ex (...) at bn_prime.c:319 418 bn_check_top(a); #3 ... in BN_generate_prime_ex (...) at bn_prime.c:199 #0 BN_mod_exp_mont (...) at bn_exp.c:418 #4 ... in rsa_builtin_keygen (...) at rsa_gen.c:171 #1 ... in witness (...) at bn_prime.c:356 ... 1[Gri+19] expanded our methodology and tooling into a CI tool called TriggerFlow.

https://gitlab.com/nisec/triggerflow 8 / 21

slide-9
SLIDE 9

default

Contents

Introduction Side-Channel Leakage Finding The BN_FLG_CONSTTIME A New Methodology The Tool Leakage Analysis RSA Key Generation Binary GCD The Attack Conclusion Lessons Learned

9 / 21

slide-10
SLIDE 10

default

RSA Key Generation

Algorithm 1: OpenSSL RSA key generation

Input: Key size n and public exponent e. Output: Public and private key pair.

1 begin 2

while gcd(p − 1, e) = 1 do

3

p ← rand n/2-bit prime /* Generate p */

4

while gcd(q − 1, e) = 1 do

5

q ← rand n/2-bit prime /* Generate q */

6

d ← e−1 mod (p − 1)(q − 1) /* Priv exp */

7

dp ← d mod (p − 1)

8

dq ← d mod (q − 1) /* CRT parameters */

9

iq ← q−1 mod p

10

return (N, e), (d, p, q, dp, dq, iq) 10 / 21

slide-11
SLIDE 11

default

Binary GCD

Algorithm 2: Binary GCD

Input: Integers a and b such that 0 < a < b. Output: Greatest common divisor of a and b.

1 begin 2

u ← a, v ← b, i ← 0

3

while even(u) and even(v) do

4

u ← u/2, v ← v/2, i ← i + 1

5

while u = 0 do

6

while even(u) do

7

u ← u/2 /* u-loop */

8

while even(v) do

9

v ← v/2 /* v-loop */

10

if u ≥ v then

11

u ← u − v /* sub-step */

12

else

13

v ← v − u

14

return v · 2i

Coppersmith bound 512

e = 2 - 1 e = 2 +1

1023 NIST

256

768 1007

16

11 / 21

slide-12
SLIDE 12

default

Contents

Introduction Side-Channel Leakage Finding The BN_FLG_CONSTTIME A New Methodology The Tool Leakage Analysis RSA Key Generation Binary GCD The Attack Conclusion Lessons Learned

12 / 21

slide-13
SLIDE 13

default

Memory Hierarchy

13 / 21

slide-14
SLIDE 14

default

FLUSH+RELOAD and Performance Degradation

1) Victim executes its own process, filling the cache 3) Victim may or may not execute its own process again while the attacker waits 4) Attacker reloads the data and measures the loading time 2) Attacker flushes victim's data from the cache and waits 5) Attacker traces the victim's process execution and infers information about the victim

14 / 21

slide-15
SLIDE 15

default

Attack Scenario

Core 0 Core 1 Core 2 Core 3 L1 L1 L1 L1 L1 L1 L1 L1 L2 L2 L2 L2 Victim Attacker Flush+Reload Attacker

  • Perf. Degradation

Shared LLC OpenSSL

15 / 21

slide-16
SLIDE 16

default

The Attack 1/2

◮ OpenSSL 1.0.2k. ◮ FLUSH+RELOAD [YF14]. ◮ Templating. ◮ Pearson correlation. ◮ Low-pass filter. ◮ Horizontal analysis. ◮ Sequence of ops.

Trace Latency (filtered) Template Latency (filtered)

  • 0.4
  • 0.2

0.2 0.4 50000 100000 150000 200000 250000 Correlation 100 200 300 284400 284500 284600 284700 284800 284900 285000 285100 285200 285300 Trace, Latency Time (samples) subtraction probe shift probe

LLLSLLSLSLLLLLSL...LS

16 / 21

slide-17
SLIDE 17

default

The Attack 2/2

◮ Use expand-and-prune [HMM10] error correction algorithm. ◮ Obtain a ranked list of partial prime factors. ◮ Formulate lattice problems for the candidates. ◮ Run in a cluster for 4 hours. ◮ Recover private keys with a 27% success rate.

17 / 21

slide-18
SLIDE 18

default

Contents

Introduction Side-Channel Leakage Finding The BN_FLG_CONSTTIME A New Methodology The Tool Leakage Analysis RSA Key Generation Binary GCD The Attack Conclusion Lessons Learned

18 / 21

slide-19
SLIDE 19

default

TL;DNL

◮ We developed a simple methodology and tool to track existing flaws leading

to insecure code paths in crypto libraries.

◮ We discovered three new flaws affecting OpenSSL during RSA key generation. ◮ We performed a cache-timing attack on the GCD algorithm, allowing us to

fully recover RSA keys with a success rate of 27%.

◮ Our general strategy was:

◮ FLUSH+RELOAD and performance degradation. ◮ Signal processing. ◮ Error correction algorithm. ◮ Lattice problem solving.

19 / 21

slide-20
SLIDE 20

default

Responsible Disclosure

We reported our findings to OpenSSL security team, and they confirmed affected versions2 1.1.0-1.1.0h and 1.0.2-1.0.2o. OpenSSL assigned CVE-2018-0737 based on our work and adopted the proposed patches.

◮ Lesson 1: Secure by default. These and similar flaws can be prevented with

a secure-by-default approach. ◮ Adopt constant-time algorithms by default, e.g. [BY19]

◮ Lesson 2: Knowledge transfer. The engineers and cryptographers must

work side-by-side to ensure that academic results permeate over real-world products.

2OpenSSL 1.1.1 did not exist at the time of disclosure.

20 / 21

slide-21
SLIDE 21

default

Thank you for listening. Questions?

21 / 21