Digital Signatures: RSA, ECDSA & Ed25519
Compare RSA, ECDSA P-256, and Ed25519 across signature size, verification speed, nonce-leak risks, and production signing for JWTs, webhooks, and builds.
In this lesson (3 bite-sized sections)
Signatures prove origin without sharing a secret
HMAC authenticates messages between parties that share a secret key, which breaks down the moment you have untrusted verifiers. If 100 microservices verify JWTs signed with a shared HMAC secret, any single compromised service can forge admin tokens for the entire company. Asymmetric digital signatures separate the two powers: one isolated issuer holds the private signing key, while every verifier caches only the public key. That single split powers TLS certificates, JWTs, webhook verification, and software supply-chain signing.
Three signature families matter in real architectures: RSA-PSS (legacy interoperability and fast verification, huge keys and slow signing), ECDSA P-256 (ubiquitous in FIPS environments, WebAuthn, and TLS, compact 64-byte signatures, fragile nonce handling), and Ed25519 (modern default with 32-byte keys, 64-byte signatures, deterministic signing, and strong side-channel resistance). When forced to support RSA for older enterprise clients, require RSA-PSS with at least 2048-bit (ideally 3072-bit) keys and never ship raw PKCS#1 v1.5 signing where parsing quirks invite forgery. On high-volume edge proxies or blockchain verifiers, Ed25519 also supports batch verification, checking dozens of signatures in one multi-scalar multiplication far faster than individual calls.
| Scheme | Public key | Signature | Relative speed | Key operational risk |
|---|---|---|---|---|
| RSA-2048 (PSS) | 256 bytes | 256 bytes | Slow sign (~1 ms), fast verify (~0.05 ms) | Legacy PKCS#1 v1.5 padding oracle traps; large keys |
| ECDSA P-256 | 33-65 bytes | 64 bytes | Fast sign (~0.05 ms), moderate verify (~0.15 ms) | Catastrophic key leak if signing nonce k repeats or biases |
| Ed25519 | 32 bytes | 64 bytes | Very fast sign & verify (~0.04-0.1 ms), batchable | Not in older FIPS-only HSMs; watch strict-verify variants |
Why ECDSA nonce reuse is an instant private-key leak
Every ECDSA signature picks a secret per-message integer k. If a broken RNG reuses the same k across two different messages m1 and m2 (famously Sony's PlayStation 3 firmware signer, which hardcoded a constant k), an attacker needs zero brute force to recover the long-term private key d using grade-school algebra. Even a tiny few-bit bias in k across a few hundred signatures enables lattice attacks that extract d.
Production signing patterns: JWTs, webhooks, and artifacts
In distributed systems, signatures fail far more often in the verification wrapper than in the curve math. Three rules prevent real incidents. First, pin allowed algorithms on the verifier side: JWT libraries historically suffered algorithm-confusion attacks where an attacker switched alg: RS256 to alg: HS256 and signed a forged token using the server's public RSA key as an HMAC secret. Second, sign canonical structured payloads with domain separation (like a timestamp plus raw request body for webhooks, or an explicit prefix like myapp-v1-webhook:) so a signature issued for one API cannot be replayed in another context. Third, distribute public keys via versioned kid headers (for example a cached JWKS endpoint) so issuers can rotate keys smoothly without invalidating active tokens or artifacts.
Assign each production signing scenario to the best-fitting signature primitive.
Sort 4 more items to check
Recap: use asymmetric signatures whenever verifiers should not be able to forge, default to Ed25519 (or RFC 6979 ECDSA P-256 for FIPS/hardware enclaves), pin verifier algorithm allowlists to kill alg confusion, and include key IDs plus domain separation on every signed envelope.
Sources: RFC 8032, EdDSA and Ed25519 · RFC 6979, Deterministic ECDSA · FIPS 186-5, Digital Signature Standard
Apply
Your turn
The task this lesson builds to.
Specify the signing architecture for an API platform that issues short-lived session JWTs verified by 120 microservices, signs release binaries for external customers, and sends outbound webhooks to customer endpoints.
Think about
- Which of the three channels needs asymmetric signatures versus bilateral HMAC?
- How do you choose between Ed25519 and ECDSA P-256 for FIPS vs non-FIPS environments?
- What verifier checks stop JWT alg-confusion and cross-channel signature replay?
Draft your design answer here Save your draft, compare against the model answer, and track progress.
Practice
Make it stick
A second problem on the same idea, so it survives past today.
Diagnose a security report showing two ECDSA P-256 firmware signatures issued by your IoT signing service share the exact same r coordinate. Explain what has been compromised, how to verify the blast radius, and how to recover safely across 500,000 deployed devices.
Think about
- What can an attacker compute offline from two signatures sharing
r? - Why is patching the RNG alone insufficient without revoking the signing key?
- How do you rotate firmware trust anchors on 500,000 fielded IoT devices without bricking them?
Draft your design answer here Save your draft, compare against the model answer, and track progress.