Signed Cryptographic Program Verification with Typed C RYPTO L INE - - PowerPoint PPT Presentation

signed cryptographic program verification with typed
SMART_READER_LITE
LIVE PREVIEW

Signed Cryptographic Program Verification with Typed C RYPTO L INE - - PowerPoint PPT Presentation

Signed Cryptographic Program Verification with Typed C RYPTO L INE Yu-Fu Fu 1 , Jiaxiang Liu 2 , Xiaomu Shi 2 , Ming-Hsien Tsai 1 , Bow-Yaw Wang 1 , Bo-Yin Yang 1 1 Academia Sinica 2 Shenzhen University ACM CCS 2019 1/42 Outline Introduction 1


slide-1
SLIDE 1

Signed Cryptographic Program Verification with Typed CRYPTOLINE

Yu-Fu Fu1, Jiaxiang Liu2, Xiaomu Shi2, Ming-Hsien Tsai1, Bow-Yaw Wang1, Bo-Yin Yang1

1Academia Sinica 2Shenzhen University

ACM CCS 2019

1/42

slide-2
SLIDE 2

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

2/42

slide-3
SLIDE 3

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

3/42

slide-4
SLIDE 4

Practical Cryptography

Cryptographic program is written in C or ASM for efficiency. Computation over large finite field is not trivial in C and ASM. Split a large number into several smaller numbers (a.k.a. limbs). (e.g. 4 or 5 uint64 t/register to store 255-bit keys for Curve25519) Computation over limbs is error-prone. A simple bug can cause catastrophic damages. (e.g. a missing bound check in Heartbleed)

4/42

slide-5
SLIDE 5

Practical Cryptography

Cryptographic program is written in C or ASM for efficiency. Computation over large finite field is not trivial in C and ASM. Split a large number into several smaller numbers (a.k.a. limbs). (e.g. 4 or 5 uint64 t/register to store 255-bit keys for Curve25519) Computation over limbs is error-prone. A simple bug can cause catastrophic damages. (e.g. a missing bound check in Heartbleed)

In this work, we focus on implementation written in C.

4/42

slide-6
SLIDE 6

Functional Correctness

So.... How to achieve the functional correctness?

5/42

slide-7
SLIDE 7

Functional Correctness

So.... How to achieve the functional correctness? Test?

5/42

slide-8
SLIDE 8

Functional Correctness

So.... How to achieve the functional correctness? Test? State space is too BIG, HARD to cover

5/42

slide-9
SLIDE 9

Functional Correctness

So.... How to achieve the functional correctness? Test? State space is too BIG, HARD to cover

Verification

5/42

slide-10
SLIDE 10

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

6/42

slide-11
SLIDE 11

Previous Work

7/42

slide-12
SLIDE 12

Previous Work

Proof Assistant + SMT Solver (CHL+14)

can only verify some simple code in tolerable time. many human-added annotations.

SMT: Satisfiability modulo theories

7/42

slide-13
SLIDE 13

Previous Work

Proof Assistant + SMT Solver (CHL+14)

can only verify some simple code in tolerable time. many human-added annotations.

Proof Assistant + SMT Solver + Algebra Solver (TWY17)

can deal with more complex operations like multiplication

SMT solver cannot deal with large integers multiplication well

SMT: Satisfiability modulo theories

7/42

slide-14
SLIDE 14

Previous Work

Proof Assistant + SMT Solver (CHL+14)

can only verify some simple code in tolerable time. many human-added annotations.

Proof Assistant + SMT Solver + Algebra Solver (TWY17)

can deal with more complex operations like multiplication

SMT solver cannot deal with large integers multiplication well

DSL + SMT Solver + Algebra Solver (PTW+18)

Untyped CRYPTOLINE (only unsigned) Target: ASM (some real-word examples in OpenSSL) integer size is fixed (32/64 bit register)

SMT: Satisfiability modulo theories DSL: Domain-specific language

7/42

slide-15
SLIDE 15

Goal

More real-world examples. Try to verify the C implementation once instead of ASM for every platforms.

most implementation now are still written in C instead of human-optimized ASM

Less verification effort and friendly to normal cryptographic library developers.

8/42

slide-16
SLIDE 16

Target Cryptographic Libraries

