Skip to content

Commit

Permalink
transforms and multiply_ntt work
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmucb committed Apr 27, 2024
1 parent d2acd81 commit 113db5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion v2/kyber/kyber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ bool ntt_inv(int g, coefficient_vector& in, coefficient_vector* out) {
bool multiply_ntt(int g, coefficient_vector& in1, coefficient_vector& in2,
coefficient_vector* out) {
int zeta;
for (int j = 0; j < in1.len_ / 2; j += 2) {
for (int j = 0; j < in1.len_; j += 2) {
int k =((int) bit_reverse((j/2)) >> 1);
k = 2 * k + 1;
zeta = exp_in_ntt(in1.q_, k, g);
Expand Down
18 changes: 17 additions & 1 deletion v2/kyber/test_kyber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ bool test_kyber_support() {
return false;
}

int prod = 1;
// int gamma[128];
for (int i = 0; i < 128; i++) {
int z;
Expand All @@ -630,9 +631,10 @@ bool test_kyber_support() {
printf("g: %d, i: %3d, bit_rev(7,i): %3d, 2 * bitrev(i) + 1: %3d, g^(%3d): %4d\n",
g, i, ((int) bit_reverse(i) >> 1), k, k, z);
}
prod = (z * prod) % p.q_;
}
if (FLAGS_print_all) {
printf("\n");
printf("prod: %d\n\n", prod);
}

// check that f x h (in normal domain) = ntt_inv(f_ntt x h_ntt)) where mult is in ntt_domain
Expand Down Expand Up @@ -711,7 +713,20 @@ bool test_kyber_support() {
print_coefficient_vector(product);
printf("\n");
}
if (!coefficient_vector_zero(&f)) {
return false;
}
if (!coefficient_vector_zero(&h)) {
return false;
}
if (!coefficient_vector_zero(&product)) {
return false;
}

#if 0
f.c_[0] = 1;
h.c_[0] = 1;
#else
for (int i = 0; i < f.len_; i++) {
/*
f.c_[i] = i;
Expand All @@ -720,6 +735,7 @@ bool test_kyber_support() {
f.c_[i] = 1;
h.c_[i] = 1;
}
#endif
if (!ntt(g, f, &f_ntt)) {
printf("f x h ntt transform fails\n");
return false;
Expand Down

0 comments on commit 113db5a

Please sign in to comment.