Elliptic Curves, ECDSA and the Nonce-Reuse Failure
In December 2010 a group called fail0verflow showed at the Chaos Communication Congress that Sony had signed every PlayStation 3 software update with the same ECDSA "random" number. From two signatures they computed Sony's private signing key with high-school algebra, and anyone could then sign code the console would trust. Elliptic-curve signatures are short, fast and strong, but ECDSA has this one sharp edge, and it has cut Bitcoin wallets, Android apps and hardware tokens too.
Elliptic curves in one page
An elliptic curve over a prime field is the set of points with
plus a "point at infinity". Points can be added with a geometric rule (draw the line through two points, take the third intersection, reflect), and adding a point to itself times gives the scalar multiple . Computing from is fast (double-and-add, about 256 steps for a 256-bit ). Recovering from and , the elliptic-curve discrete logarithm problem, has no known algorithm much faster than about steps for a group of order . That is why a 256-bit curve gives about 128-bit security while RSA needs 3,072 bits for the same. The algebra is developed in Elliptic Curves and Scalar Multiplication.
A key pair is a random scalar (private) and the point (public). Common curves: P-256 (secp256r1, NIST, the usual curve for ECDSA TLS certificates and WebAuthn), P-384, secp256k1 (Bitcoin, Ethereum), and Curve25519/edwards25519 (X25519 and Ed25519, the next lessons).
ECDSA
To sign a message hash with private key on a curve with base point of order :
The signature is . Verification uses only the public key : compute , and check that .
Signing with the library
The private scalar below is fixed so the public key is the same on every run; real keys come from ec.generate_private_key(ec.SECP256R1()). The signatures themselves use a fresh each time, so the example prints verification results instead of signature bytes.
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.asymmetric.utils import decode_dss_signature
from cryptography.hazmat.primitives import hashes
from cryptography.exceptions import InvalidSignature
priv = ec.derive_private_key(0x1D2C3B4A_5968_7766_5544_3322_1100_FFEE, ec.SECP256R1()) # fixed toy scalar
pub = priv.public_key()
nums = pub.public_numbers()
print("curve:", pub.curve.name, " public point x:", hex(nums.x)[:18] + "...")
msg = b"transfer 10 tokens to 10.10.0.20"
sig1 = priv.sign(msg, ec.ECDSA(hashes.SHA256()))
sig2 = priv.sign(msg, ec.ECDSA(hashes.SHA256()))
r1, _ = decode_dss_signature(sig1); r2, _ = decode_dss_signature(sig2)
print("two signatures of the same message differ (fresh k each time):", r1 != r2)
pub.verify(sig1, msg, ec.ECDSA(hashes.SHA256())); print("verify: OK")
try:
pub.verify(sig1, msg + b"0", ec.ECDSA(hashes.SHA256()))
except InvalidSignature:
print("verify altered message: InvalidSignature")
# The nonce-reuse algebra on P-256's group order n, with toy numbers chosen by this example:
n = 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551
x, k, r = 123456789, 987654321, 55555 # toy private key, reused nonce, the shared r
z1, z2 = 1111, 2222 # two message hashes
s1 = pow(k, -1, n) * (z1 + r * x) % n
s2 = pow(k, -1, n) * (z2 + r * x) % n
k_rec = (z1 - z2) * pow(s1 - s2, -1, n) % n
x_rec = (s1 * k_rec - z1) * pow(r, -1, n) % n
print("recovered k:", k_rec == k, " recovered private key:", x_rec == x)curve: secp256r1 public point x: 0xf5256fa64b8b1f34...
two signatures of the same message differ (fresh k each time): True
verify: OK
verify altered message: InvalidSignature
recovered k: True recovered private key: True
The nonce-reuse failure
If the same signs two different hashes and , both signatures have the same (it depends only on ), and an observer sees it immediately. Subtracting the two signing equations eliminates the private key:
The last part of the example does exactly this arithmetic on numbers it chose (it is the computation, not an attack on anyone's key) and recovers both and the private key. That is the PS3 break: Sony's code used a constant . The same algebra emptied Bitcoin wallets in 2013 when Android's SecureRandom produced repeated values, and partial leaks are enough too: if a few bits of each are biased or leak through timing, lattice methods (the "hidden number problem") recover the key from hundreds to tens of thousands of signatures, as in the 2019 TPM-Fail and Minerva attacks on TPMs, smart cards and crypto libraries; the 2024 EUCLEAK side channel on Infineon-based security keys leaked the nonce through electromagnetic measurements during signing.
This lesson keeps the attack conceptual: the algebra above, on numbers the example made up. The defence matters more than the attack.
How ECDSA weaknesses are detected
- Repeated values: any two signatures under one key with equal mean a reused nonce; scanning your own signature logs, transaction histories or firmware-signing records for duplicates is cheap. Researchers find vulnerable keys on public blockchains this way.
- Code review: custom ECDSA implementations, drawn from a non-cryptographic generator, from a timestamp or a counter, or from a hash of the message alone (without the private key).
- Side channels: non-constant-time scalar multiplication in firmware; vendor advisories for TPMs, HSMs and security keys.
- Curve and parameter checks: unusual curves, missing validation that received points are on the curve (invalid-curve attacks on ECDH).
How it is fixed
- Deterministic nonces (RFC 6979): derive from the private key and the message hash with HMAC-DRBG, so it is unique per message without any randomness at signing time. Many libraries do this, and FIPS 186-5 (2023) approves deterministic ECDSA. Some add extra randomness on top ("hedged" signatures) as a defence against fault attacks.
- Prefer Ed25519, whose design makes the nonce deterministic by construction (Ed25519 Signatures).
- Use maintained, constant-time libraries and certified hardware; rotate keys from affected devices after advisories.
- If a reuse is found: treat the key as compromised, revoke it, re-sign with a new key.
Pitfalls
- "Our random generator is fine" without checking it on the actual hardware at first boot.
- Signing a message hash that is longer than the curve order without the standard truncation, or a hash the attacker controls without the message.
- Accepting both and as distinct signatures in systems that use signature bytes as identifiers (ECDSA signature malleability; Bitcoin made the high- form non-standard for this reason).
Practice
1. A log of firmware signatures shows two entries with identical $r$ but different $s$. What do you conclude and do?
The same nonce signed two different images, so the private signing key can be computed from public data. Revoke the key, ship a new verification key through a trusted channel, re-sign, and fix the nonce generation (RFC 6979 or Ed25519).
2. Why does RFC 6979 include the private key in the nonce derivation and not only the message?
If depended only on the message, anyone could compute it from public data and then solve for from a single signature. Mixing in the private key keeps secret and unique per message.
3. Why is a 256-bit elliptic-curve key about as strong as a 3,072-bit RSA key?
The best attacks on the elliptic-curve discrete logarithm take about steps for a 256-bit group, while factoring has sub-exponential algorithms, so RSA needs a much larger modulus for 128-bit security.
Test yourself
What happens if ECDSA signs two different messages with the same nonce ?
- Nothing, is public anyway
- The private key can be computed from the two signatures
- Only the messages leak
- The signatures become invalid
How can a defender detect nonce reuse in their own ECDSA signatures?
- Look for equal values
- Look for equal values under the same key
- Count signatures
- Check the curve name
What does RFC 6979 specify?
- A new curve
- Deterministic generation of ECDSA nonces from the key and message hash
- Certificate formats
- A padding scheme for RSA
Which famous break used a constant ECDSA nonce?
- SHAttered
- The PlayStation 3 code-signing key (2010)
- Heartbleed
- Sweet32