Top Banner
Side-Channel Attack on OpenSSL ECDSA Naomi Benger Joop van de Pol Nigel Smart Yuval Yarom 1
39

Side-Channel Attack on OpenSSL ECDSA

Jan 03, 2016

Download

Documents

Side-Channel Attack on OpenSSL ECDSA. Naomi Benger Joop van de Pol Nigel Smart Yuval Yarom. Outline. Background ECDSA wNAF scalar multiplication Hidden Number Problem The Flush+Reload Technique Attacking OpenSSL ECDSA Improved lattice technique - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Side-Channel Attack on  OpenSSL  ECDSA

1

Side-Channel Attack on OpenSSL ECDSA

Naomi Benger Joop van de Pol Nigel Smart Yuval Yarom

Page 2: Side-Channel Attack on  OpenSSL  ECDSA

2

Outline

• Background• ECDSA• wNAF scalar multiplication• Hidden Number Problem

• The FLUSH+RELOAD Technique• Attacking OpenSSL ECDSA– Improved lattice technique– Using information from the double and add chain

Page 3: Side-Channel Attack on  OpenSSL  ECDSA

3

ECDSASigner has a private key 1<α<q-1 and a public key Q=[α]G

1. Compute h=Hash(m)

2. Randomly select an ephemeral key 1<k<q

3. Compute (x,y)=[k]G

4. Take r=x mod q; If r=0 repeat from 25. Take s=(h+r·α)/k mod q; if s=0 repeat from 26. (r,s) is the signature

Note that

Page 4: Side-Channel Attack on  OpenSSL  ECDSA

4

wNAF Form

To compute [d]G, first write d in wNAF form:

Such that if di≠0 then di+1=…=di+w+1=0.

Page 5: Side-Channel Attack on  OpenSSL  ECDSA

5

Scalar Multiplication with wNAF form

Precompute {±G, ±[3]G,…, ±[2w-1]G}

x=0

for i=n-1 downto 0

x = Double(x)

if (di≠0) then

x = Add(x, [di]G)

end

end

return x

Page 6: Side-Channel Attack on  OpenSSL  ECDSA

6

Notation

Note that implies

Page 7: Side-Channel Attack on  OpenSSL  ECDSA

7

The Hidden Number ProblemSuppose we know numbers ti, ui such that

Page 8: Side-Channel Attack on  OpenSSL  ECDSA

8

The Hidden Number ProblemSuppose we know numbers ti, ui such that

We can construct a lattice

And a vector

Which is very close to a lattice vector that depends on α.

Page 9: Side-Channel Attack on  OpenSSL  ECDSA

9

HNP and ECDSARecall that We want

In terms of k:

Or in terms of ti and ui:0n

Page 10: Side-Channel Attack on  OpenSSL  ECDSA

10

HNP and ECDSARecall that We want

In terms of k:

Or in terms of ti and ui:0n

al

Page 11: Side-Channel Attack on  OpenSSL  ECDSA

11

HNP and ECDSARecall that We want

In terms of k:

Or in terms of ti and ui:0n

0l

Page 12: Side-Channel Attack on  OpenSSL  ECDSA

12

HNP and ECDSARecall that We want

In terms of k:

Or in terms of ti and ui:0n-l

Page 13: Side-Channel Attack on  OpenSSL  ECDSA

13

HNP and ECDSARecall that We want

In terms of k:

Or in terms of ti and ui:0n-(l+1)

Page 14: Side-Channel Attack on  OpenSSL  ECDSA

14

HNP and ECDSA – State of the Art

• Useful information:– l bits for l known LSBs– Between l-1 and l bits for l known MSBs– l/2 bits for arbitrary l consecutive bits

• Liu and Nguyen 2013 – 160 bit key, 100 signatures, 2 known bits– Expected 200 observed signatures

Page 15: Side-Channel Attack on  OpenSSL  ECDSA

15

The X86 Cache

• Memory is slower than the processor

• The cache utilises locality to bridge the gap– Divides memory into lines– Stores recently used lines

• Shared caches improve performance for multi-core processors

Processor

Memory

Cache

Page 16: Side-Channel Attack on  OpenSSL  ECDSA

16

Cache Consistency

• Memory and cache can be in inconsistent states– Rare, but possible

• Solution: Flushing the cache contents– Ensures that the next load is

served from the memory

Processor

Memory

Cache

Page 17: Side-Channel Attack on  OpenSSL  ECDSA

17

The FLUSH+RELOAD Technique

• Exploits cache behaviour to leak information on victim access to shared memory.– Shared text segments– Shared libraries– Memory de-duplication

• Spy monitors victim’s access to shared code– Spy can determine what victim does– Spy can infer the data the victim operates on

