Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmucb committed Apr 5, 2024
1 parent 468228e commit 8d168b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
17 changes: 11 additions & 6 deletions v2/dilithium/dilithium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ bool c_from_h(int size_in, byte* H, int* c) {


// A is R_q[k*l]
// t is module coefficient vector of length l
// t is module coefficient vector of length k
// s1 is module coefficient vector of length l
// s2 is module coefficient vector of length k
bool dilithium_keygen(dilithium_parameters& params, module_array* A,
Expand All @@ -463,13 +463,15 @@ bool dilithium_keygen(dilithium_parameters& params, module_array* A,
// s1: dim l, s2: dim k
// tv = As1 (dim k)
// t := tv + s2 (dim k)
if (t->dim_ != params.k_ || s1->dim_ != params.l_ || s2->dim_ != params.k_)
if (t->dim_ != params.k_ || s1->dim_ != params.l_ || s2->dim_ != params.k_) {
printf("keygen dims wrong, t: %d, s1: %d, s2: %d, k: %d, l: %d\n",
t->dim_, s1->dim_, s2->dim_, params.k_, params.l_);
return false;
}

module_vector tv(params.q_, params.n_, params.k_);

for (int r = 0; r < params.k_; r++) {
for (int c = 0; c < params.l_; r++) {
for (int c = 0; c < params.l_; c++) {
for (int k = 0; k < params.n_; k++) {
int s = 0;
int l = crypto_get_random_bytes(3, (byte*)&s);
Expand All @@ -482,21 +484,24 @@ bool dilithium_keygen(dilithium_parameters& params, module_array* A,
// (s_1, s_2) := S_eta^l x S_eta^k
for (int ll = 0; ll < s1->dim_; ll++) {
if (!rand_coefficient(params.eta_, *(s1->c_[ll]))) {
printf("rand_coefficient failed on s1\n");
return false;
}
}

for (int ll = 0; ll < s1->dim_; ll++) {
for (int ll = 0; ll < s2->dim_; ll++) {
if (!rand_coefficient(params.eta_, *(s2->c_[ll]))) {
printf("rand_coefficient failed on s2\n");
return false;
}
}

if (!module_apply_array(*A, *s1, &tv)) {
printf("module_apply_array failed\n");
return false;
}
// t := As_1 + s_2
if (module_vector_add(tv, *s2, t)) {
if (!module_vector_add(tv, *s2, t)) {
return false;
}
return true;
Expand Down
11 changes: 4 additions & 7 deletions v2/dilithium/test_dilithium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ bool test_module_arith() {
}

bool test_dilithium1() {
return true;

dilithium_parameters params;
init_dilithium_parameters(&params);
Expand All @@ -362,9 +361,9 @@ bool test_dilithium1() {
}

module_array A(params.q_, 256, params.k_, params.l_);
module_vector t(params.q_, params.l_, params.n_);
module_vector s1(params.q_, params.k_, params.n_);
module_vector s2(params.q_, params.l_, params.n_);
module_vector t(params.q_, params.n_, params.k_);
module_vector s1(params.q_, params.n_, params.l_);
module_vector s2(params.q_, params.n_, params.k_);

if (FLAGS_print_all) {
printf("A.q_: %d, A.n_: %d, A.nr_: %d, A.nc_: %d\n",
Expand All @@ -382,13 +381,10 @@ bool test_dilithium1() {
coefficient_vector* vp = A.c_[A.index(r, c)];
if (vp == nullptr)
continue;
// printf("k: %d t: %d, r: %d, c: %d, index: %d\n", k, t, r, c, A.index(r, c));
// printf("Size A.c_[A.index(r, c)].size %d\n", vp->c_.size());
A.c_[A.index(r, c)]->c_[k] = t;
}
}
}
return true;

if (!dilithium_keygen(params, &A, &t, &s1, &s2)) {
printf("dilithium_keygen failed\n");
Expand All @@ -408,6 +404,7 @@ bool test_dilithium1() {
print_module_vector(s2);
printf("\n");
}
return true;

int m_len = 3;
byte M[3] = {0x1, 0x2, 0x3};
Expand Down

0 comments on commit 8d168b7

Please sign in to comment.