Jasmin: High-Assurance and High-Speed Cryptography Jos Bacelar - - PowerPoint PPT Presentation

jasmin high assurance and high speed cryptography
SMART_READER_LITE
LIVE PREVIEW

Jasmin: High-Assurance and High-Speed Cryptography Jos Bacelar - - PowerPoint PPT Presentation

Jasmin: High-Assurance and High-Speed Cryptography Jos Bacelar Almeida Manuel Barbosa Gilles Barthe Arthur Blot Benjamin Grgoire Vincent Laporte Tiago Oliveira Hugo Pacheco Benedick Schmidt Pierre-Yves Strub CCS17 2017-11-02


slide-1
SLIDE 1

Jasmin: High-Assurance and High-Speed Cryptography

José Bacelar Almeida Manuel Barbosa Gilles Barthe Arthur Blot Benjamin Grégoire Vincent Laporte Tiago Oliveira Hugo Pacheco Benedick Schmidt Pierre-Yves Strub CCS’17 — 2017-11-02

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 0 / 22

slide-2
SLIDE 2

Implementing “crypto”: a subtle equilibrium

◮ Correct ◮ Fast ◮ Secure (side-channel free)

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 1 / 22

slide-3
SLIDE 3

A gap between C and assembly

C

◮ Portable ◮ Convenient software-engineering abstractions ◮ Readable, maintainable

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 2 / 22

slide-4
SLIDE 4

A gap between C and assembly

C

◮ Portable ◮ Convenient software-engineering abstractions ◮ Readable, maintainable

Assembly

◮ Efficiency ◮ Control (instruction selection and scheduling) ◮ Precise semantics

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 2 / 22

slide-5
SLIDE 5

Jasmin: the blossoming programming language

A language A formal semantics A (correct) compiler Tooling for proof of safety and leakage-freedom

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 3 / 22

slide-6
SLIDE 6

Jasmin by example

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 4 / 22

slide-7
SLIDE 7

Jasmin “Hello World!” (constant-time swapping)

param int n = 4; inline fn cswap(stack b64[n] x, stack b64[n] y, reg b64 swap) − → stack b64[n], stack b64[n] { reg b64 tmp1, tmp2, mask; inline int i; mask = swap * 0xffffffffffffffff; for i = 0 to n { tmp1 = x[i]; tmp1 ^= y[i]; tmp1 &= mask; tmp2 = x[i]; tmp2 ^= tmp1; x[i] = tmp2; tmp2 = y[i]; tmp2 ^= tmp1; y[i] = tmp2; } return x, y; }

Zero-cost abstractions

◮ Variable names ◮ Global parameters ◮ Arrays ◮ Loops ◮ Inline functions (with custom

calling conventions)

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 5 / 22

slide-8
SLIDE 8

Control down to the instruction-set architecture level

reg bool cf; reg b64 addt0, addt1, t10, t11, t12, t13; // . . . t10 = [workp + 4 * 8]; t11 = [workp + 5 * 8]; t12 = [workp + 6 * 8]; t13 = [workp + 7 * 8]; // . . . cf, t10 += [workp + 8 * 8]; cf, t11 += [workp + 9 * 8] + cf; cf, t12 += [workp + 10 * 8] + cf; cf, t13 += [workp + 11 * 8] + cf; addt0 = 0; addt1 = 38; addt1 = addt0 if ! cf; ◮ Direct memory access ◮ The carry flag is an ordinary boolean

variable

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 6 / 22

slide-9
SLIDE 9

Control down to the instruction-set architecture level

reg bool cf; reg b64 addt0, addt1, t10, t11, t12, t13; // . . . t10 = [workp + 4 * 8]; t11 = [workp + 5 * 8]; t12 = [workp + 6 * 8]; t13 = [workp + 7 * 8]; // . . . cf, t10 += [workp + 8 * 8]; cf, t11 += [workp + 9 * 8] + cf; cf, t12 += [workp + 10 * 8] + cf; cf, t13 += [workp + 11 * 8] + cf; addt0 = 0; addt1 = 38; addt1 = addt0 if ! cf; ◮ Direct memory access ◮ The carry flag is an ordinary boolean

variable

reg b64 i, j; stack b64 is, js; // . . . j = 62; i = 3; while (i >=s 0) { is = i; // . . . while (j >=s 0) { js = j; // . . . j = js; j -= 1; } j = 63; i = is; i -= 1; } ◮ Control over loop unrolling ◮ Control over spilling

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 6 / 22

slide-10
SLIDE 10

The Jasmin compiler

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 7 / 22

slide-11
SLIDE 11

Goals / Features

◮ Predictability and control of the generated assembly ◮ Zero-cost abstractions ◮ Correct (Coq proofs, machine-checked) ◮ Preserves constant-time

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 8 / 22

slide-12
SLIDE 12

Compilation passes

◮ For loop unrolling ◮ Function inlining ◮ Constant-propagation ◮ Redundancy elimination ◮ Sharing of stack variables ◮ Register array expansion ◮ Lowering ◮ Register allocation ◮ Linearization

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 9 / 22

slide-13
SLIDE 13

A correctness theorem

Each pass proved on its own Maximal use of validation Reuse of a single checker (core) for various passes Suitable theorem for libraries (aka separate compilation)

Theorem (Jasmin compiler correctness)

∀ p p′ · compile(p) = ok(p′) − → ∀ f · f ∈ exports(p) − → ∀ va m vr m′ · enough-stack-space(f , p′, m) − → f , va, m ⇓p vr, m′ − → f , va, m ⇓p′ vr, m′

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 10 / 22

