forked from wolfSSL/wolfssl
Update wc_KyberKey API to wc_MlKem
Co-Authored-By: sean@wolfssl.com <sean@wolfssl.com>
This commit is contained in:
46
src/tls.c
46
src/tls.c
@ -8133,7 +8133,7 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse)
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_Init(type, kem, ssl->heap, ssl->devId);
|
||||
ret = wc_MlKem_Init(type, kem, ssl->heap, ssl->devId);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("Failed to initialize Kyber Key.");
|
||||
}
|
||||
@ -8151,10 +8151,10 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse)
|
||||
if (ret == 0) {
|
||||
XMEMSET(ecc_kse, 0, sizeof(*ecc_kse));
|
||||
|
||||
ret = wc_KyberKey_PrivateKeySize(kem, &privSz);
|
||||
ret = wc_MlKem_PrivateKeySize(kem, &privSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PublicKeySize(kem, &pubSz);
|
||||
ret = wc_MlKem_PublicKeySize(kem, &pubSz);
|
||||
}
|
||||
|
||||
if (ret == 0 && ecc_group != 0) {
|
||||
@ -8181,17 +8181,17 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse)
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_MakeKey(kem, ssl->rng);
|
||||
ret = wc_MlKem_MakeKey(kem, ssl->rng);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("Kyber keygen failure");
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_EncodePublicKey(kem, pubKey + ecc_kse->pubKeyLen,
|
||||
ret = wc_MlKem_EncodePublicKey(kem, pubKey + ecc_kse->pubKeyLen,
|
||||
pubSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_EncodePrivateKey(kem, privKey, privSz);
|
||||
ret = wc_MlKem_EncodePrivateKey(kem, privKey, privSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
if (ecc_kse->pubKeyLen > 0)
|
||||
@ -8217,7 +8217,7 @@ static int TLSX_KeyShare_GenPqcKey(WOLFSSL *ssl, KeyShareEntry* kse)
|
||||
WOLFSSL_BUFFER(kse->pubKey, kse->pubKeyLen );
|
||||
#endif
|
||||
|
||||
wc_KyberKey_Free(kem);
|
||||
wc_MlKem_Free(kem);
|
||||
TLSX_KeyShare_FreeAll(ecc_kse, ssl->heap);
|
||||
XFREE(pubKey, ssl->heap, DYNAMIC_TYPE_PUBLIC_KEY);
|
||||
XFREE(privKey, ssl->heap, DYNAMIC_TYPE_PRIVATE_KEY);
|
||||
@ -8887,7 +8887,7 @@ static int TLSX_KeyShare_ProcessPqc(WOLFSSL* ssl, KeyShareEntry* keyShareEntry)
|
||||
return BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
ret = wc_KyberKey_Init(type, kem, ssl->heap, ssl->devId);
|
||||
ret = wc_MlKem_Init(type, kem, ssl->heap, ssl->devId);
|
||||
if (ret != 0) {
|
||||
wc_ecc_free(&eccpubkey);
|
||||
WOLFSSL_MSG("Error creating Kyber KEM");
|
||||
@ -8895,7 +8895,7 @@ static int TLSX_KeyShare_ProcessPqc(WOLFSSL* ssl, KeyShareEntry* keyShareEntry)
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_SharedSecretSize(kem, &ssSz);
|
||||
ret = wc_MlKem_SharedSecretSize(kem, &ssSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
sharedSecretLen = ssSz;
|
||||
@ -8925,19 +8925,19 @@ static int TLSX_KeyShare_ProcessPqc(WOLFSSL* ssl, KeyShareEntry* keyShareEntry)
|
||||
}
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_CipherTextSize(kem, &ctSz);
|
||||
ret = wc_MlKem_CipherTextSize(kem, &ctSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PrivateKeySize(kem, &privSz);
|
||||
ret = wc_MlKem_PrivateKeySize(kem, &privSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_DecodePrivateKey(kem, keyShareEntry->privKey, privSz);
|
||||
ret = wc_MlKem_DecodePrivateKey(kem, keyShareEntry->privKey, privSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_Decapsulate(kem, sharedSecret + outlen,
|
||||
ret = wc_MlKem_Decapsulate(kem, sharedSecret + outlen,
|
||||
keyShareEntry->ke + keyShareEntry->keLen - ctSz, ctSz);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("wc_KyberKey decapsulation failure.");
|
||||
WOLFSSL_MSG("wc_MlKem decapsulation failure.");
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
}
|
||||
@ -8990,7 +8990,7 @@ static int TLSX_KeyShare_ProcessPqc(WOLFSSL* ssl, KeyShareEntry* keyShareEntry)
|
||||
XFREE(sharedSecret, ssl->heap, DYNAMIC_TYPE_SECRET);
|
||||
|
||||
wc_ecc_free(&eccpubkey);
|
||||
wc_KyberKey_Free(kem);
|
||||
wc_MlKem_Free(kem);
|
||||
return ret;
|
||||
}
|
||||
#endif /* WOLFSSL_HAVE_KYBER */
|
||||
@ -9379,7 +9379,7 @@ static int server_generate_pqc_ciphertext(WOLFSSL* ssl,
|
||||
return MEMORY_E;
|
||||
}
|
||||
|
||||
ret = wc_KyberKey_Init(type, kem, ssl->heap, ssl->devId);
|
||||
ret = wc_MlKem_Init(type, kem, ssl->heap, ssl->devId);
|
||||
if (ret != 0) {
|
||||
wc_ecc_free(&eccpubkey);
|
||||
WOLFSSL_MSG("Error creating Kyber KEM");
|
||||
@ -9406,13 +9406,13 @@ static int server_generate_pqc_ciphertext(WOLFSSL* ssl,
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PublicKeySize(kem, &pubSz);
|
||||
ret = wc_MlKem_PublicKeySize(kem, &pubSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_CipherTextSize(kem, &ctSz);
|
||||
ret = wc_MlKem_CipherTextSize(kem, &ctSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_SharedSecretSize(kem, &ssSz);
|
||||
ret = wc_MlKem_SharedSecretSize(kem, &ssSz);
|
||||
}
|
||||
|
||||
if (ret == 0 && len != pubSz + ecc_kse->pubKeyLen) {
|
||||
@ -9464,14 +9464,14 @@ static int server_generate_pqc_ciphertext(WOLFSSL* ssl,
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_DecodePublicKey(kem, data + ecc_kse->pubKeyLen,
|
||||
ret = wc_MlKem_DecodePublicKey(kem, data + ecc_kse->pubKeyLen,
|
||||
pubSz);
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_Encapsulate(kem, ciphertext + ecc_kse->pubKeyLen,
|
||||
ret = wc_MlKem_Encapsulate(kem, ciphertext + ecc_kse->pubKeyLen,
|
||||
sharedSecret + outlen, ssl->rng);
|
||||
if (ret != 0) {
|
||||
WOLFSSL_MSG("wc_KyberKey encapsulation failure.");
|
||||
WOLFSSL_MSG("wc_MlKem encapsulation failure.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -9497,7 +9497,7 @@ static int server_generate_pqc_ciphertext(WOLFSSL* ssl,
|
||||
XFREE(sharedSecret, ssl->heap, DYNAMIC_TYPE_SECRET);
|
||||
XFREE(ciphertext, ssl->heap, DYNAMIC_TYPE_TLSX);
|
||||
wc_ecc_free(&eccpubkey);
|
||||
wc_KyberKey_Free(kem);
|
||||
wc_MlKem_Free(kem);
|
||||
return ret;
|
||||
}
|
||||
#endif /* WOLFSSL_HAVE_KYBER */
|
||||
|
78
tests/api.c
78
tests/api.c
@ -26996,40 +26996,40 @@ static int test_wc_kyber_make_key_kats(void)
|
||||
}
|
||||
|
||||
#ifndef WOLFSSL_NO_ML_KEM_512
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_512, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_512, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_MakeKeyWithRandom(key, seed_512, sizeof(seed_512)),
|
||||
0);
|
||||
ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
|
||||
ExpectIntEQ(wc_MlKem_EncodePublicKey(key, pubKey,
|
||||
WC_ML_KEM_512_PUBLIC_KEY_SIZE), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
|
||||
ExpectIntEQ(wc_MlKem_EncodePrivateKey(key, privKey,
|
||||
WC_ML_KEM_512_PRIVATE_KEY_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, ek_512, WC_ML_KEM_512_PUBLIC_KEY_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, dk_512, WC_ML_KEM_512_PRIVATE_KEY_SIZE), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM_768
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_768, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_768, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_MakeKeyWithRandom(key, seed_768, sizeof(seed_768)),
|
||||
0);
|
||||
ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
|
||||
ExpectIntEQ(wc_MlKem_EncodePublicKey(key, pubKey,
|
||||
WC_ML_KEM_768_PUBLIC_KEY_SIZE), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
|
||||
ExpectIntEQ(wc_MlKem_EncodePrivateKey(key, privKey,
|
||||
WC_ML_KEM_768_PRIVATE_KEY_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, ek_768, WC_ML_KEM_768_PUBLIC_KEY_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, dk_768, WC_ML_KEM_768_PRIVATE_KEY_SIZE), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM_1024
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_1024, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_MakeKeyWithRandom(key, seed_1024,
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_1024, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_MakeKeyWithRandom(key, seed_1024,
|
||||
sizeof(seed_1024)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncodePublicKey(key, pubKey,
|
||||
ExpectIntEQ(wc_MlKem_EncodePublicKey(key, pubKey,
|
||||
WC_ML_KEM_1024_PUBLIC_KEY_SIZE), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncodePrivateKey(key, privKey,
|
||||
ExpectIntEQ(wc_MlKem_EncodePrivateKey(key, privKey,
|
||||
WC_ML_KEM_1024_PRIVATE_KEY_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(pubKey, ek_1024, WC_ML_KEM_1024_PUBLIC_KEY_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(privKey, dk_1024, WC_ML_KEM_1024_PRIVATE_KEY_SIZE), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
@ -27979,31 +27979,31 @@ static int test_wc_kyber_encapsulate_kats(void)
|
||||
}
|
||||
|
||||
#ifndef WOLFSSL_NO_ML_KEM_512
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_512, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_512,
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_512, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_DecodePublicKey(key, ek_512, sizeof(ek_512)), 0);
|
||||
ExpectIntEQ(wc_MlKem_EncapsulateWithRandom(key, ct, ss, seed_512,
|
||||
sizeof(seed_512)), 0);
|
||||
ExpectIntEQ(XMEMCMP(ct, c_512, WC_ML_KEM_512_CIPHER_TEXT_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(ss, k_512, WC_ML_KEM_SS_SZ), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM_768
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_768, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_768,
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_768, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_DecodePublicKey(key, ek_768, sizeof(ek_768)), 0);
|
||||
ExpectIntEQ(wc_MlKem_EncapsulateWithRandom(key, ct, ss, seed_768,
|
||||
sizeof(seed_768)), 0);
|
||||
ExpectIntEQ(XMEMCMP(ct, c_768, WC_ML_KEM_768_CIPHER_TEXT_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(ss, k_768, WC_ML_KEM_SS_SZ), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM_1024
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_1024, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_EncapsulateWithRandom(key, ct, ss, seed_1024,
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_1024, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_DecodePublicKey(key, ek_1024, sizeof(ek_1024)), 0);
|
||||
ExpectIntEQ(wc_MlKem_EncapsulateWithRandom(key, ct, ss, seed_1024,
|
||||
sizeof(seed_1024)), 0);
|
||||
ExpectIntEQ(XMEMCMP(ct, c_1024, WC_ML_KEM_1024_CIPHER_TEXT_SIZE), 0);
|
||||
ExpectIntEQ(XMEMCMP(ss, k_1024, WC_ML_KEM_SS_SZ), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
@ -29390,25 +29390,25 @@ static int test_wc_kyber_decapsulate_kats(void)
|
||||
}
|
||||
|
||||
#ifndef WOLFSSL_NO_ML_KEM_512
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_512, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_512, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_DecodePrivateKey(key, dk_512, sizeof(dk_512)), 0);
|
||||
ExpectIntEQ(wc_MlKem_Decapsulate(key, ss, c_512, sizeof(c_512)), 0);
|
||||
ExpectIntEQ(XMEMCMP(ss, kprime_512, WC_ML_KEM_SS_SZ), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM_768
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_768, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_768, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_DecodePrivateKey(key, dk_768, sizeof(dk_768)), 0);
|
||||
ExpectIntEQ(wc_MlKem_Decapsulate(key, ss, c_768, sizeof(c_768)), 0);
|
||||
ExpectIntEQ(XMEMCMP(ss, kprime_768, WC_ML_KEM_SS_SZ), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM_1024
|
||||
ExpectIntEQ(wc_KyberKey_Init(WC_ML_KEM_1024, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_KyberKey_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
|
||||
ExpectIntEQ(wc_KyberKey_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
|
||||
ExpectIntEQ(wc_MlKem_Init(WC_ML_KEM_1024, key, NULL, INVALID_DEVID), 0);
|
||||
ExpectIntEQ(wc_MlKem_DecodePrivateKey(key, dk_1024, sizeof(dk_1024)), 0);
|
||||
ExpectIntEQ(wc_MlKem_Decapsulate(key, ss, c_1024, sizeof(c_1024)), 0);
|
||||
ExpectIntEQ(XMEMCMP(ss, kprime_1024, WC_ML_KEM_SS_SZ), 0);
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
#endif
|
||||
|
||||
XFREE(key, NULL, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
|
@ -9666,16 +9666,16 @@ static void bench_kyber_keygen(int type, const char* name, int keySize,
|
||||
do {
|
||||
/* while free pending slots in queue, submit ops */
|
||||
for (times = 0; times < agreeTimes || pending > 0; times++) {
|
||||
wc_KyberKey_Free(key);
|
||||
ret = wc_KyberKey_Init(type, key, HEAP_HINT, INVALID_DEVID);
|
||||
wc_MlKem_Free(key);
|
||||
ret = wc_MlKem_Init(type, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
goto exit;
|
||||
|
||||
#ifdef KYBER_NONDETERMINISTIC
|
||||
ret = wc_KyberKey_MakeKey(key, &gRng);
|
||||
ret = wc_MlKem_MakeKey(key, &gRng);
|
||||
#else
|
||||
unsigned char rand[KYBER_MAKEKEY_RAND_SZ] = {0,};
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, rand, sizeof(rand));
|
||||
#endif
|
||||
if (ret != 0)
|
||||
goto exit;
|
||||
@ -9708,24 +9708,24 @@ static void bench_kyber_encap(int type, const char* name, int keySize,
|
||||
word32 ctSz;
|
||||
DECLARE_MULTI_VALUE_STATS_VARS()
|
||||
|
||||
ret = wc_KyberKey_PublicKeySize(key1, &pubLen);
|
||||
ret = wc_MlKem_PublicKeySize(key1, &pubLen);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
ret = wc_KyberKey_EncodePublicKey(key1, pub, pubLen);
|
||||
ret = wc_MlKem_EncodePublicKey(key1, pub, pubLen);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
ret = wc_KyberKey_Init(type, key2, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(type, key2, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
ret = wc_KyberKey_DecodePublicKey(key2, pub, pubLen);
|
||||
ret = wc_MlKem_DecodePublicKey(key2, pub, pubLen);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ret = wc_KyberKey_CipherTextSize(key2, &ctSz);
|
||||
ret = wc_MlKem_CipherTextSize(key2, &ctSz);
|
||||
if (ret != 0) {
|
||||
return;
|
||||
}
|
||||
@ -9736,10 +9736,10 @@ static void bench_kyber_encap(int type, const char* name, int keySize,
|
||||
/* while free pending slots in queue, submit ops */
|
||||
for (times = 0; times < agreeTimes || pending > 0; times++) {
|
||||
#ifdef KYBER_NONDETERMINISTIC
|
||||
ret = wc_KyberKey_Encapsulate(key2, ct, ss, &gRng);
|
||||
ret = wc_MlKem_Encapsulate(key2, ct, ss, &gRng);
|
||||
#else
|
||||
unsigned char rand[KYBER_ENC_RAND_SZ] = {0,};
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key2, ct, ss, rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key2, ct, ss, rand,
|
||||
sizeof(rand));
|
||||
#endif
|
||||
if (ret != 0)
|
||||
@ -9766,7 +9766,7 @@ exit_encap:
|
||||
do {
|
||||
/* while free pending slots in queue, submit ops */
|
||||
for (times = 0; times < agreeTimes || pending > 0; times++) {
|
||||
ret = wc_KyberKey_Decapsulate(key1, ss, ct, ctSz);
|
||||
ret = wc_MlKem_Decapsulate(key1, ss, ct, ctSz);
|
||||
if (ret != 0)
|
||||
goto exit_decap;
|
||||
RECORD_MULTI_VALUE_STATS();
|
||||
@ -9838,8 +9838,8 @@ void bench_kyber(int type)
|
||||
bench_kyber_keygen(type, name, keySize, &key1);
|
||||
bench_kyber_encap(type, name, keySize, &key1, &key2);
|
||||
|
||||
wc_KyberKey_Free(&key2);
|
||||
wc_KyberKey_Free(&key1);
|
||||
wc_MlKem_Free(&key2);
|
||||
wc_MlKem_Free(&key1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -79,7 +79,7 @@ int ext_kyber_enabled(int id)
|
||||
* @return BAD_FUNC_ARG when key is NULL or type is unrecognized.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId)
|
||||
int wc_MlKem_Init(int type, KyberKey* key, void* heap, int devId)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -135,7 +135,7 @@ int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId)
|
||||
*
|
||||
* @param [in, out] key Kyber key object to dispose of.
|
||||
*/
|
||||
void wc_KyberKey_Free(KyberKey* key)
|
||||
void wc_MlKem_Free(KyberKey* key)
|
||||
{
|
||||
if (key != NULL) {
|
||||
/* Ensure all private data is zeroed. */
|
||||
@ -155,7 +155,7 @@ void wc_KyberKey_Free(KyberKey* key)
|
||||
* @return BAD_FUNC_ARG when key or len is NULL.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_PrivateKeySize(KyberKey* key, word32* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -210,7 +210,7 @@ int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len)
|
||||
* @return BAD_FUNC_ARG when key or len is NULL.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_PublicKeySize(KyberKey* key, word32* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -265,7 +265,7 @@ int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len)
|
||||
* @return BAD_FUNC_ARG when key or len is NULL.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_CipherTextSize(KyberKey* key, word32* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -319,7 +319,7 @@ int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len)
|
||||
* @return 0 on success.
|
||||
* @return 0 to indicate success.
|
||||
*/
|
||||
int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_SharedSecretSize(KyberKey* key, word32* len)
|
||||
{
|
||||
(void)key;
|
||||
/* Validate parameters. */
|
||||
@ -346,7 +346,7 @@ int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len)
|
||||
* @return BAD_FUNC_ARG when key or rng is NULL.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
int wc_MlKem_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
{
|
||||
int ret = 0;
|
||||
#ifdef HAVE_LIBOQS
|
||||
@ -418,13 +418,13 @@ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
|
||||
int wc_MlKem_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
|
||||
int len)
|
||||
{
|
||||
(void)rand;
|
||||
(void)len;
|
||||
/* OQS doesn't support external randomness. */
|
||||
return wc_KyberKey_MakeKey(key, NULL);
|
||||
return wc_MlKem_MakeKey(key, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -439,7 +439,7 @@ int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
int wc_MlKem_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
WC_RNG* rng)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -460,7 +460,7 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
|
||||
#ifdef WOLF_CRYPTO_CB
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_CipherTextSize(key, &ctlen);
|
||||
ret = wc_MlKem_CipherTextSize(key, &ctlen);
|
||||
}
|
||||
if ((ret == 0)
|
||||
#ifndef WOLF_CRYPTO_CB_FIND
|
||||
@ -517,13 +517,13 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
int wc_MlKem_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
unsigned char* ss, const unsigned char* rand, int len)
|
||||
{
|
||||
(void)rand;
|
||||
(void)len;
|
||||
/* OQS doesn't support external randomness. */
|
||||
return wc_KyberKey_Encapsulate(key, ct, ss, NULL);
|
||||
return wc_MlKem_Encapsulate(key, ct, ss, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -541,7 +541,7 @@ int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
* @return BUFFER_E when len is not the length of cipher text for the key type.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
int wc_MlKem_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
const unsigned char* ct, word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -556,7 +556,7 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_CipherTextSize(key, &ctlen);
|
||||
ret = wc_MlKem_CipherTextSize(key, &ctlen);
|
||||
}
|
||||
if ((ret == 0) && (len != ctlen)) {
|
||||
ret = BUFFER_E;
|
||||
@ -621,7 +621,7 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return BUFFER_E when len is not the correct size.
|
||||
*/
|
||||
int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
int wc_MlKem_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -633,7 +633,7 @@ int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PrivateKeySize(key, &privLen);
|
||||
ret = wc_MlKem_PrivateKeySize(key, &privLen);
|
||||
}
|
||||
|
||||
/* Ensure the data is the correct length for the key type. */
|
||||
@ -661,7 +661,7 @@ int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return BUFFER_E when len is not the correct size.
|
||||
*/
|
||||
int wc_KyberKey_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
int wc_MlKem_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -673,7 +673,7 @@ int wc_KyberKey_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PublicKeySize(key, &pubLen);
|
||||
ret = wc_MlKem_PublicKeySize(key, &pubLen);
|
||||
}
|
||||
|
||||
/* Ensure the data is the correct length for the key type. */
|
||||
@ -701,7 +701,7 @@ int wc_KyberKey_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
* available.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
int wc_MlKem_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int privLen = 0;
|
||||
@ -711,7 +711,7 @@ int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PrivateKeySize(key, &privLen);
|
||||
ret = wc_MlKem_PrivateKeySize(key, &privLen);
|
||||
}
|
||||
|
||||
/* Check buffer is big enough for encoding. */
|
||||
@ -738,7 +738,7 @@ int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
* @return BAD_FUNC_ARG when key or out is NULL or public key not available.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
int wc_MlKem_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int pubLen = 0;
|
||||
@ -748,7 +748,7 @@ int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_KyberKey_PublicKeySize(key, &pubLen);
|
||||
ret = wc_MlKem_PublicKeySize(key, &pubLen);
|
||||
}
|
||||
|
||||
/* Check buffer is big enough for encoding. */
|
||||
|
@ -106,7 +106,7 @@ volatile sword16 kyber_opt_blocker = 0;
|
||||
* @return BAD_FUNC_ARG when key is NULL or type is unrecognized.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId)
|
||||
int wc_MlKem_Init(int type, KyberKey* key, void* heap, int devId)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -197,7 +197,7 @@ int wc_KyberKey_Init(int type, KyberKey* key, void* heap, int devId)
|
||||
*
|
||||
* @param [in, out] key Kyber key object to dispose of.
|
||||
*/
|
||||
void wc_KyberKey_Free(KyberKey* key)
|
||||
void wc_MlKem_Free(KyberKey* key)
|
||||
{
|
||||
if (key != NULL) {
|
||||
/* Dispose of PRF object. */
|
||||
@ -220,7 +220,7 @@ void wc_KyberKey_Free(KyberKey* key)
|
||||
* @return BAD_FUNC_ARG when key or rng is NULL.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
int wc_MlKem_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned char rand[KYBER_MAKEKEY_RAND_SZ];
|
||||
@ -240,7 +240,7 @@ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
}
|
||||
if (ret == 0) {
|
||||
/* Make a key pair from the random. */
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, rand, sizeof(rand));
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, rand, sizeof(rand));
|
||||
}
|
||||
|
||||
/* Ensure seeds are zeroized. */
|
||||
@ -261,7 +261,7 @@ int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng)
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
|
||||
int wc_MlKem_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
|
||||
int len)
|
||||
{
|
||||
byte buf[2 * KYBER_SYM_SZ + 1];
|
||||
@ -453,7 +453,7 @@ int wc_KyberKey_MakeKeyWithRandom(KyberKey* key, const unsigned char* rand,
|
||||
* @return BAD_FUNC_ARG when key or len is NULL.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_CipherTextSize(KyberKey* key, word32* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -517,7 +517,7 @@ int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len)
|
||||
* @return 0 on success.
|
||||
* @return 0 to indicate success.
|
||||
*/
|
||||
int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_SharedSecretSize(KyberKey* key, word32* len)
|
||||
{
|
||||
(void)key;
|
||||
|
||||
@ -734,7 +734,7 @@ static int kyberkey_encapsulate(KyberKey* key, const byte* msg, byte* coins,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
int wc_MlKem_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
WC_RNG* rng)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -751,7 +751,7 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
}
|
||||
if (ret == 0) {
|
||||
/* Encapsulate with the random. */
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, rand,
|
||||
sizeof(rand));
|
||||
}
|
||||
|
||||
@ -771,7 +771,7 @@ int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct, unsigned char* ss,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
int wc_MlKem_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
unsigned char* ss, const unsigned char* rand, int len)
|
||||
{
|
||||
#ifdef WOLFSSL_KYBER_ORIGINAL
|
||||
@ -842,7 +842,7 @@ int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
|
||||
#ifndef WOLFSSL_NO_MALLOC
|
||||
/* Determine how big an encoded public key will be. */
|
||||
ret = wc_KyberKey_PublicKeySize(key, &pubKeyLen);
|
||||
ret = wc_MlKem_PublicKeySize(key, &pubKeyLen);
|
||||
if (ret == 0) {
|
||||
/* Allocate dynamic memory for encoded public key. */
|
||||
pubKey = (byte*)XMALLOC(pubKeyLen, key->heap,
|
||||
@ -854,7 +854,7 @@ int wc_KyberKey_EncapsulateWithRandom(KyberKey* key, unsigned char* ct,
|
||||
if (ret == 0) {
|
||||
#endif
|
||||
/* Encode public key - h is hash of encoded public key. */
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pubKey, pubKeyLen);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pubKey, pubKeyLen);
|
||||
#ifndef WOLFSSL_NO_MALLOC
|
||||
}
|
||||
/* Dispose of encoded public key. */
|
||||
@ -1119,7 +1119,7 @@ static int kyber_derive_secret(const byte* z, const byte* ct, word32 ctSz,
|
||||
* @return BUFFER_E when len is not the length of cipher text for the key type.
|
||||
* @return MEMORY_E when dynamic memory allocation failed.
|
||||
*/
|
||||
int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
int wc_MlKem_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
const unsigned char* ct, word32 len)
|
||||
{
|
||||
byte msg[KYBER_SYM_SZ];
|
||||
@ -1274,7 +1274,7 @@ int wc_KyberKey_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return BUFFER_E when len is not the correct size.
|
||||
*/
|
||||
int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
int wc_MlKem_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -1354,7 +1354,7 @@ int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
p += k * KYBER_POLY_SIZE;
|
||||
|
||||
/* Decode the public key that is after the private key. */
|
||||
ret = wc_KyberKey_DecodePublicKey(key, p, pubLen);
|
||||
ret = wc_MlKem_DecodePublicKey(key, p, pubLen);
|
||||
}
|
||||
if (ret == 0) {
|
||||
/* Skip over public key. */
|
||||
@ -1384,7 +1384,7 @@ int wc_KyberKey_DecodePrivateKey(KyberKey* key, const unsigned char* in,
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
* @return BUFFER_E when len is not the correct size.
|
||||
*/
|
||||
int wc_KyberKey_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
int wc_MlKem_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -1481,7 +1481,7 @@ int wc_KyberKey_DecodePublicKey(KyberKey* key, const unsigned char* in,
|
||||
* @return BAD_FUNC_ARG when key or len is NULL.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_PrivateKeySize(KyberKey* key, word32* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -1547,7 +1547,7 @@ int wc_KyberKey_PrivateKeySize(KyberKey* key, word32* len)
|
||||
* @return BAD_FUNC_ARG when key or len is NULL.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len)
|
||||
int wc_MlKem_PublicKeySize(KyberKey* key, word32* len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -1617,7 +1617,7 @@ int wc_KyberKey_PublicKeySize(KyberKey* key, word32* len)
|
||||
* available.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
int wc_MlKem_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int k = 0;
|
||||
@ -1698,7 +1698,7 @@ int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
p += KYBER_POLY_SIZE * k;
|
||||
|
||||
/* Encode public key. */
|
||||
ret = wc_KyberKey_EncodePublicKey(key, p, pubLen);
|
||||
ret = wc_MlKem_EncodePublicKey(key, p, pubLen);
|
||||
p += pubLen;
|
||||
}
|
||||
/* Ensure hash of public key is available. */
|
||||
@ -1730,7 +1730,7 @@ int wc_KyberKey_EncodePrivateKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
* @return BAD_FUNC_ARG when key or out is NULL or public key not available.
|
||||
* @return NOT_COMPILED_IN when key type is not supported.
|
||||
*/
|
||||
int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
int wc_MlKem_EncodePublicKey(KyberKey* key, unsigned char* out, word32 len)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int k = 0;
|
||||
|
@ -39515,22 +39515,22 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_KYBER_ORIGINAL
|
||||
ret = wc_KyberKey_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(KYBER512, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, kyber512_rand,
|
||||
sizeof(kyber512_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, KYBER512_PUBLIC_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv, KYBER512_PRIVATE_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -39540,7 +39540,7 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
if (XMEMCMP(priv, kyber512_sk, sizeof(kyber512_sk)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
|
||||
sizeof(kyber512enc_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -39551,7 +39551,7 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
if (XMEMCMP(ss, kyber512_ss, sizeof(kyber512_ss)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, sizeof(kyber512_ct));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -39559,22 +39559,22 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM
|
||||
ret = wc_KyberKey_Init(WC_ML_KEM_512, key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(WC_ML_KEM_512, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, kyber512_rand,
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, kyber512_rand,
|
||||
sizeof(kyber512_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_512_PUBLIC_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, WC_ML_KEM_512_PUBLIC_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv,
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv,
|
||||
WC_ML_KEM_512_PRIVATE_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -39585,7 +39585,7 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
if (XMEMCMP(priv, ml_kem_512_sk, sizeof(ml_kem_512_sk)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, kyber512enc_rand,
|
||||
sizeof(kyber512enc_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -39596,7 +39596,7 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
if (XMEMCMP(ss, ml_kem_512_ss, sizeof(ml_kem_512_ss)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_512_ct));
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_512_ct));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -39607,7 +39607,7 @@ static wc_test_ret_t kyber512_kat(void)
|
||||
out:
|
||||
|
||||
if (key_inited)
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
@ -40887,22 +40887,22 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_KYBER_ORIGINAL
|
||||
ret = wc_KyberKey_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(KYBER768, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, kyber768_rand,
|
||||
sizeof(kyber768_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, KYBER768_PUBLIC_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv, KYBER768_PRIVATE_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -40912,7 +40912,7 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
if (XMEMCMP(priv, kyber768_sk, sizeof(kyber768_sk)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
|
||||
sizeof(kyber768enc_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -40923,7 +40923,7 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
if (XMEMCMP(ss, kyber768_ss, sizeof(kyber768_ss)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, sizeof(kyber768_ct));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -40931,22 +40931,22 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM
|
||||
ret = wc_KyberKey_Init(WC_ML_KEM_768, key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(WC_ML_KEM_768, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, kyber768_rand,
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, kyber768_rand,
|
||||
sizeof(kyber768_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_768_PUBLIC_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, WC_ML_KEM_768_PUBLIC_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv,
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv,
|
||||
WC_ML_KEM_768_PRIVATE_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -40957,7 +40957,7 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
if (XMEMCMP(priv, ml_kem_768_sk, sizeof(ml_kem_768_sk)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, kyber768enc_rand,
|
||||
sizeof(kyber768enc_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -40968,7 +40968,7 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
if (XMEMCMP(ss, ml_kem_768_ss, sizeof(ml_kem_768_ss)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_768_ct));
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_768_ct));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -40979,7 +40979,7 @@ static wc_test_ret_t kyber768_kat(void)
|
||||
out:
|
||||
|
||||
if (key_inited)
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
@ -42666,22 +42666,22 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_KYBER_ORIGINAL
|
||||
ret = wc_KyberKey_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(KYBER1024, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, kyber1024_rand,
|
||||
sizeof(kyber1024_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, KYBER_MAX_PUBLIC_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv, KYBER_MAX_PRIVATE_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -42691,7 +42691,7 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
if (XMEMCMP(priv, kyber1024_sk, sizeof(kyber1024_sk)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
|
||||
sizeof(kyber1024enc_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -42702,7 +42702,7 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
if (XMEMCMP(ss, kyber1024_ss, sizeof(kyber1024_ss)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, sizeof(kyber1024_ct));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -42710,22 +42710,22 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
#endif
|
||||
#ifndef WOLFSSL_NO_ML_KEM
|
||||
ret = wc_KyberKey_Init(WC_ML_KEM_1024, key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(WC_ML_KEM_1024, key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKeyWithRandom(key, kyber1024_rand,
|
||||
ret = wc_MlKem_MakeKeyWithRandom(key, kyber1024_rand,
|
||||
sizeof(kyber1024_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, WC_ML_KEM_MAX_PUBLIC_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv,
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv,
|
||||
WC_ML_KEM_MAX_PRIVATE_KEY_SIZE);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -42736,7 +42736,7 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
if (XMEMCMP(priv, ml_kem_1024_sk, sizeof(ml_kem_1024_sk)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
|
||||
ret = wc_MlKem_EncapsulateWithRandom(key, ct, ss, kyber1024enc_rand,
|
||||
sizeof(kyber1024enc_rand));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
@ -42747,7 +42747,7 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
if (XMEMCMP(ss, ml_kem_1024_ss, sizeof(ml_kem_1024_ss)) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_1024_ct));
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, sizeof(ml_kem_1024_ct));
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
@ -42758,7 +42758,7 @@ static wc_test_ret_t kyber1024_kat(void)
|
||||
out:
|
||||
|
||||
if (key_inited)
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
@ -42862,59 +42862,59 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||
|
||||
for (i = 0; i < (int)(sizeof(testData) / sizeof(*testData)); i++) {
|
||||
ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
else
|
||||
key_inited = 1;
|
||||
|
||||
ret = wc_KyberKey_MakeKey(key, &rng);
|
||||
ret = wc_MlKem_MakeKey(key, &rng);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub, testData[i][2]);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub, testData[i][2]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv, testData[i][1]);
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv, testData[i][1]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_DecodePublicKey(key, pub, testData[i][2]);
|
||||
ret = wc_MlKem_DecodePublicKey(key, pub, testData[i][2]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_Encapsulate(key, ct, ss, &rng);
|
||||
ret = wc_MlKem_Encapsulate(key, ct, ss, &rng);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePublicKey(key, pub2, testData[i][2]);
|
||||
ret = wc_MlKem_EncodePublicKey(key, pub2, testData[i][2]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
if (XMEMCMP(pub, pub2, testData[i][2]) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
|
||||
ret = wc_MlKem_Init(testData[i][0], key, HEAP_HINT, INVALID_DEVID);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_DecodePrivateKey(key, priv, testData[i][1]);
|
||||
ret = wc_MlKem_DecodePrivateKey(key, priv, testData[i][1]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_Decapsulate(key, ss_dec, ct, testData[i][3]);
|
||||
ret = wc_MlKem_Decapsulate(key, ss_dec, ct, testData[i][3]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
if (XMEMCMP(ss, ss_dec, KYBER_SS_SZ) != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
ret = wc_KyberKey_EncodePrivateKey(key, priv2, testData[i][1]);
|
||||
ret = wc_MlKem_EncodePrivateKey(key, priv2, testData[i][1]);
|
||||
if (ret != 0)
|
||||
ERROR_OUT(WC_TEST_RET_ENC_I(i), out);
|
||||
|
||||
@ -42945,7 +42945,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t kyber_test(void)
|
||||
out:
|
||||
|
||||
if (key_inited)
|
||||
wc_KyberKey_Free(key);
|
||||
wc_MlKem_Free(key);
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||
|
@ -188,34 +188,34 @@ typedef struct KyberKey KyberKey;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WOLFSSL_API int wc_KyberKey_Init(int type, KyberKey* key, void* heap,
|
||||
WOLFSSL_API int wc_MlKem_Init(int type, KyberKey* key, void* heap,
|
||||
int devId);
|
||||
WOLFSSL_API void wc_KyberKey_Free(KyberKey* key);
|
||||
WOLFSSL_API void wc_MlKem_Free(KyberKey* key);
|
||||
|
||||
WOLFSSL_API int wc_KyberKey_MakeKey(KyberKey* key, WC_RNG* rng);
|
||||
WOLFSSL_API int wc_KyberKey_MakeKeyWithRandom(KyberKey* key,
|
||||
WOLFSSL_API int wc_MlKem_MakeKey(KyberKey* key, WC_RNG* rng);
|
||||
WOLFSSL_API int wc_MlKem_MakeKeyWithRandom(KyberKey* key,
|
||||
const unsigned char* rand, int len);
|
||||
|
||||
WOLFSSL_API int wc_KyberKey_CipherTextSize(KyberKey* key, word32* len);
|
||||
WOLFSSL_API int wc_KyberKey_SharedSecretSize(KyberKey* key, word32* len);
|
||||
WOLFSSL_API int wc_MlKem_CipherTextSize(KyberKey* key, word32* len);
|
||||
WOLFSSL_API int wc_MlKem_SharedSecretSize(KyberKey* key, word32* len);
|
||||
|
||||
WOLFSSL_API int wc_KyberKey_Encapsulate(KyberKey* key, unsigned char* ct,
|
||||
WOLFSSL_API int wc_MlKem_Encapsulate(KyberKey* key, unsigned char* ct,
|
||||
unsigned char* ss, WC_RNG* rng);
|
||||
WOLFSSL_API int wc_KyberKey_EncapsulateWithRandom(KyberKey* key,
|
||||
WOLFSSL_API int wc_MlKem_EncapsulateWithRandom(KyberKey* key,
|
||||
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_MlKem_Decapsulate(KyberKey* key, unsigned char* ss,
|
||||
const unsigned char* ct, word32 len);
|
||||
|
||||
WOLFSSL_API int wc_KyberKey_DecodePrivateKey(KyberKey* key,
|
||||
WOLFSSL_API int wc_MlKem_DecodePrivateKey(KyberKey* key,
|
||||
const unsigned char* in, word32 len);
|
||||
WOLFSSL_API int wc_KyberKey_DecodePublicKey(KyberKey* key,
|
||||
WOLFSSL_API int wc_MlKem_DecodePublicKey(KyberKey* key,
|
||||
const unsigned char* in, 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,
|
||||
WOLFSSL_API int wc_MlKem_PrivateKeySize(KyberKey* key, word32* len);
|
||||
WOLFSSL_API int wc_MlKem_PublicKeySize(KyberKey* key, word32* len);
|
||||
WOLFSSL_API int wc_MlKem_EncodePrivateKey(KyberKey* key, unsigned char* out,
|
||||
word32 len);
|
||||
WOLFSSL_API int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out,
|
||||
WOLFSSL_API int wc_MlKem_EncodePublicKey(KyberKey* key, unsigned char* out,
|
||||
word32 len);
|
||||
|
||||
|
||||
@ -271,21 +271,21 @@ WOLFSSL_API int wc_KyberKey_EncodePublicKey(KyberKey* key, unsigned char* out,
|
||||
#define MlKemKey KyberKey
|
||||
|
||||
#define wc_MlKemKey_Init(key, type, heap, devId) \
|
||||
wc_KyberKey_Init(type, key, heap, devId)
|
||||
#define wc_MlKemKey_Free wc_KyberKey_Free
|
||||
#define wc_MlKemKey_MakeKey wc_KyberKey_MakeKey
|
||||
#define wc_MlKemKey_MakeKeyWithRandom wc_KyberKey_MakeKeyWithRandom
|
||||
#define wc_MlKemKey_CipherTextSize wc_KyberKey_CipherTextSize
|
||||
#define wc_MlKemKey_SharedSecretSize wc_KyberKey_SharedSecretSize
|
||||
#define wc_MlKemKey_Encapsulate wc_KyberKey_Encapsulate
|
||||
#define wc_MlKemKey_EncapsulateWithRandom wc_KyberKey_EncapsulateWithRandom
|
||||
#define wc_MlKemKey_Decapsulate wc_KyberKey_Decapsulate
|
||||
#define wc_MlKemKey_DecodePrivateKey wc_KyberKey_DecodePrivateKey
|
||||
#define wc_MlKemKey_DecodePublicKey wc_KyberKey_DecodePublicKey
|
||||
#define wc_MlKemKey_PrivateKeySize wc_KyberKey_PrivateKeySize
|
||||
#define wc_MlKemKey_PublicKeySize wc_KyberKey_PublicKeySize
|
||||
#define wc_MlKemKey_EncodePrivateKey wc_KyberKey_EncodePrivateKey
|
||||
#define wc_MlKemKey_EncodePublicKey wc_KyberKey_EncodePublicKey
|
||||
wc_MlKem_Init(type, key, heap, devId)
|
||||
#define wc_MlKemKey_Free wc_MlKem_Free
|
||||
#define wc_MlKemKey_MakeKey wc_MlKem_MakeKey
|
||||
#define wc_MlKemKey_MakeKeyWithRandom wc_MlKem_MakeKeyWithRandom
|
||||
#define wc_MlKemKey_CipherTextSize wc_MlKem_CipherTextSize
|
||||
#define wc_MlKemKey_SharedSecretSize wc_MlKem_SharedSecretSize
|
||||
#define wc_MlKemKey_Encapsulate wc_MlKem_Encapsulate
|
||||
#define wc_MlKemKey_EncapsulateWithRandom wc_MlKem_EncapsulateWithRandom
|
||||
#define wc_MlKemKey_Decapsulate wc_MlKem_Decapsulate
|
||||
#define wc_MlKemKey_DecodePrivateKey wc_MlKem_DecodePrivateKey
|
||||
#define wc_MlKemKey_DecodePublicKey wc_MlKem_DecodePublicKey
|
||||
#define wc_MlKemKey_PrivateKeySize wc_MlKem_PrivateKeySize
|
||||
#define wc_MlKemKey_PublicKeySize wc_MlKem_PublicKeySize
|
||||
#define wc_MlKemKey_EncodePrivateKey wc_MlKem_EncodePrivateKey
|
||||
#define wc_MlKemKey_EncodePublicKey wc_MlKem_EncodePublicKey
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Reference in New Issue
Block a user