1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 15:39:07 +00:00

Add test for Z packing/unpacking

This commit is contained in:
Henry Case 2023-01-09 11:11:04 +00:00
parent c84c6aa8b4
commit 5af68581f8

View File

@ -6,6 +6,7 @@
#include <random> #include <random>
extern "C" { extern "C" {
#include "sign/dilithium/dilithium2/clean/reduce.h" #include "sign/dilithium/dilithium2/clean/reduce.h"
#include "sign/dilithium/dilithium2/clean/poly.h"
#include "sign/dilithium/dilithium2/clean/params.h" #include "sign/dilithium/dilithium2/clean/params.h"
} }
@ -93,3 +94,18 @@ TEST(Dilithium, MontREDC) {
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(3347556), 2070606); ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(3347556), 2070606);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-2581810), 910169); ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-2581810), 910169);
} }
TEST(Dilithium, PolyZ) {
std::random_device rd;
std::uniform_int_distribution<int32_t> dist_z(-((1<<17)-1), 1<<17);
uint8_t out[576];
poly p1, p2;
for (auto &x : p1.coeffs) { x = dist_z(rd); }
PQCLEAN_DILITHIUM2_CLEAN_polyz_pack(out, &p1);
PQCLEAN_DILITHIUM2_CLEAN_polyz_unpack(&p2, out);
for (size_t j=0; j<256; j++) {
ASSERT_EQ(p1.coeffs[j], p2.coeffs[j]);
}
}