Digital signatures
A signature anyone can check
A digital signature is computed from a message by the owner of the private key d, and anyone who has the public key Q can check it: the signature fits only this message and only this key. That is the difference from a MAC, where the same key computes and checks the tag — whoever can check a tag can also issue one. A signature can be checked without being able to produce it. A signature does not encrypt: the message stays in the clear.
ECDSA (FIPS 186-5, Section 6) works on an elliptic curve from the Elliptic curves station: the public key is Q = d · G. What gets signed is the message hash z (see the Hash functions station). For every signature a one-time k is drawn, and the signer computes R = k · G, r = x(R) mod n and s = k⁻¹ · (z + r · d) mod n. The verifier computes u₁ = z · s⁻¹ and u₂ = r · s⁻¹, then R′ = u₁ · G + u₂ · Q. Since Q = d · G, R′ = s⁻¹ · (z + r · d) · G = k · G = R, so x(R′) mod n must give r. The toy computes this on the curve from the “Break it” mode of the Elliptic curves station, with a 12-bit n = 4003, so that every number fits on screen; as in the standard, z is as many leading bits of SHA-256 as n has.
Toy implementation — do not use in productionECDSA on a curve with a 12-bit n, computed on BigInt and not in constant time — unsafe outside learning. The real thing: ECDSA P-256 or Ed25519 from WebCrypto.
ECDSA on a small curve
- Curve
- y² = x³ − 3x + 26 mod 4093, n = 4003, G = (0, 1656)
-998 B too long — the limit is 1 KB.
-998 B too long — the limit is 1 KB.
Computing SHA-256…
Draw k again and you get another signature of the same message — also valid. ECDSA is randomized; why k must never repeat is section 2.
Signature versus MAC
A MAC tag is checked with the same key that computes it, so every verifier can also issue tags. Here the verifier has only Q: to sign a changed message it would need d, and computing d from Q is the discrete logarithm.
Real signatures are computed by WebCrypto: ECDSA on P-256 and Ed25519 — EdDSA on the curve edwards25519 (RFC 8032), which FIPS 186-5 approves as well. A P-256 public key has 65 B, an Ed25519 one 32 B, and the signature is 64 B in both cases. ECDSA draws k for every signature, while Ed25519 derives the nonce from the key and the message, so the same message always gives the same signature. A browser without Ed25519 in WebCrypto shows only ECDSA in the frame below.
Real signatures in your browser
WebCrypto will generate ECDSA P-256 and Ed25519 keys on your device, time key generation, signing and verification (mean of 50 runs), and sign the same message twice with each key.
Nothing measured yet.
ECDSA takes a new k for every signature, so its security depends on the random number generator at the moment of signing. Ed25519 computes the nonce as SHA-512 of part of the private key and the message (RFC 8032 §5.1.6): the same message gives the same signature, and different messages get different nonces.
One nonce too many
The nonce k must be secret and different in every signature. Two signatures with the same k have the same r = x(k · G) mod n — the repeat is visible at once. The two equations s = k⁻¹ · (z + r · d) give s₁ − s₂ = k⁻¹ · (z₁ − z₂), so the attacker computes k = (z₁ − z₂) · (s₁ − s₂)⁻¹ mod n and then the private key d = (s₁ · k − z₁) · r⁻¹ mod n. That is how the key Sony signed PS3 software with fell in 2010 (section 3). In the toy below the victim’s key is a real P-256 key from WebCrypto, and the faulty signer is toy ECDSA with a broken generator. The same toy ECDSA with the nonces of RFC 6979 produces that standard’s signatures to the bit, so the victim’s signatures are genuine: WebCrypto accepts them, and later accepts the signature you make with the recovered key too.
Toy implementation — do not use in productionThe faulty signer is toy ECDSA on P-256 (BigInt, not constant-time) with a broken nonce generator. The victim’s key, the verification and the forged signature come from WebCrypto.
A faulty signer and a repeated nonce
The signer’s nonce generator is broken: it drew k once, at start-up, and hands it to every signature — like getRandomNumber() in the PS3.
The victim generates a key and signs two messages…
The fix is a nonce that cannot repeat across different messages: RFC 6979 or Ed25519. The attack actually needs less than a repeat — a few known bits of many nonces are enough (described below the frame).
The fix is a nonce that does not depend on the random number generator at the moment of signing. RFC 6979 derives k from the private key and the message hash (HMAC-DRBG), and FIPS 186-5 approves this variant as deterministic ECDSA, useful for devices without a good source of randomness. Ed25519 has done this from the start. The switch in the toy turns RFC 6979 on: every message gets a different k, and the same formulas give a number that is not the key. FIPS 186-5 adds, however, that deterministic implementations need particular protection against side-channel and fault attacks, especially in hardware.
A repeat is not even needed. It is enough for the nonce to be slightly predictable: a few known bits of the nonce from many signatures add up to a lattice problem that yields d. In the Minerva attack the signing time revealed the bit length of the nonce in five libraries (among them libgcrypt, wolfSSL and SunEC from OpenJDK) and in a card with an Atmel AT90SC chip; a 256-bit key from a library fell after about 1,200 signatures (Jancar et al., TCHES 2020). The same kind of leak was found in Intel’s firmware TPM and in a TPM chip by STMicroelectronics (TPM-Fail). The toy does not compute these attacks — they show why a signature must be computed in constant time.
The second attack on the map would come from a quantum computer. ECDSA and Ed25519 rest on the discrete logarithm on a curve, RSA on factoring, and Shor’s algorithm solves both problems in polynomial time (resource estimates are in the Elliptic curves and RSA stations). Whoever has such a computer and a public key will recover d and sign whatever they like. That is why NIST published FIPS 204 in August 2024 — the lattice-based ML-DSA signatures; the ML-DSA station covers them.
Where ECDSA and Ed25519 sign
- PS3 (2010)At 27C3 in December 2010, fail0verflow showed that Sony signed PS3 programs with ECDSA using the same nonce in different signatures. From a pair of such signatures the team computed the nonce and the private key — and with it could sign any program.Source (PS3 (2010))
- Bitcoin wallets on Android (2013)Android’s implementation of SecureRandom had severe flaws: repeated r values were observed in transaction signatures, which let the private key be computed and the funds stolen. Bitcoin Wallet bypassed the system SecureRandom, read /dev/urandom instead and moved the funds to a new key.Source (Bitcoin wallets on Android (2013))
- TPM-Fail (2019)Intel’s firmware TPM and a TPM chip by STMicroelectronics signed in secret-dependent time. A local attacker recovered the ECDSA key from Intel fTPM in 4–20 minutes, and a remote one — the authentication key of a VPN server — in about 5 hours.Source (TPM-Fail (2019))
- TLS 1.3The server signs the handshake transcript with its certificate key. RFC 9846 requires every implementation to support ecdsa_secp256r1_sha256 signatures — ECDSA on P-256 with SHA-256 — next to two RSA schemes; an ed25519 scheme is defined as well.Source (TLS 1.3)
- Passkeys (WebAuthn)The authenticator signs its own data together with the hash of the client data, which contains the server’s challenge; the server knows only the public key. Per WebAuthn Level 3, sites that want to support a wide range of authenticators should accept at least EdDSA (−8), ES256 (−7, ECDSA on P-256) and RS256 (−257).Source (Passkeys (WebAuthn))
- Signed commits in GitCommits and tags can be signed with a GPG key, an SSH key or an S/MIME certificate, and GitHub marks them as verified. GitHub calls SSH signatures (e.g. with Ed25519 keys) the simplest; verifying them needs Git 2.34 or later.Source (Signed commits in Git)
Platform signatures, never your own nonce
Sign with the platform’s functions: Ed25519 or ECDSA P-256 from WebCrypto, ECDsa in .NET. Let the library
generate the private key as non-extractable (see the WebCrypto station). Leave the nonce
to the implementation — these APIs do not even expose it. Before signing, prepend a fixed context to the data
(domain separation), so that a signature from one place cannot be used in another.
// an Ed25519 key; the private key cannot be exported
const { privateKey, publicKey } = await crypto.subtle.generateKey(
{ name: 'Ed25519' }, false, ['sign', 'verify']);
// domain separation: a fixed prefix says what this signature is for
const data = new TextEncoder().encode('trapdoorlab/transfer/v1\n' + json);
const sig = await crypto.subtle.sign({ name: 'Ed25519' }, privateKey, data);
const ok = await crypto.subtle.verify({ name: 'Ed25519' }, publicKey, sig, data);using var key = ECDsa.Create(ECCurve.NamedCurves.nistP256);
// the platform picks k; the signature is r ‖ s, 64 B
byte[] sig = key.SignData(data, HashAlgorithmName.SHA256);
bool ok = key.VerifyData(data, sig, HashAlgorithmName.SHA256);Do not pick k yourself or compute ECDSA with your own code, as this toy does: a repeated, predictable or even
partly known nonce gives the key away, and the timing of BigInt arithmetic leaks its bits. Do not sign raw data
without context with the same key in two protocols — a signature from one can then be moved to the other. Do not
confuse signing with encryption: a signature hides nothing, and “encrypting with the private key” is a shorthand
from textbook RSA that does not fit ECDSA or Ed25519 — confidentiality comes from encryption, e.g. AES-GCM.
// ✕ your own nonce: Math.random() is not a CSPRNG, and a repeated k gives d away
const k = BigInt(Math.floor(Math.random() * 2 ** 53));
const s = mod(inverse(k, n) * (z + r * d), n);
// ✕ a signature without context: the same bytes mean something else in another protocol
const sig = await crypto.subtle.sign(alg, key, enc.encode(json));