Skip to content

pqc tests: sign with raw sk in CompositeSignaturesTest and compare full secret in MLKEMTest - #2578

Open
suimins wants to merge 1 commit into
bcgit:mainfrom
suimins:fix-pqc-test-assertions
Open

suimins wants to merge 1 commit into
bcgit:mainfrom
suimins:fix-pqc-test-assertions

Conversation

@suimins

@suimins suimins commented Nov 26, 2026

Copy link
Copy Markdown

This pull request fixes two test-assertion gaps in the PQC test suite:

  1. CompositeSignaturesTest (prov): In compositeSignaturesTest(), privKey is constructed from the raw sk bytes, checked for re-encoding, and then overwritten with the key decoded from sk_pkcs8 before signing. As a result, the key built from the raw sk encoding is never used to sign. Because all 18 composite test vectors carry the same private key in both sk and sk_pkcs8, this signs and verifies with both keys (privKey and pkcs8Key) for composite vectors while keeping the single-key path for standalone ML-DSA and leaving the re-encoding check unchanged.
  2. MLKEMTest (core): In testEncapDecap_encapsulation() and testEncapDecapCombinedVectorSet(), the two encapsulation checks compare the expected shared secret k against the generated secret only over secret.length (Arrays.areEqual(k, 0, secret.length, secret, 0, secret.length)), so an empty or truncated secret with a matching prefix would still pass. This replaces both with full-array Arrays.areEqual(k, secret), matching the decapsulation checks in the same class.

Testing

Compiled :core:compileTestJava and :prov:compileTestJava on main at 6560e91d with JDK 25 (./gradlew) and ran both test classes against bc-test-data:

  • org.bouncycastle.pqc.crypto.test.MLKEMTest: 17/17 tests passed (0.308s)
  • org.bouncycastle.jcajce.provider.test.CompositeSignaturesTest: 28/28 tests passed (14.402s)

Disclosure

AI tools were used to assist in auditing the test suite and drafting this pull request; all changes were reviewed, compiled, and verified locally.

…ll secret in MLKEMTest

In CompositeSignaturesTest.compositeSignaturesTest(), privKey built from
the raw sk bytes was overwritten by the key decoded from sk_pkcs8 before
signing, leaving the raw-sk signing path untested. Sign and verify with
both keys for composite vectors while keeping the single-key path for
standalone ML-DSA.

In MLKEMTest.testEncapDecap_encapsulation() and
testEncapDecapCombinedVectorSet(), replace the prefix-only comparison
over secret.length with full-array Arrays.areEqual(k, secret), matching
the decapsulation checks.
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