Skip to content
Trapdoor·Lab

The Schnorr protocol

1Toy

Proof that you know the key

The private key x and the public key X = x · G are the same pair as in the Elliptic curves station: X is easy to compute from x, but x cannot be recovered from X — that is the discrete logarithm (the Arithmetic modulo p station). Claus Schnorr’s protocol (CRYPTO ’89) lets you convince someone that you know x without revealing it. It is the real version of Ali Baba’s cave, with the discrete logarithm as the door. There are three moves: the prover draws a secret r and sends the commitment R = r · G; only then does the verifier draw the challenge c; the prover answers s = r + c · x mod n. The verifier checks that s · G = R + c · X — always true for an honest prover, because (r + c · x) · G = r · G + c · (x · G).

Why it convinces: whoever can answer two different challenges c₁ and c₂ for the same R knows x, because x = (s₁ − s₂) / (c₁ − c₂) mod n. Someone who does not know x can prepare a response for only one challenge, guessed before sending R, and passes with probability 1/(n − 1) — one round of the cave gave 1/2. Why it reveals nothing: a triple (R, c, s) that passes the check can be made without x — pick c and s, then compute R = s · G − c · X. This simulator is the cave’s edited film: a transcript convinces only the verifier who drew c itself after receiving R. The toy computes on the curve from the “Break it” mode of the Elliptic curves station, with a 12-bit n = 4003 — the same as the toy of the Digital signatures station. The “Prover without the key” switch turns the prover into a cheater who guesses the challenge.

Fiat and Shamir (CRYPTO ’86) replaced the verifier with a hash function: c = H(R ‖ X ‖ m). The prover computes the challenge itself, but only after fixing R, because R is in the hash. The message m turns the proof into a signature (R, s) that anyone can check. The toy computes H as RFC 9591 does in Appendix B: hash_to_field from RFC 9380 on SHA-256, with a domain separation tag (DST). The same code on the P-256 curve with the context FROST-P256-SHA256-v1 reproduces the signature of the RFC 9591 test vector (Appendix E.4) byte for byte. This is not Bitcoin’s variant: BIP-340 computes Schnorr signatures on the secp256k1 curve, with 32-byte public keys and tagged hashes. WebCrypto has no Schnorr signatures on P-256; it has Ed25519, and RFC 8032 calls EdDSA a variant of Schnorr’s signature system.

Toy implementation — not for productionA curve with a 12-bit n, computed on BigInt and not in constant time — unsafe outside learning. Real Schnorr signatures: Ed25519 from WebCrypto, or a library implementing BIP-340 or RFC 9591.

The Schnorr protocol on a small group

Group
y² = x³ − 3x + 26 mod 4093, n = 4003, G = (0, 1656)

Computing the challenge…

Only the verifier who drew c itself after receiving R is convinced. To anyone else the transcript proves nothing — a cheater without the key can produce the same one.

2Break it

One r, two responses

The formula that proves the prover knows x also works against it. If r repeats in the responses to two different challenges, then s₁ − s₂ = (c₁ − c₂) · x, and anyone who saw both computes x = (s₁ − s₂) · (c₁ − c₂)⁻¹ mod n. In the interactive protocol the attacker can be the verifier itself: all it takes is a device with a broken generator answering it twice with the same R. In signatures the hash picks the challenge, but two different messages give two different values of c for the same R — two equations again. In ECDSA (the Digital signatures station) the attacker has to recover the nonce first; here x falls out of a single division. The victim in the toy has a key on the real P-256 curve, and its signatures are the Schnorr of RFC 9591.

Toy implementation — not for productionSchnorr on P-256 as in RFC 9591 (Appendix B), computed with toy arithmetic (BigInt, not constant-time). WebCrypto has no Schnorr signatures on P-256.

One r, two responses

You are on the attacker’s side. You see the victim’s public key X and two of its responses. Recover the private key x and sign your own message with it.

The victim’s device has a broken generator: it drew r once, at startup, and uses it in every session. You play the verifier and send two different challenges in two sessions.

KPrivate key x hidden

The victim generates a key and responds twice…

