Skip to content

Commit 7827872

Browse files
authored
Merge pull request #10497 from Frauschi/mldsa_rename
ML-DSA renaming part 2
2 parents 46c6b60 + 2a30ce3 commit 7827872

11 files changed

Lines changed: 1759 additions & 1526 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ MICRIUM_MALLOC
361361
MICROCHIP_MPLAB_HARMONY
362362
MICROCHIP_MPLAB_HARMONY_3
363363
MICRO_SESSION_CACHEx
364+
MLDSA_USE_HINT_CT
364365
MLKEM_NONDETERMINISTIC
365366
MODULE_SOCK_TCP
366367
MP_31BIT
@@ -963,8 +964,6 @@ WOLFSSL_XIL_MSG_NO_SLEEP
963964
WOLFSSL_ZEPHYR
964965
WOLF_ALLOW_BUILTIN
965966
WOLF_CRYPTO_CB_CMD
966-
WOLF_CRYPTO_CB_ONLY_ECC
967-
WOLF_CRYPTO_CB_ONLY_RSA
968967
WOLF_CRYPTO_DEV
969968
WOLF_NO_TRAILING_ENUM_COMMAS
970969
WindowsCE

doc/dilithium-to-mldsa-migration.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ the legacy API.
3737
| `wc_dilithium_*` (lifecycle / sizing) | `wc_MlDsaKey_*` |
3838
| `wc_Dilithium_*` (DER encode / decode) | `wc_MlDsaKey_*` |
3939
| internal lower-case `dilithium_*` helpers | `mldsa_*` |
40+
| `DILITHIUM_*` algorithm-parameter macros | `MLDSA_*` (matches `MLKEM_*` in `wc_mlkem.h`) |
41+
| `DILITHIUM_LEVEL{2,3,5}_*_SIZE`, `ML_DSA_LEVEL{2,3,5}_*_SIZE`, `DILITHIUM_ML_DSA_{44,65,87}_*_SIZE` | `WC_MLDSA_{44,65,87}_*_SIZE` |
42+
| `DEBUG_DILITHIUM` | `DEBUG_MLDSA` |
43+
44+
The `WC_ML_DSA_{44,65,87}` / `WC_ML_DSA_{44,65,87}_DRAFT` / `WC_ML_DSA_DRAFT`
45+
public level identifiers and the `PARAMS_ML_DSA_{44,65,87}_*`
46+
per-parameter-set internal constants intentionally **keep** their
47+
underscored `ML_DSA_` spelling — the level identifiers are established
48+
public names and the `PARAMS_*` family is internal-only, so neither
49+
benefits from a rename.
50+
51+
The `WOLFSSL_NO_ML_DSA_{44,65,87}` parameter-set disable gates are
52+
likewise kept in their underscored form (matching the
53+
`WOLFSSL_NO_ML_KEM_{512,768,1024}` spelling in `wc_mlkem.h`).
4054

