Skip to content

Commit 41b258e

Browse files
committed
wolfssl/wolfcrypt/dilithium.h: use macros, not inlines, for all legacy (!WOLFSSL_NO_DILITHIUM_LEGACY_NAMES) wrappers;
tests/api/test_mldsa.c: suppress -Wunreachable-code around wc_mldsa_canonical_api_check() and wc_mldsa_legacy_alias_check(); wolfcrypt/benchmark/benchmark.c, wolfcrypt/src/wc_lms.c, wolfssl/wolfcrypt/wc_lms.h, wrapper/rust/wolfssl-wolfcrypt/src/lms.rs: revert removal of WC_LMS_PARM_NONE in 69027c2 (used by wolfACVP).
1 parent ace1db5 commit 41b258e

6 files changed

Lines changed: 57 additions & 135 deletions

File tree

tests/api/test_mldsa.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30455,6 +30455,9 @@ int test_mldsa_x509_pubkey_sigtype(void)
3045530455
*/
3045630456
#if defined(HAVE_DILITHIUM)
3045730457

30458+
PRAGMA_CLANG_DIAG_PUSH
30459+
PRAGMA_CLANG("clang diagnostic ignored \"-Wunreachable-code\"")
30460+
3045830461
#ifdef __GNUC__
3045930462
#define WOLFSSL_MLDSA_API_CHECK_INLINE static __inline__ \
3046030463
__attribute__((unused, always_inline))
@@ -30714,4 +30717,6 @@ WOLFSSL_MLDSA_API_CHECK_INLINE void wc_mldsa_legacy_alias_check(void)
3071430717
}
3071530718
#endif /* !WOLFSSL_NO_DILITHIUM_LEGACY_NAMES */
3071630719

30720+
PRAGMA_CLANG_DIAG_POP
30721+
3071730722
#endif /* HAVE_DILITHIUM */

wolfcrypt/benchmark/benchmark.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11700,6 +11700,7 @@ static void bench_lms_sign_verify(enum wc_LmsParm parm, byte* pub)
1170011700
XMEMCPY(key.pub, lms_pub_L4_H5_W8, HSS_MAX_PUBLIC_KEY_LEN);
1170111701
break;
1170211702

11703+
case WC_LMS_PARM_NONE:
1170311704
case WC_LMS_PARM_L1_H15_W2:
1170411705
case WC_LMS_PARM_L1_H15_W4:
1170511706
case WC_LMS_PARM_L2_H10_W8:

wolfcrypt/src/wc_lms.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ static const wc_LmsParamsMap wc_lms_map[] = {
258258
LMS_PARAMS(2, 5, 8, 3, LMS_SHA256_M32_H5 , LMOTS_SHA256_N32_W8,
259259
WC_SHA256_DIGEST_SIZE) },
260260
#if LMS_MAX_HEIGHT >= 15
261+
{ WC_LMS_PARM_NONE , "LMS_NONE" ,
262+
LMS_PARAMS(1, 15, 2, 1, LMS_SHA256_M32_H15, LMOTS_SHA256_N32_W2,
263+
WC_SHA256_DIGEST_SIZE) },
261264
{ WC_LMS_PARM_L2_H15_W2 , "LMS/HSS_L2_H15_W2",
262265
LMS_PARAMS(2, 15, 2, 1, LMS_SHA256_M32_H15, LMOTS_SHA256_N32_W2,
263266
WC_SHA256_DIGEST_SIZE) },

wolfssl/wolfcrypt/dilithium.h

