Skip to content
Series 7 · The cryptography of signatures · 7.5

How a signature is made.

RSA PSS, ECDSA and EdDSA step by step: what is computed, what is verified and where the risk lies.

October 202611 min read

The previous articles introduced the parts: a hash function that condenses the document, and a hard mathematical problem, factoring or the discrete logarithm, that separates the private key from the public one. This article puts them together. It walks, equation by equation, through the three signature schemes that dominate practice (RSA PSS, ECDSA and EdDSA) and pauses where they tend to fail, which is almost never in the mathematics.

The common skeleton

  1. Hash. H(m) is computed over the exact bytes to be signed. From this point on, the document exists only through its hash.
  2. Transform with the private key. Each scheme turns the hash into a signature through an operation that only the holder of the private key can perform.
  3. Distribute. The document travels with the signature and, usually, with the certificate that binds the public key to an identity.
  4. Verify. The recipient recomputes the hash and checks, with the public key, that the signature matches that hash. A single differing bit in the document or in the signature makes the check fail.

In RSA, as shown in the article devoted to that algorithm, the transformation is direct: the hash, with PSS padding, is raised to the private exponent. Discrete logarithm signatures work differently, and they are worth examining in detail.

ECDSA, equation by equation

ECDSA has a long lineage. Taher ElGamal proposed the first signature based on the discrete logarithm in 1985. Claus Schnorr published a simpler and more elegant variant in 1989, but patented it. NIST, looking for an unencumbered scheme, adopted a variant of ElGamal in 1991, DSA, standardized in FIPS 186 in 1994. Scott Vanstone proposed carrying it over to elliptic curves in 1992, and ECDSA was standardized by the end of that decade. Today it is specified in FIPS 186 5 and SEC 1.

The parameters are a curve, a generator point G of prime order n, the private key d and the public key Q = d · G. Let z be the hash of the message, taken as a number and truncated to the size of n.

Sign
1. Choose k at random, 1 ≤ k < n    the nonce: secret and fresh for every signature
2. R = k · G,   r = xR mod n
3. s = k1 (z + r · d) mod n
4. The signature is the pair (r, s)
Verify
w = s1 mod n,   u1 = z · w,   u2 = r · w
X = u1 · G + u2 · Q,   accept if xX mod n = r

Why does it work? Because, if everything is legitimate, u1 · G + u2 · Q = w(z + r · d) · G, and w(z + r · d) = k by the way s was built. The verifier reconstructs the point R without knowing either k or d. With the 19 point toy curve from the previous article you can follow it by hand: with d = 7, k = 10 and z = 3, you get r = 7 and s = 9; the verifier computes u1 = 13, u2 = 5 and obtains 13 · G + 5 · Q = 48 · G = 10 · G, whose x coordinate is 7. It matches.

The next lab does the same with real numbers: it generates a key pair on P 256 in your browser, using the platform’s built in cryptography, and signs and verifies whatever text you type.

LabA real ECDSA signature, made in this browser
Document
Public key (x, y), 64 bytes…
Signed hash…
r…
s…
Generating keys…

The private key never leaves this browser and is never shown. Sign the same text twice: r and s change every time, because ECDSA uses a fresh random number for each signature, and both verify.

The nonce: a tiny piece carrying all the risk

In ECDSA, the number k is as secret as the private key. If it leaks, the equation for s has a single unknown, d, and it can be solved. But the most famous mistake is not leaking it; it is reusing it. If two different messages are signed with the same k, the two signatures share r, and a subtraction is all it takes:

s1 s2 = k1 (z1 z2)  ⇒  k = (z1 z2) / (s1 s2) mod n
d = (s1 · k z1) / r mod n
On the toy curve: with z1 = 3, z2 = 9 and the same k, the signatures are (7, 9) and (7, 2). Then k = (3 9) / (9 2) = 13 · 11 = 10 and d = (9 · 10 3) / 7 = 11 · 11 = 7, all modulo 19. The private key falls to two public signatures.

This is no academic curiosity. In 2010 it was shown that a widely sold video game console signed its software with a constant k, and its master key was exposed. In 2013, a flaw in the random number generator of a mobile platform caused cryptocurrency wallets to reuse nonces, and funds were stolen. The article in this series devoted to real world failures returns to both cases.

