Blog / A02:2021 Cryptographic Failures
A02:2021 · Cryptographic Failures

A key generator that borrows its entropy is not yours to trust

When the code that makes a private key takes its randomness from the caller, the key's secrecy moves out of your hands. An incorrectly seeded caller is enough to make it recoverable.

object receives arandomness sourceuses it directlyfor…a poorly seededsource yields…the private keybecomes guessabledownstreamsecrets…ATTACKER INPUTIMPACToutput is predictable
Attack path · object receives a randomness source → uses it directly for key generation → a poorly seeded source yields low entropy → the private key becomes guessable → downstream secrets compromised

When the code that makes a private key takes its randomness from the caller, the key's secrecy moves out of your hands. An incorrectly seeded caller is enough to make it recoverable.

What goes wrong

A constructor takes a randomness source and uses it, unmodified, to produce the private half of a key pair. The intent is flexibility. The effect is that key strength now depends on a decision made somewhere else, by code that may not realize it is making a security decision.

You do not need a malicious caller for this to bite. An honest one that initializes the generator badly, reuses an instance that has already been drained, or wires in a deterministic implementation for some unrelated reason produces the same result: a private key an attacker can reproduce. Once the key is guessable, so is everything derived from it.

The safe default is boring. Generate entropy at the point of use, from the platform's cryptographic source, and do not offer an override. Fewer knobs, fewer ways to get it silently wrong.

The pattern

Vulnerable
def build_identity(rng):
    # rng comes from the caller and is trusted as-is
    priv = generate_private_key(rng)
    pub = derive_public(priv)
    return Identity(priv, pub)

# somewhere far away, harmless-looking:
identity = build_identity(SeededRandom(seed=42))
Hardened
def build_identity():
    # entropy is created here, from the platform CSPRNG
    rng = system_secure_random()
    priv = generate_private_key(rng)
    pub = derive_public(priv)
    return Identity(priv, pub)

identity = build_identity()   # no way to weaken it from outside
How the pipeline adjudicated itHELD
ABCDEFGH

Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

Why it matters to you

The distance between the vulnerable line and the line that abuses it is the danger. The generator gets chosen in one file and the key gets made in another, so no single reviewer sees both. Close the door inside the primitive and the far-away mistake can no longer reach it.

Check your own code