diff --git a/wolfcrypt/src/ext_kyber.c b/wolfcrypt/src/ext_kyber.c index 6fbfc000e..3246de0fc 100644 --- a/wolfcrypt/src/ext_kyber.c +++ b/wolfcrypt/src/ext_kyber.c @@ -25,6 +25,7 @@ #include #include +#include #ifdef WOLFSSL_HAVE_KYBER #include @@ -304,8 +305,11 @@ int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len) int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng) { int ret = 0; +#ifdef HAVE_LIBOQS const char* algName = NULL; OQS_KEM *kem = NULL; +#endif + (void)rng; /* Validate parameter. */ @@ -339,6 +343,7 @@ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng) ret = BAD_FUNC_ARG; } } + OQS_KEM_free(kem); #endif /* HAVE_LIBOQS */ #ifdef HAVE_PQM4 if (ret == 0) { @@ -353,8 +358,6 @@ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng) ForceZero(key, sizeof(*key)); } - OQS_KEM_free(kem); - return ret; } @@ -394,8 +397,11 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss, WC_RNG* rng) { int ret = 0; +#ifdef HAVE_LIBOQS const char * algName = NULL; OQS_KEM *kem = NULL; +#endif + (void)rng; /* Validate parameters. */ @@ -421,6 +427,8 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss, ret = BAD_FUNC_ARG; } } + + OQS_KEM_free(kem); #endif /* HAVE_LIBOQS */ #ifdef HAVE_PQM4 if (ret == 0) { @@ -431,8 +439,6 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss, } #endif /* HAVE_PQM4 */ - OQS_KEM_free(kem); - return ret; } @@ -477,9 +483,11 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss, const unsigned char* ct, word32 len) { int ret = 0; - const char * algName = NULL; word32 ctlen = 0; +#ifdef HAVE_LIBOQS + const char * algName = NULL; OQS_KEM *kem = NULL; +#endif /* Validate parameters. */ if ((key == NULL) || (ss == NULL) || (ct == NULL)) { @@ -510,18 +518,18 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss, ret = BAD_FUNC_ARG; } } + + OQS_KEM_free(kem); #endif /* HAVE_LIBOQS */ #ifdef HAVE_PQM4 if (ret == 0) { - if (crypto_kem_enc(ss, ct, key->priv) != 0) { + if (crypto_kem_dec(ss, ct, key->priv) != 0) { WOLFSSL_MSG("PQM4 Decapsulation failure."); ret = BAD_FUNC_ARG; } } #endif /* HAVE_PQM4 */ - OQS_KEM_free(kem); - return ret; } diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 152f09ebb..0e399ae1f 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -2811,6 +2811,8 @@ extern void uITRON4_free(void *p) ; #define HAVE_PQC #define WOLFSSL_HAVE_KYBER #define WOLFSSL_KYBER512 +#define WOLFSSL_NO_KYBER768 +#define WOLFSSL_NO_KYBER1024 #endif #if defined(HAVE_PQC) && !defined(HAVE_LIBOQS) && !defined(HAVE_PQM4) && \