36 fprintf(stderr,
"Matrix size: %dx%d\n", in->
k, in->
n);
38 for(i = 0; i < in->
k; i++) {
39 fprintf(stderr,
"%3d: ",i);
40 for(j = 0; j < in->
n; j++) {
41 fprintf(stderr,
"%x ", in->
elements[i][j]);
43 fprintf(stderr,
"\n");
50 fprintf(stderr,
"Poly (deg = %d): ", p->
deg);
53 fprintf(stderr,
"0\n");
57 for (i = p->
deg; i >= 0; i--) {
61 fprintf(stderr,
"+ ");
63 fprintf(stderr,
"alpha^(%d).x^%d ", math_ctx->
log_table[p->
coef[i]], i);
65 fprintf(stderr,
"\n");
70 for(i = 0; i < v->
len; i++) {
71 fprintf(stderr,
"%x ", v->
elements[i]);
73 fprintf(stderr,
"\n");
119 e = e % math_ctx->
ord;
122 e = e + math_ctx->
ord;
133 if (a->
n != b->
k || x->
k != a->
k || x->
n != b->
n){
140 for (i = 0; i < a->
k; i++) {
141 for (j = 0; j < b->
n; j++) {
146 for (i = 0; i < a->
k; i++) {
147 for (k = 0; k < a->
n; k++) {
151 for (j = 0; j < b->
n; j++) {
173 for (i = 0; i <= out_deg; i++) {
197 max_deg_q = a->
deg - b->
deg;
214 for (i = a->
deg; i >= 0; i--) {
215 if (dividend->
deg < divider->
deg) {
221 exponent = dividend->
deg - divider->
deg;
222 q->
coef[exponent] = leader;
238 int max_deg = a->
deg + b->
deg;
247 for (i = a->
deg; i >= 0; i--) {
248 for (j = b->
deg; j >= 0; j--) {
259 if (a->
deg == -1 || n <= 0) {
266 if (n < tmp->deg + 1) {
278 if (a->
deg == -1 || n <= 0) {
310 else if (e == 1 || a->
deg < 0) {
319 for (i = 1; i < e; i++) {
334 for (i = a->
deg; i >= 0; i--) {
365 for (i = a->
deg; i >= mod->
deg; i--) {
393 for (i = 0; i < out->
k; i++) {
405 for (i = 0; i < out->
k; i++) {
406 for (j = 0; j < out->
k; j++) {
413 for (i = 0; i < out->
k; i++) {
414 for (j = 0; j < out->
k; j++) {
425 for (i = 0; i < x->
len; i++) {
427 for (j = 0; j < mat->
n; j++) {
442 sqr = math_ctx->
exp_table[exponent >> 1];
443 if ((exponent & 1) == 1) {
444 sqr_alpha = math_ctx->
exp_table[(math_ctx->
ord + 1) / 2];
457 if (out->
deg < mod->
deg) {
465 for (i = 0; i < tmp->
len; i++) {
493 if (poly->
coef[i] != 0) {
505 if (m->
n != permutation->
size) {
506 BPU_printError(
"BPU_gf2MatPermute: permutation size not correct m->n = %d, p->size = %d", m->
n, permutation->
size);
511 for (j = 0; j < m->
n; j++) {
512 for (i = 0; i < m->
k; i++) {
520 int i, j, bit, bit_in_element = -1, act_element = 0;
522 if (out->
k != m->
k * element_bit_size || out->
n != m->
n) {
528 for (j = 0; j < m->
n; j++) {
536 for (i = 0; i < m->
k; i++) {
537 for (bit = 0; bit < element_bit_size; bit++) {
578 else if (b->
deg == -1) {
590 while (old_r->
deg > end_deg && r->
deg > -1) {
639 for (i = 1; i <= poly->
deg; i++) {
650 for (i = 0; i <= p1->
deg; i++) {
673 for (i = 0; i < math_ctx->
ord; i++) {
698 for (i = 0; i < exponent; i++) {
723 for (j = 2; j <= p->
deg; j++) {
734 for (i = 0; i < exponent; i++) {
778 if (d->
deg != 0 || d->
coef[0] != 1) {
781 #ifdef BPU_CONF_PRINT
809 for (j = 0; j <= poly->
deg; j++) {
817 if (poly->
deg >= len) {
824 for (i = 0; i <= poly->
deg; i++) {
832 for (i = 0; i < vec->
len; i++) {
847 for (k = 0; k < mat->
n; k++) {
854 for (i = 0; i < mat->
n; i++) {
861 for (i = index; i < mat->
k; i++) {
871 for (i = 0; i < vec->
len; i++) {
882 for (k = 0; k < tmp->
len; k++) {
889 for (k = 0; k < tmp->
len; k++) {
897 for (i = 0; i < mat->
k; i++) {
908 for (i = 0; i < mat->
k; i++) {
911 BPU_printError(
"################# unbeliviable 'badness' ###########");
928 for (i = 1; i < t; i++) {
935 #if defined(DEBUG_L) || defined(WARNING_L)
BPU_T_GF2_16x BPU_gf2xMulMod(BPU_T_GF2_16x a, BPU_T_GF2_16x b, BPU_T_GF2_16x mod)
Multiplication over Galois field, modulus mod.
void BPU_gf2xMatNull(BPU_T_GF2_16x_Matrix *mat)
#define BPU_getBit(w, n)
Check if is set bit at n-th index.
#define BPU_gf2xPolyLeadCoef(poly_gf2_16x_p)
void BPU_gf2xPolyMul(BPU_T_GF2_16x_Poly *out, const BPU_T_GF2_16x_Poly *a, const BPU_T_GF2_16x_Poly *b, const BPU_T_Math_Ctx *math_ctx)
BPU_T_GF2_16x BPU_gf2xGetPseudoInv(const BPU_T_GF2_16x a, const BPU_T_GF2_16x res, const BPU_T_Math_Ctx *math_ctx)
Get GF2_16x element which is a * return = res.
int BPU_gf2xPolyExtEuclid(BPU_T_GF2_16x_Poly *d, BPU_T_GF2_16x_Poly *s, BPU_T_GF2_16x_Poly *t, const BPU_T_GF2_16x_Poly *a, const BPU_T_GF2_16x_Poly *b, const int end_deg, const BPU_T_Math_Ctx *math_ctx)
Extended Euclidean to find greatest common divisor and Bézout coefficients s, t, where gcd(a...
BPU_T_GF2_16x * exp_table
there are all elements referenced by i, so at i-th index is g^i element, g - generator ...
BPU_T_Perm_Element * elements
permutation vector
int BPU_gf2xGetDeg(BPU_T_GF2_32x poly)
Get degree of polynomial over GF2.
void BPU_printGf2xVec(const BPU_T_GF2_16x_Vector *v)
BPU_printGf2xVec print GF2x vector.
void BPU_gf2xPolyGenRandom(BPU_T_GF2_16x_Poly *p, int t, const BPU_T_Math_Ctx *math_ctx)
#define BPU_gf2xPolyNull(d_pointer)
Copy Polynomial.
int BPU_gf2xMatMalloc(BPU_T_GF2_16x_Matrix **m, int rows, int cols)
Allocate memory for matrix.
int BPU_gf2xMatMul(BPU_T_GF2_16x_Matrix *x, const BPU_T_GF2_16x_Matrix *a, const BPU_T_GF2_16x_Matrix *b, const BPU_T_Math_Ctx *math_ctx)
void BPU_gf2xMatRoot(BPU_T_GF2_16x_Matrix *out, const BPU_T_GF2_16x_Poly *mod, const BPU_T_Math_Ctx *math_ctx)
BPU_T_GF2_16x ** elements
all element of matrix
int BPU_gf2xPolyMalloc(BPU_T_GF2_16x_Poly **p, int16_t max_deg)
void BPU_gf2xVecMulMat(BPU_T_GF2_16x_Vector *out, const BPU_T_GF2_16x_Vector *x, const BPU_T_GF2_16x_Matrix *mat, const BPU_T_Math_Ctx *math_ctx)
#define BPU_printWarning(fmt,...)
print warning message with filename, line
void BPU_gf2xPolyShr(BPU_T_GF2_16x_Poly *a, int n)
Shift polynomial right, it is like a div x^n.
BPU_T_GF2_16x * log_table
there are all indexes referenced by element, so alpha elemnet (g^i) -> i
void BPU_gf2xPolyMod(BPU_T_GF2_16x_Poly *out, const BPU_T_GF2_16x_Poly *a, const BPU_T_GF2_16x_Poly *mod, const BPU_T_Math_Ctx *math_ctx)
Calculate reminder of a. Example a mod b = reminder.
int BPU_gf2xPolyGetDeg(BPU_T_GF2_16x_Poly *poly)
Get degree of polynomial over GF2x.
uint32_t BPU_prngGetRand(int from, int to)
Get random unsigned int 32 value from given range (from <= return <= to)
void BPU_printGf2xPoly(const BPU_T_GF2_16x_Poly *p, const BPU_T_Math_Ctx *math_ctx)
BPU_printGf2xPoly print GF2x polynomial.
int BPU_gf2xMatPermute(BPU_T_GF2_16x_Matrix *out, const BPU_T_GF2_16x_Matrix *m, const BPU_T_Perm_Vector *permutation)
#define BPU_gf2xInvElement(gf2_16x_e, math_ctx_p)
Get inverse element of galois field.
void BPU_gf2xMatMulElRow(BPU_T_GF2_16x_Matrix *mat, const BPU_T_GF2_16x element, int row, const BPU_T_Math_Ctx *math_ctx)
BPU_T_GF2_16x BPU_gf2xPolyMakeMonic(BPU_T_GF2_16x_Poly *a, const BPU_T_Math_Ctx *math_ctx)
Make from polynomial monic polynomial.
uint8_t len
number of elements
void BPU_gf2xPolyMulEl(BPU_T_GF2_16x_Poly *a, BPU_T_GF2_16x el, const BPU_T_Math_Ctx *math_ctx)
Multiplication polynomial over GF2_16x and element from GF2_16x.
void BPU_gf2xMatClearCol(BPU_T_GF2_16x_Matrix *mat, int index, const BPU_T_Math_Ctx *math_ctx)
#define BPU_printError(fmt,...)
print error message with filename, line
BPU_T_GF2_16x BPU_gf2xPowerModT(BPU_T_GF2_16x a, int e, const BPU_T_Math_Ctx *math_ctx)
E-th power of a. It uses precomputed log and exp tables.
#define BPU_gf2xMulModT(a, b, math_ctx)
Multiplication over Galois field, modulus mod.
int BPU_gf2xMatConvertToGf2Mat(BPU_T_GF2_Matrix *out, const BPU_T_GF2_16x_Matrix *m, int element_bit_size)
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
void BPU_gf2xPolyToVec(BPU_T_GF2_16x_Vector *vec, const BPU_T_GF2_16x_Poly *poly, int len)
void BPU_gf2xMatXorRows(BPU_T_GF2_16x_Matrix *mat, int index, int j, const BPU_T_Math_Ctx *math_ctx)
#define BPU_printDebug(fmt,...)
print debug message with filename, line
BPU_T_Perm_Element size
permutation size
void BPU_gf2xSwap(BPU_T_GF2_16x *a, BPU_T_GF2_16x *b)
void BPU_gf2xMatFree(BPU_T_GF2_16x_Matrix **m)
Free dynamically or statically allocated matrix.
int BPU_gf2xMatFindPivot(const BPU_T_GF2_16x_Matrix *mat, int index)
void BPU_gf2xMatInsertPoly(BPU_T_GF2_16x_Matrix *mat, const BPU_T_GF2_16x_Poly *poly, int i)
BPU_T_GF2_16x BPU_gf2xRoot(BPU_T_GF2_16x element, const BPU_T_Math_Ctx *math_ctx)
void BPU_gf2xPolyGenGoppa(BPU_T_GF2_16x_Poly *p, int t, const BPU_T_Math_Ctx *math_ctx)
void BPU_gf2xMatSwapRows(BPU_T_GF2_16x_Matrix *mat, int i, int j)
void BPU_gf2xPolyRoot(BPU_T_GF2_16x_Poly *out, const BPU_T_GF2_16x_Poly *poly, const BPU_T_GF2_16x_Poly *mod, const BPU_T_Math_Ctx *math_ctx)
BPU_gf2xPolyRoot calculate root of given polynomial over GF2x.
BPU_T_GF2_16x * coef
Polynomial over GF2m.
void BPU_gf2xPolyFree(BPU_T_GF2_16x_Poly **p)
BPU_T_GF2_16x BPU_gf2xPolyEval(const BPU_T_GF2_16x_Poly *poly, const BPU_T_GF2_16x x, const BPU_T_Math_Ctx *math_ctx)
Evaluate polynomial over GF2^m with x.
int BPU_gf2xPolyCmp(const BPU_T_GF2_16x_Poly *p1, const BPU_T_GF2_16x_Poly *p2)
void BPU_gf2xPolyShl(BPU_T_GF2_16x_Poly *a, int n)
Shift polynomial left, it is like a mul 1/x^n.
void BPU_gf2xPolyCopy(BPU_T_GF2_16x_Poly *dest, const BPU_T_GF2_16x_Poly *src)
Copy Polynomial.
void BPU_gf2xMatGEM(BPU_T_GF2_16x_Matrix *mat, const BPU_T_Math_Ctx *math_ctx)
void BPU_gf2xVecToPoly(BPU_T_GF2_16x_Poly *poly, const BPU_T_GF2_16x_Vector *vec)
void BPU_gf2xVecMulEl(BPU_T_GF2_16x_Vector *vec, BPU_T_GF2_16x element, const BPU_T_Math_Ctx *math_ctx)
void BPU_gf2xPolyAdd(BPU_T_GF2_16x_Poly *out, const BPU_T_GF2_16x_Poly *a, const BPU_T_GF2_16x_Poly *b)
int BPU_gf2xPolyResize(BPU_T_GF2_16x_Poly *p, int16_t max_deg)
BPU_gf2xPolyResize Resize polynomial, increase max deg.
int ord
group ord, number of elements
int BPU_gf2xPolyIrredTest(const BPU_T_GF2_16x_Poly *p, const BPU_T_Math_Ctx *math_ctx)
void BPU_printGf2xMat(const BPU_T_GF2_16x_Matrix *in)
void BPU_gf2xPolyPower(BPU_T_GF2_16x_Poly *a, int e, const BPU_T_Math_Ctx *math_ctx)
Calculate power of polynomial.
uint8_t mod_deg
modulo degree, galois finite field GF(2^m)
void BPU_gf2xPolyDiv(BPU_T_GF2_16x_Poly *q, BPU_T_GF2_16x_Poly *r, const BPU_T_GF2_16x_Poly *a, const BPU_T_GF2_16x_Poly *b, const BPU_T_Math_Ctx *math_ctx)
void BPU_gf2xVecFree(BPU_T_GF2_16x_Vector **vec)
BPU_gf2xVecFree Free vector structure.
BPU_T_GF2 ** elements
all element of matrix
void BPU_gf2xPolyInv(BPU_T_GF2_16x_Poly *out, const BPU_T_GF2_16x_Poly *a, const BPU_T_GF2_16x_Poly *mod, const BPU_T_Math_Ctx *math_ctx)
Get inverse polynomial over GF2_16x.
int BPU_gf2xVecMalloc(BPU_T_GF2_16x_Vector **vec, int size)
BPU_gf2xVecMalloc Malloc vector structure.