Skip to content

ml-kem: check the shared secret and ek in the semi-expanded decapsulation test - #430

Open
suimins wants to merge 1 commit into
RustCrypto:masterfrom
suimins:fix-ml-kem-semi-expanded-decaps-check
Open

suimins wants to merge 1 commit into
RustCrypto:masterfrom
suimins:fix-ml-kem-semi-expanded-decaps-check

Conversation

@suimins

@suimins suimins commented Nov 26, 2026

Copy link
Copy Markdown

The semi-expanded decapsulation test (mlkem_decaps_test! in ml-kem/tests/wycheproof.rs) discards the decapsulated shared secret (let _ss = dk.decapsulate(&test_c);), so a decapsulation returning wrong bytes still passes. It also does not compare ek against dk.encapsulation_key().

The currently pinned thirdparty/wycheproof revision (ad6ac186a990) has no K or ek values in the semi-expanded decapsulation test files (mlkem_{512,768,1024}_semi_expanded_decaps_test.json), so this updates the thirdparty/wycheproof submodule to ee7b4f7e6119 ("Add ML-KEM re-encryption test vectors."), where all 9 valid rows across ML-KEM-512/768/1024 include expected K and all 27 rows include ek.

Changes

  • Update thirdparty/wycheproof submodule from ad6ac186a990 to ee7b4f7e6119.
  • Compare test.ek against dk.encapsulation_key().to_bytes() after importing dk in mlkem_decaps_test!.
  • Assert test.result == ExpectedResult::Valid when decapsulation succeeds and compare the returned shared secret ss against expected K.

Verification

Ran the ml-kem CI test matrix locally on master (b26db85a) with RUSTFLAGS="-Dwarnings" (rustc 1.93.0):

  • cargo test --no-default-features — all passed
  • cargo test — all passed
  • cargo test --all-features — all passed (36 unit tests, 3 accumulated, 1 debug, 1 ACVP encap-decap, 1 ACVP key-gen, 3 pkcs8, 12 wycheproof, 1 doctest)
  • cargo fmt --check and cargo clippy --all-targets --all-features -- -Dwarnings — clean

(Checked open/closed issues and PRs in RustCrypto/KEMs for duplicates; none found. Note: unpublished private advisories cannot be searched.)

…tion test

In mlkem_decaps_test!, the decapsulated shared secret was discarded
(let _ss = dk.decapsulate(&test_c);) and ek was not compared against
dk.encapsulation_key().

Update thirdparty/wycheproof from ad6ac186a990 to ee7b4f7e6119 (which
adds K and ek to the semi-expanded decapsulation vectors), compare ek
after importing dk, assert ExpectedResult::Valid on decapsulation, and
compare the returned shared secret with K.

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