Reuse is not even necessary. If the nonces carry a small bias, for example if their leading bits tend to be zero because the implementation leaks their length through computation time, a few hundred or a few thousand signatures are enough to reconstruct the key using lattice techniques. That is why RFC 6979 exists: it defines how to derive k deterministically from the private key and the message, using HMAC. The signatures are still standard ECDSA, verifiable by anyone, but they no longer depend on a good random number generator at signing time.

Malleability

If (r, s) is a valid ECDSA signature, so is (r, n s). This does not allow signing new messages, but it does allow changing the representation of an existing signature without invalidating it. For most uses it is irrelevant; where the signature serves as an identifier, as in some blockchains, the form with s less than n/2 is required.

EdDSA: Schnorr, deterministic and complete

Schnorr’s patent expired in 2008, and in 2011 Daniel Bernstein and four coauthors published Ed25519, a Schnorr type signature on the Edwards curve equivalent to Curve25519. It was designed to eliminate ECDSA’s pitfalls at the root.

Keys: from a 32 byte secret seed, h = SHA512(seed); a = scalar derived from the first half of h; A = a · B
Sign: r = SHA512(second half of h ‖ M) mod L;   R = r · B
         S = (r + SHA512(R ‖ A ‖ M) · a) mod L;   signature = (R, S), 64 bytes
Verify: 8 · S · B = 8 · R + 8 · SHA512(R ‖ A ‖ M) · A
B is the base point and L its order, a prime of about 2252. The factor 8 is the curve’s cofactor.

One detail matters for large documents. Pure EdDSA hashes the full message twice, once for the nonce and once for the challenge, which means reading through it twice. For cases where that is a problem there is a prehashed variant, Ed25519ph, at the price of making security also depend on the collision resistance of that prehash function, something the pure version does not need.

ECDSA demands a perfect random number for every signature. EdDSA decided never to ask for one.

The three, side by side

RSA PSS 3072ECDSA P 256Ed25519
Security128 bits128 bitsabout 128 bits
Public key384 bytes64 bytes (33 compressed)32 bytes
Signature384 bytes64 bytes (about 72 in DER)64 bytes
Randomness when signingsalt; if it fails, security degrades without exposing the keycritical nonce, unless RFC 6979none
Signingslowfastvery fast
Verificationvery fastmoderatefast
StandardsRFC 8017, FIPS 186 5FIPS 186 5, SEC 1RFC 8032, FIPS 186 5

In legally binding document signing, all three coexist. RSA dominates through legacy and because secure signature creation devices have supported it for decades; ECDSA is growing with identity documents and new certificates; EdDSA, accepted by NIST since 2023, is the natural choice for systems designed from scratch. For the verifier, what matters is that the scheme and its parameters are identified unambiguously in the signature, so that the check can be reproduced twenty years from now.

Key takeaways

Every signature hashes the document and transforms the hash with the private key; verifying means recomputing the hash and checking its relationship to the public key. ECDSA signs with s = k1(z + r · d), and its weak point is the nonce k: reusing it, leaking it or biasing it hands over the key. EdDSA derives the nonce from the message and uses complete formulas, closing that door by design.

Sources

  1. NIST, FIPS 186 5, Digital Signature Standard, 2023
  2. IETF, RFC 8017, PKCS #1: RSA Cryptography Specifications Version 2.2, 2016
  3. Bellare and Rogaway, “The Exact Security of Digital Signatures: How to Sign with RSA and Rabin”, Eurocrypt 1996
  4. SECG, SEC 1: Elliptic Curve Cryptography, version 2.0, 2009
  5. IETF, RFC 6979, Deterministic Usage of DSA and ECDSA, 2013
  6. Bernstein, Duif, Lange, Schwabe and Yang, “High speed high security signatures”, CHES 2011
  7. IETF, RFC 8032, Edwards Curve Digital Signature Algorithm (EdDSA), 2017

← All notes

Trust Notes

Articles for those who decide how an organization signs: principles, practices and criteria that hold up as rules and technologies change.

A publication of Signing Flows, by Interfase.

Series