1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-26 17:31:38 +00:00
pqcrypto/test/ut.cpp

47 lines
1.3 KiB
C++
Raw Normal View History

2021-03-24 10:25:45 +00:00
#include <algorithm>
#include <vector>
#include <gtest/gtest.h>
2021-03-24 23:34:34 +00:00
#include <pqc/pqc.h>
2021-03-24 10:25:45 +00:00
TEST(Kyber,KEMOneOff) {
2021-03-24 23:22:44 +00:00
for (int i=0; i<PQC_ALG_KEM_MAX; i++) {
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p = pqc_kem_alg_by_id(i);
2021-03-24 10:25:45 +00:00
2021-05-10 16:01:48 +01:00
std::vector<uint8_t> ct(pqc_ciphertext_bsz(p));
std::vector<uint8_t> ss1(pqc_shared_secret_bsz(p));
std::vector<uint8_t> ss2(pqc_shared_secret_bsz(p));
std::vector<uint8_t> sk(pqc_private_key_bsz(p));
std::vector<uint8_t> pk(pqc_public_key_bsz(p));
2021-03-24 10:25:45 +00:00
ASSERT_TRUE(
pqc_keygen(p, pk.data(), sk.data()));
ASSERT_TRUE(
pqc_kem_encapsulate(p, ct.data(), ss1.data(), pk.data()));
ASSERT_TRUE(
pqc_kem_decapsulate(p, ss2.data(), ct.data(), sk.data()));
ASSERT_TRUE(
std::equal(ss1.begin(), ss1.end(), ss2.begin()));
}
}
TEST(Kyber,SIGNOneOff) {
2021-03-24 23:22:44 +00:00
for (int i=0; i<PQC_ALG_SIG_MAX; i++) {
2021-05-10 16:01:48 +01:00
const pqc_ctx_t *p = pqc_sig_alg_by_id(i);
2021-03-24 10:25:45 +00:00
uint8_t msg[1234];
2021-05-10 16:01:48 +01:00
std::vector<uint8_t> sig(pqc_signature_bsz(p));
std::vector<uint8_t> sk(pqc_private_key_bsz(p));
std::vector<uint8_t> pk(pqc_public_key_bsz(p));
2021-03-24 10:25:45 +00:00
ASSERT_TRUE(
pqc_keygen(p, pk.data(), sk.data()));
uint64_t sigsz = sig.size();
ASSERT_TRUE(
pqc_sig_create(p, sig.data(), &sigsz, msg, 1234, sk.data()));
ASSERT_TRUE(
pqc_sig_verify(p, sig.data(), sigsz, msg, 1234, pk.data()));
}
}