Exploiting dummy codes in Elliptic Curve Cryptography Andy Russon - - PowerPoint PPT Presentation

exploiting dummy codes in elliptic curve cryptography
SMART_READER_LITE
LIVE PREVIEW

Exploiting dummy codes in Elliptic Curve Cryptography Andy Russon - - PowerPoint PPT Presentation

Exploiting dummy codes in Elliptic Curve Cryptography Andy Russon 4 June 2020 2/20 About me PhD thesis on elliptic curves Orange, and Universit de Rennes 1 Risk assessment and audit Interest: challenges (root-me, CryptoHack), korean


slide-1
SLIDE 1

Exploiting dummy codes in Elliptic Curve Cryptography

Andy Russon 4 June 2020

slide-2
SLIDE 2

2/20

About me

PhD thesis on elliptic curves Orange, and Université de Rennes 1 Risk assessment and audit Interest: challenges (root-me, CryptoHack), korean movies, science-fjction

slide-3
SLIDE 3

3/20

Introduction

About Elliptic Curve Cryptography: Public-key cryptography with small parameters, keys, signatures, etc

Parameter size ECC RSA 128-bit security ECC RSA 256-bit security

Protocols: TLS 1.3, SSH, Bitcoin, Signal, etc Servers, smart cards, IoT devices, etc

slide-4
SLIDE 4

4/20

Introduction

Hard to implement secure and effjcient cryptography. Depends on threat model (physical access to the device, etc) One protection can lead to a vulnerability Passive attacks: timing, power analysis, etc Active attacks: difgerential fault analysis, C safe-errors C safe-error attacks against protected implementations to attack ECDSA1.

1Fouque et al., “Safe-Errors on SPA Protected Implementations with the Atomicity Technique”;

Dubeuf, Hely, and Beroulle, “Enhanced Elliptic Curve Scalar Multiplication Secure Against Side Channel Attacks and Safe Errors.”

slide-5
SLIDE 5

5/20

In this presentation

We extend the previous results, and show that a C safe-error attack is also possible on these implementations: Assembly optimized implementation of P-256:

OpenSSL since version 1.0.2 BoringSSL LibreSSL/OpenBSD

P-224, P-384 and P-521 in BoringSSL

slide-6
SLIDE 6

6/20

Plan

1 Why dummy codes in ECC? 2 Presentation of the attack 3 Why it works 4 Mitigations and conclusion

slide-7
SLIDE 7

7/20

Operations on elliptic curves

Basic operations: Addition: P + Q Doubling: P + P = 2P P + O = O + P = P

slide-8
SLIDE 8

7/20

Operations on elliptic curves

P Q P Q P E : y2 = x3 − 3x + 137 mod 251 O Basic operations: Addition: P + Q Doubling: P + P = 2P P + O = O + P = P

slide-9
SLIDE 9

7/20

Operations on elliptic curves

P Q P Q P E : y2 = x3 − 3x + 137 mod 251 O Basic operations: Addition: P + Q Doubling: P + P = 2P P + O = O + P = P

slide-10
SLIDE 10

7/20

Operations on elliptic curves

