#include "testing.h"
int test_addmul(
gf2e *ff, rci_t m, rci_t n, rci_t l) {
int fail_ret = 0;
mzed_t *A = random_mzed_t(ff, m, l);
mzed_t *B = random_mzed_t(ff, l, n);
mzed_t *C0 = random_mzed_t(ff, m, n);
mzed_set_canary(C1);
mzed_set_canary(C2);
mzed_set_canary(C3);
mzed_set_canary(C4);
mzed_set_canary(C5);
m4rie_check( mzed_canary_is_alive(A) );
m4rie_check( mzed_canary_is_alive(B) );
m4rie_check( mzed_canary_is_alive(C1) );
m4rie_check( mzed_canary_is_alive(C2) );
m4rie_check( mzed_canary_is_alive(C3) );
m4rie_check( mzed_canary_is_alive(C4) );
m4rie_check( mzed_canary_is_alive(C5) );
return fail_ret;
}
int test_mul(
gf2e *ff, rci_t m, rci_t n, rci_t l) {
int fail_ret = 0;
const mzed_t *A = random_mzed_t(ff, m, l);
const mzed_t *B = random_mzed_t(ff, l, n);
mzed_t *C0 = random_mzed_t(ff, m, n);
mzed_t *C1 = random_mzed_t(ff, m, n);
mzed_t *C2 = random_mzed_t(ff, m, n);
mzed_t *C3 = random_mzed_t(ff, m, n);
mzed_t *C4 = random_mzed_t(ff, m, n);
mzed_t *C5 = random_mzed_t(ff, m, n);
m4rie_check( mzed_canary_is_alive((
mzed_t*)A) );
m4rie_check( mzed_canary_is_alive((
mzed_t*)B) );
m4rie_check( mzed_canary_is_alive(C1) );
m4rie_check( mzed_canary_is_alive(C2) );
m4rie_check( mzed_canary_is_alive(C3) );
m4rie_check( mzed_canary_is_alive(C4) );
m4rie_check( mzed_canary_is_alive(C5) );
return fail_ret;
}
int test_scalar(
gf2e *ff, rci_t m, rci_t n) {
int fail_ret = 0;
word a = random() & ((1<<ff->
degree)-1);
while (!a)
a = random() & ((1<<ff->
degree)-1);
mzed_t *B = random_mzed_t(ff, m, n);
mzed_t *C1 = random_mzed_t(ff, m, n);
mzed_t *B1 = random_mzed_t(ff, m, n);
return fail_ret;
}
int test_batch(
gf2e *ff, rci_t m, rci_t l, rci_t n) {
int fail_ret = 0;
printf(
"mul: k: %2d, minpoly: 0x%05x m: %5d, l: %5d, n: %5d ",(
int)ff->
degree, (
unsigned int)ff->
minpoly, (
int)m, (
int)l, (
int)n);
m4rie_check(test_scalar(ff, m, m) == 0); printf("."); fflush(0);
m4rie_check(test_scalar(ff, l, l) == 0); printf("."); fflush(0);
m4rie_check(test_scalar(ff, n, n) == 0); printf("."); fflush(0);
m4rie_check(test_scalar(ff, m, l) == 0); printf("."); fflush(0);
m4rie_check(test_scalar(ff, l, n) == 0); printf("."); fflush(0);
m4rie_check(test_scalar(ff, m, n) == 0); printf("."); fflush(0);
m4rie_check(test_scalar(ff, l, m) == 0); printf("."); fflush(0);
if(m == l && m == n) {
m4rie_check( test_mul(ff, m, l, n) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, m, l, n) == 0); printf("."); fflush(0);
printf(" ");
} else {
m4rie_check( test_mul(ff, m, l, n) == 0); printf("."); fflush(0);
m4rie_check( test_mul(ff, m, n, l) == 0); printf("."); fflush(0);
m4rie_check( test_mul(ff, n, m, l) == 0); printf("."); fflush(0);
m4rie_check( test_mul(ff, n, l, m) == 0); printf("."); fflush(0);
m4rie_check( test_mul(ff, l, m, n) == 0); printf("."); fflush(0);
m4rie_check( test_mul(ff, l, n, m) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, m, l, n) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, m, n, l) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, n, m, l) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, n, l, m) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, l, m, n) == 0); printf("."); fflush(0);
m4rie_check(test_addmul(ff, l, n, m) == 0); printf("."); fflush(0);
}
if (fail_ret == 0)
printf(" passed\n");
else
printf(" FAILED\n");
return fail_ret;
}
int main(int argc, char **argv) {
srandom(17);
int runlong = parse_parameters(argc, argv);
int fail_ret = 0;
for(int k=2; k<=16; k++) {
fail_ret += test_batch(ff, 1, 1, 1);
fail_ret += test_batch(ff, 1, 2, 3);
fail_ret += test_batch(ff, 11, 12, 13);
fail_ret += test_batch(ff, 21, 22, 23);
fail_ret += test_batch(ff, 13, 2, 90);
fail_ret += test_batch(ff, 32, 33, 34);
fail_ret += test_batch(ff, 63, 64, 65);
if(k<=12 || runlong) {
fail_ret += test_batch(ff, 127, 128, 129);
fail_ret += test_batch(ff, 200, 20, 112);
}
}
return fail_ret;
}