Skip to content
PQ Stealth Addresses

Demo

Everything else here is abstract, which is what makes the theorems apply to any curve and also what makes nothing executable. This module fixes a tiny instance -- the additive group of ZMod 23, where discrete logs are division -- so the scheme and the attack can be RUN: exactly why the attack is executable here, and why the instance offers no security. Each #eval is wrapped in #guard_msgs, so the numbers in the docstrings are build-checked assertions.

See docs/dksap-asymmetry.md.

instFactPrime23

23 is prime, so ZMod 23 is a field.

instance instFactPrime23 : Fact (Nat.Prime 23) := ⟨by norm_num⟩

Demo.lean:26-27 ↗

F

abbrev F := ZMod 23

Demo.lean:32-33 ↗

gen

def gen : F := 5

Demo.lean:35-36 ↗

hash

def hash (x : F) : F := 7 * x + 3

Demo.lean:39-40 ↗

gen_injective

theorem gen_injective : Function.Injective (fun x : F => x • gen) := by
proof
  simpa only [smul_eq_mul] using mul_left_injective₀ (b := gen) (by decide)

Demo.lean:42-44 ↗

A tiny field and a generator

m

Recipient's spending secret.

def m : F := 9

Demo.lean:48-48 ↗

v

def v : F := 4

Demo.lean:50-50 ↗

r

def r : F := 3

Demo.lean:52-52 ↗

M

def M : F := m • gen

Demo.lean:54-54 ↗

V

def V : F := v • gen

Demo.lean:56-56 ↗

R

def R : F := r • gen

Demo.lean:58-58 ↗

P

def P : F := M + (hash (r • V)) • gen

Demo.lean:60-60 ↗

honestKey

def honestKey : F := m + hash (v • R)

Demo.lean:62-63 ↗

One recipient, one payment

genInv

The generator's multiplicative inverse, 5 * 14 = 70 = 1 mod 23.

def genInv : F := 14

Demo.lean:69-70 ↗

genInv_spec

theorem genInv_spec : genInv * gen = 1 := by decide

Demo.lean:72-73 ↗

dlog

def dlog (x : F) : F := genInv * x

Demo.lean:76-77 ↗

recovered

def recovered : F := recover hash (dlog M) (dlog V) R

Demo.lean:79-80 ↗

The attack

Run it

scheme

DKSAP at the toy instance.

def scheme : StealthScheme (F × F) (F × F) (F × F) := dksap gen hash

Demo.lean:127-128 ↗

gen_bijective

theorem gen_bijective : Function.Bijective (fun x : F => x • gen) :=
  Finite.injective_iff_bijective.mp gen_injective

Demo.lean:131-133 ↗