OpenSSL: UBIQUITOUS BoringSSL: Chrome, Android NaCl: reference implementation wolfSSL: embedded systems Bitcoin’s libsecp256k1: ECDSA used by MANY cryptocurrencies (Ethereum, Zcash, Ripple, · · · )

9/42

slide-17
SLIDE 17

What Curves We Verified

OpenSSL: 32/64: integer size

NIST P-224 : 2224 − 296 + 1 (unsigned 64) NIST P-256 : 2256 − 2224 + 2192 + 296 − 1 (unsigned 64) NIST P-521 : 2521 − 1 (unsigned 64) Curve25519 : 2255 − 19 (unsigned 64, signed 32)

BoringSSL: Curve25519 (unsigned 64) NaCl: Curve25519 (unsigned 64, signed 64) wolfSSL: Curve25519 (same as OpenSSL ’s) (signed 32) Bitcoin: Secp256k1 (2256 − 232 − 29 − 28 − 27 − 26 − 24 − 1) (unsigned, signed)

10/42

slide-18
SLIDE 18

Contribution

Typed CRYPTOLINE – unsigned and signed, arbitrary size integers

type system (type checking & type inference)

A GCC plugin that translates GIMPLECRYPTOLINE into Typed CRYPTOLINE

GIMPLECRYPTOLINE – a subset of GIMPLE

GIMPLE: a GCC IR used in machine-independent optimization

Verify GIMPLE code after machine-independent optimization First to verify signed C implementation in cryptographic libraries used in industry Found a bug in NaCl’s Curve25519 - Case study

11/42

slide-19
SLIDE 19

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

12/42

slide-20
SLIDE 20

Typed CRYPTOLINE Program

Program - instructions Specification

Assumption (Precondition) Assertion (Postcondition) Properties {algebra && range}

range: variables should be in a proper range (e.g. a < 251) checked by SMT solver (Boolector, MathSAT, Z3 · · · ) algebra: mathematical properties (e.g. c = a × b) checked by algebraic solver (Sage, Singular, Mathematica · · · )

Hoare triple: {assumption} program {assertion}

13/42

slide-21
SLIDE 21

