21 Commits

Author SHA1 Message Date
Lukas Zobernig 58ce150e60 ml-dsa: fix hardcoded MlDsa44 in Wycheproof verification tests (#1382)
The mldsa_verify_test macro previously hardcoded MlDsa44 for decoding both verifying keys and signatures. Due to public key length mismatches, this caused tests for ML-DSA-65 and ML-DSA-87 to fail type conversion and be silently skipped.

Using $params ensures test vectors for all parameter sets are properly decoded and verified.
2026-06-17 08:03:34 -06:00
Tony Arcieri 62fa7ac438 ml-dsa: implement KeyInit, KeyExport, KeySizeUser (#1342)
Implements these traits sourced from the `crypto-common` crate.

Also implements the `Generate` trait for key generation, replacing the
previous `KeyGen` trait, which this commit deprecates in favor of using
`KeyInit` and `Generate`.

This also adds a `getrandom` feature that forwards through to
`crypto-common`, making methods available on the `Generate` trait when
enabled.
2026-05-09 14:19:30 -06:00
Tony Arcieri f9f4c60d78 ml-dsa: rename ExpandedSigningKey field/method to expanded_key (#1340)
This is a vestige from when `SigningKey` was a keypair type.

Also marks it `#[doc(hidden)]` as it exists primarily for testing.
2026-05-08 09:34:29 -06:00
Tony Arcieri 0c7cf02d1b ml-dsa: apply and fix workspace-level lints (#1338)
Applies the workspace-level config added in #1323 to this crate and
fixes any failures.
2026-05-07 21:14:26 -06:00
Arthur Gautier c5989c900e ml-dsa: lower stack size of KeyGen::from_seed by up to 207kb (#1261)
This reworks the API to make KeyGen::from_seed return a
`SeededSigningKey` instead of a `KeyPair`.
The `SeededSigningKey` effectively replaces the `KeyPair`, and instead
of eagerly generating the VerifyingKey (implementing
`signature::KeypairRef`), it implements `signature::Keypair` and makes
the verifying key when requested.

This reduces the depth of the stack when calling from_seed and reduces
the size of the stack by 207kb using ML-DSA-87 in debug/tests builds
(the heaviest consumers).

This is an API break.
2026-03-25 13:32:06 -06:00
Tony Arcieri 2a49521211 ml-dsa: updates for module_lattice::{encoding, utils} (#1191)
These were renamed in RustCrypto/KEMs#221
2026-01-29 16:21:12 -07:00
Tony Arcieri 400961412b ml-dsa: fix Wycheproof verification test failures (#1187)
Corrects the check for monotonically increasing hint indexes reported as
GHSA-5x2r-hc65-25f9 and reproduced in #1176.

It seems the logic for checking the hint "cuts" (`y[omega + i]`) needs
to remain the same, however.

With this change, we pass the full set of Wycheproof verification test
vectors (i.e. it seems to have fixed the other failure we were
experiencing as well)
2026-01-27 14:18:00 -07:00
Tony Arcieri b316da4152 ml-dsa: adapt many_round_trip_test into a proptest (#1184)
Replaces ad hoc randomized testing with proptest, which can
automatically report seeds to reproduce failures experienced in CI, and
can automatically track and test previous regressions.
2026-01-26 10:42:56 -07:00
Tony Arcieri 39d03e27e5 ml-dsa: add Wycheproof verification tests (#1176)
Adds Wycheproof verification tests for ML-DSA-44/65/87.

On ML-DSA-44, this reproduced an issue previously reported as
GHSA-5x2r-hc65-25f9 by @orenyomtov:

> Test #18: signature with a repeated hint (Invalid)

Likewise, on ML-DSA-44 only we are also failing this case:

> Test #68: public key with t1 component set to zero (Valid)

I have added an exceptions for those two for now, and all the other
tests pass.

I opened #1183 as a tracking issue for these verification failures.
2026-01-26 09:38:27 -07:00
Tony Arcieri b2bffe5fc7 ml-dsa: initial Wycheproof test vectors (#1175)
Uses a similar strategy to `rsa`, cloning the Wycheproof test vectors as
a submodule and parsing the JSON files directly (I tried to use
`wycheproof2blb` and it seems really out of date).

Adds the following as an initial integration:
- `mldsa_44_sign_seed_test`
- `mldsa_65_sign_seed_test`
- `mldsa_87_sign_seed_test`
2026-01-25 16:41:24 -07:00
Tony Arcieri 3138dd20e3 ml-dsa: rename and deprecate ExpandedSigningKey (#1145)
Renames `EncodedSigningKey` to `ExpandedSigningKey` to contrast it with
seeds, the preferred API. Also renames the `decode` and `encode`
functions to `from_expanded` and `to_expanded`, similar to the changes
made to `ml-kem`'s `DecapsulationKey` in RustCrypto/KEMs#163,
which also deprecated these APIs.

We don't properly implement validation of such keys which can lead to
panics in the event they were improperly or maliciously generated
(#1133), a problem avoided by using seeds. For now, this merely
documents the panic condition.

Most implementers have opted not to provide support for this key format
due to these problems (it's also actually more expensive to validate an
expanded key than it is to use a seed), and also where seeds are the
same size regardless of security level, the expanded keys vary in size.
2026-01-10 14:09:23 -07:00
Tony Arcieri f1d81af0b2 ml-dsa: update PKCS#8 support (#1093)
The latest versions of `draft-ietf-lamps-dilithium-certificates` place
the seed in an implicit Context-Specific field with a tag number of 0.

This updates the test vectors from the following commit:

https://github.com/lamps-wg/dilithium-certificates/tree/1fcc048b8a6e3404b0e0bb80c71286551ac9604d

We only support seeds, at least until the standard is out-of-draft.

Closes #1092
2025-10-29 12:07:29 -06:00
Tom French 21e60bad04 chore: apply unreachable_pub lint (#1062) 2025-10-16 12:22:45 -06:00
daxpedda 8aa41de7b8 ml-dsa: DigestSigner cleanup (#1073) 2025-09-18 09:26:54 -06:00
Liam Gray ecc8d2768a ml-dsa: rename KeyGen::key_gen_internal to from_seed (#1054)
Despite NIST's somewhat scary "internal" naming, seeds are now the
preferred format for ML-DSA keys.

Closes #1045
2025-09-12 08:54:21 -06:00
Tony Arcieri 137ec7935c Bump hybrid-array to v0.4 (#1047) 2025-09-01 20:24:14 -06:00
Arthur Gautier 0e69f92b56 Upgrade all crates to the 2024 edition and bump MSRV to 1.85 (#913) 2025-02-28 20:12:00 -05:00
Tony Arcieri b4c90c53d5 Add proptests with round trip check (#897)
- Ensures we can verify signatures we've produced
- Ensures we can decode signatures we've encoded
2025-02-12 15:15:28 -07:00
Arthur Gautier e7c698a094 ml-dsa: support for encoding PKCS#8 private keys (#892) 2025-01-25 19:15:34 -07:00
Arthur Gautier f7e7312d94 ml-dsa: implement initial pkcs8/spki traits (#891) 2025-01-25 10:30:30 -07:00
Richard Barnes 1d3a1d1945 Add support for ML-DSA (#877) 2025-01-19 14:00:26 -07:00