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
function startExchange(peerKeyBytes):
// peer key comes straight from the caller
peerKey = parse(peerKeyBytes)
// not checked: encoding, on-curve, subgroup
secret = agree(myPrivateKey, peerKey)
return secretfunction 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 secretGrounding 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 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
- Find every place a peer or caller public key enters key agreement.
- Confirm you validate encoding, on-curve status, and subgroup membership before use.
- Reject all-zero or otherwise degenerate shared secrets.
- Pin down which layer owns key validation instead of assuming the library does.