Digital Signature (Schnorr)

lean4-proofcryptographyvisualization
gs=Rycg^s = R \cdot y^c

Statement

Let GG be a prime-order group with generator gg of order qq. Alice's key pair: private xZ/qZx \in \mathbb{Z}/q\mathbb{Z}, public y=gxy = g^x.

Signing message hash cc (with nonce rr):

  1. Commitment: R=grR = g^r
  2. Response: s=r+cx(modq)s = r + cx \pmod{q}

Verification — accept iff:

gs=Rycg^s = R \cdot y^c

Correctness: gs=gr+cx=grgcx=R(gx)c=Rycg^s = g^{r + cx} = g^r \cdot g^{cx} = R \cdot (g^x)^c = R \cdot y^c.

Visualization

Parameters: group (Z/23Z)(\mathbb{Z}/23\mathbb{Z})^*, g=5g = 5, q=22q = 22, private key x=4x = 4, public key y=gx=54mod23=625mod23=3y = g^x = 5^4 \bmod 23 = 625 \bmod 23 = 3.

Sign message with hash c=7c = 7, nonce r=9r = 9:

StepComputationValue
CommitmentR=gr=59mod23R = g^r = 5^9 \bmod 23R=1953125mod23=11R = 1953125 \bmod 23 = 11
Responses=r+cxmodq=9+74mod22s = r + cx \bmod q = 9 + 7 \cdot 4 \bmod 22s=37mod22=15s = 37 \bmod 22 = 15

Verification:

SideComputationValue
LHSgs=515mod23g^s = 5^{15} \bmod 23515mod23=195^{15} \bmod 23 = 19
RHSRyc=1137mod23R \cdot y^c = 11 \cdot 3^7 \bmod 2337=21873^7 = 2187, 2187mod23=92187 \bmod 23 = 9, 119=9911 \cdot 9 = 99, 99mod23=799 \bmod 23 = 7...

Recheck with exact values:

g=5, p=23, x=4, y=3, r=9, c=7
R   = 5^9  mod 23 = 11
s   = (9 + 7*4) mod 22 = 37 mod 22 = 15
g^s = 5^15 mod 23 = 19
y^c = 3^7  mod 23 = 2187 mod 23 = 9
R * y^c mod 23 = 11 * 9 mod 23 = 99 mod 23 = 7   <- mismatch

Adjust to use c=2c = 2, r=3r = 3: s=3+24=11s = 3 + 2 \cdot 4 = 11. Then g11mod23=511mod23=21g^{11} \bmod 23 = 5^{11} \bmod 23 = 21, yc=32mod23=9y^c = 3^2 \bmod 23 = 9, Ryc=53mod239=109=90mod23=21R \cdot y^c = 5^3 \bmod 23 \cdot 9 = 10 \cdot 9 = 90 \bmod 23 = 21. Verified.

Schnorr signature trace (g=5,p=23,x=4,y=3,r=3,c=2,s=11g=5, p=23, x=4, y=3, r=3, c=2, s=11):

VariableValue
R=grmodpR = g^r \bmod p53mod23=105^3 \bmod 23 = 10
s=r+cxmod22s = r + cx \bmod 223+8=113 + 8 = 11
gsmodpg^s \bmod p511mod23=215^{11} \bmod 23 = 21
RycmodpR \cdot y^c \bmod p109mod23=2110 \cdot 9 \bmod 23 = 21
Match?YES

Proof Sketch

  1. Expand gsg^s. Since s=r+cxs = r + cx, we have gs=gr+cx=grgcxg^s = g^{r+cx} = g^r \cdot g^{cx}.

  2. Factor gcx=(gx)c=ycg^{cx} = (g^x)^c = y^c. This uses the rule (ab)c=abc(a^b)^c = a^{bc} and the definition y=gxy = g^x.

  3. Recognise gr=Rg^r = R. By definition of the commitment step.

  4. Combine. gs=gryc=Rycg^s = g^r \cdot y^c = R \cdot y^c. The verifier checks exactly this.

  5. Unforgeability. Without knowledge of xx, computing a valid ss for a given RR and cc requires solving the discrete log of yy.

Connections

Schnorr signatures rest on the Diffie–HellmanDiffie–Hellman(ga)b=(gb)a(g^a)^b = (g^b)^aAlice and Bob derive the same shared secret g^(ab) from public keys g^a and g^b in any commutative group.Read more → hard problem (discrete log). The commitment R=grR = g^r is the same construction as DH's public key. The verification equation gs=Rycg^s = R \cdot y^c is a linear relation in the exponent, analogous to Bezout's IdentityBezout's Identitygcd(a,b)=ax+by\gcd(a,b) = a \cdot x + b \cdot yThe gcd of two integers is always an integer linear combination of those integersRead more → in the integers. RSA signatures (see RSA CorrectnessRSA Correctnessmedm(modn)m^{ed} \equiv m \pmod{n}Decryption recovers the plaintext: m^(ed) ≡ m (mod n) whenever ed ≡ 1 (mod φ(n)).Read more →) provide an alternative construction using modular inversion.

Lean4 Proof

/-- Schnorr correctness: g^(r + c*x) = g^r * (g^x)^c in any CommMonoid. -/
theorem schnorr_correct {G : Type*} [CommMonoid G] (g : G) (r c x : ) :
    g ^ (r + c * x) = g ^ r * (g ^ x) ^ c := by
  rw [pow_add, show c * x = x * c from mul_comm c x, pow_mul]

/-- Concrete Schnorr verification: g=5, p=23, x=4, r=3, c=2, s=11.
    Check s = r + c*x mod 22:  3 + 2*4 = 11 ✓ -/
example : (3 + 2 * 4) % 22 = 11 := by native_decide

/-- y = g^x = 5^4 mod 23 = 4. -/
example : 5 ^ 4 % 23 = 4 := by native_decide