Fast Public Key Crypto and Curve25519

Kevin Burke

@derivativeburke

What is cryptography?

Sending messages without someone in the middle being able to read them

Assumes someone in the middle can read (encrypted) message

Middleman may try to forge/tamper with messages

Not: steganography

Steganography: grape juice

Steganography: blinking

Symmetric cryptography

Applying a reversible transformation to a message

Usually involves a secret key

Example: rot13

Example: shared text

Decrypt shared text

Enigma

Example: Enigma

Example: Enigma 2

Example: Enigma 3

Example: Enigma 4

Example: Enigma 10

Example: One time pad

Example: SIGSALY

SIGSALY (Pentagon)

SIGSALY (Downing St)

Nowadays: Stream ciphers

Stream ciphers

Stream cipher inputs:

What is a nonce?

Without it, ciphertext is identical

Imagine SIGSALY twice

SIGSALY (Pentagon)

SIGSALY (Pentagon)

Attacker

Attacker

What if you want to accept messages from anyone?

Public-key cryptography

Basics

Alice, Bob exchange public keys only

Basics, cont'd

Key Math Points

Diffie Hellman basics

Alice's public/private keys

Bob's public/private keys

Alice computes shared key

Bob computes shared key

Hard to reverse

Pick a number (mod 37)

Curve25519 description

Why curve25519?

1. Misuse resistance

Which way does this door open?

A plain door

Which way does this door open?

A door with panic bar

Bad design has consequences

Victoria Hall

Victoria Hall

Crash bars became law

A door with panic bar

Don Norman

Don Norman's book

Prone to misuse: JWT
small subgroup attack

JWT small subgroup attack

all the libraries that I checked missed validating that the received public key ... is on the curve

Curve25519: deliberately chosen to avoid small subgroup attacks

Generating a private key

  1. Generate 32 bytes of random data
  2. byte[0] = byte[0] & 248
  3. byte[31] = byte[31] & 127
  4. byte[31] = byte[31] | 64

1,2,4,8 is the only subgroup
byte[0] = byte[0] & 248

2. Speed

Floating point math works well with Intel registers

Add/mult mod 2255 - 19
is fast to compute

Alice's public/private keys

3. Timing Attacks

Array lookups are not constant time

Array lookups are not constant time

Compute values in pairs

  1. x[b] (b ∈ {0, 1})
  2. x[b] = (1 - b)x[0] + bx[1]

Paper ships with assembly implementation

burke.services

Thanks!

Kevin Burke

kev.inburke.com

kev@inburke.com

@derivativeburke


These slides are available at:

kev.inburke.com/slides/curve25519

/

#