Lines changed: 46 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@
5252
* always fires whenever either is defined; the legacy spelling
5353
* remains as an alias kept around for unmigrated consumer code.
5454
*
55-
* 2. Macro / static-inline aliases for the legacy type and function
56-
* names (dilithium_key, wc_dilithium_params, wc_dilithium_*,
57-
* wc_Dilithium_*) so application code written against the
58-
* pre-standardization API keeps compiling. Suppressed by defining
59-
* WOLFSSL_NO_DILITHIUM_LEGACY_NAMES.
55+
* 2. Macro aliases for the legacy type and function names (dilithium_key,
56+
* wc_dilithium_params, wc_dilithium_*, wc_Dilithium_*) so application code
57+
* written against the pre-standardization API keeps compiling. Suppressed
58+
* by defining WOLFSSL_NO_DILITHIUM_LEGACY_NAMES.
6059
*
6160
* New code must include <wolfssl/wolfcrypt/wc_mldsa.h> directly and use
6261
* the wc_MlDsaKey / wc_MlDsaKey_* / WOLFSSL_MLDSA_* names. */
@@ -381,146 +380,58 @@
381380

382381
/* Legacy default-args / arg-reorder wrappers. The legacy form takes the key
383382
* pointer last (or near last); the FIPS 204 / ML-KEM convention used by the
384-
* canonical wc_MlDsaKey_* names puts the key first. The wrappers below are
385-
* static inline functions (rather than function-like macros) so that
386-
* (a) `&wc_dilithium_init`-style address-of expressions remain valid in
387-
* source (they yield the inline wrapper's address - note this is a
388-
* translation-unit-local symbol, not the previously-exported library
389-
* symbol) and (b) each wrapper preserves the legacy signature byte-for-byte.
390-
* Each wrapper is gated to match its canonical target's gating so
391-
* unused-on-this-build wrappers don't reference undeclared symbols. */
392-
393-
#ifdef __GNUC__
394-
/* Suppress -Wunused-function for translation units that don't call every
395-
* legacy wrapper. */
396-
#define WOLFSSL_DILITHIUM_LEGACY_INLINE static __inline__ \
397-
__attribute__((unused, always_inline))
398-
#else
399-
#define WOLFSSL_DILITHIUM_LEGACY_INLINE static WC_INLINE
400-
#endif
401-
402-
WOLFSSL_DILITHIUM_LEGACY_INLINE
403-
int wc_dilithium_init(wc_MlDsaKey* key) {
404-
return wc_MlDsaKey_Init(key, NULL, INVALID_DEVID);
405-
}
383+
* canonical wc_MlDsaKey_* names puts the key first. */
406384

