Directional keys only stay separate if their derivation inputs differ. Two caller-supplied context values could be equal, collapsing send and receive to one key under one nonce.
What goes wrong
A two-way encrypted channel derives one key per direction so that a message sent one way can't be replayed back, and so the two streams stay independent. That separation rests entirely on the two derivation contexts being different from each other. Here both contexts come from the caller, and nothing requires them to differ or ties them to an authenticated identity.
Set them equal and both directions derive the same key. The same call also feeds one nonce to both cipher instances. Same key plus same nonce under AES-GCM is the textbook failure. The keystream repeats, so XOR two ciphertexts and the plaintext falls out. On top of that, the reuse leaks enough to forge a valid tag. A property that important should never depend on the caller happening to pass distinct values.
The pattern
Package build(byte[] secret, byte[] sInfo,
byte[] rInfo, byte[] nonce) {
var sendKey = hkdf(secret, sInfo);
var recvKey = hkdf(secret, rInfo); // sInfo == rInfo -> equal keys
var a = new Cipher(sendKey, nonce);
var b = new Cipher(recvKey, nonce); // same nonce both ways
return new Package(a, b);
}Package build(byte[] secret, Identity from,
Identity to, byte[] nonce) {
require(!from.equals(to));
var sendKey = hkdf(secret, label("s2r", from, to));
var recvKey = hkdf(secret, label("r2s", from, to));
return new Package(new Cipher(sendKey, nonce),
new Cipher(recvKey, freshNonce()));
}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.
Why it matters to you
This is a full break of confidentiality and integrity on the channel, and it's reachable with inputs the caller already holds. No key theft, no side channel. If two peers can be steered into the same context, or an attacker controls one side, the encryption becomes decoration.
Any time a security property depends on two inputs being different, the code has to enforce that, not assume it. Bind the context to identities you authenticated and reject the collision case outright.
Check your own code
- Where directional keys are derived, assert the two contexts are distinct before deriving.
- Bind derivation context to authenticated identities, not to caller-passed strings.
- Never share one nonce across two cipher instances, even for a single call.