Provably secure compilation of side-channel countermeasures: the - - PowerPoint PPT Presentation

provably secure compilation of side channel
SMART_READER_LITE
LIVE PREVIEW

Provably secure compilation of side-channel countermeasures: the - - PowerPoint PPT Presentation

Provably secure compilation of side-channel countermeasures: the case of cryptographic constant-time Gilles Barthe Benjamin Grgoire Vincent Laporte CSF18, 2018-07-12 Vincent Laporte et alii Provably secure compilation of


slide-1
SLIDE 1

Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time”

Gilles Barthe Benjamin Grégoire Vincent Laporte CSF’18, 2018-07-12

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 0 / 16

slide-2
SLIDE 2

Side channels

Running a program of physical devices leak information through side channels.

▶ Light ▶ Heat ▶ Sound ▶ Power ▶ Time ▶ … ▶ Memory cache ▶ Branch predictor ▶ …

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 1 / 16

slide-3
SLIDE 3

Constant-time programming

Sofuware-based countermeasure against timing atuacks and cache atuacks. Guideline: control-fmow and memory accesses should not depend on sensitive data. Rationale: crypto implementations without this property are vulnerable. Caveat: wide range of atuacker models.

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 2 / 16

slide-4
SLIDE 4

Secure compilation

▶ Can we reason about “constant-time” at the source level? ▶ Do compilers preserve “constant-time”-ness?

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 3 / 16

slide-5
SLIDE 5

Counter-example Α: emulation of conditional-move

Before

int cmove(int x, int y, bool b) { return x + (y − x) * b; }

Afuer

int cmove(int x, int y, bool b) { if (b) { return y; } else { return x; } }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 4 / 16

slide-6
SLIDE 6

Counter-example Α: emulation of conditional-move

Before

int cmove(int x, int y, bool b) { return x + (y − x) * b; }

Afuer

int cmove(int x, int y, bool b) { if (b) { return y; } else { return x; } }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 4 / 16

slide-7
SLIDE 7

Counter-example Β: double-word multiplication

Before

long long llmul(long long x, long long y) { return x * y; }

𝑦 = 𝑏𝑐 = 𝑏𝑂 + 𝑐 𝑧 = 𝑑𝑒 = 𝑑𝑂 + 𝑒 𝑦𝑧 = (𝑏𝑒 + 𝑑𝑐)𝑂 + 𝑐𝑒 (mod 𝑂 2) Afuer

long long llmul(long long x, long long y) { long a = High(x); long c = High(y); if (a | c) { /* … */ } else { return Low(x) * Low(y); } }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 5 / 16

slide-8
SLIDE 8

Counter-example Β: double-word multiplication

Before

long long llmul(long long x, long long y) { return x * y; }

𝑦 = 𝑏𝑐 = 𝑏𝑂 + 𝑐 𝑧 = 𝑑𝑒 = 𝑑𝑂 + 𝑒 𝑦𝑧 = (𝑏𝑒 + 𝑑𝑐)𝑂 + 𝑐𝑒 (mod 𝑂 2) Afuer

long long llmul(long long x, long long y) { long a = High(x); long c = High(y); if (a | c) { /* … */ } else { return Low(x) * Low(y); } }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 5 / 16

slide-9
SLIDE 9

Counter-example Γ: tabulation

Before

char rot13(char x) { return 'a' + ((x - 'a' + 13) % 26); }

Afuer

char rot13(char x) { static char table[26] = ”nopqrstuvwxyzabcdefghijklm”; return table[x - 'a']; }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 6 / 16

slide-10
SLIDE 10

Counter-example Γ: tabulation

Before

char rot13(char x) { return 'a' + ((x - 'a' + 13) % 26); }

Afuer

char rot13(char x) { static char table[26] = ”nopqrstuvwxyzabcdefghijklm”; return table[x - 'a']; }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 6 / 16

slide-11
SLIDE 11

Counter-example Δ: speculative load introduction

Before

if (false) { let x = *ptr; … x … }

Afuer

let x = *ptr; if (false) { … x … }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 7 / 16

slide-12
SLIDE 12

Counter-example Δ: speculative load introduction

Before

if (false) { let x = *ptr; … x … }

Afuer

let x = *ptr; if (false) { … x … }

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 7 / 16

slide-13
SLIDE 13

Good news…

Some compilers do preserve “constant-time”-ness. Let’s prove it (very formally)! Case studies:

▶ Constant folding ▶ Constant propagation ▶ Variable spilling ▶ Expression fmatuening ▶ Loop peeling ▶ Pull common instructions out of branches ▶ Swap independent instructions ▶ Linearization

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 8 / 16

slide-14
SLIDE 14

A non-interference property

Decorate the small-step relation with a leakage: a

b ℓ Defjnition (Constant-time)

For every two execution prefjxes the leakages agree whenever the inputs agree: 𝜒(𝑗, 𝑗′) ⟹ ℓ0 ⋅ ℓ1 ⋅ ℓ2 = ℓ′

0 ⋅ ℓ′ 1 ⋅ ℓ′ 2

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 9 / 16

