dsa: add Wycheproof verification test vectors#1369
Open
arpitjain099 wants to merge 2 commits into
Open
Conversation
Add a test suite that runs the C2SP Wycheproof DSA test vectors through the crate's verification path, covering the dsa_2048_224_sha224, dsa_2048_224_sha256, dsa_2048_256_sha256, and dsa_3072_256_sha256 groups (1432 vectors total). The vectors come from the existing thirdparty/wycheproof submodule. Each test loads the DER SubjectPublicKeyInfo into a VerifyingKey, parses the DER-encoded signature, and verifies it with the group's hash (SHA-224 or SHA-256) via DigestVerifier, asserting the observed result matches the expected one. Valid vectors that parse are sanity-checked through the prehash verifier as well. The only acceptable-class vectors carry the MissingZero flag (a non-canonical ASN.1 integer for r). The crate requires canonical DER integers and rejects them, which Wycheproof permits for acceptable cases, so they are handled explicitly rather than skipped. The raw P1363 (r || s) signature files are not loaded because the crate parses only DER signatures. Closes RustCrypto#816 Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
The new dsa wycheproof test reads vectors from the thirdparty/wycheproof submodule, but the dsa test job's checkout did not fetch submodules, so the files were missing and the test panicked on all platforms. Add submodules: recursive to the checkout (matching the ml-dsa workflow). With the submodule present the 4 DSA tests pass. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
Author
|
The all-platform failure was just CI not checking out the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #816
The
dsatest suite previously only covered a handful of RFC vectors. This adds adsa/tests/wycheproof.rssuite that runs the C2SP Wycheproof DSA test vectors through the crate's verification path, which gives much broader coverage of the malformed-input and edge-case space.What it does
The vectors come from the
thirdparty/wycheproofsubmodule that is already wired into this repo (the same source theml-dsaWycheproof tests use), so there is no new vendored data and no new runtime dependency. Rungit submodule update --initbefore running the suite.Four test groups are exercised, 1432 vectors in total:
dsa_2048_224_sha224_test.json(336 vectors)dsa_2048_224_sha256_test.json(364 vectors)dsa_2048_256_sha256_test.json(366 vectors)dsa_3072_256_sha256_test.json(366 vectors)For each group the test loads the DER
SubjectPublicKeyInfointo aVerifyingKey, parses the DER-encoded signature into aSignature, and verifies it with the group's hash (SHA-224 or SHA-256) throughDigestVerifier. The observed accept/reject result is asserted against the Wycheproof expected result. Valid vectors that parse are additionally cross-checked through thePrehashVerifierentrypoint so both verification APIs stay in agreement.Breakdown across the four files: 296
valid, 1132invalid, 4acceptable.Edge cases handled explicitly
acceptable/MissingZero: the onlyacceptable-class vectors in these files carry theMissingZeroflag, a legacy ASN.1 integer forrthat omits its leading0x00padding byte. The crate requires canonical DER integers (UintRef) and rejects these, which is conformant because Wycheproof allows an implementation to either accept or reject anacceptablevector. This is handled with a comment rather than skipped silently.SEQUENCE { r, s }is treated as a verification failure. That is the desired behaviour for theinvalidcases and would only be a regression for avalidcase (which the assertion catches).*_p1363_test.jsonfiles use the rawr || sIEEE P1363 signature encoding. Thedsacrate parses only DER signatures, so those files are intentionally not loaded; this is documented at the top of the test file.Testing
The full
cargo test -p dsasuite andcargo clippy -p dsa --tests --all-featuresare both green.Two small dev-dependencies were added to support the JSON loading (
serdeandserde_json, matching the versions already used by theml-dsaWycheproof tests), and theserdefeature was enabled on the existinghexdev-dependency.