Repository navigation
Commit fa74cd8
Add external mu (message representative) support for ML-DSA (#14979)
* Add external mu (message representative) support to ML-DSA
Adds sign_mu()/verify_mu() to the ML-DSA private/public key classes for
signing and verifying a precomputed 64-byte external mu, as defined in
FIPS 204. mu already incorporates the public key and any context string,
so these methods take no context.
Per-backend mechanism:
- OpenSSL 3.5+: set the integer "mu" signature parameter
(OSSL_SIGNATURE_PARAM_MU) and pass mu through EVP_DigestSign.
- AWS-LC: EVP_PKEY_sign/EVP_PKEY_verify, which use the "ExternalMu"
format for ML-DSA keys.
- BoringSSL: the EVP layer has no external-mu support, so use the
low-level MLDSA*_{sign,verify}_message_representative functions.
* Add external-mu known-answer tests for ML-DSA
Derive mu from the existing deterministic pure KAT vectors (whose
signatures come from an independent reference implementation) and check
that verify_mu accepts each reference signature for its derived mu and
rejects it for a tampered mu, across ML-DSA-44/65/87.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Add ML-DSA external-mu Wycheproof tests
The Wycheproof ML-DSA sign vectors carry a precomputed mu ('External Mu')
for every case with a valid signature, including the mu-only 'Internal'
cases NIST provides without an accompanying message or context. The
signing tests skip those, so add external-mu tests that exercise
verify_mu against the vector mu/signature pairs, confirm a perturbed mu
fails, and (when msg/ctx are present) check the derived mu matches the
vector.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Build the ML-DSA mu OSSL_PARAM on the stack
Replace the allocating OSSL_PARAM_BLD in set_mu with a fixed two-element
OSSL_PARAM array constructed via OSSL_PARAM_construct_uint. The provider
reads the 'mu' flag back with OSSL_PARAM_get_int, which accepts an
unsigned integer param. This removes the builder's allocation-failure
branch, which was unreachable in practice and left uncovered.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Address ML-DSA external-mu review feedback
- docs: describe how mu is computed and note there is no API to compute
it yet, replacing the lower-value note about context.
- backend: drop the redundant pyo3 signature attribute on verify_mu (no
optional arguments, matching sign_mu).
- openssl: note that the OpenSSL external-mu path must use digest-sign
because ML-DSA does not implement EVP_PKEY_sign_init.
- tests: clarify why the wycheproof external-mu helper filters on both
the presence of mu and a valid result.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Infer ML-DSA variant from the key in sign_mu/verify_mu
sign_mu and verify_mu took the ML-DSA variant as a caller-supplied
argument, which is unsound: nothing tied it to the key. Infer it from
the pkey via MlDsaVariant::from_pkey instead, matching how sign/verify
work, and drop the argument from both functions and their callers. Only
the BoringSSL low-level path actually needs the variant.
Also trim the sign_mu/verify_mu docs back to a concise note that there
is no API to compute mu.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Propagate ML-DSA public key parse errors in verify_mu
The BoringSSL verify_mu path re-parses the raw public key, which was
already validated when the key was constructed, so the parse cannot fail
in practice. Returning Ok(false) on that impossible failure left three
unreachable lines uncovered. Propagate the error with ? instead (as
sign_mu already does), which keeps coverage at 100%.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Address ML-DSA external-mu review feedback
- Assert mu.len() == MLDSA_MU_BYTES in sign_mu/verify_mu. The BoringSSL
path hands mu to the low-level API as a bare pointer read for a fixed
length, so enforce it for soundness instead of trusting callers.
- Use CBS_init to build the CBS in verify_mu rather than constructing the
struct by hand, so we don't depend on its field layout.
- Use std::ffi::c_uint for the mu OSSL_PARAM value.
- Consolidate the wycheproof external-mu tests into a single test over
all three vector files, resolving the key type from the vector's
algorithm field.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
* Fix mypy type for ML-DSA external-mu key class lookup
mypy inferred the _MLDSA_PUBLIC_KEYS dict value as type[object] (the
classes share no base), so public_key_class.from_public_bytes failed to
type check. Annotate the dict with the union of the three public key
types; add a __future__ annotations import so the annotation stays lazy
on Python 3.9.
https://claude.ai/code/session_01MmjphxZ6ookRpjUhQouKjf
---------
Co-authored-by: Claude <[email protected]>1 parent f594db3 commit fa74cd8
7 files changed
Lines changed: 646 additions & 3 deletions
File tree
- docs/hazmat/primitives/asymmetric
- src
- cryptography/hazmat/primitives/asymmetric
- rust
- cryptography-openssl/src
- src/backend
- tests
- hazmat/primitives
- wycheproof
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
98 | 113 | | |
99 | 114 | | |
100 | 115 | | |
| |||
227 | 242 | | |
228 | 243 | | |
229 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
230 | 264 | | |
231 | 265 | | |
232 | 266 | | |
| |||
281 | 315 | | |
282 | 316 | | |
283 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
284 | 333 | | |
285 | 334 | | |
286 | 335 | | |
| |||
413 | 462 | | |
414 | 463 | | |
415 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
416 | 484 | | |
417 | 485 | | |
418 | 486 | | |
| |||
467 | 535 | | |
468 | 536 | | |
469 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
470 | 553 | | |
471 | 554 | | |
472 | 555 | | |
| |||
599 | 682 | | |
600 | 683 | | |
601 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
602 | 704 | | |
603 | 705 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
58 | 70 | | |
59 | 71 | | |
60 | 72 | | |
| |||
138 | 150 | | |
139 | 151 | | |
140 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
141 | 162 | | |
142 | 163 | | |
143 | 164 | | |
| |||
198 | 219 | | |
199 | 220 | | |
200 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
201 | 234 | | |
202 | 235 | | |
203 | 236 | | |
| |||
281 | 314 | | |
282 | 315 | | |
283 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
284 | 326 | | |
285 | 327 | | |
286 | 328 | | |
| |||
341 | 383 | | |
342 | 384 | | |
343 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
344 | 398 | | |
345 | 399 | | |
346 | 400 | | |
| |||
424 | 478 | | |
425 | 479 | | |
426 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
427 | 490 | | |
428 | 491 | | |
429 | 492 | | |
| |||
0 commit comments