Skip to content

Commit

Permalink
pretty print
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmucb committed Apr 15, 2024
1 parent 6b9b65a commit 36db9f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 8 additions & 4 deletions v2/kyber/kyber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,10 @@ bool ntt(short int g, coefficient_vector& in, coefficient_vector* out) {
k++;
for (int j = 0; j < s + l; j++) {
short int t = (z * read_ntt(out->c_, j+l)) % in.q_;
write_ntt(j + l, (read_ntt(out->c_, j) - t) % in.q_, out->c_);
write_ntt(j, (read_ntt(out->c_, j) + t) % in.q_, out->c_);
short int s1 = (in.q_ + read_ntt(out->c_, j) - t) % in.q_;
write_ntt(j + l, s1, out->c_);
short int s2 = (in.q_ + (read_ntt(out->c_, j) + t) % in.q_) % in.q_;
write_ntt(j, s2, out->c_);
}
}
}
Expand All @@ -629,8 +631,10 @@ bool ntt_inv(short int g, coefficient_vector& in, coefficient_vector* out) {
k--;
for (int j = s; j < s + l; j += 2 * l) {
short int t = read_ntt(out->c_, j);
write_ntt(j, (t + read_ntt(out->c_, j + l)) % in.q_, out->c_);
write_ntt(j + l, (in.q_ + (z * read_ntt(out->c_, j + l)) - t )% in.q_, out->c_);
short int s1 = (in.q_ + (z * read_ntt(out->c_, j + l)) - t ) % in.q_;
write_ntt(j, s1, out->c_);
short int s2 = (in.q_ + ((z * read_ntt(out->c_, j + l) % in.q_)) - t ) % in.q_;
write_ntt(j + l, s2, out->c_);
}
}
}
Expand Down
23 changes: 19 additions & 4 deletions v2/kyber/test_kyber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool test_kyber_support() {
}

int bb_len = 16;
byte bb[bb_len] = {
byte bb[16] = {
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
};
Expand Down Expand Up @@ -365,6 +365,9 @@ bool test_kyber_support() {
printf("Cant zero ntt_inv_out");
return false;
}
for (int i = 0; i < p.n_; i++) {
ntt_in.c_[i] = i;
}
if (!ntt(g, ntt_in, &ntt_out)) {
printf("Could not ntt transfom\n");
return false;
Expand All @@ -374,17 +377,29 @@ bool test_kyber_support() {
return false;
}
if (FLAGS_print_all) {
printf("ntt in: ");
printf("\nntt in: \n");
printf(" ");
print_coefficient_vector(ntt_in);
printf("\n");
printf("ntt out: ");
printf("\nntt out:\n");
printf(" ");
print_coefficient_vector(ntt_out);
printf("\n");
printf("ntt inv out: ");
printf("\nntt inv out: \n");
printf(" ");
print_coefficient_vector(ntt_inv_out);
printf("\n");
}

#if 0
for (int i = 0; i < 256; i++) {
if (ntt_in.c_[i] != ntt_inv_out.c_[i]) {
printf("input and ntt_inv(ntt(input)) do not match at %d\n", i);
return false;
}
}
#endif

/*
if (!ntt_add(coefficient_vector& in1, coefficient_vector& in2, coefficient_vector* out)) {
printf("Could not inverse ntt_add\n");
Expand Down

0 comments on commit 36db9f0

Please sign in to comment.