forked from wolfSSL/wolfssl
Update Kyber APIs to ML-KEM APIs
- Change struct KyberKey to struct MlKemKey - Add backward compatibility typedef for KyberKey - Add function declarations for new wc_MlKemKey_ functions - Add backward compatibility #defines to map old wc_KyberKey APIs to new wc_MlKemKey APIs - Update wc_MlKemKey_Init to take key first and type second - Create new files wc_mlkem.h and wc_mlkem.c with updated content - Update internal APIs with lowercase kyberkey to lowercase mlkemkey Co-Authored-By: sean@wolfssl.com <sean@wolfssl.com>
This commit is contained in:
2107
wolfcrypt/src/wc_mlkem.c
Normal file
2107
wolfcrypt/src/wc_mlkem.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
/* wc_kyber.h
|
||||
/* wc_mlkem.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 wolfSSL Inc.
|
||||
*
|
||||
@ -20,12 +20,12 @@
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file wolfssl/wolfcrypt/wc_kyber.h
|
||||
\file wolfssl/wolfcrypt/wc_mlkem.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WOLF_CRYPT_WC_KYBER_H
|
||||
#define WOLF_CRYPT_WC_KYBER_H
|
||||
#ifndef WOLF_CRYPT_WC_MLKEM_H
|
||||
#define WOLF_CRYPT_WC_MLKEM_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
@ -98,8 +98,8 @@ enum {
|
||||
/* The data type of the pseudo-random function. */
|
||||
#define KYBER_PRF_T wc_Shake
|
||||
|
||||
/* Kyber key. */
|
||||
struct KyberKey {
|
||||
/* ML-KEM key. */
|
||||
struct MlKemKey {
|
||||
/* Type of key: KYBER512, KYBER768, KYBER1024 */
|
||||
int type;
|
||||
/* Dynamic memory allocation hint. */
|
||||
@ -136,6 +136,9 @@ struct KyberKey {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For backward compatibility */
|
||||
typedef struct MlKemKey KyberKey;
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_init(void);
|
||||
|
||||
@ -358,7 +361,53 @@ WOLFSSL_LOCAL unsigned int kyber_arm32_rej_uniform(sword16* p, unsigned int len,
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* ML-KEM API */
|
||||
WOLFSSL_API int wc_MlKemKey_Init(MlKemKey* key, int type);
|
||||
WOLFSSL_API void wc_MlKemKey_Free(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_PrivateKeySize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_PublicKeySize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_CipherTextSize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_SharedSecretSize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_MakeKey(MlKemKey* key, WC_RNG* rng);
|
||||
WOLFSSL_API int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, WC_RNG* rng,
|
||||
const byte* seed, word32 seedSz);
|
||||
WOLFSSL_API int wc_MlKemKey_Encapsulate(MlKemKey* key, WC_RNG* rng,
|
||||
byte* ct, word32 ctSz,
|
||||
byte* ss, word32 ssSz);
|
||||
WOLFSSL_API int wc_MlKemKey_EncapsulateWithRandom(MlKemKey* key, WC_RNG* rng,
|
||||
byte* ct, word32 ctSz,
|
||||
byte* ss, word32 ssSz,
|
||||
const byte* seed, word32 seedSz);
|
||||
WOLFSSL_API int wc_MlKemKey_Decapsulate(MlKemKey* key,
|
||||
byte* ss, word32 ssSz,
|
||||
const byte* ct, word32 ctSz);
|
||||
WOLFSSL_API int wc_MlKemKey_DecodePrivateKey(MlKemKey* key,
|
||||
const byte* priv, word32 privSz);
|
||||
WOLFSSL_API int wc_MlKemKey_DecodePublicKey(MlKemKey* key,
|
||||
const byte* pub, word32 pubSz);
|
||||
WOLFSSL_API int wc_MlKemKey_EncodePrivateKey(MlKemKey* key,
|
||||
byte* priv, word32 privSz);
|
||||
WOLFSSL_API int wc_MlKemKey_EncodePublicKey(MlKemKey* key,
|
||||
byte* pub, word32 pubSz);
|
||||
|
||||
/* Backward compatibility defines */
|
||||
#define wc_KyberKey_Init(type, key) wc_MlKemKey_Init((key), (type))
|
||||
#define wc_KyberKey_Free wc_MlKemKey_Free
|
||||
#define wc_KyberKey_PrivateKeySize wc_MlKemKey_PrivateKeySize
|
||||
#define wc_KyberKey_PublicKeySize wc_MlKemKey_PublicKeySize
|
||||
#define wc_KyberKey_CipherTextSize wc_MlKemKey_CipherTextSize
|
||||
#define wc_KyberKey_SharedSecretSize wc_MlKemKey_SharedSecretSize
|
||||
#define wc_KyberKey_MakeKey wc_MlKemKey_MakeKey
|
||||
#define wc_KyberKey_MakeKeyWithRandom wc_MlKemKey_MakeKeyWithRandom
|
||||
#define wc_KyberKey_Encapsulate wc_MlKemKey_Encapsulate
|
||||
#define wc_KyberKey_EncapsulateWithRandom wc_MlKemKey_EncapsulateWithRandom
|
||||
#define wc_KyberKey_Decapsulate wc_MlKemKey_Decapsulate
|
||||
#define wc_KyberKey_DecodePrivateKey wc_MlKemKey_DecodePrivateKey
|
||||
#define wc_KyberKey_DecodePublicKey wc_MlKemKey_DecodePublicKey
|
||||
#define wc_KyberKey_EncodePrivateKey wc_MlKemKey_EncodePrivateKey
|
||||
#define wc_KyberKey_EncodePublicKey wc_MlKemKey_EncodePublicKey
|
||||
|
||||
#endif /* WOLFSSL_HAVE_KYBER */
|
||||
|
||||
#endif /* WOLF_CRYPT_WC_KYBER_H */
|
||||
#endif /* WOLF_CRYPT_WC_MLKEM_H */
|
||||
|
||||
|
412
wolfssl/wolfcrypt/wc_mlkem.h
Normal file
412
wolfssl/wolfcrypt/wc_mlkem.h
Normal file
@ -0,0 +1,412 @@
|
||||
/* wc_mlkem.h
|
||||
*
|
||||
* Copyright (C) 2006-2025 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL.
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
/*!
|
||||
\file wolfssl/wolfcrypt/wc_mlkem.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef WOLF_CRYPT_WC_MLKEM_H
|
||||
#define WOLF_CRYPT_WC_MLKEM_H
|
||||
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
#include <wolfssl/wolfcrypt/sha3.h>
|
||||
#include <wolfssl/wolfcrypt/kyber.h>
|
||||
|
||||
#ifdef WOLFSSL_HAVE_KYBER
|
||||
|
||||
#ifdef noinline
|
||||
#define KYBER_NOINLINE noinline
|
||||
#elif defined(_MSC_VER)
|
||||
#define KYBER_NOINLINE __declspec(noinline)
|
||||
#elif defined(__GNUC__)
|
||||
#define KYBER_NOINLINE __attribute__((noinline))
|
||||
#else
|
||||
#define KYBER_NOINLINE
|
||||
#endif
|
||||
|
||||
enum {
|
||||
/* Flags of Kyber keys. */
|
||||
KYBER_FLAG_PRIV_SET = 0x0001,
|
||||
KYBER_FLAG_PUB_SET = 0x0002,
|
||||
KYBER_FLAG_BOTH_SET = 0x0003,
|
||||
KYBER_FLAG_H_SET = 0x0004,
|
||||
KYBER_FLAG_A_SET = 0x0008,
|
||||
|
||||
/* 2 bits of random used to create noise value. */
|
||||
KYBER_CBD_ETA2 = 2,
|
||||
/* 3 bits of random used to create noise value. */
|
||||
KYBER_CBD_ETA3 = 3,
|
||||
|
||||
/* Number of bits to compress to. */
|
||||
KYBER_COMP_4BITS = 4,
|
||||
KYBER_COMP_5BITS = 5,
|
||||
KYBER_COMP_10BITS = 10,
|
||||
KYBER_COMP_11BITS = 11,
|
||||
};
|
||||
|
||||
|
||||
/* SHAKE128 rate. */
|
||||
#define XOF_BLOCK_SIZE 168
|
||||
|
||||
/* Modulus of co-efficients of polynomial. */
|
||||
#define KYBER_Q 3329
|
||||
|
||||
|
||||
/* Kyber-512 parameters */
|
||||
#ifdef WOLFSSL_KYBER512
|
||||
/* Number of bits of random to create noise from. */
|
||||
#define KYBER512_ETA1 KYBER_CBD_ETA3
|
||||
#endif /* WOLFSSL_KYBER512 */
|
||||
|
||||
/* Kyber-768 parameters */
|
||||
#ifdef WOLFSSL_KYBER768
|
||||
/* Number of bits of random to create noise from. */
|
||||
#define KYBER768_ETA1 KYBER_CBD_ETA2
|
||||
#endif /* WOLFSSL_KYBER768 */
|
||||
|
||||
/* Kyber-1024 parameters */
|
||||
#ifdef WOLFSSL_KYBER1024
|
||||
/* Number of bits of random to create noise from. */
|
||||
#define KYBER1024_ETA1 KYBER_CBD_ETA2
|
||||
#endif /* WOLFSSL_KYBER1024 */
|
||||
|
||||
|
||||
|
||||
/* The data type of the hash function. */
|
||||
#define KYBER_HASH_T wc_Sha3
|
||||
|
||||
/* The data type of the pseudo-random function. */
|
||||
#define KYBER_PRF_T wc_Shake
|
||||
|
||||
/* ML-KEM key. */
|
||||
struct MlKemKey {
|
||||
/* Type of key: KYBER512, KYBER768, KYBER1024 */
|
||||
int type;
|
||||
/* Dynamic memory allocation hint. */
|
||||
void* heap;
|
||||
#if defined(WOLF_CRYPTO_CB)
|
||||
/* Device Id. */
|
||||
int devId;
|
||||
#endif
|
||||
/* Flags indicating what is stored in the key. */
|
||||
int flags;
|
||||
|
||||
/* A pseudo-random function object. */
|
||||
KYBER_HASH_T hash;
|
||||
/* A pseudo-random function object. */
|
||||
KYBER_PRF_T prf;
|
||||
|
||||
/* Private key as a vector. */
|
||||
sword16 priv[KYBER_MAX_K * KYBER_N];
|
||||
/* Public key as a vector. */
|
||||
sword16 pub[KYBER_MAX_K * KYBER_N];
|
||||
/* Public seed. */
|
||||
byte pubSeed[KYBER_SYM_SZ];
|
||||
/* Public hash - hash of encoded public key. */
|
||||
byte h[KYBER_SYM_SZ];
|
||||
/* Randomizer for decapsulation. */
|
||||
byte z[KYBER_SYM_SZ];
|
||||
#ifdef WOLFSSL_MLKEM_CACHE_A
|
||||
/* A matrix from key generation. */
|
||||
sword16 a[KYBER_MAX_K * KYBER_MAX_K * KYBER_N];
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For backward compatibility */
|
||||
typedef struct MlKemKey KyberKey;
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_init(void);
|
||||
|
||||
#ifndef WOLFSSL_MLKEM_MAKEKEY_SMALL_MEM
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_keygen(sword16* priv, sword16* pub, sword16* e, const sword16* a,
|
||||
int kp);
|
||||
#else
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_keygen_seeds(sword16* priv, sword16* pub, KYBER_PRF_T* prf,
|
||||
sword16* e, int kp, byte* seed, byte* noiseSeed);
|
||||
#endif
|
||||
#ifndef WOLFSSL_MLKEM_ENCAPSULATE_SMALL_MEM
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_encapsulate(const sword16* pub, sword16* bp, sword16* v,
|
||||
const sword16* at, sword16* sp, const sword16* ep, const sword16* epp,
|
||||
const sword16* m, int kp);
|
||||
#else
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_encapsulate_seeds(const sword16* pub, KYBER_PRF_T* prf, sword16* bp,
|
||||
sword16* tp, sword16* sp, int kp, const byte* msg, byte* seed,
|
||||
byte* coins);
|
||||
#endif
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decapsulate(const sword16* priv, sword16* mp, sword16* bp,
|
||||
const sword16* v, int kp);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_gen_matrix(KYBER_PRF_T* prf, sword16* a, int kp, byte* seed,
|
||||
int transposed);
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_get_noise(KYBER_PRF_T* prf, int kp, sword16* vec1, sword16* vec2,
|
||||
sword16* poly, byte* seed);
|
||||
|
||||
#if defined(USE_INTEL_SPEEDUP) || \
|
||||
(defined(WOLFSSL_ARMASM) && defined(__aarch64__))
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_kdf(byte* seed, int seedLen, byte* out, int outLen);
|
||||
#endif
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_hash_init(KYBER_HASH_T* hash);
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_hash_new(KYBER_HASH_T* hash, void* heap, int devId);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_hash_free(KYBER_HASH_T* hash);
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_hash256(wc_Sha3* hash, const byte* data, word32 dataLen, byte* out);
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_hash512(wc_Sha3* hash, const byte* data1, word32 data1Len,
|
||||
const byte* data2, word32 data2Len, byte* out);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_prf_init(KYBER_PRF_T* prf);
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_prf_new(KYBER_PRF_T* prf, void* heap, int devId);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_prf_free(KYBER_PRF_T* prf);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_cmp(const byte* a, const byte* b, int sz);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_vec_compress_10(byte* r, sword16* v, unsigned int kp);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_vec_compress_11(byte* r, sword16* v);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_vec_decompress_10(sword16* v, const unsigned char* b,
|
||||
unsigned int kp);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_vec_decompress_11(sword16* v, const unsigned char* b);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_compress_4(byte* b, sword16* p);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_compress_5(byte* b, sword16* p);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decompress_4(sword16* p, const unsigned char* b);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decompress_5(sword16* p, const unsigned char* b);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_from_msg(sword16* p, const byte* msg);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_to_msg(byte* msg, sword16* p);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_from_bytes(sword16* p, const byte* b, int k);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_to_bytes(byte* b, sword16* p, int k);
|
||||
|
||||
#ifdef USE_INTEL_SPEEDUP
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_keygen_avx2(sword16* priv, sword16* pub, sword16* e,
|
||||
const sword16* a, int kp);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_encapsulate_avx2(const sword16* pub, sword16* bp, sword16* v,
|
||||
const sword16* at, sword16* sp, const sword16* ep, const sword16* epp,
|
||||
const sword16* m, int kp);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decapsulate_avx2(const sword16* priv, sword16* mp, sword16* bp,
|
||||
const sword16* v, int kp);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
unsigned int kyber_rej_uniform_n_avx2(sword16* p, unsigned int len,
|
||||
const byte* r, unsigned int rLen);
|
||||
WOLFSSL_LOCAL
|
||||
unsigned int kyber_rej_uniform_avx2(sword16* p, unsigned int len, const byte* r,
|
||||
unsigned int rLen);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_redistribute_21_rand_avx2(const word64* s, byte* r0, byte* r1,
|
||||
byte* r2, byte* r3);
|
||||
void kyber_redistribute_17_rand_avx2(const word64* s, byte* r0, byte* r1,
|
||||
byte* r2, byte* r3);
|
||||
void kyber_redistribute_16_rand_avx2(const word64* s, byte* r0, byte* r1,
|
||||
byte* r2, byte* r3);
|
||||
void kyber_redistribute_8_rand_avx2(const word64* s, byte* r0, byte* r1,
|
||||
byte* r2, byte* r3);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_sha3_blocksx4_avx2(word64* s);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_sha3_128_blocksx4_seed_avx2(word64* s, byte* seed);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_sha3_256_blocksx4_seed_avx2(word64* s, byte* seed);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_cbd_eta2_avx2(sword16* p, const byte* r);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_cbd_eta3_avx2(sword16* p, const byte* r);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_from_msg_avx2(sword16* p, const byte* msg);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_to_msg_avx2(byte* msg, sword16* p);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_from_bytes_avx2(sword16* p, const byte* b);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_to_bytes_avx2(byte* b, sword16* p);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_compress_10_avx2(byte* r, const sword16* p, int n);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decompress_10_avx2(sword16* p, const byte* r, int n);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_compress_11_avx2(byte* r, const sword16* p, int n);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decompress_11_avx2(sword16* p, const byte* r, int n);
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_compress_4_avx2(byte* r, const sword16* p);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decompress_4_avx2(sword16* p, const byte* r);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_compress_5_avx2(byte* r, const sword16* p);
|
||||
WOLFSSL_LOCAL
|
||||
void kyber_decompress_5_avx2(sword16* p, const byte* r);
|
||||
|
||||
|
||||
WOLFSSL_LOCAL
|
||||
int kyber_cmp_avx2(const byte* a, const byte* b, int sz);
|
||||
#elif defined(__aarch64__) && defined(WOLFSSL_ARMASM)
|
||||
WOLFSSL_LOCAL void kyber_ntt(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_invntt(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_ntt_sqrdmlsh(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_invntt_sqrdmlsh(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_basemul_mont(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_basemul_mont_add(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_add_reduce(sword16* r, const sword16* a);
|
||||
WOLFSSL_LOCAL void kyber_add3_reduce(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_rsub_reduce(sword16* r, const sword16* a);
|
||||
WOLFSSL_LOCAL void kyber_to_mont(sword16* p);
|
||||
WOLFSSL_LOCAL void kyber_to_mont_sqrdmlsh(sword16* p);
|
||||
WOLFSSL_LOCAL void kyber_sha3_blocksx3_neon(word64* state);
|
||||
WOLFSSL_LOCAL void kyber_shake128_blocksx3_seed_neon(word64* state, byte* seed);
|
||||
WOLFSSL_LOCAL void kyber_shake256_blocksx3_seed_neon(word64* state, byte* seed);
|
||||
WOLFSSL_LOCAL unsigned int kyber_rej_uniform_neon(sword16* p, unsigned int len,
|
||||
const byte* r, unsigned int rLen);
|
||||
WOLFSSL_LOCAL int kyber_cmp_neon(const byte* a, const byte* b, int sz);
|
||||
WOLFSSL_LOCAL void kyber_csubq_neon(sword16* p);
|
||||
WOLFSSL_LOCAL void kyber_from_msg_neon(sword16* p, const byte* msg);
|
||||
WOLFSSL_LOCAL void kyber_to_msg_neon(byte* msg, sword16* p);
|
||||
#elif defined(WOLFSSL_ARMASM_THUMB2) && defined(WOLFSSL_ARMASM)
|
||||
#define kyber_ntt kyber_thumb2_ntt
|
||||
#define kyber_invntt kyber_thumb2_invntt
|
||||
#define kyber_basemul_mont kyber_thumb2_basemul_mont
|
||||
#define kyber_basemul_mont_add kyber_thumb2_basemul_mont_add
|
||||
#define kyber_rej_uniform_c kyber_thumb2_rej_uniform
|
||||
|
||||
WOLFSSL_LOCAL void kyber_thumb2_ntt(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_thumb2_invntt(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_thumb2_basemul_mont(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_thumb2_basemul_mont_add(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_thumb2_csubq(sword16* p);
|
||||
WOLFSSL_LOCAL unsigned int kyber_thumb2_rej_uniform(sword16* p,
|
||||
unsigned int len, const byte* r, unsigned int rLen);
|
||||
#elif defined(WOLFSSL_ARMASM)
|
||||
#define kyber_ntt kyber_arm32_ntt
|
||||
#define kyber_invntt kyber_arm32_invntt
|
||||
#define kyber_basemul_mont kyber_arm32_basemul_mont
|
||||
#define kyber_basemul_mont_add kyber_arm32_basemul_mont_add
|
||||
#define kyber_rej_uniform_c kyber_arm32_rej_uniform
|
||||
|
||||
WOLFSSL_LOCAL void kyber_arm32_ntt(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_arm32_invntt(sword16* r);
|
||||
WOLFSSL_LOCAL void kyber_arm32_basemul_mont(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_arm32_basemul_mont_add(sword16* r, const sword16* a,
|
||||
const sword16* b);
|
||||
WOLFSSL_LOCAL void kyber_arm32_csubq(sword16* p);
|
||||
WOLFSSL_LOCAL unsigned int kyber_arm32_rej_uniform(sword16* p, unsigned int len,
|
||||
const byte* r, unsigned int rLen);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
/* ML-KEM API */
|
||||
WOLFSSL_API int wc_MlKemKey_Init(MlKemKey* key, int type);
|
||||
WOLFSSL_API void wc_MlKemKey_Free(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_PrivateKeySize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_PublicKeySize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_CipherTextSize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_SharedSecretSize(MlKemKey* key);
|
||||
WOLFSSL_API int wc_MlKemKey_MakeKey(MlKemKey* key, WC_RNG* rng);
|
||||
WOLFSSL_API int wc_MlKemKey_MakeKeyWithRandom(MlKemKey* key, WC_RNG* rng,
|
||||
const byte* seed, word32 seedSz);
|
||||
WOLFSSL_API int wc_MlKemKey_Encapsulate(MlKemKey* key, WC_RNG* rng,
|
||||
byte* ct, word32 ctSz,
|
||||
byte* ss, word32 ssSz);
|
||||
WOLFSSL_API int wc_MlKemKey_EncapsulateWithRandom(MlKemKey* key, WC_RNG* rng,
|
||||
byte* ct, word32 ctSz,
|
||||
byte* ss, word32 ssSz,
|
||||
const byte* seed, word32 seedSz);
|
||||
WOLFSSL_API int wc_MlKemKey_Decapsulate(MlKemKey* key,
|
||||
byte* ss, word32 ssSz,
|
||||
const byte* ct, word32 ctSz);
|
||||
WOLFSSL_API int wc_MlKemKey_DecodePrivateKey(MlKemKey* key,
|
||||
const byte* priv, word32 privSz);
|
||||
WOLFSSL_API int wc_MlKemKey_DecodePublicKey(MlKemKey* key,
|
||||
const byte* pub, word32 pubSz);
|
||||
WOLFSSL_API int wc_MlKemKey_EncodePrivateKey(MlKemKey* key,
|
||||
byte* priv, word32 privSz);
|
||||
WOLFSSL_API int wc_MlKemKey_EncodePublicKey(MlKemKey* key,
|
||||
byte* pub, word32 pubSz);
|
||||
|
||||
/* Backward compatibility defines */
|
||||
#define wc_KyberKey_Init(type, key) wc_MlKemKey_Init((key), (type))
|
||||
#define wc_KyberKey_Free wc_MlKemKey_Free
|
||||
#define wc_KyberKey_PrivateKeySize wc_MlKemKey_PrivateKeySize
|
||||
#define wc_KyberKey_PublicKeySize wc_MlKemKey_PublicKeySize
|
||||
#define wc_KyberKey_CipherTextSize wc_MlKemKey_CipherTextSize
|
||||
#define wc_KyberKey_SharedSecretSize wc_MlKemKey_SharedSecretSize
|
||||
#define wc_KyberKey_MakeKey wc_MlKemKey_MakeKey
|
||||
#define wc_KyberKey_MakeKeyWithRandom wc_MlKemKey_MakeKeyWithRandom
|
||||
#define wc_KyberKey_Encapsulate wc_MlKemKey_Encapsulate
|
||||
#define wc_KyberKey_EncapsulateWithRandom wc_MlKemKey_EncapsulateWithRandom
|
||||
#define wc_KyberKey_Decapsulate wc_MlKemKey_Decapsulate
|
||||
#define wc_KyberKey_DecodePrivateKey wc_MlKemKey_DecodePrivateKey
|
||||
#define wc_KyberKey_DecodePublicKey wc_MlKemKey_DecodePublicKey
|
||||
#define wc_KyberKey_EncodePrivateKey wc_MlKemKey_EncodePrivateKey
|
||||
#define wc_KyberKey_EncodePublicKey wc_MlKemKey_EncodePublicKey
|
||||
|
||||
#endif /* WOLFSSL_HAVE_KYBER */
|
||||
|
||||
#endif /* WOLF_CRYPT_WC_MLKEM_H */
|
Reference in New Issue
Block a user