Typed CRYPTOLINE Program Example - Naive Addition

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no assumption 4 && 5 and [ // range prop 6 a0 <u (2**63)@64, a1 <u (2**63)@64, 7 b0 <u (2**63)@64, b1 <u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

14/42

slide-22
SLIDE 22

Typed CRYPTOLINE Program Example - Naive Addition

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no assumption 4 && 5 and [ // range prop 6 a0 <u (2**63)@64, a1 <u (2**63)@64, 7 b0 <u (2**63)@64, b1 <u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

14/42

slide-23
SLIDE 23

Typed CRYPTOLINE Program Example - Naive Addition

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no assumption 4 && 5 and [ // range prop 6 a0 <u (2**63)@64, a1 <u (2**63)@64, 7 b0 <u (2**63)@64, b1 <u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

14/42

slide-24
SLIDE 24

Typed CRYPTOLINE Program Example - Naive Addition

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no assumption 4 && 5 and [ // range prop 6 a0 <u (2**63)@64, a1 <u (2**63)@64, 7 b0 <u (2**63)@64, b1 <u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

14/42

slide-25
SLIDE 25

Typed CRYPTOLINE Program Example - Naive Addition

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no assumption 4 && 5 and [ // range prop 6 a0 <u (2**63)@64, a1 <u (2**63)@64, 7 b0 <u (2**63)@64, b1 <u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

14/42

limbs 64 [a0, a1, · · · , an] = n

i=0 ai × 264×i

slide-26
SLIDE 26

Typed CRYPTOLINE Program Example - Naive Addition

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no assumption 4 && 5 and [ // range prop 6 a0 <u (2**63)@64, a1 <u (2**63)@64, 7 b0 <u (2**63)@64, b1 <u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

14/42

263 − 1 + 263 − 1 = 264 − 2 ≤ 264 − 1

slide-27
SLIDE 27

Typed CRYPTOLINE Program Example - Overflow

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no restriction 4 && 5 and [ // range prop 6 a0 <=u (2**63)@64, a1 <=u (2**63)@64, 7 b0 <=u (2**63)@64, b1 <=u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

15/42

slide-28
SLIDE 28

Typed CRYPTOLINE Program Example - Overflow

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no restriction 4 && 5 and [ // range prop 6 a0 <=u (2**63)@64, a1 <=u (2**63)@64, 7 b0 <=u (2**63)@64, b1 <=u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

15/42

slide-29
SLIDE 29

Typed CRYPTOLINE Program Example - Overflow

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no restriction 4 && 5 and [ // range prop 6 a0 <=u (2**63)@64, a1 <=u (2**63)@64, 7 b0 <=u (2**63)@64, b1 <=u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

15/42

slide-30
SLIDE 30

Typed CRYPTOLINE Program Example - Overflow

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no restriction 4 && 5 and [ // range prop 6 a0 <=u (2**63)@64, a1 <=u (2**63)@64, 7 b0 <=u (2**63)@64, b1 <=u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

15/42

slide-31
SLIDE 31

Typed CRYPTOLINE Program Example - Overflow

1 proc main (uint64 a0, uint64 a1, uint64 b0, uint64 b1) = 2 { 3 true // algebraic prop; true means no restriction 4 && 5 and [ // range prop 6 a0 <=u (2**63)@64, a1 <=u (2**63)@64, 7 b0 <=u (2**63)@64, b1 <=u (2**63)@64 8 ] 9 } 10 add c0 a0 b0; // c0 = a0 + b0 11 add c1 a1 b1; // c1 = a1 + b1 12 { 13 limbs 64 [c0, c1] 14 = 15 limbs 64 [a0, a1] + limbs 64 [b0, b1] 16 && 17 and [ 18 c0 >=u a0, c1 >=u a1 // true iff not overflow 19 ] 20 }

15/42

263 + 263 = 264 264 − 1 264 = 0 (mod 264)

slide-32
SLIDE 32

Program Safety Check by SMT Solver

Safety in our context means that following kinds of errors do not exist. Overflow / Underflow

16/42

slide-33
SLIDE 33

Program Safety Check by SMT Solver

Safety in our context means that following kinds of errors do not exist. Overflow / Underflow Cast between types (uint64 ↔ int64, uint64 ↔ uint32) Value preserving casting (vpc) 2’s complement representation for signed integers uint4 ↔ int4 (0111)2 = 7 (unsigned) = 7 (signed) (1111)2 = 15 (unsigned) =

  • 1

(signed)

16/42

slide-34
SLIDE 34

Program Safety Check by SMT Solver

Safety in our context means that following kinds of errors do not exist. Overflow / Underflow Cast between types (uint64 ↔ int64, uint64 ↔ uint32) Value preserving casting (vpc) 2’s complement representation for signed integers uint4 ↔ int4 (0111)2 = 7 (unsigned) = 7 (signed) ✓ (1111)2 = 15 (unsigned) =

  • 1

(signed) ✗

BUG (vpc) or on purpose (cast) Counterexample by SMT solver

16/42

slide-35
SLIDE 35

Typed CRYPTOLINE Program Example - Cast v.s. VPC

1 proc main (uint64 a ,uint64 b)= 2 { 3 true 4 && 5 and [ 6 a <u (2**63), b <u (2**63) 7 ] 8 } 9 cast wa@int64 a; 10 cast wb@int64 b; 11 mul c wa wb; 12 { ... } 1 proc main (uint64 a ,uint64 b)= 2 { 3 true 4 && 5 and [ 6 a <u (2**63), b <u (2**63) 7 ] 8 } 9 vpc wa@int64 a; 10 vpc wb@int64 b; 11 mul c wa wb; 12 { ... }

Figure: cast = vpc in some cases

under the assumption, sign bit will never be 1.

17/42

✓ ✓

slide-36
SLIDE 36

Typed CRYPTOLINE Program Example - VPC Error

1 proc main (uint64 a ,uint64 b)= 2 { 3 true 4 && 5 and [ 6 a <=u (2**63), b <=u (2**63) 7 ] 8 } 9 cast wa@int64 a; 10 cast wb@int64 b; 11 mul c wa wb; 12 { ... } 1 proc main (uint64 a ,uint64 b)= 2 { 3 true 4 && 5 and [ 6 a <=u (2**63), b <=u (2**63) 7 ] 8 } 9 vpc wa@int64 a; 10 vpc wb@int64 b; 11 mul c wa wb; 12 { ... }

Figure: cast = vpc in some cases

263 = (100....0)2

18/42

✓ ✗

slide-37
SLIDE 37

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

19/42

slide-38
SLIDE 38

GCC Plugin

Introduced in GCC 4.5.0 Let us add custom optimization passes Able to access AST (abstract syntax tree)

No need to write parser by yourself!

20/42

slide-39
SLIDE 39

Verification Workflow Using GCC Plugin

Parse Gimplify Machine- independent Optimize Generate Cryptoline Keep Compiling Manual Modification Cryptoline Verifier Counterexample Success

21/42

slide-40
SLIDE 40

GIMPLE Example

1 f0_3 = *f_2(D); 2 f1_4 = MEM[(const int32_t*)f_2(D)+4B]; 3 ... 4 g0_14 = *g_13(D); 5 g1_15 = MEM[(const int32_t*)g_13(D)+4B]; 6 ... 7 h0_24 = f0_3 - g0_14; 8 h1_25 = f1_4 - g1_15; 9 ... 10 *h_34(D) = h0_24; 11 MEM[(int32_t*)h_34(D)+4B] = h1_25; 12 ...

?LHS = MEM[?RHS] ⇒ Load from RHS to LHS MEM[?LHS] = ?RHS ⇒ Store RHS to LHS

22/42

slide-41
SLIDE 41

GIMPLE Example

1 f0_3 = *f_2(D); 2 f1_4 = MEM[(const int32_t*)f_2(D)+4B]; 3 ... 4 g0_14 = *g_13(D); 5 g1_15 = MEM[(const int32_t*)g_13(D)+4B]; 6 ... 7 h0_24 = f0_3 - g0_14; 8 h1_25 = f1_4 - g1_15; 9 ... 10 *h_34(D) = h0_24; 11 MEM[(int32_t*)h_34(D)+4B] = h1_25; 12 ...

?LHS = MEM[?RHS] ⇒ Load from RHS to LHS MEM[?LHS] = ?RHS ⇒ Store RHS to LHS

22/42

slide-42
SLIDE 42

GIMPLE Example

1 f0_3 = *f_2(D); 2 f1_4 = MEM[(const int32_t*)f_2(D)+4B]; 3 ... 4 g0_14 = *g_13(D); 5 g1_15 = MEM[(const int32_t*)g_13(D)+4B]; 6 ... 7 h0_24 = f0_3 - g0_14; 8 h1_25 = f1_4 - g1_15; 9 ... 10 *h_34(D) = h0_24; 11 MEM[(int32_t*)h_34(D)+4B] = h1_25; 12 ...

?LHS = MEM[?RHS] ⇒ Load from RHS to LHS MEM[?LHS] = ?RHS ⇒ Store RHS to LHS

22/42

slide-43
SLIDE 43

GIMPLE Example

1 f0_3 = *f_2(D); 2 f1_4 = MEM[(const int32_t*)f_2(D)+4B]; 3 ... 4 g0_14 = *g_13(D); 5 g1_15 = MEM[(const int32_t*)g_13(D)+4B]; 6 ... 7 h0_24 = f0_3 - g0_14; 8 h1_25 = f1_4 - g1_15; 9 ... 10 *h_34(D) = h0_24; 11 MEM[(int32_t*)h_34(D)+4B] = h1_25; 12 ...

?LHS = MEM[?RHS] ⇒ Load from RHS to LHS MEM[?LHS] = ?RHS ⇒ Store RHS to LHS

22/42

slide-44
SLIDE 44

GIMPLE Example

1 f0_3 = *f_2(D); 2 f1_4 = MEM[(const int32_t*)f_2(D)+4B]; 3 ... 4 g0_14 = *g_13(D); 5 g1_15 = MEM[(const int32_t*)g_13(D)+4B]; 6 ... 7 h0_24 = f0_3 - g0_14; 8 h1_25 = f1_4 - g1_15; 9 ... 10 *h_34(D) = h0_24; 11 MEM[(int32_t*)h_34(D)+4B] = h1_25; 12 ...

?LHS = MEM[?RHS] ⇒ Load from RHS to LHS MEM[?LHS] = ?RHS ⇒ Store RHS to LHS

22/42

slide-45
SLIDE 45

GIMPLECRYPTOLINE Example

generated by the plugin automatically. later manually add assumption / assertion.

1 proc main () = 2 { true && true } 3 mov f03 f2 0; // f0_3 = *f_2 4 mov f14 f2 4; // f1_4 = MEM[(...) f_2 + 4] 5 ... 6 mov g014 g13 0; 7 mov g115 g13 4; 8 ... 9 sub h024 f03 g014; // h0_24 = f0_3 - g0_14 10 sub h125 f14 g115; 11 ... 12 mov h34 0 h024; // *h_34 = h0_24 13 mov h34 4 h125; // MEM[(...) h_34 + 4] 14 { true && true }

use pointer name and offset to represent the variable

23/42

slide-46
SLIDE 46

GIMPLECRYPTOLINE Example

generated by the plugin automatically. later manually add assumption / assertion.

1 proc main () = 2 { true && true } 3 mov f03 f2 0; // f0_3 = *f_2 4 mov f14 f2 4; // f1_4 = MEM[(...) f_2 + 4] 5 ... 6 mov g014 g13 0; 7 mov g115 g13 4; 8 ... 9 sub h024 f03 g014; // h0_24 = f0_3 - g0_14 10 sub h125 f14 g115; 11 ... 12 mov h34 0 h024; // *h_34 = h0_24 13 mov h34 4 h125; // MEM[(...) h_34 + 4] 14 { true && true }

use pointer name and offset to represent the variable

23/42

slide-47
SLIDE 47

GIMPLECRYPTOLINE Example

generated by the plugin automatically. later manually add assumption / assertion.

1 proc main () = 2 { true && true } 3 mov f03 f2 0; // f0_3 = *f_2 4 mov f14 f2 4; // f1_4 = MEM[(...) f_2 + 4] 5 ... 6 mov g014 g13 0; 7 mov g115 g13 4; 8 ... 9 sub h024 f03 g014; // h0_24 = f0_3 - g0_14 10 sub h125 f14 g115; 11 ... 12 mov h34 0 h024; // *h_34 = h0_24 13 mov h34 4 h125; // MEM[(...) h_34 + 4] 14 { true && true }

use pointer name and offset to represent the variable

23/42

slide-48
SLIDE 48

GIMPLECRYPTOLINE Example

generated by the plugin automatically. later manually add assumption / assertion.

1 proc main () = 2 { true && true } 3 mov f03 f2 0; // f0_3 = *f_2 4 mov f14 f2 4; // f1_4 = MEM[(...) f_2 + 4] 5 ... 6 mov g014 g13 0; 7 mov g115 g13 4; 8 ... 9 sub h024 f03 g014; // h0_24 = f0_3 - g0_14 10 sub h125 f14 g115; 11 ... 12 mov h34 0 h024; // *h_34 = h0_24 13 mov h34 4 h125; // MEM[(...) h_34 + 4] 14 { true && true }

use pointer name and offset to represent the variable

23/42

slide-49
SLIDE 49

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

24/42

slide-50
SLIDE 50

Case Study - Field Subtraction in NaCl Curve25519

5 uint64 limbs and use signed computation

25/42

slide-51
SLIDE 51

Case Study - Field Subtraction in NaCl Curve25519

5 uint64 limbs and use signed computation

25/42

slide-52
SLIDE 52

Case Study - Field Subtraction in NaCl Curve25519

5 uint64 limbs and use signed computation

25/42

slide-53
SLIDE 53

Case Study - Field Subtraction in NaCl Curve25519

5 uint64 limbs and use signed computation

25/42

slide-54
SLIDE 54

Case Study - Field Subtraction in NaCl Curve25519

5 uint64 limbs and use signed computation

25/42

slide-55
SLIDE 55

Case Study - Field Subtraction in NaCl Curve25519

5 uint64 limbs and use signed computation

25/42

slide-56
SLIDE 56

Figure: Bitwise tricks (signed right shift) & Reduction chain

26/42

slide-57
SLIDE 57

Figure: Bitwise tricks (signed right shift) & Reduction chain

sign bit(out[a]) == 1/0 ↔ t is all 1/0

26/42

slide-58
SLIDE 58

Verify by CRYPTOLINE - Pre-condition

Assume Program Assert a4 a3 a2 a1 a0 255 204 153 102 51

27/42

slide-59
SLIDE 59

Verify by CRYPTOLINE - Pre-condition

Assume Program Assert a4 a3 a2 a1 a0 255 204 153 102 51

27/42

slide-60
SLIDE 60

Verify by CRYPTOLINE - Pre-condition

Assume Program Assert a4 a3 a2 a1 a0 255 204 153 102 51

27/42

slide-61
SLIDE 61

Verify by CRYPTOLINE - Pre-condition

Assume Program Assert a4 a3 a2 a1 a0 255 204 153 102 51

27/42

slide-62
SLIDE 62

Verify by CRYPTOLINE - Init type casting

Assume Program Assert Init Instr Return uint64 → int64 bridge assumption and program vpc: value preserve casting (will do safety check)

28/42

slide-63
SLIDE 63

Verify by CRYPTOLINE - Instructions

Assume Program Assert Init Instr Return ssub: signed subtraction (usub/ssub explicitly ⇒ type checking, sub ⇒ type inference)

29/42

slide-64
SLIDE 64

Verify by CRYPTOLINE - Return type casting

Assume Program Assert Init Instr Return int64 → uint64 bridge program and assertion vpc: value preserve casting (will do safety check)

30/42

slide-65
SLIDE 65

Verify by CRYPTOLINE - Post-condition

Assume Program Assert limbs 51[a0, a1, · · · , an] = n

i=0 ai × 251×i

mod m: under modulo m

31/42

slide-66
SLIDE 66

Verify by CRYPTOLINE - Return type casting - Revisit

Assume Program Assert Init Instr Return vpc: value preserve casting (will do safety check)

32/42

slide-67
SLIDE 67

Verify by CRYPTOLINE - Return type casting - Revisit

Assume Program Assert Init Instr Return vpc: value preserve casting (will do safety check)

Safety Check Failed

32/42

slide-68
SLIDE 68

Counterexample generated by SMT solvers

Figure: output by MathSAT

33/42

slide-69
SLIDE 69

Counterexample generated by SMT solvers

Figure: output by MathSAT

33/42

slide-70
SLIDE 70

Found Counterexample translated to C language

34/42

slide-71
SLIDE 71

Check whether the program result is correct !

35/42

slide-72
SLIDE 72

Check whether the program result is correct !

Underflow and not in proper range 0xffffffffffffffff = 264 − 1

35/42

0x0 0x1 0x5f6080e 0x0 0x0

slide-73
SLIDE 73

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

36/42

slide-74
SLIDE 74

Glimpse Evaluation Result

82 C functions (when paper is submitted) Evaluated on two different machines

much more range properties and safety check by SMT solver ⇒ done in parallel a few algebraic properties (most have only 1)

field operation group operation

M1: Macbook 13” 2C/4T 16GB M2: Ubuntu Server 18C/36T 1024GB

37/42

slide-75
SLIDE 75

Evaluation Table - all functions

38/42

slide-76
SLIDE 76

Some comparisons

Montgomery Ladder step∗ involves 4 add, 4 sub, 4 square, 6 mul (Curve25519) (field operations) F U/S LIR LCL TRM1 TAM1 TRM2 TAM2 TH

  • penSSL

5 * U64 923 1047 9.3m 0.93s 2m 0.61s boringSSL 5 * U64 927 1073 7.8m 0.89s 2m 0.56s boringSSL 10 * U32 2715 3419 27.5m 59s 6.3m 42s 2h wolfSSL 10 * S32 2770 2770 OOT 12s 18.9h 8s LIR: lines of IR LCL: lines of CRYPTOLINE TR(range, safety), TA(algebra): used time OOT: used time > 1day TH: human effort (one person) Montgomery Ladder is used for scalar multiplication of elliptic curve point Q = aP

39/42

slide-77
SLIDE 77

Outline

1

Introduction

2

Previous Work & Contribution

3

Typed CRYPTOLINE Example

4

Use GCC to generate CRYPTOLINE

5

Case Study - NaCl

6

Evaluation

7

Conclusion

40/42

slide-78
SLIDE 78

Conclusion

A lightweight and easy to use method to verify cryptographic software involving both unsigned/signed operations. A GCC Plugin reducing human effort Verify several functions in well-known cryptographic libraries.

OpenSSL BoringSSL NaCl wolfSSL Bitcoin’s libsecp256k1

41/42

slide-79
SLIDE 79

CryptoLine Verifier GCC Plugin This Slide1

github.com/fmlab-iis

Signed Cryptographic Program Verification with Typed CRYPTOLINE Open Access

1twleo.com/slides/ccs19-slide.pdf 42/42