#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;
}
static mzed_t * mzed_mul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B)
Compute C = A*B.
Definition: conversion.h:177
static mzed_t * mzed_addmul_blm(mzed_t *C, const mzed_t *A, const mzed_t *B)
Compute C += A*B.
Definition: conversion.h:265
static mzed_t * mzed_addmul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B)
Compute C += A*B.
Definition: conversion.h:196
static mzed_t * mzed_mul_blm(mzed_t *C, const mzed_t *A, const mzed_t *B)
Compute C = A*B.
Definition: conversion.h:246
void gf2e_free(gf2e *ff)
Definition: gf2e.c:56
gf2e * gf2e_init(const word minpoly)
Definition: gf2e.c:4
M4RIE_DLL_EXPORT const word * irreducible_polynomials[17]
all Irreducible polynomials over GF(2) up to degree 16.
Definition: gf2e.c:85
static word gf2e_inv(const gf2e *ff, word a)
a^(-1) % minpoly
Definition: gf2e.h:94
mzed_t * mzed_copy(mzed_t *A, const mzed_t *B)
Copy matrix A to B.
Definition: mzed.c:196
mzed_t * mzed_cling(mzed_t *A, const mzd_slice_t *Z)
Pack a bitslice matrix into a packed represenation.
Definition: conversion.c:88
mzd_slice_t * mzed_slice(mzd_slice_t *A, const mzed_t *Z)
Unpack the matrix Z into bitslice representation.
Definition: conversion.c:56
mzed_t * mzed_init(const gf2e *k, rci_t m, rci_t n)
Create a new matrix of dimension m x n over ff.
Definition: mzed.c:28
static void mzd_slice_free(mzd_slice_t *A)
Free a matrix created with mzd_slice_init().
Definition: mzd_slice.h:145
void mzed_free(mzed_t *A)
Free a matrix created with mzed_init().
Definition: mzed.c:39
mzed_t * mzed_mul(mzed_t *C, const mzed_t *A, const mzed_t *B)
.
Definition: mzed.c:90
mzed_t * mzed_addmul(mzed_t *C, const mzed_t *A, const mzed_t *B)
.
Definition: mzed.c:96
mzed_t * mzed_addmul_strassen(mzed_t *C, const mzed_t *A, const mzed_t *B, int cutoff)
using Strassen-Winograd.
Definition: strassen.c:38
mzed_t * mzed_mul_scalar(mzed_t *C, const word a, const mzed_t *B)
.
Definition: mzed.c:141
mzed_t * mzed_addmul_newton_john(mzed_t *C, const mzed_t *A, const mzed_t *B)
using Newton-John tables.
Definition: newton_john.c:503
mzd_slice_t * mzd_slice_mul_scalar(mzd_slice_t *C, const word a, const mzd_slice_t *B)
.
Definition: mzd_slice.c:25
mzed_t * mzed_mul_strassen(mzed_t *C, const mzed_t *A, const mzed_t *B, int cutoff)
using Strassen-Winograd.
Definition: strassen.c:33
mzed_t * mzed_mul_newton_john(mzed_t *C, const mzed_t *A, const mzed_t *B)
using Newton-John tables.
Definition: newton_john.c:498
mzed_t * mzed_addmul_naive(mzed_t *C, const mzed_t *A, const mzed_t *B)
using naive cubic multiplication.
Definition: mzed.c:123
mzed_t * mzed_mul_naive(mzed_t *C, const mzed_t *A, const mzed_t *B)
using naive cubic multiplication.
Definition: mzed.c:118
static int mzed_cmp(mzed_t *A, mzed_t *B)
Return -1,0,1 if if A < B, A == B or A > B respectively.
Definition: mzed.h:472
deg_t degree
Definition: gf2e.h:63
word minpoly
Definition: gf2e.h:64
Dense matrices over represented as slices of matrices over .
Definition: mzd_slice.h:56
Dense matrices over represented as packed matrices.
Definition: mzed.h:59