slide-15
SLIDE 15

A non-interference property

Decorate the small-step relation with a leakage: a

b ℓ Defjnition (Constant-time)

For every two execution prefjxes

i i′ s0 s′ ℓ0 ℓ′ s1 s′

1

ℓ1 ℓ′

1

s2 s′

2

ℓ2 ℓ′

2

. . . . . .

the leakages agree whenever the inputs agree: 𝜒(𝑗, 𝑗′) ⟹ ℓ0 ⋅ ℓ1 ⋅ ℓ2 = ℓ′

0 ⋅ ℓ′ 1 ⋅ ℓ′ 2

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 9 / 16

slide-16
SLIDE 16

Leakage?

Any combination of:

▶ tick per step ▶ branching conditions ▶ dereferenced addresses ▶ arguments of arithmetic operators (division, shifu, etc.) ▶ content of freed memory ▶ …

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 10 / 16

slide-17
SLIDE 17

Compiler correctness & simulation diagrams

Given a relation ≈ between source and target execution states, if initial states (for the same input values) are in relation if related fjnal states yield the same result If the following diagram holds

a α b β ≈ ≈

then the compiler is correct (moreover, the ≈ relation is a relational invariant of any two related executions).

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 11 / 16

slide-18
SLIDE 18

Lockstep 2-simulation

▶ Each target step is related by the simulation proof to a source step. ▶ Use this relation to justify that the target leakage is benign. ▶ Take two instances of the simulation diagram with equal source leakage;

and prove that target leakages are equal:

a α b β a′ α′ b′ β′

≈ ≈ ≈ ≈

t t τ τ

Use relations ≡ between states to link the two executions.

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 12 / 16

slide-19
SLIDE 19

Lockstep 2-simulation

▶ Each target step is related by the simulation proof to a source step. ▶ Use this relation to justify that the target leakage is benign. ▶ Take two instances of the simulation diagram with equal source leakage;

and prove that target leakages are equal:

a α b β a′ α′ b′ β′

≈ ≈ ≈ ≈

t t τ τ

Use relations ≡ between states to link the two executions.

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 12 / 16

slide-20
SLIDE 20

Many-steps simulation

▶ Some compilation passes require a more general simulation diagram

+

a α b β ≈ ≈

▶ Issue: how to (universally) quantify over instances of this diagram? ▶ Complying with hypotheses and conclusions is not enough ▶ Explicitly state the number of target steps: use a function “𝑜 = num-steps(𝑏, 𝛽)”

and prove the simulation diagram for this number of steps

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 13 / 16

slide-21
SLIDE 21

Many-steps simulation

▶ Some compilation passes require a more general simulation diagram

+

a α b β ≈ ≈

+ +

a α b β β′ ≈ ≈ ≈

▶ Issue: how to (universally) quantify over instances of this diagram? ▶ Complying with hypotheses and conclusions is not enough ▶ Explicitly state the number of target steps: use a function “𝑜 = num-steps(𝑏, 𝛽)”

and prove the simulation diagram for this number of steps

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 13 / 16

slide-22
SLIDE 22

Many-steps simulation

▶ Some compilation passes require a more general simulation diagram

n

a α b β ≈ ≈

+ +

a α b β β′ ≈ ≈ ≈

▶ Issue: how to (universally) quantify over instances of this diagram? ▶ Complying with hypotheses and conclusions is not enough ▶ Explicitly state the number of target steps: use a function “𝑜 = num-steps(𝑏, 𝛽)”

and prove the simulation diagram for this number of steps

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 13 / 16

slide-23
SLIDE 23

Many-steps 2-simulation

▶ Tie 2-diagram then generalizes to many-steps:

a α b β a′ α′ b′ β′

n n′

≈ ≈ ≈ ≈

t t τ τ

▶ NB: also works for 𝑜, 𝑜′ = 0 (the size of the source state needs to strictly decrease)

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 14 / 16

slide-24
SLIDE 24

Example: constant-propagation

  • 1. Analysis: what variables have a statically known value
  • 2. Simplify expressions, as in constant folding, using the analysis result
  • 3. Remove (some) trivial branches (depending on heuristics), e.g.:

▶ if 1 𝑑1 𝑑2 → 𝑑1 ▶ loop 𝑑1 0 𝑑2 → 𝑑1

Correctness:

▶ Need to remember the analysis results (e.g., with annotations in the program)

Constant-time preservation:

▶ Need to remember which branches are simplifjed (with similar annotations)

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 15 / 16

slide-25
SLIDE 25

Take-away

▶ A general theorem to reduce constant-time preservation to one diagram. ▶ Builds atop correctness proofs. ▶ Constant-time preservation is usually (much) simpler to prove. ▶ Can be instantiated to several leakage/adversary models. ▶ Many transformations are actually secure. ▶ Direct proof vs. translation validation is irrelevant

(we prove that all correct runs of the transformation are secure).

Vincent Laporte et alii Provably secure compilation of side-channel countermeasures: the case of cryptographic “constant-time” CSF’18 2018-07-12 16 / 16