@@ -232,6 +232,9 @@ def make_flags(prefix, fips):
232232 flags .append ("--enable-pwdbased" )
233233 flags .append ("--enable-pkcs7" )
234234
235+ # ML-KEM
236+ flags .append ("--enable-kyber" )
237+
235238 # disabling other configs enabled by default
236239 flags .append ("--disable-oldtls" )
237240 flags .append ("--disable-oldnames" )
@@ -442,6 +445,8 @@ def build_ffi(local_wolfssl, features):
442445 #include <wolfssl/wolfcrypt/curve25519.h>
443446 #include <wolfssl/wolfcrypt/poly1305.h>
444447 #include <wolfssl/wolfcrypt/chacha20_poly1305.h>
448+ #include <wolfssl/wolfcrypt/kyber.h>
449+ #include <wolfssl/wolfcrypt/wc_kyber.h>
445450 """
446451
447452 init_source_string = """
@@ -478,6 +483,7 @@ def build_ffi(local_wolfssl, features):
478483 int AESGCM_STREAM_ENABLED = """ + str (features ["AESGCM_STREAM" ]) + """;
479484 int RSA_PSS_ENABLED = """ + str (features ["RSA_PSS" ]) + """;
480485 int CHACHA20_POLY1305_ENABLED = """ + str (features ["CHACHA20_POLY1305" ]) + """;
486+ int ML_KEM_ENABLED = """ + str (features ["ML_KEM" ]) + """;
481487 """
482488
483489 ffibuilder .set_source ( "wolfcrypt._ffi" , init_source_string ,
@@ -513,6 +519,7 @@ def build_ffi(local_wolfssl, features):
513519 extern int AESGCM_STREAM_ENABLED;
514520 extern int RSA_PSS_ENABLED;
515521 extern int CHACHA20_POLY1305_ENABLED;
522+ extern int ML_KEM_ENABLED;
516523
517524 typedef unsigned char byte;
518525 typedef unsigned int word32;
@@ -922,6 +929,30 @@ def build_ffi(local_wolfssl, features):
922929 int wolfCrypt_GetPrivateKeyReadEnable_fips(enum wc_KeyType);
923930 """
924931
932+ if features ["ML_KEM" ]:
933+ cdef += """
934+ static const int WC_ML_KEM_512;
935+ static const int WC_ML_KEM_768;
936+ static const int WC_ML_KEM_1024;
937+ static const int INVALID_DEVID;
938+ typedef struct {...; } KyberKey;
939+ int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len);
940+ int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len);
941+ int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len);
942+ int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len);
943+ int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId);
944+ void wc_KyberKey_Free(KyberKey* key);
945+ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng);
946+ int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand, int len);
947+ int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len);
948+ int wc_KyberKey_DecodePublicKey(KyberKey* key, const unsigned char* in, word32 len);
949+ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss, WC_RNG* rng);
950+ int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct, unsigned char* ss, const unsigned char* rand, int len);
951+ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss, const unsigned char* ct, word32 len);
952+ int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len);
953+ int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in, word32 len);
954+ """
955+
925956 ffibuilder .cdef (cdef )
926957
927958def main (ffibuilder ):
@@ -951,7 +982,8 @@ def main(ffibuilder):
951982 "WC_RNG_SEED_CB" : 0 ,
952983 "AESGCM_STREAM" : 1 ,
953984 "RSA_PSS" : 1 ,
954- "CHACHA20_POLY1305" : 1
985+ "CHACHA20_POLY1305" : 1 ,
986+ "ML_KEM" : 1
955987 }
956988
957989 # Ed448 requires SHAKE256, which isn't part of the Windows build, yet.
0 commit comments