Page 18: Side-Channel Attack on  OpenSSL  ECDSA

18

FLUSH+RELOAD

• FLUSH memory line• Wait a bit• Measure time to

RELOAD line– slow-> no access– fast-> access

• Repeat

Processor

Memory

Cache

Page 19: Side-Channel Attack on  OpenSSL  ECDSA

19

Uses

• OpenSSL AES (Gullasch et al. 2011)• GnuPG RSA (CVE 2013-4242) [Yarom & Falkner

2014]• OpenSSL ECDSA over binary fields (CVE 2014-

0076) [Yarom & Benger 2014]• OpenSSL ECDSA over prime fields – this work.• OpenSSL AES (cross-VM) [Irazoqui et al. 2014]• PaaS clouds [Zhang et al. 2014]

Page 20: Side-Channel Attack on  OpenSSL  ECDSA

20

Attacking OpenSSL wNAF

• Achieve sharing with the victim code• Use FLUSH+RELOAD to recover the double and

add chain of the wNAF calculation• Divide time into slots of 1200 cycles (about

0.4μs)• In each slot, probe a memory line in the code

of the Double and Add functions.

Page 21: Side-Channel Attack on  OpenSSL  ECDSA

21

Problem I - Speculative Execution

Solution:Place probe here

x=0for i=n-1 downto 0 x = Double(x) if (di≠0) then x = Add(x, [di]G) endendreturn x

Page 22: Side-Channel Attack on  OpenSSL  ECDSA

22

Problem II - Overlap

Page 23: Side-Channel Attack on  OpenSSL  ECDSA

23

Problem II - Overlapif (!BN_mod_sub_quick(n0, n2, &r->X, p)) goto err;if (!field_mul(group, n0, n1, n0, ctx)) goto err;if (!BN_mod_sub_quick(&r->Y, n0, n3, p)) goto err;

0x59d62a: mov 0x8(%rsp),%rcx0x59d62f: mov %rbx,%r80x59d632: mov 0x18(%rsp),%rdx0x59d637: mov %rbp,%rdi0x59d63a: mov %rcx,%rsi0x59d63d: callq *0x38(%rsp)0x59d641: test %eax,%eax

Page 24: Side-Channel Attack on  OpenSSL  ECDSA

24

Demo

Page 25: Side-Channel Attack on  OpenSSL  ECDSA

25

Sample TraceRaw:D||||D|D|||D||||A||||D|||D||||D|||D|||A|A|||D|||D||||D|||D||||D|||D|||A||||D|||D|D|||D|||D||||D||A|A|||D|||D|D|||D|||D|||A||||D|||D|||D|||D|||D|||A|A||||D|||D|||D||||D||A|A|||D||||D|||D|||D|||A|||D|||D|||D|D|||D|||D|||A||||D|||D|||D|||D|D|||D|||D|||D|||A|||D|D|||D||…

Processed:DDDADDDDADDDDDDADDDDDADDDDADDDDDADDDDADDDDADDDDDADDDDDDDADDDDADDDDADDDDDADDDDADDDDDDDADDDDDDADDDDADDDDADDDDADDDDADDDDADDDDDADDDDDADDDDADDDDADDDDADDDDADDDDADDDDADDDDDDDADDDDDADDDDADDDDDDADDDDADDDDDDADDDDDADDDDADDDDDADDDDDADDDDDADDDDDADDDDXDDDADDDDADDDDADDDDADDDDDADDDDADDDDDDADDDDDADDDDADDDDDDADDDDDDADDDDADD

Page 26: Side-Channel Attack on  OpenSSL  ECDSA

26

Using the LSBsThe trace: DDDADDDDADDDDD…DDDDDDADDDDADD

Reveals 3 LSBs (100). A different trace might reveal fewer bits. How do we deal with that?

Page 27: Side-Channel Attack on  OpenSSL  ECDSA

27

Using the LSBsThe trace: DDDADDDDADDDDD…DDDDDDADDDDADD

Reveals 3 LSBs (100). A different trace might reveal fewer bits. How do we deal with that?

We vary the z per (ti, ui) tuple.

Page 28: Side-Channel Attack on  OpenSSL  ECDSA

28

Results• For secp256k1

Expected# Sigs d Time (s)

SuccessProb.

Time / Prob.

200 100 611.13 .035 17460220 110 79.67 .020 3933240 60 2.68 .005 536260 65 2.26 .055 41280 70 4.46 .295 15300 75 13.54 .530 26

Page 29: Side-Channel Attack on  OpenSSL  ECDSA

29

