BitPunch McEliece  v0.0.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gf2.c
Go to the documentation of this file.
1 /*
2 This file is part of BitPunch
3 Copyright (C) 2013-2015 Frantisek Uhrecky <frantisek.uhrecky[what here]gmail.com>
4 Copyright (C) 2013-2015 Andrej Gulyas <andrej.guly[what here]gmail.com>
5 Copyright (C) 2013-2014 Marek Klein <kleinmrk[what here]gmail.com>
6 Copyright (C) 2013-2014 Filip Machovec <filipmachovec[what here]yahoo.com>
7 Copyright (C) 2013-2014 Jozef Kudlac <jozef[what here]kudlac.sk>
8 
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "gf2.h"
23 #include "perm.h"
24 
25 #include <stdlib.h>
26 #include <bitpunch/debugio.h>
27 #include <bitpunch/prng/prng.h>
28 
29 #ifdef BPU_CONF_PRINT
30 /* ==================================== Print functions ==================================== */
31 void BPU_printBinaryMsb(uint32_t in, int len) {
32  if (len > 0) {
33  BPU_printBinaryMsb(in >> 1, len - 1);
34 
35  fprintf(stderr, "%d", (int) (in & (0x1u)));
36  }
37 }
38 
39 void BPU_printBinaryMsbLn(uint32_t in, int len) {
40  BPU_printBinaryMsb(in, len);
41  fprintf(stderr, "\n");
42 }
43 
44 void BPU_printBinaryMsb32(uint32_t in) {
45  BPU_printBinaryMsb(in, 32);
46 }
47 
48 void BPU_printBinaryMsb32Ln(uint32_t in) {
49  BPU_printBinaryMsbLn(in, 32);
50 }
51 
52 void BPU_printBinaryLsb(uint32_t in, int len) {
53  if (len > 0) {
54  fprintf(stderr, "%d", (int) (in & (0x1u)));
55 
56  BPU_printBinaryLsb(in >> 1, len - 1);
57  }
58 }
59 
60 void BPU_printBinaryLsbLn(uint32_t in, int len) {
61  BPU_printBinaryLsb(in, len);
62  fprintf(stderr, "\n");
63 }
64 
65 void BPU_printBinaryLsb32(uint32_t in) {
66  BPU_printBinaryLsb(in, 32);
67 }
68 
69 void BPU_printBinary32LsbLn(uint32_t in) {
70  BPU_printBinaryLsbLn(in, 32);
71 }
72 
74  int i, j, bits_to_print;
75 
76  fprintf(stderr, "Matrix size: %dx%d\n", m->k, m->n);
77 
78  for (i = 0; i < m->k; i++) {
79  fprintf(stderr, "%4d: ",i);
80 
81  for (j = 0; j <= m->elements_in_row - 1; j++) {
82  if (j == m->elements_in_row-1) {
83  if (m->n%(m->element_bit_size) != 0) {
84  bits_to_print = m->n % m->element_bit_size;
85  }
86  else {
87  bits_to_print = m->element_bit_size;
88  }
89  }
90  else {
91  bits_to_print = m->element_bit_size;
92  }
93  BPU_printBinaryLsb(m->elements[i][j], bits_to_print);
94  // fprintf(stderr, " "); // medzera medzi elementami
95  }
96  fprintf(stderr, "\n");
97  }
98 }
99 
101  int j, bits_to_print;
102 
103  fprintf(stderr, "Vec (%4d): ", v->len);
104  for (j = 0; j <= v->elements_in_row - 1; j++) {
105  if (j == v->elements_in_row-1) {
106  if (v->len % (v->element_bit_size) != 0) {
107  bits_to_print = v->len % v->element_bit_size;
108  }
109  else {
110  bits_to_print = v->element_bit_size;
111  }
112  }
113  else {
114  bits_to_print = v->element_bit_size;
115  }
116  BPU_printBinaryLsb(v->elements[j], bits_to_print);
117  fprintf(stderr, " ");
118  }
119  fprintf(stderr, "\n");
120 }
121 
123  int j, bits_to_print;
124 
125  fprintf(stderr, "Vec (%4d): ", v->len);
126  for (j = 0; j <= v->elements_in_row - 1; j++) {
127  if (j == v->elements_in_row-1) {
128  if (v->len % (v->element_bit_size) != 0) {
129  bits_to_print = v->len % v->element_bit_size;
130  }
131  else {
132  bits_to_print = v->element_bit_size;
133  }
134  }
135  else {
136  bits_to_print = v->element_bit_size;
137  }
138  BPU_printBinaryMsbLn(v->elements[j], bits_to_print);
139  fprintf(stderr, " ");
140  }
141  fprintf(stderr, "\n");
142 }
143 
145  int i;
146  for (i = 0; i < vec->len; ++i)
147  {
148  if (BPU_gf2VecGetBit(vec, i)) {
149  fprintf(stderr, "%d ", i);
150  }
151  }
152  fprintf(stderr, "\n");
153 }
154 
156  int i;
157 
158  fprintf(stderr, "Sparse poly (%i): ", v->weight);
159  for (i = 0; i < v->weight; i++) {
160  fprintf(stderr, "%3i ", v->index[i]);
161  }
162  fprintf(stderr, "\n");
163 }
164 
166  int j, bits_to_print;
167 
168  for (j = 0; j < v->elements_in_row; j++) {
169  if (j == v->elements_in_row-1) {
170  if (v->len % (v->element_bit_size) != 0) {
171  bits_to_print = v->len % v->element_bit_size;
172  }
173  else {
174  bits_to_print = v->element_bit_size;
175  }
176  }
177  else {
178  bits_to_print = v->element_bit_size;
179  }
180  BPU_printBinaryLsb(v->elements[j], bits_to_print);
181  }
182 }
183 
185  int j, bits_to_print;
186 
187  fprintf(stderr, "Poly (%4d): ", v->len-1);
188  for (j = v->elements_in_row - 1; j >= 0; j--) {
189  if (j == v->elements_in_row-1) {
190  if (v->len % (v->element_bit_size) != 0) {
191  bits_to_print = v->len % v->element_bit_size;
192  }
193  else {
194  bits_to_print = v->element_bit_size;
195  }
196  }
197  else {
198  bits_to_print = v->element_bit_size;
199  }
200  BPU_printBinaryMsb(v->elements[j], bits_to_print);
201  }
202  fprintf(stderr, "\n");
203 }
204 
206  int ele, i;
207  BPU_T_GF2_Poly temp;
208 
209  fprintf(stderr, "%s QC Matrix(%i x %i) with %i elements", v->isVertical ? "VERTICAL" : "HORIZONTAL", (v->is_I_appended ? v->k : 0) + v->n, v->k, v->element_count);
210  if (v->is_I_appended)
211  fprintf(stderr, " and Identity matrix");
212  fprintf(stderr, "\n");
213 
214  for (ele = 0; ele < v->element_count; ele++) {
215  BPU_gf2PolyCopy(&temp, &v->matrices[ele]);
216  for (i = 0; i < v->element_size; i++) {
218  fprintf(stderr, "\n");
219  BPU_gf2PolyMulX(&temp);
220  }
221  BPU_gf2PolyFree(&temp, 0);
222  }
223 }
224 
226  int i;
228 
229  fprintf(stderr, "%s QC Matrix(%i x %i) with %i elements\n", v->isVertical ? "VERTICAL" : "HORIZONTAL", v->n, v->k, v->element_count);
230 
231  for (i = 0; i < v->k; i++) {
232  BPU_gf2SparseQcMatrixGetRow(&row, v, i);
234  BPU_gf2SparsePolyFree(&row, 0);
235  }
236 }
237 /* ------------------------------------ Print functions ------------------------------------ */
238 #endif // BPU_CONF_PRINT
239 
241  int i, j;
242 
243  if (w > out->len) {
244  BPU_printError("weight error w > l");
245  return -2;
246  }
247  //vector of random weight
248  if(w == 0) {
249  for(i = 0; i < out->len; i++) {
250  BPU_gf2VecSetBit(out, i, BPU_prngGetRand(0, 2));
251  }
252  }
253  //vector of required weight
254  else {
255  BPU_gf2VecNull(out);
256 
257  for(i = 0; i < w; i++) {
258  j = BPU_prngGetRand(0, out->len);
259 
260  if(BPU_gf2VecGetBit(out, j) == 0) {
261  BPU_gf2VecSetBit(out, j, 1);
262  }
263  else{
264  i--;
265  }
266  }
267  }
268  return 0;
269 }
270 
272  int i, j;
273 
274  if (out->k != in->k || out->n != in->n) {
275  BPU_printError("BPU_gf2MatCopy: wrong matrix size");
276 
277  return -1;
278  }
279 
280  // copy the matrix
281  for (i = 0; i < in->k; i++) {
282  for (j = 0; j < in->elements_in_row; j++) {
283  out->elements[i][j] = in->elements[i][j];
284  }
285  }
286  return 0;
287 }
288 
289 int BPU_gf2VecPermute(BPU_T_GF2_Vector *vec, const BPU_T_Perm_Vector *permutation) {
290  int i;
291  BPU_T_GF2_Vector *tmp;
292 
293  BPU_gf2VecMalloc(&tmp, vec->len);
294 
295  for (i = 0; i < permutation->size; i++) {
296  BPU_gf2VecSetBit(tmp, i, BPU_gf2VecGetBit(vec, permutation->elements[i]));
297  }
298  BPU_gf2VecCopy(vec, tmp);
299 
300  BPU_gf2VecFree(&tmp);
301 
302  return 0;
303 }
304 
305 BPU_T_GF2 BPU_gf2MatGetMaskedBit(const BPU_T_GF2_Matrix *m, uint32_t row, uint32_t bit) {
306  int segment, bit_in_segment;
307 
308  segment = bit / (m->element_bit_size);
309  bit_in_segment = bit % (m->element_bit_size);
310  // TODO: consider repleacing di literal 1u
311  return m->elements[row][segment] & ((uint32_t)1 << bit_in_segment);
312 }
313 
315  int segment, bit_in_segment;
316 
317  segment = bit / (vec->element_bit_size);
318  bit_in_segment = bit % (vec->element_bit_size);
319  // TODO: consider repleacing di literal 1u
320  return vec->elements[segment] & ((uint32_t)1 << bit_in_segment);
321 }
322 
324  int i, j;
325 
326  if (out->k != in->n || out->n != in->k) {
327  BPU_printError("Wrong matrix dimenzion");
328 
329  return -1;
330  }
331  for (i = 0; i < in->k; i++) {
332  for (j = 0; j < in->n; j++) {
333  BPU_gf2MatSetBit(out, j, i, BPU_gf2MatGetBit(in, i, j));
334  } // col loop
335  } // row loop
336 
337  return 0;
338 }
339 
341  BPU_T_GF2 tmp;
342  tmp = *a;
343  *a = *b;
344  *b = tmp;
345 }
346 
347 void BPU_gf2MatSwapRows(BPU_T_GF2_Matrix *mat, int i, int j) {
348  int k;
349  for (k = 0; k < mat->elements_in_row; k++) {
350  BPU_gf2Swap(&(mat->elements[i][k]), &(mat->elements[j][k]));
351  }
352 }
353 
354 
355 
356 int BPU_gf2MatFindRow(const BPU_T_GF2_Matrix *mat, int i, int start_index) {
357  int k;
358  for (k = start_index; k < mat->k; k++) {
359  if ( BPU_gf2MatGetMaskedBit(mat, k, i) ){
360  return k;
361  }
362  }
363  return -1;
364 }
365 
366 int BPU_gf2MatFindCol(const BPU_T_GF2_Matrix *mat, int i, int start_index) {
367  int k;
368  for (k = start_index; k < mat->n; k++) {
369  if ( BPU_gf2MatGetMaskedBit(mat, i, k) ){
370  return k;
371  }
372  }
373  return -1;
374 }
375 
377  int act_position = 0;
378  int i;
379  int row;
380 
381  for (act_position = 0; act_position < inout->k; act_position++) {
382  row = BPU_gf2MatFindRow(inout, act_position, act_position);
383  if (row == -1){
384  BPU_printWarning("Not systematic");
385  return -1;
386  }
387  BPU_gf2MatSwapRows(inout, act_position, row);
388 
389  // xor with the rest of rows if needed
390  for (i = 0; i < inout->k; i++) {
391  if ( BPU_gf2MatGetMaskedBit(inout, i, act_position) && act_position != i) {
392  BPU_gf2MatXorRows(inout, i, act_position);
393  }
394  }
395  }
396  return 0;
397 }
398 
400  int len = vec1->len + vec2->len;
401  int i;
402 
403  if (out->len != len) {
404  if (BPU_gf2VecResize(out, len)) {
405  BPU_printError("resize error");
406  return -1;
407  }
408  }
409  else {
410  BPU_gf2VecNull(out);
411  }
412  // copy first vector
413  BPU_gf2VecCopy(out, vec1);
414 
415  // copy second vector
416  for (i = 0; i < vec2->len; i++) {
417  BPU_gf2VecSetBit(out, i + vec1->len, BPU_gf2VecGetBit(vec2, i));
418  }
419  out->len = len;
420 
421  return 0;
422 }
423 
424 int BPU_gf2VecCrop(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const int start, const int length) {
425  int i;
426  int counter = 0;
427 
428  //input test
429  if (start < 0 || (length+start) > in->len) {
430  BPU_printError("cropVector: bad params");
431  return -1;
432  }
433  if (out->len < length) {
434  BPU_printError("cropVector: out vector is smaller then needed");
435  return -1;
436  }
437  for (i = start; i < start+length; i++) {
438  BPU_gf2VecSetBit(out, counter, BPU_gf2VecGetBit(in, i));
439  counter++;
440  }
441  return 0;
442 }
443 
445  if (out->len != in->n) {
446  BPU_printError("dimension is wrong out->len %d != in->n %d", out->len, in->n);
447  return -1;
448  }
449  BPU_gf2MatCopyRowToVec(out, in, row);
450 
451  return 0;
452 }
453 
455  // if there is not enough space resize
456  if (dest->elements_in_row < src->elements_in_row) {
457  BPU_gf2VecResize(dest, src->elements_in_row * src->element_bit_size * sizeof(BPU_T_GF2));
458  }
459  else {
460  BPU_gf2VecNull(dest);
461  }
462  memcpy((void *) (dest->elements), (void *) (src->elements), sizeof(BPU_T_GF2) * (src->elements_in_row));
463 
464  dest->len = src->len;
465 }
466 
468  int i;
469 
470  if (v1->len != v2->len) {
471  return -1;
472  }
473  for (i = 0; i < v1->len; i++) {
474  if (BPU_gf2VecGetBit(v1, i) != BPU_gf2VecGetBit(v2, i)) {
475  return i + 1;
476  }
477  }
478  return 0;
479 }
480 
482  int i;
483 
484  if (out->len != in->len) {
485  BPU_printError("BPU_gf2VecXor: length error (el. in row) %d != %d, len %d != %d", out->elements_in_row, in->elements_in_row, out->len, in->len);
486 
487  return -1;
488  }
489  for (i = 0; i < out->elements_in_row; i++) {
490  out->elements[i] ^= in->elements[i];
491  }
492  return 0;
493 }
494 
496  int i, j;
497 
498  if ((v->len != b->k) || (out->len != b->n)) {
499  BPU_printError("wrong vector and matrix dimension v->len = %d, b->k = %d", v->len, b->k);
500  BPU_printError("wrong vector and matrix dimension out->len = %d, b->n = %d", out->len, b->n);
501 
502  return -1;
503  }
504  // null elements
505  BPU_gf2VecNull(out);
506 
507  for (i = 0; i < v->len; i++) {
508  if (BPU_gf2VecGetBit(v, i)) {
509  // xor rows
510  for (j = 0; j < out->elements_in_row; j++) {
511  out->elements[j] ^= b->elements[i][j];
512  }
513  }
514  }
515  return 0;
516 }
517 
518 void BPU_gf2MatXorRows(BPU_T_GF2_Matrix *mat, int i, int j) {
519  int k;
520 
521  for (k = 0; k < mat->elements_in_row; k++) {
522  mat->elements[i][k] ^= mat->elements[j][k];
523  }
524 }
525 
527  int i, j;
528  int bit = 0;
529  BPU_T_GF2_Vector *vector;
530  int length;
531 
532  if (inout->n != permutation->size) {
533  BPU_printError("permutation size not correct m->n = %d, p->size = %d", inout->n, permutation->size);
534 
535  return -1;
536  }
537  length = inout->elements_in_row * (inout->element_bit_size / 8);
538 
539  BPU_gf2VecMalloc(&vector, permutation->size);
540 
541  for (i = 0; i < inout->k; i++) {
542  memcpy((vector->elements), inout->elements[i], length);
543  for (j = 0; j < permutation->size; j++) {
544  bit = BPU_gf2VecGetBit(vector, permutation->elements[j]);
545  BPU_gf2MatSetBit(inout, i, j, bit);
546  }
547  }
548  BPU_gf2VecFree(&vector);
549  return 0;
550 }
551 
552 int BPU_gf2MatCrop(BPU_T_GF2_Matrix *m, uint16_t width) {
553  BPU_T_GF2_Vector *row, *cropped_row;
554  int length, i, new_length;
555 
556  length = m->elements_in_row * (m->element_bit_size / 8);
557  BPU_gf2VecMalloc(&row, m->n);
558  BPU_gf2VecMalloc(&cropped_row, width);
559  new_length = cropped_row->elements_in_row * (m->element_bit_size / 8);
560  for (i = 0; i < m->k; i++) {
561  memcpy(row->elements, m->elements[i], length);
562  BPU_gf2VecCrop(cropped_row, row, m->k, width);
563  free(m->elements[i]);
564  m->elements[i] = (BPU_T_GF2*) malloc(new_length);
565  memcpy(m->elements[i], cropped_row->elements, new_length);
566  }
567  m->n = cropped_row->len;
568  m->elements_in_row = cropped_row->elements_in_row;
569 
570  BPU_gf2VecFree(&row);
571  BPU_gf2VecFree(&cropped_row);
572 
573  return 0;
574 }
575 
576 uint8_t BPU_getParity(BPU_T_GF2 dword) {
577  uint32_t tmp = dword;
578  tmp = (tmp >> 16) ^ tmp;
579  tmp = (tmp >> 8 ) ^ tmp;
580  tmp = (tmp >> 4 ) ^ tmp;
581  tmp = (tmp >> 2 ) ^ tmp;
582  tmp = (tmp >> 1 ) ^ tmp;
583  return tmp & 1;
584 }
585 
587 
588  int i;
589  // allocate output poly
590  BPU_gf2PolyMalloc(out, in->len);
591 
592  // copy all elements
593  if (in->len != 0)
594  for (i = 0; i < in->elements_in_row; i++) {
595  out->elements[i] = in->elements[i];
596  }
597 }
598 
600  int i, counter, bit;
601 
602  // allocate output matrix
604 
605  // transpose polynoms
606  for (i = 0; i < in->element_count; i++) {
607  counter = 0;
608  // allocate sparse poly
609  BPU_gf2SparsePolyMalloc(&out->matrices[i], wi[i]);
610  // set bits
611  for (bit = 0; bit < in->matrices[i].len; bit++) {
612  if (BPU_gf2VecGetBit(&in->matrices[i], bit) == 1ul) {
613  out->matrices[i].index[counter] = (uint32_t)(bit);
614  counter++;
615  }
616  }
617  // weight error
618  if (counter != wi[i]) {
619  BPU_printError("weight error. Weight should be %i, but is %i.\n", wi[i], counter);
620  return -1;
621  }
622  }
623  return 0;
624 }
625 
626 int BPU_gf2PolyInitRand(BPU_T_GF2_Poly *out, int l, int w, int set_deg) {
627  int ret;
628 
629  // allocate output poly
630  ret = BPU_gf2PolyMalloc(out, l);
631 
632  // set random bits
633  if (w >= 0)
634  ret = BPU_gf2VecRand((BPU_T_GF2_Vector*) out, w);
635 
636  // set poly deg
637  if (set_deg) BPU_gf2PolySetDeg(out, -1);
638 
639  return ret;
640 }
641 
643  int i;
644  // allocate output poly
646  // copy all indexes
647  for (i = 0; i < in->weight; i++) {
648  out->index[i] = in->index[i];
649  }
650 }
651 
653  int counter, coeff, ele, zero_coeff_is_set;
654 
655  // allocate memory for output matrix
657 
658  // for all polynoms
659  for (ele = 0; ele < in->element_count; ele++) {
660  counter = 0; zero_coeff_is_set = 0;
661 
662  // alloc new matrix of same weight
663  BPU_gf2SparsePolyMalloc(&out->matrices[ele], in->matrices[ele].weight);
664 
665  // is zero coeff set?
666  zero_coeff_is_set = (in->matrices[ele].index[0] == 0ul);
667  // set zero coeff
668  if (zero_coeff_is_set) {
669  out->matrices[ele].index[counter] = 0ul;
670  counter++;
671  }
672 
673  // for other coeffs
674  for (coeff = in->matrices[ele].weight-1; coeff >= (1-!zero_coeff_is_set); coeff--) {
675  out->matrices[ele].index[counter] = in->element_size - in->matrices[ele].index[coeff];
676  counter++;
677  }
678  }
679 }
680 
681 void BPU_gf2PolyShiftLeft(BPU_T_GF2_Poly *a, int shift_count) {
682  int i;
683  int diff, bit_shift, start, shift_right, shift_left;
684  uint32_t ele1, ele2;
685 
686  // allocate new poly, with additional bits
687  // BPU_gf2PolyMalloc(&poly, a->len+shift_count);
688  BPU_gf2PolySetDeg(a, a->len+shift_count);
689 
690  // calc element shift and bit shift
691  diff = shift_count / a->element_bit_size;
692  bit_shift = shift_count % a->element_bit_size;
693 
694  start = diff;
695  // shift elements
696  for (i = a->elements_in_row-1; i >= start; i--) {
697  // not the first element, concat two elements
698  if (i-start != 0) {
699 
700  // get first element
701  if ((a->element_bit_size - bit_shift) >= a->element_bit_size) {
702  ele1 = 0ul;
703  shift_right = 0;
704  }
705  else {
706  ele1 = a->elements[i-start-1];
707  shift_right = a->element_bit_size - bit_shift;
708  }
709 
710  // get second element
711  if ((i-start) >= a->elements_in_row) {
712  ele2 = 0ul;
713  shift_left = 0;
714  }
715  else {
716  ele2 = a->elements[i-start];
717  shift_left = bit_shift;
718  }
719 
720  // set element
721  a->elements[i] = (ele1 >> shift_right) ^ (ele2 << shift_left);
722  }
723  // first element, just shift
724  else
725  a->elements[i] = a->elements[i-start] << bit_shift;
726  }
727 
728  // set zeros in the beginning
729  for (i = 0; i < diff; i++)
730  a->elements[i] = 0ul;
731 }
732 
734  int ele;
735 
736  // scan all elements and found highest non zero element
737  for (ele = a->elements_in_row-1; ele >= 0; ele--) {
738  if (a->elements[ele] != 0ul)
739  // find highest bit in highest non zero element
740  return msb32(a->elements[ele], 1, a->element_bit_size, a->element_bit_size) + ele*a->element_bit_size;
741  }
742 
743  // poly is zero
744  return -1;
745 }
746 
748  int j, orig_elements_in_row = a->elements_in_row;
749 
750  // find max degree
751  if (deg == -1) {
753  }
754 
755  if (deg != -1) {
756  // set degree and element count
757  a->len = deg;
758  a->elements_in_row = a->len / a->element_bit_size + ((a->len % a->element_bit_size) != 0 ? 1 : 0);
759  // reallocate elements
760  a->elements = (BPU_T_GF2*) realloc(a->elements, sizeof(BPU_T_GF2) * a->elements_in_row);
761  // null new elements
762  for (j = orig_elements_in_row; j < a->elements_in_row; j++)
763  a->elements[j] = 0ul;
764  }
765  // poly is zero
766  else {
767  a->len = 0;
768  a->elements_in_row = 0;
769  }
770 }
771 
773  int ele;
774  uint8_t shift = a->element_bit_size-1;
775 
776  // save highest bit
777  uint32_t msb = BPU_gf2VecGetBit(a, a->len-1);
778  // null highest bit
779  BPU_gf2VecSetBit(a, a->len-1, 0ul);
780 
781  // for all elements
782  for (ele = a->elements_in_row-1; ele >= 1; ele--) {
783  a->elements[ele] = (a->elements[ele] << 1) ^ (a->elements[ele-1] >> shift);
784  }
785 
786  // last element just shift
787  a->elements[0] <<= 1;
788  // and set lowest bit
789  a->elements[0] ^= msb;
790 }
791 
793  int i;
794 
795  // for all elements
796  for (i = 0; i < a->elements_in_row-1; i++) {
797  // shift right by one and add lowest bit from next element
798  a->elements[i] = (a->elements[i] >> 1) ^ ((a->elements[i+1] & 1ul) << (a->element_bit_size-1));
799  }
800 
801  // last element just shift
802  a->elements[a->elements_in_row-1] >>= 1;
803 
804 }
805 
806 void BPU_gf2PolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in, int crop) {
807  int i;
808 
809  // if out poly is zero, just copy in into out
810  if (out->len == 0) {
811  BPU_gf2PolyFree(out, 0);
812  BPU_gf2PolyCopy(out, in);
813  }
814  // if in is non zero
815  else if (in->len != 0) {
816  // if deg(in) > deg(out)
817  if (in->len > out->len)
818  // set degree
819  BPU_gf2PolySetDeg(out, in->len);
820  // make add
821  for (i = 0; i < in->elements_in_row; i++)
822  out->elements[i] ^= in->elements[i];
823  }
824 
825  // if set new degree
826  if (crop) BPU_gf2PolySetDeg(out, -1);
827 }
828 
829 // operation add with binary polynomials with high degree
831  int i;
832 
833  // for all coefficients
834  for (i = 0; i < in->weight; i++)
835  // make add
836  BPU_gf2VecSetBit(out, in->index[i], BPU_gf2VecGetBit(out, in->index[i]) ^ 1ul);
837 }
838 
840  int i, hw = 0;
841 
842  // for all coefficients
843  for (i = 0; i < b->weight; i++)
844  // if both poly has set coeff
845  if (BPU_gf2VecGetBit(a, b->index[i]) == 1ul)
846  // increase hamming weight
847  hw++;
848 
849  return hw;
850 }
851 
853  int i;
854 
855  // if rownum is in matrix
856  if (row_num < m->k) {
857  // allocate output polynom
858  BPU_gf2SparsePolyCopy(p, &m->matrices[row_num / m->element_size]);
859  // VERTICAL QC matrix
860  if (m->isVertical)
861  // for all coefficients
862  for (i = 0; i < p->weight; i++)
863  // shift coefficients
864  p->index[i] = ((p->index[i]) + row_num) % m->element_size;
865  // horizontal matrix is not supported
866  else {
867  BPU_printError("BPU_QcMatrixGetRow: HORIZONTAL matrix not supported\n");
868  }
869  }
870  // row num is out of the matrix
871  else {
872  BPU_printError("BPU_QcMatrixGetRow: row with index %i does not exist\n", row_num);
873  }
874 }
875 
876 void BPU_gf2PolyMulMod(const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b, BPU_T_GF2_Poly *c, const BPU_T_GF2_Poly *m, int crop) {
877  int i;
878  BPU_T_GF2_Poly temp_b;
879 
880  // if one of factors is zero, product will also be zero
881  if (a->len == 0 || b->len == 0) {
882  BPU_gf2PolyMalloc(c, 0);
883  return;
884  }
885 
886  // copy b to temp_b and prolong to modulo lenght - 1
887  BPU_gf2PolyCopy(&temp_b, b);
888  BPU_gf2PolySetDeg(&temp_b, m->len-1);
889 
890  // malloc multiplication product
891  BPU_gf2PolyMalloc(c, m->len);
892 
893  // for length of a
894  for (i = 0; i < a->len; i++) {
895  // 1 in a -> multiply
896  if (BPU_gf2VecGetBit(a, i) == 1ul)
897  BPU_gf2PolyAdd(c, &temp_b, 0);
898 
899  // multiply b by 2
900  BPU_gf2PolyMulX(&temp_b);
901  }
902 
903  // if do not crop the result length
904  if (!crop)
905  BPU_gf2PolySetDeg(c, m->len-1);
906  else
907  BPU_gf2PolySetDeg(c, -1);
908 
909  BPU_gf2PolyFree(&temp_b, 0);
910 }
911 
913  BPU_T_GF2_Poly divisor, dividend;
914  int limit_deg = a->len - b->len;
915  int i = 0;
916 
917  // copy a, b
918  BPU_gf2PolyCopy(&divisor, b);
919  BPU_gf2PolyCopy(&dividend, a);
920 
921  // allocate quotient
922  BPU_gf2PolyMalloc(q, a->len);
923 
924  // divisor shift to deg of dividend
925  BPU_gf2PolyShiftLeft(&divisor, a->len - b->len);
926 
927  while (dividend.len >= b->len) {
928  if (dividend.len == divisor.len) {
929  BPU_gf2VecSetBit(q, limit_deg - i, 1ul);
930 
931  // dividend - divisor
932  BPU_gf2PolyAdd(&dividend, &divisor, 1);
933  }
934 
935  // divisor degree decreased by 1
936  BPU_gf2PolyShiftRightOne(&divisor);
937  // set actual degree
938  BPU_gf2PolySetDeg(&divisor, -1);
939  i++;
940  }
941 
942  BPU_gf2PolyCopy(r, &dividend);
943  BPU_gf2PolySetDeg(q, -1);
944 
945  // free
946  BPU_gf2PolyFree(&dividend, 0);
947  BPU_gf2PolyFree(&divisor, 0);
948 }
949 
950 // XGCD with binary polynomial with high degree
952  BPU_T_GF2_Poly tmp, tmp_2, old_s, old_t, old_r, r, q;
953  int deg = (a->len > b->len) ? a->len : b->len;
954 
955  // allocate Bezout coeffitients
956  BPU_gf2PolyMalloc(s, 0);
957  BPU_gf2PolyMalloc(t, deg);
958  BPU_gf2PolyMalloc(&old_s, deg);
959  BPU_gf2PolyMalloc(&old_t, 0);
960 
961  // set initial values
962  BPU_gf2PolyCopy(&r, a);
963  BPU_gf2PolyCopy(&old_r, b);
964 
965  if (a->len == 0) {
966  old_t.elements[0] = 1ul;
967  BPU_gf2PolySetDeg(&old_t, -1);
968  }
969  else if (b->len == 0) {
970  BPU_gf2PolyFree(&old_r, 0);
971  BPU_gf2PolyCopy(&old_r, a);
972  old_s.elements[0] = 1ul;
973  BPU_gf2PolySetDeg(&old_s, -1);
974  }
975  // run algoritm, if everything is OK
976  else {
977  // set initial values
978  old_s.elements[0] = 1ul;
979  BPU_gf2PolySetDeg(&old_s, -1);
980  t->elements[0] = 1ul;
981  BPU_gf2PolySetDeg(t, -1);
982 
983  // while loop until r is not zero
984  while (r.len > 0) {
985  // divide
986  BPU_gf2PolyDiv(&q, &tmp, &old_r, &r);
987 
988  // save old reminder
989  BPU_gf2PolyFree(&old_r, 0);
990  BPU_gf2PolyCopy(&old_r, &r);
991 
992  // save current reminder
993  BPU_gf2PolyFree(&r, 0);
994  BPU_gf2PolyCopy(&r, &tmp);
995 
996  // free
997  BPU_gf2PolyFree(&tmp, 0);
998 
999  // save s quocient
1000  BPU_gf2PolyCopy(&tmp, &old_s);
1001  BPU_gf2PolyFree(&old_s, 0);
1002  BPU_gf2PolyCopy(&old_s, s);
1003 
1004  BPU_gf2PolyMulMod(&q, s, &tmp_2, m, 1);
1005  BPU_gf2PolyAdd(&tmp, &tmp_2, 1);
1006  BPU_gf2PolyFree(s, 0);
1007  BPU_gf2PolyCopy(s, &tmp);
1008 
1009  // free
1010  BPU_gf2PolyFree(&tmp, 0);
1011  BPU_gf2PolyFree(&tmp_2, 0);
1012 
1013  // save t quocient
1014  BPU_gf2PolyCopy(&tmp, &old_t);
1015  BPU_gf2PolyFree(&old_t, 0);
1016  BPU_gf2PolyCopy(&old_t, t);
1017  BPU_gf2PolyMulMod(&q, t, &tmp_2, m, 1);
1018  BPU_gf2PolyAdd(&tmp, &tmp_2, 1);
1019  BPU_gf2PolyFree(t, 0);
1020  BPU_gf2PolyCopy(t, &tmp);
1021 
1022  // free
1023  BPU_gf2PolyFree(&tmp_2, 0);
1024  BPU_gf2PolyFree(&tmp, 0);
1025  BPU_gf2PolyFree(&q, 0);
1026  }
1027  }
1028  // prepare return values
1029  BPU_gf2PolyFree(t, 0);
1030  BPU_gf2PolyFree(s, 0);
1031  BPU_gf2PolyCopy(d, &old_r);
1032  BPU_gf2PolyCopy(s, &old_s);
1033  BPU_gf2PolyCopy(t, &old_t);
1034 
1035  // free
1036  BPU_gf2PolyFree(&old_s, 0);
1037  BPU_gf2PolyFree(&old_t, 0);
1038  BPU_gf2PolyFree(&old_r, 0);
1039  BPU_gf2PolyFree(&r, 0);
1040 }
1041 
1043  BPU_T_GF2_Poly d, s;
1044  int ret = 1;
1045 
1046  // call XGCD
1047  BPU_gf2PolyExtEuclidA(&d, &s, out, a, m, m);
1048 
1049  // if GCD (a,m) is not 1
1050  if (d.len != 1 || d.elements[0] != 1ul) {
1051  BPU_printDebug("inverse polynomial NOT found");
1052  ret = 0;
1053  }
1054 
1055  // free
1056  BPU_gf2PolyFree(&d, 0);
1057  BPU_gf2PolyFree(&s, 0);
1058  return ret;
1059 }
1060 
1062  int i;
1063 
1064  // allocate output poly
1065  BPU_gf2PolyMalloc(out, in->len);
1066 
1067  // copy zero coefficient
1068  BPU_gf2VecSetBit(out, 0, BPU_gf2VecGetBit(in, 0));
1069 
1070  // swap other coefficients
1071  for (i = 1; i < out->len; i++) {
1072  BPU_gf2VecSetBit(out, out->len-i, BPU_gf2VecGetBit(in, i));
1073  }
1074 }
1075 
1077  int i;
1078 
1079  // allocate output matrix
1081 
1082  // transpose all polynoms
1083  for (i = 0; i < in->element_count; i++)
1084  BPU_gf2PolyTransp(&out->matrices[i], &in->matrices[i]);
1085 }
1086 
1088  int i;
1089 
1090  // scan all elements
1091  for (i = 0; i < a->elements_in_row; i++)
1092  // if there is non zero element, poly is not zero
1093  if (a->elements[i] != 0ul)
1094  return 0;
1095 
1096  // all elements are zero, so also poly is zero
1097  return 1;
1098 }
int BPU_gf2PolyIsZero(const BPU_T_GF2_Poly *a)
Definition: gf2.c:1087
int BPU_gf2MatFindCol(const BPU_T_GF2_Matrix *mat, int i, int start_index)
Definition: gf2.c:366
int BPU_gf2VecMalloc(BPU_T_GF2_Vector **v, int len)
Definition: gf2types.c:97
uint32_t weight
weight of polynomial
Definition: gf2types.h:64
#define BPU_gf2VecNull(v_pointer)
Null GF2 vector.
Definition: gf2types.h:112
void BPU_gf2PolyMulMod(const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b, BPU_T_GF2_Poly *c, const BPU_T_GF2_Poly *m, int crop)
Definition: gf2.c:876
int BPU_gf2VecXor(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in)
Xor two Vectors GF2 and store result in first vector.
Definition: gf2.c:481
int BPU_gf2SparsePolyAndHW(const BPU_T_GF2_Poly *a, const BPU_T_GF2_Sparse_Poly *b)
Definition: gf2.c:839
BPU_T_GF2_Sparse_Poly * matrices
all cyclic matrices of matrix
Definition: gf2types.h:91
void BPU_printGf2Poly(const BPU_T_GF2_Poly *v)
Definition: gf2.c:184
uint8_t isVertical
if 1, elements are in vertical orientation, if 0 horizontal orientation
Definition: gf2types.h:94
void BPU_gf2PolyDiv(BPU_T_GF2_Poly *q, BPU_T_GF2_Poly *r, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b)
Definition: gf2.c:912
BPU_T_Perm_Element * elements
permutation vector
Definition: permtypes.h:32
BPU_T_GF2 BPU_gf2VecGetMaskedBit(const BPU_T_GF2_Vector *vec, uint32_t bit)
Definition: gf2.c:314
void BPU_gf2PolyMulX(BPU_T_GF2_Poly *a)
Definition: gf2.c:772
void BPU_gf2SparseQcMatrixGetRow(BPU_T_GF2_Sparse_Poly *p, const BPU_T_GF2_Sparse_Qc_Matrix *m, int row_num)
Definition: gf2.c:852
uint32_t k
rows of whole matrix
Definition: gf2types.h:80
void BPU_printBinaryMsbLn(uint32_t in, int len)
Print number as binary string in big endian so msb is first printed.
Definition: gf2.c:39
void BPU_gf2VecFree(BPU_T_GF2_Vector **v)
Free dynamically or statically allocated vector.
Definition: gf2types.c:45
uint16_t element_count
number of cyclic matrices
Definition: gf2types.h:92
int msb32(uint32_t x, int start, int len, int ele_size)
Definition: int.c:35
void BPU_printGf2VecMsb(const BPU_T_GF2_Vector *v)
BPU_printGf2VecMsb Most significant bit is printed first.
Definition: gf2.c:122
void BPU_printGf2Mat(const BPU_T_GF2_Matrix *m)
Definition: gf2.c:73
void BPU_gf2MatSwapRows(BPU_T_GF2_Matrix *mat, int i, int j)
Definition: gf2.c:347
int BPU_gf2PolyInitRand(BPU_T_GF2_Poly *out, int l, int w, int set_deg)
Definition: gf2.c:626
void BPU_printGf2PolyForMatrix(const BPU_T_GF2_Poly *v)
Definition: gf2.c:165
uint16_t elements_in_row
number of elements in one row
Definition: gf2types.h:46
void BPU_gf2PolyExtEuclidA(BPU_T_GF2_Poly *d, BPU_T_GF2_Poly *s, BPU_T_GF2_Poly *t, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b, const BPU_T_GF2_Poly *m)
Definition: gf2.c:951
void BPU_printBinaryMsb32Ln(uint32_t in)
Print number as binary string in big endian so msb is first printed.
Definition: gf2.c:48
void BPU_gf2PolyFree(BPU_T_GF2_Poly *p, int is_dyn)
Definition: gf2types.c:187
uint32_t element_size
size of cyclic matrix
Definition: gf2types.h:77
BPU_T_GF2 BPU_gf2MatGetMaskedBit(const BPU_T_GF2_Matrix *m, uint32_t row, uint32_t bit)
Definition: gf2.c:305
int BPU_gf2VecRand(BPU_T_GF2_Vector *out, int w)
Definition: gf2.c:240
uint8_t is_I_appended
if matrix has identity matrix on left
Definition: gf2types.h:81
uint32_t * index
indexes of set coefficients. 0 is coefficient for x^0
Definition: gf2types.h:63
void BPU_gf2SparsePolyCopy(BPU_T_GF2_Sparse_Poly *out, const BPU_T_GF2_Sparse_Poly *in)
Definition: gf2.c:642
#define BPU_printWarning(fmt,...)
print warning message with filename, line
Definition: debugio.h:55
uint32_t k
rows
Definition: gf2types.h:47
int BPU_gf2MatPermute(BPU_T_GF2_Matrix *inout, BPU_T_Perm_Vector *permutation)
Definition: gf2.c:526
void BPU_gf2PolyShiftLeft(BPU_T_GF2_Poly *a, int shift_count)
Definition: gf2.c:681
void BPU_printGf2SparsePoly(const BPU_T_GF2_Sparse_Poly *v)
Definition: gf2.c:155
uint32_t BPU_prngGetRand(int from, int to)
Get random unsigned int 32 value from given range (from <= return <= to)
Definition: prng.c:28
int BPU_gf2VecCmp(const BPU_T_GF2_Vector *v1, const BPU_T_GF2_Vector *v2)
BPU_gf2VecCmp Compare two vectors.
Definition: gf2.c:467
void BPU_gf2MatXorRows(BPU_T_GF2_Matrix *mat, int i, int j)
Definition: gf2.c:518
void BPU_printBinary32LsbLn(uint32_t in)
Print number as binary string in little endian so lsb is first printed.
Definition: gf2.c:69
int BPU_gf2VecMulMat(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *v, const BPU_T_GF2_Matrix *b)
Definition: gf2.c:495
int BPU_gf2MatGetRowAsGf2Vec(BPU_T_GF2_Vector *out, const BPU_T_GF2_Matrix *in, int row)
Definition: gf2.c:444
int BPU_gf2PolyGetHighestBitPos(BPU_T_GF2_Poly *a)
Definition: gf2.c:733
void BPU_printGf2SparseQcMatrix(const BPU_T_GF2_Sparse_Qc_Matrix *v)
Definition: gf2.c:225
#define BPU_printError(fmt,...)
print error message with filename, line
Definition: debugio.h:47
#define BPU_gf2MatSetBit(m_pointer, s, t, bit)
Definition: gf2.h:201
void BPU_printGf2VecOnes(const BPU_T_GF2_Vector *vec)
BPU_printGf2VecOnes Print only ones.
Definition: gf2.c:144
uint32_t k
rows of whole matrix
Definition: gf2types.h:96
uint32_t BPU_T_GF2
Definition: gf2types.h:26
void BPU_gf2PolyTransp(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in)
Definition: gf2.c:1061
void BPU_gf2SparseQcMatrixTransp(BPU_T_GF2_Sparse_Qc_Matrix *out, const BPU_T_GF2_Sparse_Qc_Matrix *in)
Definition: gf2.c:652
uint32_t n
cols of whole matrix
Definition: gf2types.h:79
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
Definition: gf2types.h:45
uint32_t element_size
size of cyclic matrix
Definition: gf2types.h:93
BPU_T_GF2 * elements
all element of matrix
Definition: gf2types.h:33
void BPU_gf2SparseQcMatrixMalloc(BPU_T_GF2_Sparse_Qc_Matrix *v, int element_count, int element_size, int isVertical)
Definition: gf2types.c:154
#define BPU_printDebug(fmt,...)
print debug message with filename, line
Definition: debugio.h:63
int BPU_gf2VecResize(BPU_T_GF2_Vector *v, int len)
BPU_gf2VecResize Resize vecor.
Definition: gf2types.c:107
BPU_T_Perm_Element size
permutation size
Definition: permtypes.h:33
uint16_t element_count
number of cyclic matrices
Definition: gf2types.h:76
#define BPU_gf2VecSetBit(v_pointer, i, bit)
Definition: gf2.h:215
int BPU_gf2QcMatrixToSparse(BPU_T_GF2_Sparse_Qc_Matrix *out, const BPU_T_GF2_QC_Matrix *in, const int wi[])
Definition: gf2.c:599
int BPU_gf2MatMakeSystematic(BPU_T_GF2_Matrix *inout)
It brings Matrix GF2 into the systematic form -> with I on the left side.
Definition: gf2.c:376
void BPU_gf2VecCopy(BPU_T_GF2_Vector *dest, const BPU_T_GF2_Vector *src)
Copy VectorGF2.
Definition: gf2.c:454
int BPU_gf2MatCrop(BPU_T_GF2_Matrix *m, uint16_t width)
Crop matrix GF2 from left.
Definition: gf2.c:552
int BPU_gf2MatFindRow(const BPU_T_GF2_Matrix *mat, int i, int start_index)
Definition: gf2.c:356
uint16_t elements_in_row
number of elements in one row
Definition: gf2types.h:35
void BPU_gf2PolyShiftRightOne(BPU_T_GF2_Poly *a)
Definition: gf2.c:792
int BPU_gf2VecPermute(BPU_T_GF2_Vector *vec, const BPU_T_Perm_Vector *permutation)
Definition: gf2.c:289
void BPU_printBinaryLsb(uint32_t in, int len)
Print number as binary string in little endian so lsb is first printed.
Definition: gf2.c:52
void BPU_printBinaryLsbLn(uint32_t in, int len)
Print number as binary string in little endian so lsb is first printed.
Definition: gf2.c:60
uint32_t n
cols
Definition: gf2types.h:48
void BPU_printBinaryMsb(uint32_t in, int len)
Print number as binary string in big endian so msb is first printed.
Definition: gf2.c:31
#define BPU_gf2MatCopyRowToVec(v_pointer, m_pointer, row)
Copy Matrix GF2 row to Vector GF2.
Definition: gf2.h:230
int BPU_gf2MatTransp(BPU_T_GF2_Matrix *out, const BPU_T_GF2_Matrix *in)
Definition: gf2.c:323
void BPU_gf2Swap(BPU_T_GF2 *a, BPU_T_GF2 *b)
Definition: gf2.c:340
void BPU_gf2SparsePolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Sparse_Poly *in)
Definition: gf2.c:830
int BPU_gf2PolyInv(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *m)
Definition: gf2.c:1042
int BPU_gf2VecCrop(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const int start, const int length)
Definition: gf2.c:424
uint32_t len
cols
Definition: gf2types.h:36
void BPU_printBinaryLsb32(uint32_t in)
Print number as binary string in little endian so lsb is first printed.
Definition: gf2.c:65
void BPU_gf2PolySetDeg(BPU_T_GF2_Poly *a, int deg)
Definition: gf2.c:747
int BPU_gf2PolyMalloc(BPU_T_GF2_Poly *p, int len)
Definition: gf2types.c:195
void BPU_gf2SparsePolyMalloc(BPU_T_GF2_Sparse_Poly *p, int weight)
Definition: gf2types.c:140
void BPU_gf2PolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in, int crop)
Definition: gf2.c:806
#define BPU_gf2MatGetBit(m_pointer, s, t)
Check if is set bit at s, t position in matrix.
Definition: gf2.h:183
void BPU_printGf2QcMatrix(const BPU_T_GF2_QC_Matrix *v)
Definition: gf2.c:205
void BPU_printGf2Vec(const BPU_T_GF2_Vector *v)
Definition: gf2.c:100
BPU_T_GF2_Poly * matrices
all cyclic matrices of matrix
Definition: gf2types.h:75
void BPU_gf2SparsePolyFree(BPU_T_GF2_Sparse_Poly *p, int is_dyn)
Definition: gf2types.c:147
uint8_t BPU_getParity(BPU_T_GF2 dword)
BPU_getParity Get parity of word.
Definition: gf2.c:576
int BPU_gf2MatCopy(BPU_T_GF2_Matrix *out, const BPU_T_GF2_Matrix *in)
BPU_gf2MatCopyCreate copy of input matrix.
Definition: gf2.c:271
int BPU_gf2QcMatrixMalloc(BPU_T_GF2_QC_Matrix *v, int element_count, int element_size, int isVertical, int is_I_appended)
Definition: gf2types.c:220
#define BPU_gf2VecGetBit(v_pointer, i)
Check if is set bit at i-th position in vector.
Definition: gf2.h:192
int BPU_gf2VecConcat(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *vec1, const BPU_T_GF2_Vector *vec2)
Concats two vectors without allocation ouput.
Definition: gf2.c:399
void BPU_printBinaryMsb32(uint32_t in)
Print number as binary string in big endian so msb is first printed.
Definition: gf2.c:44
void BPU_gf2PolyCopy(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in)
Definition: gf2.c:586
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
Definition: gf2types.h:34
uint8_t isVertical
if 1, elements are in vertical orientation, if 0 horizontal orientation
Definition: gf2types.h:78
uint32_t n
cols of whole matrix
Definition: gf2types.h:95
void BPU_gf2QcMatrixTransp(BPU_T_GF2_QC_Matrix *out, const BPU_T_GF2_QC_Matrix *in)
Definition: gf2.c:1076
BPU_T_GF2 ** elements
all element of matrix
Definition: gf2types.h:44