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

[dilithium] more tests

This commit is contained in:
Henry Case 2022-07-11 18:19:21 +01:00
parent ca857158ac
commit bed758a905

View File

@ -4,6 +4,10 @@
#include <gtest/gtest.h>
#include <pqc/pqc.h>
#include <random>
extern "C" {
#include "sign/dilithium/dilithium2/clean/reduce.h"
#include "sign/dilithium/dilithium2/clean/params.h"
}
TEST(KEM,OneOff) {
@ -73,3 +77,19 @@ TEST(KEMSIG,PrintSizes) {
std::cout << out.str() << std::endl;
}
}
TEST(Dilithium, MontREDC) {
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(0), 0);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(Q), 0);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(Q*100), 0);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(1), -114592);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-1), 114592);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(((uint64_t)Q<<31)-1), 114592);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-((int64_t)Q<<31)),0);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-((1ULL<<31)*(int64_t)Q)+1), -114592);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-(((int64_t)Q)<<31)+1), -114592);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce((uint64_t)1<<15), -523840);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce((uint64_t)1<<31), 4190209);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(3347556), 2070606);
ASSERT_EQ(PQCLEAN_DILITHIUM2_CLEAN_montgomery_reduce(-2581810), 910169);
}