385+
#define wc_dilithium_init(key) \
386+
wc_MlDsaKey_Init(key, NULL, INVALID_DEVID)
407387
#ifdef WOLFSSL_MLDSA_PUBLIC_KEY
408-
WOLFSSL_DILITHIUM_LEGACY_INLINE
409-
int wc_dilithium_import_public(const byte* in, word32 inLen, wc_MlDsaKey* key) {
410-
return wc_MlDsaKey_ImportPubRaw(key, in, inLen);
411-
}
388+
#define wc_dilithium_import_public(in, inLen, key) wc_MlDsaKey_ImportPubRaw(key, in, inLen)
412389
#endif
413-
414390
#ifdef WOLFSSL_MLDSA_PRIVATE_KEY
415-
WOLFSSL_DILITHIUM_LEGACY_INLINE
416-
int wc_dilithium_import_private(const byte* priv, word32 privSz, wc_MlDsaKey* key) {
417-
return wc_MlDsaKey_ImportPrivRaw(key, priv, privSz);
418-
}
419-
WOLFSSL_DILITHIUM_LEGACY_INLINE
420-
int wc_dilithium_import_private_only(const byte* in, word32 inLen, wc_MlDsaKey* key) {
421-
return wc_MlDsaKey_ImportPrivRaw(key, in, inLen);
422-
}
423-
WOLFSSL_DILITHIUM_LEGACY_INLINE
424-
int wc_dilithium_import_key(const byte* priv, word32 privSz, const byte* pub,
425-
word32 pubSz, wc_MlDsaKey* key) {
426-
return wc_MlDsaKey_ImportKey(key, priv, privSz, pub, pubSz);
427-
}
391+
#define wc_dilithium_import_private(priv, privSz, key) \
392+
wc_MlDsaKey_ImportPrivRaw(key, priv, privSz)
393+
#define wc_dilithium_import_private_only(in, inLen, key) \
394+
wc_MlDsaKey_ImportPrivRaw(key, in, inLen)
395+
#define wc_dilithium_import_key(priv, privSz, pub, pubSz, key) \
396+
wc_MlDsaKey_ImportKey(key, priv, privSz, pub, pubSz)
428397
#endif /* WOLFSSL_MLDSA_PRIVATE_KEY */
429-
430398
#ifndef WOLFSSL_MLDSA_VERIFY_ONLY
431-
#ifdef WOLFSSL_MLDSA_NO_CTX
432-
WOLFSSL_DILITHIUM_LEGACY_INLINE
433-
int wc_dilithium_sign_msg(const byte* msg, word32 msgLen, byte* sig,
434-
word32* sigLen, wc_MlDsaKey* key, WC_RNG* rng) {
435-
return wc_MlDsaKey_Sign(key, sig, sigLen, msg, msgLen, rng);
436-
}
437-
WOLFSSL_DILITHIUM_LEGACY_INLINE
438-
int wc_dilithium_sign_msg_with_seed(const byte* msg, word32 msgLen, byte* sig,
439-
word32* sigLen, wc_MlDsaKey* key,
440-
const byte* seed) {
441-
return wc_MlDsaKey_SignWithSeed(key, sig, sigLen, msg, msgLen, seed);
442-
}
443-
#endif /* WOLFSSL_MLDSA_NO_CTX */
444-
WOLFSSL_DILITHIUM_LEGACY_INLINE
445-
int wc_dilithium_sign_ctx_msg(const byte* ctx, byte ctxLen, const byte* msg,
446-
word32 msgLen, byte* sig, word32* sigLen,
447-
wc_MlDsaKey* key, WC_RNG* rng) {
448-
return wc_MlDsaKey_SignCtx(key, ctx, ctxLen, sig, sigLen, msg, msgLen, rng);
449-
}
450-
WOLFSSL_DILITHIUM_LEGACY_INLINE
451-
int wc_dilithium_sign_ctx_hash(const byte* ctx, byte ctxLen, int hashAlg,
452-
const byte* hash, word32 hashLen, byte* sig,
453-
word32* sigLen, wc_MlDsaKey* key, WC_RNG* rng) {
454-
return wc_MlDsaKey_SignCtxHash(key, ctx, ctxLen, sig, sigLen, hash,
455-
hashLen, hashAlg, rng);
456-
}
457-
WOLFSSL_DILITHIUM_LEGACY_INLINE
458-
int wc_dilithium_sign_ctx_msg_with_seed(const byte* ctx, byte ctxLen,
459-
const byte* msg, word32 msgLen,
460-
byte* sig, word32* sigLen,
461-
wc_MlDsaKey* key, const byte* seed) {
462-
return wc_MlDsaKey_SignCtxWithSeed(key, ctx, ctxLen, sig, sigLen, msg,
463-
msgLen, seed);
464-
}
465-
WOLFSSL_DILITHIUM_LEGACY_INLINE
466-
int wc_dilithium_sign_ctx_hash_with_seed(const byte* ctx, byte ctxLen,
467-
int hashAlg, const byte* hash,
468-
word32 hashLen, byte* sig,
469-
word32* sigLen, wc_MlDsaKey* key,
470-
const byte* seed) {
471-
return wc_MlDsaKey_SignCtxHashWithSeed(key, ctx, ctxLen, sig, sigLen,
472-
hash, hashLen, hashAlg, seed);
473-
}
474-
WOLFSSL_DILITHIUM_LEGACY_INLINE
475-
int wc_dilithium_sign_mu_with_seed(const byte* mu, word32 muLen, byte* sig,
476-
word32* sigLen, wc_MlDsaKey* key,
477-
const byte* seed) {
478-
return wc_MlDsaKey_SignMuWithSeed(key, sig, sigLen, mu, muLen, seed);
479-
}
399+
#ifdef WOLFSSL_MLDSA_NO_CTX
400+
#define wc_dilithium_sign_msg(msg, msgLen, sig, sigLen, key, rng) \
401+
wc_MlDsaKey_Sign(key, sig, sigLen, msg, msgLen, rng)
402+
#define wc_dilithium_sign_msg_with_seed(msg, msgLen, sig, sigLen, key, seed) \
403+
wc_MlDsaKey_SignWithSeed(key, sig, sigLen, msg, msgLen, seed)
404+
#endif /* WOLFSSL_MLDSA_NO_CTX */
405+
#define wc_dilithium_sign_ctx_msg(ctx, ctxLen, msg, msgLen, sig, sigLen, key, rng) \
406+
wc_MlDsaKey_SignCtx(key, ctx, ctxLen, sig, sigLen, msg, msgLen, rng)
407+
#define wc_dilithium_sign_ctx_hash(ctx, ctxLen, hashAlg, hash, hashLen, sig, sigLen, key, rng) \
408+
wc_MlDsaKey_SignCtxHash(key, ctx, ctxLen, sig, sigLen, hash, hashLen, hashAlg, rng)
409+
#define wc_dilithium_sign_ctx_msg_with_seed(ctx, ctxLen, msg, msgLen, sig, sigLen, key, seed) \
410+
wc_MlDsaKey_SignCtxWithSeed(key, ctx, ctxLen, sig, sigLen, msg, msgLen, seed)
411+
#define wc_dilithium_sign_ctx_hash_with_seed(ctx, ctxLen, hashAlg, hash, hashLen, sig, sigLen, key, seed) \
412+
wc_MlDsaKey_SignCtxHashWithSeed(key, ctx, ctxLen, sig, sigLen, hash, hashLen, hashAlg, seed)
413+
#define wc_dilithium_sign_mu_with_seed(mu, muLen, sig, sigLen, key, seed) \
414+
wc_MlDsaKey_SignMuWithSeed(key, sig, sigLen, mu, muLen, seed)
480415
#endif /* !WOLFSSL_MLDSA_VERIFY_ONLY */
481-
482416
#ifdef WOLFSSL_MLDSA_NO_CTX
483-
WOLFSSL_DILITHIUM_LEGACY_INLINE
484-
int wc_dilithium_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
485-
word32 msgLen, int* res, wc_MlDsaKey* key) {
486-
return wc_MlDsaKey_Verify(key, sig, sigLen, msg, msgLen, res);
487-
}
417+
#define wc_dilithium_verify_msg(sig, sigLen, msg, msgLen, res, key) \
418+
wc_MlDsaKey_Verify(key, sig, sigLen, msg, msgLen, res)
488419
#endif /* WOLFSSL_MLDSA_NO_CTX */
489-
WOLFSSL_DILITHIUM_LEGACY_INLINE
490-
int wc_dilithium_verify_ctx_msg(const byte* sig, word32 sigLen, const byte* ctx,
491-
byte ctxLen, const byte* msg, word32 msgLen,
492-
int* res, wc_MlDsaKey* key) {
493-
return wc_MlDsaKey_VerifyCtx(key, sig, sigLen, ctx, ctxLen, msg, msgLen,
494-
res);
495-
}
496-
WOLFSSL_DILITHIUM_LEGACY_INLINE
497-
int wc_dilithium_verify_ctx_hash(const byte* sig, word32 sigLen, const byte* ctx,
498-
byte ctxLen, int hashAlg, const byte* hash,
499-
word32 hashLen, int* res, wc_MlDsaKey* key) {
500-
return wc_MlDsaKey_VerifyCtxHash(key, sig, sigLen, ctx, ctxLen, hash,
501-
hashLen, hashAlg, res);
502-
}
503-
WOLFSSL_DILITHIUM_LEGACY_INLINE
504-
int wc_dilithium_verify_mu(const byte* sig, word32 sigLen, const byte* mu,
505-
word32 muLen, int* res, wc_MlDsaKey* key) {
506-
return wc_MlDsaKey_VerifyMu(key, sig, sigLen, mu, muLen, res);
507-
}
508-
420+
#define wc_dilithium_verify_ctx_msg(sig, sigLen, ctx, ctxLen, msg, msgLen, res, key) \
421+
wc_MlDsaKey_VerifyCtx(key, sig, sigLen, ctx, ctxLen, msg, msgLen, res)
422+
#define wc_dilithium_verify_ctx_hash(sig, sigLen, ctx, ctxLen, hashAlg, hash, hashLen, res, key) \
423+
wc_MlDsaKey_VerifyCtxHash(key, sig, sigLen, ctx, ctxLen, hash, hashLen, hashAlg, res)
424+
#define wc_dilithium_verify_mu(sig, sigLen, mu, muLen, res, key) \
425+
wc_MlDsaKey_VerifyMu(key, sig, sigLen, mu, muLen, res)
509426
#ifndef WOLFSSL_MLDSA_NO_ASN1
510-
#ifdef WOLFSSL_MLDSA_PRIVATE_KEY
511-
WOLFSSL_DILITHIUM_LEGACY_INLINE
512-
int wc_Dilithium_PrivateKeyDecode(const byte* input, word32* inOutIdx,
513-
wc_MlDsaKey* key, word32 inSz) {
514-
return wc_MlDsaKey_PrivateKeyDecode(key, input, inSz, inOutIdx);
515-
}
516-
#endif
517-
#ifdef WOLFSSL_MLDSA_PUBLIC_KEY
518-
WOLFSSL_DILITHIUM_LEGACY_INLINE
519-
int wc_Dilithium_PublicKeyDecode(const byte* input, word32* inOutIdx,
520-
wc_MlDsaKey* key, word32 inSz) {
521-
return wc_MlDsaKey_PublicKeyDecode(key, input, inSz, inOutIdx);
522-
}
523-
#endif
427+
#ifdef WOLFSSL_MLDSA_PRIVATE_KEY
428+
#define wc_Dilithium_PrivateKeyDecode(input, inOutIdx, key, inSz) \
429+
wc_MlDsaKey_PrivateKeyDecode(key, input, inSz, inOutIdx)
430+
#endif
431+
#ifdef WOLFSSL_MLDSA_PUBLIC_KEY
432+
#define wc_Dilithium_PublicKeyDecode(input, inOutIdx, key, inSz) \
433+
wc_MlDsaKey_PublicKeyDecode(key, input, inSz, inOutIdx)
434+
#endif
524435
#endif /* !WOLFSSL_MLDSA_NO_ASN1 */
525436