Using More InformationDDDADDDDADDDDDDADDDDDADDDDADDDDDADDDDADDDDADDDDDADDDDDDDADDDDADDDDADDDDDADDDDADDDDDDDADDDDDDADDDDADDDDADDDDADDDDADDDDADDDDDADDDDDADDDDADDDDADDDDADDDDADDDDADDDDADDDDDDDADDDDDADDDDADDDDDDADDDDADDDDDDADDDDDADDDDADDDDDADDDDDADDDDDADDDDDADDDDXDDDADDDDADDDDADDDDADDDDDADDDDADDDDDDADDDDDADDDDADDDDDDADDDDDDADDDDADD

We know how to use the revealed LSBsBut these give an average of 2 bits per observed signature.

Page 30: Side-Channel Attack on  OpenSSL  ECDSA

30

Using More InformationDDDADDDDADDDDDDADDDDDADDDDADDDDDADDDDADDDDADDDDDADDDDDDDADDDDADDDDADDDDDADDDDADDDDDDDADDDDDDADDDDADDDDADDDDADDDDADDDDADDDDDADDDDDADDDDADDDDADDDDADDDDADDDDADDDDADDDDDDDADDDDDADDDDADDDDDDADDDDADDDDDDADDDDDADDDDADDDDDADDDDDADDDDDADDDDDADDDDXDDDADDDDADDDDADDDDADDDDDADDDDADDDDDDADDDDDADDDDADDDDDDADDDDDDADDDDADD

We know how to use the revealed LSBsBut these give an average of 2 bits per observed signature.

Can we use the information about the MSBs?

Page 31: Side-Channel Attack on  OpenSSL  ECDSA

31

Using the MSBsAssume dm+l,dm≠0

Before adding [dm]G, x is: x=0for i=n-1 downto 0 x = Double(x) if (di≠0) then x = Add(x, [di]G) endendreturn x

1000…0000l+1

Page 32: Side-Channel Attack on  OpenSSL  ECDSA

32

Using the MSBsAssume dm+l,dm≠0

Before adding [dm]G, x is:

After adding [dm]G, for dm>0 it is

And for dm<0

x=0for i=n-1 downto 0 x = Double(x) if (di≠0) then x = Add(x, [di]G) endendreturn x

1000…0000l+1

100…000l+1 w

011…110l+1 w

Page 33: Side-Channel Attack on  OpenSSL  ECDSA

33

Using the MSBsAssume dm+l,dm≠0

Before adding [dm]G, x is:

After adding [dm]G, for dm>0 it is

And for dm<0

Either way,

x=0for i=n-1 downto 0 x = Double(x) if (di≠0) then x = Add(x, [di]G) endendreturn x

1000…0000l+1

100…000l+1 w

011…110l+1 w

k+2m+w 100…000m+l+1 m+w+1n

Page 34: Side-Channel Attack on  OpenSSL  ECDSA

34

Observation

For many “standard” curves, q is close to a power of two. That is, q=2n-ε such that |ε|<2p for p≪n.For example for secp256k1q=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF EBAAEDCE6AF48A03BBFD25E8CD0364141

Adding or subtracting q to an n bit number is unlikely to change the MSBs

Page 35: Side-Channel Attack on  OpenSSL  ECDSA

35

+aε

0n+p-m-l-1

For m>pUsing all the Information

100…00a0m+l+1 m+w+1n

100…00a0n+w-l n-m-l-1n

0

0a0n+w-l n-m-l-1n

0

00n+w-l n-m-l-1n

0

Page 36: Side-Channel Attack on  OpenSSL  ECDSA

36

+aε

0n+p-m-l-1

For m>pUsing all the Information

0a0n+w-l n-m-l-1n

0

00n+w-l n-m-l-1n

0

0n+w-ln 0

100…00a0m+l+1 m+w+1n

100…00a0n+w-l m+l+1n

0

Page 37: Side-Channel Attack on  OpenSSL  ECDSA

37

+aε

0n+p-m-l-1

For m>pUsing all the Information

0a0n+w-l n-m-l-1n

0

00n+w-l n-m-l-1n

0

0n+w-ln 0

0n+w-l-1n 0

n+w-l-1 0

Page 38: Side-Channel Attack on  OpenSSL  ECDSA

38

Results

With a very high probability, observing 25 signatures yields more than 13 perfect traces.

# perfect traces Time (s) Success

probability10 2.25 0.0711 4.66 0.2512 7.68 0.3813 11.3 0.54

Page 39: Side-Channel Attack on  OpenSSL  ECDSA

39

Summary• FLUSH+RELOAD provides a nearly perfect

cross-core, cross-VM side channel• No need for a fixed number of bits in HNP• Can handle the negative digits in wNAF• Can handle non-consecutive bits• Curve choice allows using almost half of the

information in each perfect trace• We can break a 256 bit curve after observing

as little as 25 signatures.