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

You trusted a peer's public key without checking it

The peer's public key goes straight into key establishment with no check that it's well formed or on the right curve. Feed it a crafted point and you steer the shared secret.

caller supplies apublic keyno format orcurve validationkey enters keyestablishmentattacker controlsor predicts…ATTACKER INPUTIMPACToutput is predictable
Attack path · caller supplies a public key → no format or curve validation → key enters key establishment → attacker controls or predicts the shared secret

The peer's public key goes straight into key establishment with no check that it's well formed or on the right curve. Feed it a crafted point and you steer the shared secret.

What goes wrong

Key agreement assumes both public keys are valid points on the expected curve. This code takes the peer's key from the caller and passes it into establishment without confirming any of that. No format check. No test that the point is even on the curve, let alone in the right subgroup. Whether the exchange is safe now depends on whether some library deeper down happens to validate.

That is a bad bet. A crafted key can sit off the curve or in a small subgroup, which lets an attacker force the shared secret into a tiny, guessable set, or recover your private key over several exchanges. A malformed key can also just crash the routine. You cannot tell which from this code, and cryptographic validation is not a thing you want left implicit.

The pattern

Vulnerable
function startExchange(peerKeyBytes):
    // peer key comes straight from the caller
    peerKey = parse(peerKeyBytes)
    // not checked: encoding, on-curve, subgroup
    secret = agree(myPrivateKey, peerKey)
    return secret
Hardened
function startExchange(peerKeyBytes):
    peerKey = parse(peerKeyBytes)
    if (!peerKey.isWellFormed()):
        throw InvalidKey()
    if (!peerKey.isOnCurve() || !peerKey.inMainSubgroup()):
        throw InvalidKey()
    secret = agree(myPrivateKey, peerKey)
    if (secret.isAllZero()):
        throw InvalidKey()
    return secret
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 security of a key exchange rests on rejecting bad peer keys, and it is the step most likely to get skipped because the happy path works without it. If the shared secret becomes predictable, every key you derive from it is predictable, which unwinds the confidentiality you thought you had. Validate peer keys where you receive them, and do not assume a library three layers down is doing it.

Check your own code