Browse Source

Add test for Z packing/unpacking

pull/25/head
Henry Case 1 year ago
parent
commit
5af68581f8
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      test/ut.cpp

+ 16
- 0
test/ut.cpp View File

@@ -6,6 +6,7 @@
#include <random>
extern "C" {
#include "sign/dilithium/dilithium2/clean/reduce.h"
#include "sign/dilithium/dilithium2/clean/poly.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(-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]);
}
}

Loading…
Cancel
Save