A derivation routine returned more bytes than it generated. The extra ones were zero padding from an oversized buffer, and they went out as part of the key.
What goes wrong
This is one of the quieter crypto traps. You allocate the destination at the target size, copy in the bytes you have, and forget that what you have is shorter than the target. Whatever the allocation left behind fills the gap, and for a fresh byte array that is zeros. The result is a key whose front is real derived material and whose tail is constant.
Nothing errors. Nothing looks wrong at a glance. In a debugger the bytes are all there, and you only notice the trouble if you happen to see the run of zeros at the end. If the consumer uses the whole result as a key, part of that key is a value an attacker can write down for free.
The pattern
byte[] expand(byte[] ikm, int wantLen) {
byte[] material = hkdf(ikm); // yields only ikm.length bytes
byte[] key = new byte[wantLen]; // the rest of this stays zero
copy(material, 0, key, 0, material.length);
return key; // trailing zeros are now key bytes
}byte[] expand(byte[] ikm, int wantLen) {
requireInRange(wantLen);
// ask HKDF for the full length up front
byte[] key = hkdf(ikm, wantLen);
assert key.length == wantLen;
return key; // no padding, no trailing zeros
}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
The silence is the danger. A key that is part entropy and part zeros survives every functional test and every round-trip you run against it. Attackers who can read your derivation, from open source or a firmware dump, know exactly which bytes are constant and skip straight to the rest.
Ask the KDF for the real length and assert that what you got back matches. A key you never had to pad is a key with nothing predictable in it.
Check your own code
- Never resize KDF output to a target with a plain zero-padding copy.
- Assert that output length equals generated length before returning a key.
- Scan derived secrets in tests for trailing runs of zero bytes.