@@ -803,6 +803,13 @@ struct dilithium_key {
803803 #define WC_DILITHIUMKEY_TYPE_DEFINED
804804#endif
805805
806+ /* When WOLFSSL_DILITHIUM_FIPS204_DRAFT is enabled the legacy (pre-FIPS 204)
807+ * no-context sign/verify API is required to handle draft-format signatures. */
808+ #if defined(WOLFSSL_DILITHIUM_FIPS204_DRAFT ) && \
809+ !defined(WOLFSSL_DILITHIUM_NO_CTX )
810+ #define WOLFSSL_DILITHIUM_NO_CTX
811+ #endif
812+
806813/* Functions */
807814
808815#ifndef WOLFSSL_DILITHIUM_VERIFY_ONLY
@@ -811,19 +818,30 @@ int wc_dilithium_make_key(dilithium_key* key, WC_RNG* rng);
811818WOLFSSL_API
812819int wc_dilithium_make_key_from_seed (dilithium_key * key , const byte * seed );
813820
821+ /* Legacy sign API without context parameter (pre-FIPS 204).
822+ * Only available when WOLFSSL_DILITHIUM_NO_CTX is defined.
823+ * New code should use wc_dilithium_sign_ctx_msg() with ctx=NULL/ctxLen=0
824+ * for FIPS 204 compliant signing with an empty context. */
825+ #ifdef WOLFSSL_DILITHIUM_NO_CTX
814826WOLFSSL_API
815827int wc_dilithium_sign_msg (const byte * msg , word32 msgLen , byte * sig ,
816828 word32 * sigLen , dilithium_key * key , WC_RNG * rng );
829+ #endif /* WOLFSSL_DILITHIUM_NO_CTX */
817830WOLFSSL_API
818831int wc_dilithium_sign_ctx_msg (const byte * ctx , byte ctxLen , const byte * msg ,
819832 word32 msgLen , byte * sig , word32 * sigLen , dilithium_key * key , WC_RNG * rng );
820833WOLFSSL_API
821834int wc_dilithium_sign_ctx_hash (const byte * ctx , byte ctxLen , int hashAlg ,
822835 const byte * hash , word32 hashLen , byte * sig , word32 * sigLen ,
823836 dilithium_key * key , WC_RNG * rng );
837+ /* Legacy seed-based sign API without context parameter (pre-FIPS 204).
838+ * Only available when WOLFSSL_DILITHIUM_NO_CTX is defined.
839+ * New code should use wc_dilithium_sign_ctx_msg_with_seed() instead. */
840+ #ifdef WOLFSSL_DILITHIUM_NO_CTX
824841WOLFSSL_API
825842int wc_dilithium_sign_msg_with_seed (const byte * msg , word32 msgLen , byte * sig ,
826843 word32 * sigLen , dilithium_key * key , const byte * seed );
844+ #endif /* WOLFSSL_DILITHIUM_NO_CTX */
827845WOLFSSL_API
828846int wc_dilithium_sign_ctx_msg_with_seed (const byte * ctx , byte ctxLen ,
829847 const byte * msg , word32 msgLen , byte * sig , word32 * sigLen ,
@@ -832,10 +850,16 @@ WOLFSSL_API
832850int wc_dilithium_sign_ctx_hash_with_seed (const byte * ctx , byte ctxLen ,
833851 int hashAlg , const byte * hash , word32 hashLen , byte * sig , word32 * sigLen ,
834852 dilithium_key * key , const byte * seed );
835- #endif
853+ #endif /* !WOLFSSL_DILITHIUM_VERIFY_ONLY */
854+ /* Legacy verify API without context parameter (pre-FIPS 204).
855+ * Only available when WOLFSSL_DILITHIUM_NO_CTX is defined.
856+ * New code should use wc_dilithium_verify_ctx_msg() with ctx=NULL/ctxLen=0
857+ * for FIPS 204 compliant verification with an empty context. */
858+ #ifdef WOLFSSL_DILITHIUM_NO_CTX
836859WOLFSSL_API
837860int wc_dilithium_verify_msg (const byte * sig , word32 sigLen , const byte * msg ,
838861 word32 msgLen , int * res , dilithium_key * key );
862+ #endif /* WOLFSSL_DILITHIUM_NO_CTX */
839863WOLFSSL_API
840864int wc_dilithium_verify_ctx_msg (const byte * sig , word32 sigLen , const byte * ctx ,
841865 byte ctxLen , const byte * msg , word32 msgLen , int * res ,
@@ -1074,8 +1098,12 @@ WOLFSSL_LOCAL void wc_mldsa_poly_make_pos_avx2(sword32* a);
10741098 wc_dilithium_export_private_only(key, out, outLen)
10751099#define wc_MlDsaKey_ImportPrivRaw (key , in , inLen ) \
10761100 wc_dilithium_import_private_only(in, inLen, key)
1101+ /* Legacy no-context sign alias: only available with WOLFSSL_DILITHIUM_NO_CTX.
1102+ * Prefer wc_MlDsaKey_SignCtx() with empty context for FIPS 204 compliance. */
1103+ #ifdef WOLFSSL_DILITHIUM_NO_CTX
10771104#define wc_MlDsaKey_Sign (key , sig , sigSz , msg , msgSz , rng ) \
10781105 wc_dilithium_sign_msg(msg, msgSz, sig, sigSz, key, rng)
1106+ #endif /* WOLFSSL_DILITHIUM_NO_CTX */
10791107#define wc_MlDsaKey_SignCtx (key , ctx , ctxSz , sig , sigSz , msg , msgSz , rng ) \
10801108 wc_dilithium_sign_ctx_msg(ctx, ctxSz, msg, msgSz, sig, sigSz, key, rng)
10811109#define wc_MlDsaKey_SignCtxHash (key , ctx , ctxSz , sig , sigSz , hash , hashSz , \
@@ -1088,8 +1116,12 @@ WOLFSSL_LOCAL void wc_mldsa_poly_make_pos_avx2(sword32* a);
10881116 wc_dilithium_export_public(key, out, outLen)
10891117#define wc_MlDsaKey_ImportPubRaw (key , in , inLen ) \
10901118 wc_dilithium_import_public(in, inLen, key)
1119+ /* Legacy no-context verify alias: only available with WOLFSSL_DILITHIUM_NO_CTX.
1120+ * Prefer wc_MlDsaKey_VerifyCtx() with empty context for FIPS 204 compliance. */
1121+ #ifdef WOLFSSL_DILITHIUM_NO_CTX
10911122#define wc_MlDsaKey_Verify (key , sig , sigSz , msg , msgSz , res ) \
10921123 wc_dilithium_verify_msg(sig, sigSz, msg, msgSz, res, key)
1124+ #endif /* WOLFSSL_DILITHIUM_NO_CTX */
10931125#define wc_MlDsaKey_VerifyCtx (key , sig , sigSz , ctx , ctxSz , msg , msgSz , res ) \
10941126 wc_dilithium_verify_ctx_msg(sig, sigSz, ctx, ctxSz, msg, msgSz, res, key)
10951127#define wc_MlDsaKey_VerifyCtxHash (key , sig , sigSz , ctx , ctxSz , hash , hashSz , \
0 commit comments