Kyber: fixes

Don't define WOLFSSL_HAVE_KYBER unless configured.
Only compile code in ext_kyber.c when WOLFSSL_HAVE_KYBER defined.
Include config.h and settings in ext_kyber.c. This allowed
HAVE_VISIBILITY to be defined.
Cleanup kyber.h.
This commit is contained in:
Sean Parkinson
2022-09-13 12:28:03 +10:00
committed by Anthony Hu
parent bcf4dbe697
commit 62c415fd50
3 changed files with 37 additions and 39 deletions

View File

@@ -19,6 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/ext_kyber.h> #include <wolfssl/wolfcrypt/ext_kyber.h>
#include <wolfssl/wolfcrypt/error-crypt.h> #include <wolfssl/wolfcrypt/error-crypt.h>
@@ -26,6 +31,8 @@
#error "KYBER-90s is not supported when building PQM4" #error "KYBER-90s is not supported when building PQM4"
#endif #endif
#ifdef WOLFSSL_HAVE_KYBER
#ifdef NO_INLINE #ifdef NO_INLINE
#include <wolfssl/wolfcrypt/misc.h> #include <wolfssl/wolfcrypt/misc.h>
#else #else
@@ -674,3 +681,4 @@ int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
return ret; return ret;
} }
#endif /* WOLFSSL_HAVE_KYBER */

View File

@@ -21,8 +21,7 @@
/*! /*!
\file wolfssl/wolfcrypt/kyber.h \file wolfssl/wolfcrypt/kyber.h
*/ */
#ifndef WOLF_CRYPT_KYBER_H #ifndef WOLF_CRYPT_KYBER_H
#define WOLF_CRYPT_KYBER_H #define WOLF_CRYPT_KYBER_H
@@ -152,17 +151,15 @@
#define KYBER_MAX_CIPHER_TEXT_SIZE KYBER512_CIPHER_TEXT_SIZE #define KYBER_MAX_CIPHER_TEXT_SIZE KYBER512_CIPHER_TEXT_SIZE
#endif #endif
enum { enum {
/* Types of Kyber keys. */ /* Types of Kyber keys. */
KYBER512 = 0, KYBER512 = 0,
KYBER768 = 1, KYBER768 = 1,
KYBER1024 = 2, KYBER1024 = 2,
KYBER_LEVEL1 = KYBER512, KYBER_LEVEL1 = KYBER512,
KYBER_LEVEL3 = KYBER768, KYBER_LEVEL3 = KYBER768,
KYBER_LEVEL5 = KYBER1024, KYBER_LEVEL5 = KYBER1024,
/* Symmetric data size. */ /* Symmetric data size. */
KYBER_SYM_SZ = 32, KYBER_SYM_SZ = 32,
@@ -174,53 +171,47 @@ enum {
KYBER_ENC_RAND_SZ = KYBER_SYM_SZ, KYBER_ENC_RAND_SZ = KYBER_SYM_SZ,
/* Encoded polynomial size. */ /* Encoded polynomial size. */
KYBER_POLY_SIZE = 384, KYBER_POLY_SIZE = 384,
}; };
/* Different structures for different implementations. */
typedef struct KyberKey KyberKey; typedef struct KyberKey KyberKey;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
WOLFSSL_API WOLFSSL_API int wc_KyberKey_Init(int type, KyberKey* key, void* heap,
int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId); int devId);
WOLFSSL_API WOLFSSL_API void wc_KyberKey_Free(KyberKey* key);
void wc_KyberKey_Free(KyberKey* key);
WOLFSSL_API WOLFSSL_API int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng);
int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng); WOLFSSL_API int wc_KyberKey_MakeKeyWithRandom(KyberKey* key,
WOLFSSL_API const unsigned char* rand, int len);
int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
int len);
WOLFSSL_API WOLFSSL_API int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len);
int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len); WOLFSSL_API int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len);
WOLFSSL_API
int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len);
WOLFSSL_API WOLFSSL_API int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct,
int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct,
unsigned char* ss, WC_RNG* rng); unsigned char* ss, WC_RNG* rng);
int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct, WOLFSSL_API int wc_KyberKey_EncapsulateWithRandom(KyberKey* key,
unsigned char* ss, const unsigned char* rand, int len); unsigned char* ct, unsigned char* ss, const unsigned char* rand, int len);
WOLFSSL_API int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss, WOLFSSL_API int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
const unsigned char* ct, word32 len); const unsigned char* ct, word32 len);
WOLFSSL_API WOLFSSL_API int wc_KyberKey_DecodePrivateKey(KyberKey* key, unsigned char* in,
int wc_KyberKey_DecodePrivateKey(KyberKey* key, unsigned char* in, word32 len); word32 len);
WOLFSSL_API WOLFSSL_API int wc_KyberKey_DecodePublicKey(KyberKey* key, unsigned char* in,
int wc_KyberKey_DecodePublicKey(KyberKey* key, unsigned char* in, word32 len); word32 len);
WOLFSSL_API
int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len);
WOLFSSL_API
int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len);
WOLFSSL_API
int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len);
WOLFSSL_API
int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len);
WOLFSSL_API int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len);
WOLFSSL_API int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len);
WOLFSSL_API int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out,
word32 len);
WOLFSSL_API int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out,
word32 len);
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */

View File

@@ -2734,7 +2734,6 @@ extern void uITRON4_free(void *p) ;
#define HAVE_DILITHIUM #define HAVE_DILITHIUM
#define HAVE_SPHINCS #define HAVE_SPHINCS
#define HAVE_KYBER #define HAVE_KYBER
#define WOLFSSL_HAVE_KYBER
#endif #endif
#ifdef HAVE_PQM4 #ifdef HAVE_PQM4