Commit c88674a
committed
Rename Dilithium implementation file/symbols to ML-DSA, add backwards-compat shims
The post-quantum signature algorithm originally implemented as Dilithium
was standardized by NIST as ML-DSA in FIPS 204. This commit renames the
implementation file pair, the public API surface, and every internal
helper to the canonical ML-DSA names, mirroring the earlier Kyber ->
ML-KEM migration in wc_mlkem.{h,c}.
This commit deliberately scopes the change to the rename + compatibility
surface only. **No in-tree consumer call sites are converted.** Existing
in-tree consumers (TLS layer, ASN.1 / EVP / cryptocb wrappers, tests,
benchmark, examples, Rust wrapper) keep using the legacy spelling and
compile through the dilithium.h symbol-alias shim and the bi-directional
settings.h gate shim. New consumer code can include
<wolfssl/wolfcrypt/wc_mldsa.h> directly and use the canonical names.
Rebased onto current master (50da0c0) so that PR wolfSSL#10399's ML-DSA
Wconversion fixes (commit 2833a4b, ~220 (sword32)/(byte)/(word32)
casts in dilithium.c plus three cast hunks in asn.c) are inherited
into the new wc_mldsa.c via the file rename. The asn.c cast hunks
land separately on master and aren't part of this commit.
File layout
-----------
wolfcrypt/src/dilithium.c -> wolfcrypt/src/wc_mldsa.c
wolfssl/wolfcrypt/dilithium.h -> wolfssl/wolfcrypt/wc_mldsa.h
The legacy <wolfssl/wolfcrypt/dilithium.h> path is reborn as a thin
compatibility shim that #include's wc_mldsa.h and provides macro
aliases for every legacy linkage symbol.
Build-gate rename
-----------------
HAVE_DILITHIUM -> WOLFSSL_HAVE_MLDSA
WOLFSSL_DILITHIUM_* -> WOLFSSL_MLDSA_* (~25 sub-config gates)
WC_DILITHIUM_CACHE_* -> WC_MLDSA_CACHE_*
WC_DILITHIUM_FIXED_ARRAY -> WC_MLDSA_FIXED_ARRAY
WC_DILITHIUMKEY_TYPE_DEFINED -> WC_MLDSAKEY_TYPE_DEFINED
The configure summary echoes "ML-DSA: yes" rather than "DILITHIUM: yes".
The --enable-dilithium configure switch is preserved as a convenience
alias for --enable-mldsa.
A new wolfssl/wolfcrypt/settings_legacy_mldsa.h is included from
settings.h after user_settings.h. It is bi-directional: defining the
legacy gate (e.g. -DHAVE_DILITHIUM) implies the canonical gate, and
defining the canonical gate (e.g. via --enable-mldsa) implies the
legacy gate. The whole shim can be globally suppressed by defining
WOLFSSL_NO_DILITHIUM_LEGACY_GATES.
Public API rename
-----------------
Type:
dilithium_key -> MlDsaKey
Init / lifecycle (wolfSSL idiom: 1-arg simple form, 3-arg _ex form):
wc_dilithium_init -> wc_MlDsaKey_Init
wc_dilithium_init_ex -> wc_MlDsaKey_Init_ex
wc_dilithium_init_id -> wc_MlDsaKey_InitId
wc_dilithium_init_label -> wc_MlDsaKey_InitLabel
wc_dilithium_new -> wc_MlDsaKey_New
wc_dilithium_delete -> wc_MlDsaKey_Delete
wc_dilithium_free -> wc_MlDsaKey_Free
Parameters / sizing:
wc_dilithium_set_level -> wc_MlDsaKey_SetParams
wc_dilithium_get_level -> wc_MlDsaKey_GetParams
wc_dilithium_size -> wc_MlDsaKey_Size
wc_dilithium_priv_size -> wc_MlDsaKey_PrivSize
wc_dilithium_pub_size -> wc_MlDsaKey_PubSize
wc_dilithium_sig_size -> wc_MlDsaKey_SigSize
wc_dilithium_check_key -> wc_MlDsaKey_CheckKey
Key generation:
wc_dilithium_make_key -> wc_MlDsaKey_MakeKey
wc_dilithium_make_key_from_seed -> wc_MlDsaKey_MakeKeyFromSeed
Raw export (no argument reorder):
wc_dilithium_export_public -> wc_MlDsaKey_ExportPubRaw
wc_dilithium_export_private[_only] -> wc_MlDsaKey_ExportPrivRaw
wc_dilithium_export_key -> wc_MlDsaKey_ExportKey
Raw import / sign / verify / DER decode (FIPS 204 / ML-KEM
convention puts the key first; legacy form put it last):
wc_dilithium_import_public(in, inLen, key)
-> wc_MlDsaKey_ImportPubRaw(key, in, inLen)
wc_dilithium_import_private[_only](priv, privSz, key)
-> wc_MlDsaKey_ImportPrivRaw(key, priv, privSz)
wc_dilithium_import_key(priv, privSz, pub, pubSz, key)
-> wc_MlDsaKey_ImportKey(key, priv, privSz, pub, pubSz)
wc_dilithium_sign_msg / sign_ctx_msg / sign_ctx_hash / *_with_seed
-> wc_MlDsaKey_Sign / SignCtx / SignCtxHash / *WithSeed
wc_dilithium_verify_msg / verify_ctx_msg / verify_ctx_hash / verify_mu
-> wc_MlDsaKey_Verify / VerifyCtx / VerifyCtxHash / VerifyMu
wc_Dilithium_PrivateKeyDecode(in, idx, key, sz)
-> wc_MlDsaKey_PrivateKeyDecode(key, in, sz, idx)
wc_Dilithium_PublicKeyDecode(in, idx, key, sz)
-> wc_MlDsaKey_PublicKeyDecode(key, in, sz, idx)
ASN.1 encode (no reorder):
wc_Dilithium_PublicKeyToDer -> wc_MlDsaKey_PublicKeyToDer
wc_Dilithium_PrivateKeyToDer -> wc_MlDsaKey_PrivateKeyToDer
wc_Dilithium_KeyToDer -> wc_MlDsaKey_KeyToDer
OpenSSL-compat enum:
Adds WC_EVP_PKEY_MLDSA / EVP_PKEY_MLDSA. The legacy
WC_EVP_PKEY_DILITHIUM / EVP_PKEY_DILITHIUM remain as enum
aliases to the same value (no ABI change for the enum itself).
Type forward declaration in wolfssl/wolfcrypt/asn_public.h:
The 6-line forward declaration `typedef struct dilithium_key
dilithium_key;` (guarded by WC_DILITHIUMKEY_TYPE_DEFINED) is
flipped to `typedef struct MlDsaKey MlDsaKey;` (guarded by
WC_MLDSAKEY_TYPE_DEFINED).
Struct field type in wolfssl/wolfcrypt/asn.h:
The two `struct dilithium_key` references inside SignatureCtx's
ML-DSA union arm reference `struct MlDsaKey` directly. The field
name (`dilithium`) is unchanged so legacy-spelled consumer code
keeps working.
Internal helper rename
----------------------
All ~80 lower-case static / file-scope helpers in wc_mldsa.{h,c} and
wc_mldsa_asm.S are renamed dilithium_* -> mldsa_* for consistency
with ML-KEM's mlkem_* convention. The two WOLFSSL_TEST_VIS encoders
wc_dilithium_encode_w1_88/32 become wc_mldsa_encode_w1_88/32. The
struct typedef wc_dilithium_params becomes wc_mldsa_params.
The FIPS 204 spec-derived constants (DILITHIUM_Q, DILITHIUM_N,
DILITHIUM_LEVEL{2,3,5}_*, DILITHIUM_ML_DSA_{44,65,87}_*) are kept
under their existing names.
Compatibility surface
---------------------
Two independent shims, each suppressible via its own opt-out:
- The wolfssl/wolfcrypt/dilithium.h compatibility shim provides
macro aliases for every legacy linkage symbol. Direct one-to-one
#defines for the no-reorder APIs and function-like macros that
swap arguments back for the 16 arg-reorder APIs. Suppressed by
defining WOLFSSL_NO_DILITHIUM_LEGACY_NAMES.
- The wolfssl/wolfcrypt/settings_legacy_mldsa.h shim is
bi-directional: defining either spelling of any of the 32
build gates implies the other. Suppressed by defining
WOLFSSL_NO_DILITHIUM_LEGACY_GATES.
A small block of internal-helper aliases at the bottom of
dilithium.h covers WOLFSSL_LOCAL `dilithium_get_oid_sum` and the
WOLFSSL_TEST_VIS `wc_dilithium_encode_w1_*` encoders that this
branch's unmigrated in-tree consumers (src/ssl_load.c and
tests/api/test_mldsa.c) still call.
Tests / verification
--------------------
A compile-time validation block at the bottom of wc_mldsa.c (under
WOLFSSL_NO_DILITHIUM_LEGACY_NAMES suppression) exercises every
legacy macro alias. The bodies sit inside `if (0)` so the compiler
parses and type-checks the expansions without emitting any runtime
call. A missing or misordered alias produces an immediate compile
error.
Wconversion preservation: master's PR wolfSSL#10399 added 220 `(sword32)`
casts (and several `(byte)` / `(word32)` casts) inside dilithium.c.
After the file rename, the new wc_mldsa.c has all 220 `(sword32)`
casts intact (count verified equal between master's dilithium.c
and our new wc_mldsa.c).
Builds clean with --enable-mldsa and --enable-dilithium (legacy
alias). make check passes; testwolfcrypt DILITHIUM test passes.
https://claude.ai/code/session_01N9vLeZw4Gsfb11N4BU1Mbe1 parent 50da0c0 commit c88674a
30 files changed
Lines changed: 3340 additions & 2466 deletions
File tree
- IDE
- INTIME-RTOS
- WIN10
- XCODE
- wolfssl-FIPS.xcodeproj
- wolfssl.xcodeproj
- cmake
- src
- tests/api
- wolfcrypt/src
- wolfssl
- openssl
- wolfcrypt
- wrapper/CSharp
- zephyr
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
679 | 679 | | |
680 | 680 | | |
681 | 681 | | |
682 | | - | |
| 682 | + | |
683 | 683 | | |
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
687 | | - | |
| 687 | + | |
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
5 | 78 | | |
6 | 79 | | |
7 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | | - | |
| 321 | + | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
280 | 281 | | |
281 | 282 | | |
282 | 283 | | |
| 284 | + | |
283 | 285 | | |
284 | 286 | | |
285 | 287 | | |
| |||
583 | 585 | | |
584 | 586 | | |
585 | 587 | | |
| 588 | + | |
586 | 589 | | |
587 | 590 | | |
588 | 591 | | |
| |||
634 | 637 | | |
635 | 638 | | |
636 | 639 | | |
| 640 | + | |
637 | 641 | | |
638 | 642 | | |
639 | 643 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| 256 | + | |
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
| |||
617 | 618 | | |
618 | 619 | | |
619 | 620 | | |
| 621 | + | |
620 | 622 | | |
621 | 623 | | |
622 | 624 | | |
| |||
983 | 985 | | |
984 | 986 | | |
985 | 987 | | |
| 988 | + | |
986 | 989 | | |
987 | 990 | | |
988 | 991 | | |
| |||
1144 | 1147 | | |
1145 | 1148 | | |
1146 | 1149 | | |
| 1150 | + | |
1147 | 1151 | | |
1148 | 1152 | | |
1149 | 1153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| |||
1029 | 1029 | | |
1030 | 1030 | | |
1031 | 1031 | | |
1032 | | - | |
1033 | | - | |
| 1032 | + | |
| 1033 | + | |
1034 | 1034 | | |
1035 | 1035 | | |
1036 | 1036 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
0 commit comments