Skip to content

Fix kbkdf::DoublePipeline: include [L]2 in A(0) - #217

Open
Mrmaxmeier wants to merge 1 commit into
RustCrypto:masterfrom
Mrmaxmeier:kbkdf-double-pipeline-a0
Open

Mrmaxmeier wants to merge 1 commit into
RustCrypto:masterfrom
Mrmaxmeier:kbkdf-double-pipeline-a0

Conversation

@Mrmaxmeier

Copy link
Copy Markdown

Hi,

DoublePipeline currently computes A(0) without [L]2, so its output doesn't match NIST SP 800-108r1 in the default use_l(true) mode.

NIST SP 800-108r1 §4.3 defines »A(0) := Label || 0x00 || Context || [L]2.«. The crate currently builds A(0) without considering use_l:

KDFs/kbkdf/src/lib.rs

Lines 190 to 197 in 19a0df6

let mut a = {
let mut h = Prf::new_from_slice(params.kin).expect("should be the right size");
h.update(params.label);
if params.use_separator {
h.update(&[0]);
}
h.update(params.context);
h.finalize().into_bytes()

while K(i) does append [L]2:

KDFs/kbkdf/src/lib.rs

Lines 230 to 241 in 19a0df6

// Fixed input data
h.update(params.label);
if params.use_separator {
h.update(&[0]);
}
h.update(params.context);
if params.use_l {
h.update(
&(<KbkdfCore<K::KeySize, Prf::OutputSize> as KbkdfUser>::L::U32).to_be_bytes()
[..],
);
}

The CAVP tests don't catch this because they pass all fixed input data as the label with use_l(false).

Notably, this changes DoublePipeline output. I did not find users of DoublePipeline via GitHub's code search so the risk of badly breaking things is fairly low imo. With this fix, I've not seen any discrepancies while differentially testing this KBKDF implementation vs. NSS's.

Thanks!

NIST SP 800-108r1 §4.3 defines `A(0) := Label || 0x00 || Context || [L]2`,
but `A(0)` omitted `[L]2` while `K(i)` included it. This changed the
output of `DoublePipeline` with `use_l(true)`, which is the default.

The CAVP vectors pass all fixed input data as the label with
`use_l(false)`, so they did not catch this.

Assisted-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant