squeezing a key through a carry bit
play

Squeezing a key through a carry bit Sean Devlin, Filippo Valsorda - PowerPoint PPT Presentation

Squeezing a key through a carry bit Sean Devlin, Filippo Valsorda One month later a = a - b The code x = a a = a + p a = a - b mod p a = a - b a = a - b The code x = a t = a a = a + p a = a - b t += p mod p a ?> t a = a - b


  1. Squeezing a key through a carry bit Sean Devlin, Filippo Valsorda

  2. One month later

  3. a = a - b The code x = a a = a + p a = a - b mod p

  4. a = a - b a = a - b The code x = a t = a a = a + p a = a - b t += p mod p a �?> t

  5. a = a - b a = a - b a < b The code x = a t = a a = a + p a = a - b t += p mod p a �?> t

  6. a = a - b a = a - b x = a t = a The bug a = a + p t += p a �?> t

  7. The bug

  8. Wrong result with probability 2 -32 The bug

  9. A carry propagation bug

  10. ECCCCCCC Elliptic Curve Cryptography Crash Course for CCC • Field: numbers modulo p • Points: like (3, 7); fitting an equation • Group: a generator point and addition • Multiplication: repeated addition

  11. ECCCCCCCC Elliptic Curve Cryptography Crash Course for CCC (cont.) • Multiplication: 5Q = Q + Q + Q + Q + Q • ECDH private key: a big integer d • ECDH public key: Q = dG (think y = g a ) • ECDH shared secret: Q 2 = dQ 1

  12. Double and add Q 2 = dQ 1 d is BIG. Like, 256 bit. Can't add Q to itself 2 256 times.

  13. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 +Q 1 Z +Q

  14. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 x2 Z +Q x2

  15. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 x2 Z +Q x2 x2

  16. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 +Q 1 Z +Q x2 x2 +Q

  17. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 x2 Z +Q x2 x2 +Q x2

  18. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 +Q 1 Z +Q x2 x2 +Q x2 +Q

  19. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 x2 Z +Q x2 x2 +Q x2 +Q x2

  20. Double and add Q 2 = dQ 1 1 0 1 0 1 1 1 0 1 0 1 1 0 1 x2 Z +Q x2 x2 +Q x2 +Q x2 x2 ...

  21. Back to the carry bug

  22. session key attacker supplied secret key secret = ScalarMult(point, scalar) ← Q 2 = dQ └─ p256PointAddA ffi neAsm └─ p256SubInternal 💦

  23. Q 1 → ScalarMult(Q 1 , ) 1 1 1 0 1 Z +Q 1 x2 x2 +Q 1 x2 +Q 1 x2 +Q 1 💦 Q 2 → ScalarMult(Q 2 , ) 0 1 1 0 1 Z +Q 2 x2 x2 +Q 2 x2 +Q 2 x2 x2 💦

  24. Q 1 → ScalarMult(Q 1 , ) → 💦 ? 1 1 0 1 Q 2 → ScalarMult(Q 2 , ) → ✅ ? 1 1 0 1 1 1 1 0 1

  25. Q 1 → 💦 0 1 1 0 1 Q 2 → 1 1 1 0 1 Q 1 → 0 0 1 1 0 1 Q 2 → 💦 1 0 1 1 0 1 Q 1 → 0 1 0 1 1 0 1 Q 2 → 1 1 0 1 1 0 1

  26. Go implementation of ScalarMult Booth's multiplication in 5-bit windows. Precomputed table of 1Q to 16Q. Add, double 5 times. 01 00010 01110 01010 01010 10010 00001 01111 10011 01101 ��../

  27. Precomp table

  28. Multiplication loop

  29. Go implementation of ScalarMult Booth's multiplication in 5-bit windows. Precomputed table of 1Q to 16Q. Add, double 5 times. 01 00010 01110 01010 01010 10010 00001 01111 10011 01101 ��../ Limbs representation: less overlap and aliasing problems. {1 0} {15 1} {7 0} {5 0} {5 0} {9 0} {1 0} {8 1} {6 1} {9 1} ��../

  30. Go implementation of ScalarMult Booth's multiplication in 5-bit windows. Precomputed table of 1Q to 16Q. Add, double 5 times. 01 00010 01110 01010 01010 10010 00001 01111 10011 01101 ��../ Attack one limb at a time, instead of one bit. 34 limb values → 17 points / 5 key bits on average.

  31. 💦 Multiplication loop 💦

  32. Assembly hook 💦

  33. 💦 💦

  34. The first limb Precomp Doubling Limb 3 3 x2 x2 x2 x2 x2 → 3 x2 5 💦

  35. The first limb Precomp Doubling Limb 3 3 x2 x2 x2 x2 x2 → 3 x2 5 💦 3 x2 6 x2 x2 x2 x2 x2 → 3 x2 6 💦 3 x2 x2 12 x2 x2 x2 x2 x2 → 3 x2 7 💦

  36. The first limb Precomp Doubling Limb 3 3 x2 x2 x2 x2 x2 → 3 x2 5 💦 3 x2 6 x2 x2 x2 x2 x2 → 3 x2 6 💦 🔦 3 x2 x2 12 x2 x2 x2 x2 x2 → 3 x2 7 💦 🔦💤

  37. The last bits

  38. Kangaroo jumps depend from the terrain at the start point. 🐿 🐿 🐿 🐿 🐿 🕴 Let a tracked kangaroo loose. Place a trap at the end.

  39. Kangaroo jumps depend from the terrain at the start point. 🐿 🐿 🐿 🐿 🐿 🕴 🐿 🐿 🐿 🐿 If the wild kangaroo intersects the path at any point, 
 it ends up in the trap.

  40. Back to elliptic curves. 🐿 🐿 A jump is Q N+1 = Q N + H(Q N ) where H is a hash. Same starting point, same jump. You run from a known starting point, then from dG. 
 If you collide, you traceback to d!

  41. A target • JSON Object Signing and Encryption, JOSE (JWT) • ECDH-ES public key algorithm • go-jose and Go 1.8.1 • Check if the service successfully decrypts payload

  42. Spot instance infrastructure Sage dispatcher /work 💼 /result

  43. Figures! • Each key: ~52 limbs, modulo the kangaroo • Each limb: ~16 points on average • Each point: ~2 26 candidate points • (2 26 * 16) candidate points: ~85 CPU hours • 85 CPU hours: $1.26 EC2 spot instances • Total: 4,400 CPU hours / $65 on EC2

  44. Demo

  45. Demo

  46. Demo

  47. Thank you! No bug is small enough. Sean Devlin @spdevlin Filippo Valsorda @FiloSottile

Recommend


More recommend