@@ -235,6 +235,9 @@ def make_flags(prefix, fips):
235235 # ML-KEM
236236 flags .append ("--enable-kyber" )
237237
238+ # ML-DSA
239+ flags .append ("--enable-dilithium" )
240+
238241 # disabling other configs enabled by default
239242 flags .append ("--disable-oldtls" )
240243 flags .append ("--disable-oldnames" )
@@ -371,6 +374,7 @@ def get_features(local_wolfssl, features):
371374 features ["AESGCM_STREAM" ] = 1 if '#define WOLFSSL_AESGCM_STREAM' in defines else 0
372375 features ["RSA_PSS" ] = 1 if '#define WC_RSA_PSS' in defines else 0
373376 features ["CHACHA20_POLY1305" ] = 1 if '#define HAVE_CHACHA' and '#define HAVE_POLY1305' in defines else 0
377+ features ["ML_DSA" ] = 1 if '#define HAVE_DILITHIUM' in defines else 0
374378
375379 if '#define HAVE_FIPS' in defines :
376380 if not fips :
@@ -447,6 +451,7 @@ def build_ffi(local_wolfssl, features):
447451 #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
448452 #include <wolfssl/wolfcrypt/kyber.h>
449453 #include <wolfssl/wolfcrypt/wc_kyber.h>
454+ #include <wolfssl/wolfcrypt/dilithium.h>
450455 """
451456
452457 init_source_string = """
@@ -484,6 +489,7 @@ def build_ffi(local_wolfssl, features):
484489 int RSA_PSS_ENABLED = """ + str (features ["RSA_PSS" ]) + """;
485490 int CHACHA20_POLY1305_ENABLED = """ + str (features ["CHACHA20_POLY1305" ]) + """;
486491 int ML_KEM_ENABLED = """ + str (features ["ML_KEM" ]) + """;
492+ int ML_DSA_ENABLED = """ + str (features ["ML_DSA" ]) + """;
487493 """
488494
489495 ffibuilder .set_source ( "wolfcrypt._ffi" , init_source_string ,
@@ -520,6 +526,7 @@ def build_ffi(local_wolfssl, features):
520526 extern int RSA_PSS_ENABLED;
521527 extern int CHACHA20_POLY1305_ENABLED;
522528 extern int ML_KEM_ENABLED;
529+ extern int ML_DSA_ENABLED;
523530
524531 typedef unsigned char byte;
525532 typedef unsigned int word32;
@@ -929,12 +936,16 @@ def build_ffi(local_wolfssl, features):
929936 int wolfCrypt_GetPrivateKeyReadEnable_fips(enum wc_KeyType);
930937 """
931938
939+ if features ["ML_KEM" ] or features ["ML_DSA" ]:
940+ cdef += """
941+ static const int INVALID_DEVID;
942+ """
943+
932944 if features ["ML_KEM" ]:
933945 cdef += """
934946 static const int WC_ML_KEM_512;
935947 static const int WC_ML_KEM_768;
936948 static const int WC_ML_KEM_1024;
937- static const int INVALID_DEVID;
938949 typedef struct {...; } KyberKey;
939950 int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len);
940951 int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len);
@@ -950,7 +961,29 @@ def build_ffi(local_wolfssl, features):
950961 int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct, unsigned char* ss, const unsigned char* rand, int len);
951962 int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss, const unsigned char* ct, word32 len);
952963 int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len);
953- int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in, word32 len);
964+ int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in, word32 len);
965+ """
966+
967+ if features ["ML_DSA" ]:
968+ cdef += """
969+ static const int WC_ML_DSA_44;
970+ static const int WC_ML_DSA_65;
971+ static const int WC_ML_DSA_87;
972+ typedef struct {...; } dilithium_key;
973+ int wc_dilithium_init_ex(dilithium_key* key, void* heap, int devId);
974+ int wc_dilithium_set_level(dilithium_key* key, byte level);
975+ void wc_dilithium_free(dilithium_key* key);
976+ int wc_dilithium_make_key(dilithium_key* key, WC_RNG* rng);
977+ int wc_dilithium_export_private(dilithium_key* key, byte* out, word32* outLen);
978+ int wc_dilithium_import_private(const byte* priv, word32 privSz, dilithium_key* key);
979+ int wc_dilithium_export_public(dilithium_key* key, byte* out, word32* outLen);
980+ int wc_dilithium_import_public(const byte* in, word32 inLen, dilithium_key* key);
981+ int wc_dilithium_sign_msg(const byte* msg, word32 msgLen, byte* sig, word32* sigLen, dilithium_key* key, WC_RNG* rng);
982+ int wc_dilithium_verify_msg(const byte* sig, word32 sigLen, const byte* msg, word32 msgLen, int* res, dilithium_key* key);
983+ typedef dilithium_key MlDsaKey;
984+ int wc_MlDsaKey_GetPrivLen(MlDsaKey* key, int* len);
985+ int wc_MlDsaKey_GetPubLen(MlDsaKey* key, int* len);
986+ int wc_MlDsaKey_GetSigLen(MlDsaKey* key, int* len);
954987 """
955988
956989 ffibuilder .cdef (cdef )
@@ -983,7 +1016,8 @@ def main(ffibuilder):
9831016 "AESGCM_STREAM" : 1 ,
9841017 "RSA_PSS" : 1 ,
9851018 "CHACHA20_POLY1305" : 1 ,
986- "ML_KEM" : 1
1019+ "ML_KEM" : 1 ,
1020+ "ML_DSA" : 1
9871021 }
9881022
9891023 # Ed448 requires SHAKE256, which isn't part of the Windows build, yet.
0 commit comments