The fix depends on the setting. In a signature r can be derived from the key and the message (as Ed25519 does): the same message then gives the same signature, and a different one a different r. An interactive session has no message, and the other side picks the challenge, so r must be freshly drawn every time.

The fix depends on who picks the challenge. In a signature r can be derived from the key and the message. Ed25519 takes it from a SHA-512 hash of a key prefix and the message (RFC 8032, §5.1.6), so the same message gives the same signature, which reveals nothing new, and two different messages give two different r. BIP-340 also hashes the key and the message into r, but recommends mixing in fresh random bytes (a so-called synthetic nonce): the same message then gives a different, equally valid signature each time, and even with a poor generator r does not repeat for two different messages. In an interactive session this does not work: there is no message, and the other side picks the challenge, so r derived from the key alone would be constant — the broken generator of the toy. The same goes for signatures by several parties: BIP-340 warns that multisignature schemes with a deterministic nonce are insecure, and RFC 9591, §7.3 requires the randomness of FROST nonces to be sampled uniformly at random, because otherwise the other participants can make a nonce repeat and recover the whole key. The Threshold signatures station tells that story.

The second attack on the map will come from a quantum computer. The Schnorr protocol and signatures rest on the discrete logarithm, and Shor’s algorithm solves it in polynomial time: whoever has a large enough quantum computer and the public key X will recover x without any mistake by the victim (the Elliptic curves station shows resource estimates). The successors are post-quantum signatures, such as ML-DSA from FIPS 204 — the ML-DSA station covers them.

3In the real world

Where Schnorr signs

  • Bitcoin (BIP-340)Schnorr signatures on the secp256k1 curve, deployed in Bitcoin: the public key is 32 B, the signature 64 B, and the challenge is a hash tagged “BIP0340/challenge” of R, the key and the message. The nonce is a hash of the key, the message and auxiliary random bytes.Source (Bitcoin (BIP-340))
  • Ed25519 (RFC 8032)The RFC calls EdDSA a variant of Schnorr’s signature system on Edwards curves. The nonce is not drawn but derived with SHA-512 from a key prefix and the message — the same message gives the same signature, a different one gets a different nonce.Source (Ed25519 (RFC 8032))
  • Ed25519 with a foreign public key45 libraries let the caller pass the private and the public key to signing separately. The same message with a different public key gives a signature with the same R and a different S — two responses to one commitment, from which the private key can be computed.Source (Ed25519 with a foreign public key)
  • FROST (RFC 9591)A threshold Schnorr signature from June 2024: several participants holding key shares produce, in two rounds, one signature that verifies like an ordinary Schnorr signature. Every nonce must be random and used once — otherwise the other participants can recover the key.Source (FROST (RFC 9591))
4Take it to your project

One commitment, one response

Good practice

Do not implement Schnorr yourself. For signatures use Ed25519 from WebCrypto (the Digital signatures station) or a BIP-340 or FROST library that passes the standard’s test vectors, and sign with a key pair the library holds. If you write an interactive proof, draw r from a cryptographic generator in every session, answer each commitment only once and delete r right away. In the non-interactive version compute the challenge from a hash of the commitment, the public key, the message and a context.

JavaScript
// interactive proof: a fresh r in every session, one response
function commit(session) {
  session.r = randomScalar(n); // crypto.getRandomValues, no modulo bias
  return mul(G, session.r);    // R
}
function respond(session, c) {
  if (session.r === null) throw new Error('this commitment has been answered');
  const s = mod(session.r + c * x, n);
  session.r = null;            // r goes away with the response
  return s;
}
Anti-pattern

Do not derive r from the key alone or from a counter, and do not answer the same commitment twice — for example when the verifier retries after a network error. Do not let a signing function take the public key separately from the private one. Do not compute a Fiat–Shamir challenge without R, the key and a context (the Ali Baba’s cave station), and do not use a deterministic nonce when several parties sign.

JavaScript
// ✕ r from the key alone: the same R in every session
const r = hashToScalar(x);
// ✕ a retry with a new challenge for the old R gives x away
const s2 = mod(session.r + c2 * x, n);
// ✕ public key from the request: same R, another challenge
const sig = sign(privateKey, request.publicKey, message);