4155
The 16 sign / verify / import / DER-decode entry points were also
4256
re-ordered to put the `MlDsaKey*` first (matching the FIPS 204 / ML-KEM
@@ -165,6 +179,77 @@ wolfSSL-internal infrastructure (an auto-generated cert-buffer data
165179
file and the static allocator's default sizing), not consumer-facing
166180
API; these changes do not require downstream code changes.
167181

182+
## Macro / comment cleanup inside `wc_mldsa.{c,h}`
183+
184+
A follow-on cleanup of the ML-DSA implementation file finished the
185+
internal naming migration that the file/symbol rename above started:
186+
187+
- All algorithm-parameter macros defined in `wolfssl/wolfcrypt/wc_mldsa.h`
188+
(`DILITHIUM_Q`, `DILITHIUM_N`, `DILITHIUM_D`, `DILITHIUM_ETA_*`,
189+
`DILITHIUM_GAMMA1_*`, `DILITHIUM_K_SZ`, `DILITHIUM_MU_SZ`,
190+
`DILITHIUM_MAX_*`, …) were renamed to canonical `MLDSA_*` spellings
191+
matching the `MLKEM_*` internal constants in
192+
`<wolfssl/wolfcrypt/wc_mlkem.h>`. The `PARAMS_ML_DSA_{44,65,87}_*`
193+
per-parameter-set internal constants and the
194+
`WC_ML_DSA_{44,65,87}` / `WC_ML_DSA_{44,65,87}_DRAFT` /
195+
`WC_ML_DSA_DRAFT` public level identifiers keep their underscored
196+
spelling — the level identifiers are established public names and
197+
the `PARAMS_*` family is internal-only.
198+
- The per-parameter-set size constants previously existed in **three**
199+
redundant spellings — `DILITHIUM_LEVEL{2,3,5}_*_SIZE`,
200+
`ML_DSA_LEVEL{2,3,5}_*_SIZE`, and
201+
`DILITHIUM_ML_DSA_{44,65,87}_*_SIZE`. They were consolidated to a
202+
single canonical family, `WC_MLDSA_{44,65,87}_*_SIZE`. All three
203+
legacy spellings remain reachable as aliases through the
204+
`<wolfssl/wolfcrypt/dilithium.h>` shim (gated by
205+
`WOLFSSL_NO_DILITHIUM_LEGACY_NAMES`); a duplicate `MLDSA_N`
206+
definition in `wc_mldsa.h` was also removed.
207+
- All ~20 file-local macros inside `wolfcrypt/src/wc_mldsa.c`
208+
(`DILITHIUM_SIGN_BYTES`, `DILITHIUM_GEN_S_*`, `DILITHIUM_HASH_OID_LEN`,
209+
`DILITHIUM_PARAMS_CNT`, `DILITHIUM_COEFF_S*`, `DILITHIUM_QINV`,
210+
`DILITHIUM_NTT_ZETA_1`, `DILITHIUM_POS_OFFSET`, …) were renamed
211+
to `MLDSA_*`. The file-local macros are not user-visible and have no
212+
alias in the shim.
213+
- The user-tunable knobs documented in the `wc_mldsa.c` file-top
214+
comment block — `DEBUG_DILITHIUM` and the five performance-tuning
215+
defines `DILITHIUM_MUL_SLOW`, `DILITHIUM_MUL_44_SLOW`,
216+
`DILITHIUM_MUL_11_SLOW`, `DILITHIUM_MUL_QINV_SLOW`,
217+
`DILITHIUM_MUL_Q_SLOW` — were renamed to `DEBUG_MLDSA` /
218+
`MLDSA_MUL_*_SLOW`. These are set from `user_settings.h` or `-D`,
219+
so a forward-translation block was added to the legacy-gates arm
220+
in `<wolfssl/wolfcrypt/dilithium.h>` (gated by
221+
`WOLFSSL_NO_DILITHIUM_LEGACY_GATES`) so consumers using the legacy
222+
spelling continue to get the intended code path.
223+
- A long-standing typo, `dilitihium_get_der_length()` (5 call sites,
224+
`static`-scope), was corrected to `mldsa_get_der_length()`.
225+
- All `DILITHIUM_*` legacy macro spellings remain reachable from
226+
unmigrated in-tree consumers (`wolfcrypt/src/asn.c`, `src/ssl_load.c`,
227+
`src/internal.c`, `src/tls13.c`, `src/ssl.c`, `src/x509.c`,
228+
`src/ssl_api_pk.c`, `src/ssl_certman.c`, `wolfssl/internal.h`,
229+
`wolfssl/wolfcrypt/asn.h`, `asn_public.h`, `oid_sum.h`,
230+
`examples/configs/user_settings_pq.h`,
231+
`wolfcrypt/benchmark/benchmark.c`, `wolfcrypt/test/test.c`,
232+
`tests/api/test_mldsa.c`) and downstream code through a new
233+
reverse-arm macro alias block in `<wolfssl/wolfcrypt/dilithium.h>`,
234+
gated by the existing `WOLFSSL_NO_DILITHIUM_LEGACY_NAMES` opt-out.
235+
- All function and section comments inside `wc_mldsa.c` had their
236+
"Dilithium" / "dilithium" prose replaced with "ML-DSA" (the file-top
237+
credit retains a parenthetical mention of the historical name).
238+
- Every algorithm-step citation was re-numbered against FIPS 204 Final
239+
(August 2024). The implementation was previously annotated with the
240+
draft (IPD) numbering — e.g. `Algorithm 18 skEncode`, `Algorithm 26
241+
ExpandA`, `Algorithm 29 Power2Round`. These were updated to the
242+
Final numbering (`Algorithm 24 skEncode`, `Algorithm 32 ExpandA`,
243+
`Algorithm 35 Power2Round`, …) and the section references were
244+
retargeted from the draft `§8.x` building-blocks group to the Final
245+
`§7.x` arrangement. SHAKE128/256 notation references were redirected
246+
from the IPD `§8.3` to the Final `§3.7`. Citation punctuation was
247+
normalized from `FIPS 204. N.M:` to `FIPS 204 §N.M,`.
248+
249+
These changes are contained to `wolfcrypt/src/wc_mldsa.c`,
250+
`wolfssl/wolfcrypt/wc_mldsa.h`, and the macro-alias block in
251+
`wolfssl/wolfcrypt/dilithium.h`. No external consumer is touched.
252+
168253
### Retained internal symbols
169254

170255
A few internal-only spellings are intentionally **not** renamed in this

src/ssl_api_pk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static int check_cert_key_dev(word32 keyOID, byte* privKey, word32 privSz,
122122
case DILITHIUM_LEVEL5k:
123123
#endif
124124
ret = wc_CryptoCb_PqcSignatureCheckPrivKey(pkey,
125-
WC_PQC_SIG_TYPE_DILITHIUM, pubKey, pubSz);
125+
WC_PQC_SIG_TYPE_MLDSA, pubKey, pubSz);
126126
break;
127127
#endif
128128
#if defined(HAVE_FALCON)

wolfcrypt/src/cryptocb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ int wc_CryptoCb_PqcKemGetDevId(int type, void* key)
11761176
return devId;
11771177

11781178
/* get devId */
1179-
if (type == WC_PQC_KEM_TYPE_KYBER) {
1179+
if (type == WC_PQC_KEM_TYPE_MLKEM) {
11801180
devId = ((KyberKey*) key)->devId;
11811181
}
11821182

@@ -1299,7 +1299,7 @@ int wc_CryptoCb_PqcSigGetDevId(int type, void* key)
12991299

13001300
/* get devId */
13011301
#if defined(HAVE_DILITHIUM)
1302-
if (type == WC_PQC_SIG_TYPE_DILITHIUM) {
1302+
if (type == WC_PQC_SIG_TYPE_MLDSA) {
13031303
devId = ((dilithium_key*) key)->devId;
13041304
}
13051305
#endif

0 commit comments

Comments
 (0)