slide-14
SLIDE 14

Beyond correctness

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 11 / 22

slide-15
SLIDE 15

Automatic proof of memory safety

◮ Goal: prove that all memory accesses are valid. ◮ Require user annotations: function

preconditions, loop invariants.

◮ Translate to Dafny ◮ Reuse the Dafny·Boogie infrastructure

fn pack(reg u64 rp, reg u64[4] xa) //@ requires valid(rp, 0 * 8, 4 * 8 - 1); { inline int i; xa = freeze(xa); for i = 0 to 3 //@ invariant valid(rp, 0 * 8, 4 * 8 - 1); { [rp + (i * 8)] = xa[i]; } }

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 12 / 22

slide-16
SLIDE 16

Automatic proof of constant-time

◮ Goal: prove that a function is “constant-time” ◮ Require user annotations: function

preconditions, loop invariants.

◮ Translate to Dafny then Boogie ◮ Build a product program and check that the

product is safe (technique adapted from the CT-verif tool)

fn mladder(stack u64[4] xr, reg u64 sp) − → (stack u64[4], stack u64[4]) //@ security requires public(sp); { . . . while (i >=s 0) //@ security invariant public(i); { . . .

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 13 / 22

slide-17
SLIDE 17

Jasmin for secure programming

◮ Infrastructure for automatic checks ◮ The compiler preserves functional correctness, safety, constant-time ◮ Known verification techniques apply to Jasmin programs ◮ Jasmin high-level features make automatic verification easier: arbitrary while loops and

pointer arithmetic are seldom used.

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 14 / 22

slide-18
SLIDE 18

Running Jasmin programs

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 15 / 22

slide-19
SLIDE 19

Jasmin programs as libraries

◮ Compliant with standard ABI ◮ Link with your own programs

written in assembly, C, OCaml, Rust. . .

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 16 / 22

slide-20
SLIDE 20

Experiment: from qhasm to Jasmin

qhasm

◮ A high-level assembly language by D. Bernstein ◮ “Included” in Jasmin ◮ . . . hence easy automatic translation from qhasm to Jasmin

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 17 / 22

slide-21
SLIDE 21

Experiment: from qhasm to Jasmin

qhasm

◮ A high-level assembly language by D. Bernstein ◮ “Included” in Jasmin ◮ . . . hence easy automatic translation from qhasm to Jasmin

Supercop

◮ A cool infrastructure for testing and comparing crypto implementations ◮ Includes various examples written in qhasm ◮ A nice supply of Jasmin programs

(since there are not many Jasmin programmers yet)

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 17 / 22

slide-22
SLIDE 22

Jasmin in Supercop

which compilation variables come

  • n

prop-

  • pti-

constant- anal- and design,

  • compiler. In

should impose Implementation qhasm Jasmin Ratio X25519-4limb-base 147 084 148 914 1.012 X25519-4limb 147 890 148 922 1.006 X25519-4limb-jasmin 143 982 X25519-5limb-base 148 354 147 200 0.992 X25519-5limb 148 572 147 090 0.990 ed25519-5limb-keypair 55 364 56 594 1.022 ed25519-5limb-sign 83 430 85 038 1.019 ed25519-5limb-open 182 520 188 180 1.031 salsa20 12 322 12 460 1.011 salsa20-xor 12 208 12 252 1.004 Figure 1: Supercop cycle count

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 18 / 22

slide-23
SLIDE 23

Conclusions

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 19 / 22

slide-24
SLIDE 24

Present

◮ The Jasmin language ◮ Correct compiler for x64 ◮ Automatic checkers for safety and constant-time ◮ Programs obtained from qhasm

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 20 / 22

slide-25
SLIDE 25

Future

◮ More target architectures ◮ Vector instructions ◮ Logic and verification tools ◮ Write more programs

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 21 / 22

slide-26
SLIDE 26

Thanks

¿ Questions ? https://github.com/jasmin-lang/jasmin

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 22 / 22

slide-27
SLIDE 27

Extra

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 23 / 22

slide-28
SLIDE 28

Jasmin vs. qhasm

qhasm

◮ Multi-platform ◮ Vector instructions

Jasmin

◮ Loops ◮ Arrays ◮ Functions ◮ Formal semantics ◮ Proof of correctness

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 24 / 22

slide-29
SLIDE 29

Jasmin vs. Bedrock

Bedrock

◮ Very low-level IL: XCAP, code-labels as r-values ◮ Embedded into Gallina (Coq) ◮ Deep emphasis on specifications and functional correctness (pervasive annotations) ◮ No optimizing compiler ◮ Programmer must declare stack usage

Jasmin

◮ New language ◮ Optimizing compiler

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 25 / 22

slide-30
SLIDE 30

Jasmin vs. HACL*

HACL*

◮ In Mozilla Firefox ◮ Formal proof of the programs

Jasmin

◮ Formal proof of the compiler ◮ Control over efficiency and low-level features ◮ For the crypto programmer (not for the type theorist)

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 26 / 22

slide-31
SLIDE 31

Jasmin vs. Vale

Vale

◮ All proofs are done at the assembly level ◮ Embedded in Dafny

Jasmin

◮ Correct compiler to assembly ◮ New language

Vincent Laporte et alii Jasmin: High-Assurance and High-Speed Cryptography 2017-11-02 27 / 22