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
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))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 outsideGrounding 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.
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
- Search for key-generation calls that take a randomness argument and audit every call site.
- Prefer APIs that expose no entropy override for long-lived keys.
- Flag any deterministic or fixed-seed RNG that can reach production key generation.