P Q P + Q P E : y2 = x3 − 3x + 137 mod 251 O Basic operations: Addition: P + Q Doubling: P + P = 2P P + O = O + P = P λ = yP − yQ xP − xQ { xP+Q = λ2 − xP − xQ yP+Q = λ(xP − xP+Q) − xP

slide-11
SLIDE 11

7/20

Operations on elliptic curves

P Q P Q 2P E : y2 = x3 − 3x + 137 mod 251 O Basic operations: Addition: P + Q Doubling: P + P = 2P P + O = O + P = P λ = 3xP + a 2yP { x2P = λ2 − 2xP y2P = λ(xP − x2P) − xP

slide-12
SLIDE 12

7/20

Operations on elliptic curves

P Q P Q P E : y2 = x3 − 3x + 137 mod 251 O Basic operations: Addition: P + Q Doubling: P + P = 2P P + O = O + P = P Scalar multiplication: kP = P + · · · + P Discrete logarithm problem: hard to fjnd k from P and kP k is often secret (private key or nonce)

slide-13
SLIDE 13

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 P = O P P D D D P P P A P P D D D P P

From power consumption, attacker remarks the missing addition and learns that: k Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-14
SLIDE 14

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P P P D D D P P P A P P D D D P P Historic of operations:

From power consumption, attacker remarks the missing addition and learns that: k Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-15
SLIDE 15

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D P P P A P P D D D P P Historic of operations: D D D

From power consumption, attacker remarks the missing addition and learns that: k Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-16
SLIDE 16

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D 11 101 24P + 5P = 29P A P P D D D P P Historic of operations: D D D A

From power consumption, attacker remarks the missing addition and learns that: k Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-17
SLIDE 17

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D 11 101 24P + 5P = 29P A 11 101 000 23 · 29P = 232P D D D P P Historic of operations: D D D A D D D

From power consumption, attacker remarks the missing addition and learns that: k Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-18
SLIDE 18

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D 11 101 24P + 5P = 29P A 11 101 000 23 · 29P = 232P D D D 11 101 000 232P = 232P Historic of operations: D D D A D D D

From power consumption, attacker remarks the missing addition and learns that: k Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-19
SLIDE 19

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D 11 101 24P + 5P = 29P A 11 101 000 23 · 29P = 232P D D D 11 101 000 232P = 232P Historic of operations: D D D A D D D

From power consumption, attacker remarks the missing addition and learns that: k = ∗ ∗ ∗ ∗ ∗ 000 Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-20
SLIDE 20

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D 11 101 24P + 5P = 29P A 11 101 000 23 · 29P = 232P D D D 11 101 000 232P = 232P Historic of operations: D D D A D D D

From power consumption, attacker remarks the missing addition and learns that: k = ∗ ∗ ∗ ∗ ∗ 000 Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-21
SLIDE 21

8/20

Windowing scalar multiplication

Available operations: point addition (A), point doubling (D) For effjciency: split k in groups of consecutive bits (windows)

Example: k = 232 = (11 101 000)2 11 3P = 3P 11 000 23 · 3P = 24P D D D 11 101 24P + 5P = 29P A 11 101 000 23 · 29P = 232P D D D 11 101 000 232P = 232P Historic of operations: D D D A D D D

From power consumption, attacker remarks the missing addition and learns that: k = ∗ ∗ ∗ ∗ ∗ 000 Solution: perform a dummy point addition: D D D A D D D A Consequence: same sequence of

  • perations for all possible secret k
slide-22
SLIDE 22

9/20

Principle of C safe-error

Dummy or not dummy?

slide-23
SLIDE 23

9/20

Principle of C safe-error

Make a fault in the last point addition (exact details in the article): D D D A D D D A

  • Point addition is not dummy:

Incorrect output for kP Point addition is dummy: Correct output for kP Last window is null: k Number

  • f bits of the last window in the targeted implementations:

Assembly optimized implementation of P-256: most signifjcant bits BoringSSL (P-224, P-384, P-521): least signifjcant bits

slide-24
SLIDE 24

9/20

Principle of C safe-error

Make a fault in the last point addition (exact details in the article): D D D A D D D A

  • Point addition is not dummy:

Incorrect output for kP Point addition is dummy: Correct output for kP Last window is null: k Number

  • f bits of the last window in the targeted implementations:

Assembly optimized implementation of P-256: most signifjcant bits BoringSSL (P-224, P-384, P-521): least signifjcant bits

slide-25
SLIDE 25

9/20

Principle of C safe-error

Make a fault in the last point addition (exact details in the article): D D D A D D D A

  • Point addition is not dummy:

Incorrect output for kP Point addition is dummy: Correct output for kP Last window is null: k = ∗ ∗ ∗ ∗ ∗ 000 Number

  • f bits of the last window in the targeted implementations:

Assembly optimized implementation of P-256: most signifjcant bits BoringSSL (P-224, P-384, P-521): least signifjcant bits

slide-26
SLIDE 26

9/20

Principle of C safe-error

Make a fault in the last point addition (exact details in the article): D D D A D D D A

  • Point addition is not dummy:

Incorrect output for kP Point addition is dummy: Correct output for kP Last window is null: k = ∗ ∗ ∗ ∗ ∗ 000 Number ℓ of bits of the last window in the targeted implementations: Assembly optimized implementation of P-256: 5 most signifjcant bits BoringSSL (P-224, P-384, P-521): 5 least signifjcant bits

slide-27
SLIDE 27

10/20

Plan

1 Why dummy codes in ECC? 2 Presentation of the attack 3 Why it works 4 Mitigations and conclusion

slide-28
SLIDE 28

11/20

Main steps of the attack

Objective: retrieve an ECDSA private key

LLL

valid signatures private key

Prerequisite: Physical access to the device Can inject a fault on potential dummy addition Acquire public data (public key, signatures, messages) Steps:

1 Make a fault in last point addition of ECDSA signature

calculation (random computational error is suffjcient)

2 Keep the signature only if valid 3 Repeat the above steps 4 Use our tool2 to recover the private key from valid signatures.

2https://github.com/orangecertcc/ecdummy (MIT license)

slide-29
SLIDE 29

11/20

Main steps of the attack

Objective: retrieve an ECDSA private key

  • LLL

valid signatures private key

Prerequisite: Physical access to the device Can inject a fault on potential dummy addition Acquire public data (public key, signatures, messages) Steps:

1 Make a fault in last point addition of ECDSA signature

calculation (random computational error is suffjcient)

2 Keep the signature only if valid 3 Repeat the above steps 4 Use our tool2 to recover the private key from valid signatures.

2https://github.com/orangecertcc/ecdummy (MIT license)

slide-30
SLIDE 30

11/20

Main steps of the attack

Objective: retrieve an ECDSA private key

  • LLL

valid signatures private key

Prerequisite: Physical access to the device Can inject a fault on potential dummy addition Acquire public data (public key, signatures, messages) Steps:

1 Make a fault in last point addition of ECDSA signature

calculation (random computational error is suffjcient)

2 Keep the signature only if valid 3 Repeat the above steps 4 Use our tool2 to recover the private key from valid signatures.

2https://github.com/orangecertcc/ecdummy (MIT license)

slide-31
SLIDE 31

11/20

Main steps of the attack

Objective: retrieve an ECDSA private key

  • LLL

valid signatures private key

Prerequisite: Physical access to the device Can inject a fault on potential dummy addition Acquire public data (public key, signatures, messages) Steps:

1 Make a fault in last point addition of ECDSA signature

calculation (random computational error is suffjcient)

2 Keep the signature only if valid 3 Repeat the above steps 4 Use our tool2 to recover the private key from valid signatures.

2https://github.com/orangecertcc/ecdummy (MIT license)

slide-32
SLIDE 32

12/20

Performance

Minimum number of valid signatures to recover the private key: Number of bits ℓ of last window 4 5 6 7 224-bit 56 45 37 31 Elliptic curve size 256-bit 65 52 43 36 384-bit 91 65 56 Average of one valid signature out of signatures attacked Example for curve P-256 in OpenSSL ( ) out of tests on average

  • valid signatures

signatures attacked

slide-33
SLIDE 33

12/20

Performance

Minimum number of valid signatures to recover the private key: Number of bits ℓ of last window 4 5 6 7 224-bit 56 45 37 31 Elliptic curve size 256-bit 65 52 43 36 384-bit 91 65 56 Average of one valid signature out of 2ℓ signatures attacked Example for curve P-256 in OpenSSL (ℓ = 5) out of 100 tests on average 54-55 valid signatures 1764 signatures attacked

slide-34
SLIDE 34

13/20

Tools for the attack

Tools for the attack in script ec.py: check_signature(curve, pubkey_point, signature) findkey(curve, pubkey_point, valid_signatures, msb, l)

l: number of bits of last window msb: last window corresponds to most or least signifjcant bits

slide-35
SLIDE 35

14/20

Demonstration of the attack

Target: assembly optimized implementation of P-256 in OpenSSL 1.1.1g Code modifjed to simulate the fault

for (i = 1; i < 37; i++) { //(...) if (i == 36) { ecp_nistz256_point_add_affine_faulty(&p.p, &p.p, &t.a); } else { ecp_nistz256_point_add_affine(&p.p, &p.p, &t.a); } }

Last window: 5 most signifjcant bits The tool will be called as findkey(secp256r1, pubkey_point, valid_signatures, True, 5)

ecp_nistz256_sqr_mont(Z1sqr, in1_z); Z1sqr[0] ^= 123456789; // "random" fault

slide-36
SLIDE 36

14/20

Demonstration of the attack

Target: assembly optimized implementation of P-256 in OpenSSL 1.1.1g Code modifjed to simulate the fault

for (i = 1; i < 37; i++) { //(...) if (i == 36) { ecp_nistz256_point_add_affine_faulty(&p.p, &p.p, &t.a); } else { ecp_nistz256_point_add_affine(&p.p, &p.p, &t.a); } }

Last window: 5 most signifjcant bits The tool will be called as findkey(secp256r1, pubkey_point, valid_signatures, True, 5)

ecp_nistz256_sqr_mont(Z1sqr, in1_z); Z1sqr[0] ^= 123456789; // "random" fault

slide-37
SLIDE 37

15/20

Plan

1 Why dummy codes in ECC? 2 Presentation of the attack 3 Why it works 4 Mitigations and conclusion

slide-38
SLIDE 38

16/20

ECDSA

Given a private key d in [1, q − 1], the process of signing a fjle is: m ← hash of the fjle k ← random secret nonce in [1, q − 1] signature: { r = x kP s = dr m k 3-> d can be recovered from partial knowledge of k for several signatures3

3Nguyen and Shparlinski, “The Insecurity of the Elliptic Curve Digital Signature Algorithm with

Partially Known Nonces.”

slide-39
SLIDE 39

16/20

ECDSA

Given a private key d in [1, q − 1], the process of signing a fjle is: m ← hash of the fjle k ← random secret nonce in [1, q − 1] signature: { r = x(kP) s = (dr + m)/k 3-> d can be recovered from partial knowledge of k for several signatures3

3Nguyen and Shparlinski, “The Insecurity of the Elliptic Curve Digital Signature Algorithm with

Partially Known Nonces.”

slide-40
SLIDE 40

16/20

ECDSA

Given a private key d in [1, q − 1], the process of signing a fjle is: m ← hash of the fjle k ← random secret nonce in [1, q − 1] signature: { r = x(kP) s = (dr + m)/k 3-> d can be recovered from partial knowledge of k for several signatures3

3Nguyen and Shparlinski, “The Insecurity of the Elliptic Curve Digital Signature Algorithm with

Partially Known Nonces.”

slide-41
SLIDE 41

17/20

Idea of the attack on ECDSA

We can rewrite the signature: k d · r/s + m/s = d u v small d u v small . . . d un vn small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-42
SLIDE 42

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d u v small d u v small . . . d un vn small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-43
SLIDE 43

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d u v small d u v small . . . d un vn small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-44
SLIDE 44

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d u v small . . . d un vn small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-45
SLIDE 45

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d un vn small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-46
SLIDE 46

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d · un + vn = small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-47
SLIDE 47

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d · un + vn = small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-48
SLIDE 48

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d · un + vn = small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-49
SLIDE 49

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d · un + vn = small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d

slide-50
SLIDE 50

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d · un + vn = small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d + =

slide-51
SLIDE 51

17/20

Idea of the attack on ECDSA

We can rewrite the signature:

unknown (“small”)

d · r/s + m/s = d · u1 + v1 = small d · u2 + v2 = small . . . d · un + vn = small

LLL

V U LLL: fjnd short vectors If the short vector is found, we get d U V short vector d + =

slide-52
SLIDE 52

18/20

Plan

1 Why dummy codes in ECC? 2 Presentation of the attack 3 Why it works 4 Mitigations and conclusion

slide-53
SLIDE 53

19/20

Mitigations

Mitigations: Scalar encoding to avoid null windows Scalar blinding Avoid these cryptographic libraries for IoT devices

slide-54
SLIDE 54

20/20

Conclusion

Wrap-up: Physical attack on ECDSA in OpenSSL and its forks Private key recovered from a few thousands signatures Proof of concept and tools for the attack available4 Open questions: are there other libraries using dummy additions?

4https://github.com/orangecertcc/ecdummy (MIT license)