forked from wolfSSL/wolfssl
Merge pull request #6131 from anhu/STM32_kyber
Changes that make kyber work on STM32
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/logging.h>
|
||||
|
||||
#ifdef WOLFSSL_HAVE_KYBER
|
||||
#include <wolfssl/wolfcrypt/ext_kyber.h>
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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) && \
|
||||
|
Reference in New Issue
Block a user