526437
/* Internal-helper aliases. These cover symbols that are *not* part of the

wolfssl/wolfcrypt/wc_lms.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ enum wc_LmsRc {
159159
* will be large. */
160160
enum wc_LmsParm {
161161
#ifndef WOLFSSL_NO_LMS_SHA256_256
162+
WC_LMS_PARM_NONE = 0,
162163
WC_LMS_PARM_L1_H5_W1 = 1,
163164
WC_LMS_PARM_L1_H5_W2 = 2,
164165
WC_LMS_PARM_L1_H5_W4 = 3,

wrapper/rust/wolfssl-wolfcrypt/src/lms.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub struct Lms {
108108

109109
#[cfg(lms_sha256_256)]
110110
impl Lms {
111+
pub const PARM_NONE: u32 = sys::wc_LmsParm_WC_LMS_PARM_NONE;
111112
pub const PARM_L1_H5_W1: u32 = sys::wc_LmsParm_WC_LMS_PARM_L1_H5_W1;
112113
pub const PARM_L1_H5_W2: u32 = sys::wc_LmsParm_WC_LMS_PARM_L1_H5_W2;
113114
pub const PARM_L1_H5_W4: u32 = sys::wc_LmsParm_WC_LMS_PARM_L1_H5_W4;

0 commit comments

Comments
 (0)