BitPunch McEliece  v0.0.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
qcmdpc.c
Go to the documentation of this file.
1 /*
2 This file is part of BitPunch
3 Copyright (C) 2015 Frantisek Uhrecky <frantisek.uhrecky[what here]gmail.com>
4 Copyright (C) 2015 Andrej Gulyas <andrej.guly[what here]gmail.com>
5 
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "qcmdpc.h"
21 
22 #ifdef BPU_CONF_ENCRYPTION
23 int BPU_mecsQcmdpcEncode(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const struct _BPU_T_Code_Ctx *ctx) {
24 
25  BPU_T_GF2_Poly temp_ct, temp_rot_row;
26  int ele, bit, i, bit_in_msg = 0;
27 
28  // copy message into cipher text
29  for (i = 0; i < in->elements_in_row; i++)
30  out->elements[i] = in->elements[i];
31 
32  // prolong ciphertext
33  BPU_gf2PolySetDeg(out, ctx->code_len);
34 
35  // calc rest of cipher text (Q x m)
37  // for all matrices in G
38  for (ele = 0; ele < ctx->code_spec->qcmdpc->G.element_count; ele++) {
39  // get matrix
40  BPU_gf2PolyCopy(&temp_rot_row, &ctx->code_spec->qcmdpc->G.matrices[ele]);
41  // for all bits in matrix
42  for (bit = 0; bit < ctx->code_spec->qcmdpc->G.element_size; bit++) {
43  // if is set bit in message
44  if (BPU_gf2PolyGetBit(in, bit_in_msg)) {
45  for (i = 0; i < temp_rot_row.elements_in_row; i++)
46  temp_ct.elements[i] ^= temp_rot_row.elements[i];
47  }
48  bit_in_msg++;
49  // get next row by shift
50  BPU_gf2PolyMulX(&temp_rot_row);
51  }
52  BPU_gf2PolyFree(&temp_rot_row, 0);
53  }
54 
55  // join ciphertext
57  BPU_gf2PolyAdd(out, &temp_ct, 0);
58  BPU_gf2PolyFree(&temp_ct, 0);
59 
60  return 0;
61 }
62 #endif
63 
64 #ifdef BPU_CONF_DECRYPTION
66 
67  int ret = 0, delta = BPU_QCMDPC_PARAM_DELTA;
68  int i;
69 
70  // BPU_printGf2Vec(ctx->e);
71  // null error vector
72  BPU_gf2VecNull(ctx->e);
73 
74  // try to decode with faster algorithm
75  if (!BPU_mecsQcmdpcDecode2(ctx->e, in, ctx)) {
76  // free decoded
77  BPU_gf2VecNull(ctx->e);
78  while(1) {
79  // if not decoded, try algorithm with lower DFR
80  if (!BPU_mecsQcmdpcDecode1(ctx->e, in, delta, ctx)) {
81  // free decoded
82  BPU_gf2VecNull(ctx->e);
83  // if not decoded decrease threshold tolerance param
84  delta--;
85  if (delta < 0) {
86  ret = -1;
87  break;
88  }
89  }
90  else
91  break;
92  }
93  }
94 
95  // if decoded, get message from first param_m bits
96  if (ret == 0) {
97  // decrypt message
98  for (i = 0; i < out->elements_in_row; i++)
99  out->elements[i] = ctx->e->elements[i] ^ in->elements[i];
100  // crop last element
101  out->elements[out->elements_in_row-1] <<= out->element_bit_size - (out->len % out->element_bit_size);
102  out->elements[out->elements_in_row-1] >>= out->element_bit_size - (out->len % out->element_bit_size);
103  }
104  else
105  BPU_gf2VecNull(ctx->e);
106 
107  return ret;
108 }
109 
110 int BPU_mecsQcmdpcDecode1(BPU_T_GF2_Vector *error_vec, const BPU_T_GF2_Vector *cipher_text, int delta, const struct _BPU_T_Code_Ctx *ctx) {
111  BPU_T_GF2_Poly syndrom;
113  int iter = -1, max, bit, upc, upc_counts[cipher_text->len], isSyndromZero = 0;
114  int flipped_bits = 0, flipped_bits_iter = 0;
115 
116  // allocate output error vector
117  // BPU_gf2PolyMalloc(error_vec, cipher_text->len);
118 
119  // calc the syndrom
120  BPU_mecsQcmdpcCalcSyndrom(&syndrom, cipher_text, ctx);
121  // check syndrom
122  if (!BPU_gf2PolyIsZero(&syndrom)) {
123  // for max iterations
124  for (iter = 0; iter < BPU_QCMDPC_PARAM_MAX_ITER; iter++) {
125  max = 0;
126  // for every bit of cipher text
127  for (bit = 0; bit < error_vec->len; bit++) {
128  // calc #UPC
129  BPU_gf2SparseQcMatrixGetRow(&row, &ctx->code_spec->qcmdpc->H, bit);
130  upc = BPU_gf2SparsePolyAndHW(&syndrom, &row);
131  upc_counts[bit] = upc;
132  if (upc > max)
133  max = upc;
134  BPU_gf2SparsePolyFree(&row, 0);
135  }
136 
137  if (max == 0) {
138  isSyndromZero = 0;
139  break;
140  }
141 
142 
143  flipped_bits_iter = 0;
144  // check which bits to flip
145  for (bit = 0; bit < error_vec->len; bit++) {
146  if (upc_counts[bit] > 0 && upc_counts[bit] >= (max-delta)) {
147  flipped_bits++; flipped_bits_iter++;
148  // flip bit
149  BPU_gf2VecSetBit(error_vec, bit, !BPU_gf2VecGetBit(error_vec, bit));
150  // update syndrom
151  BPU_gf2SparseQcMatrixGetRow(&row, &ctx->code_spec->qcmdpc->H, bit);
152  BPU_gf2SparsePolyAdd(&syndrom, &row);
153  BPU_gf2SparsePolyFree(&row, 0);
154  // check the syndrom
155  if (BPU_gf2PolyIsZero(&syndrom)) {
156  isSyndromZero = 1;
157  break;
158  }
159  }
160  }
161 
162  if (isSyndromZero)
163  break;
164  }
165  }
166  else {
167  isSyndromZero = 1;
168  }
169  //free
170  BPU_gf2PolyFree(&syndrom, 0);
171 
172  return isSyndromZero;
173 }
174 
175 int BPU_mecsQcmdpcDecode2(BPU_T_GF2_Vector *error_vec, const BPU_T_GF2_Vector *cipher_text, const struct _BPU_T_Code_Ctx *ctx) {
176  BPU_T_GF2_Poly syndrom;
178  int iter = -1, bit, upc, isSyndromZero = 0;
179  int flipped_bits = 0, flipped_bits_iter = 0;
180  const uint16_t B_store[BPU_QCMDPC_MAX_B_VALUES]={28,26,24,22,20};
181 
182  // calc the syndrom
183  BPU_mecsQcmdpcCalcSyndrom(&syndrom, cipher_text, ctx);
184 
185  // check syndrom
186  if (!BPU_gf2PolyIsZero(&syndrom)) {
187  // for max iterations
188  for (iter = 0; iter < BPU_QCMDPC_PARAM_MAX_ITER; iter++) {
189  flipped_bits_iter = 0;
190  // for every bit of cipher text
191  for (bit = 0; bit < error_vec->len; bit++) {
192  // calc #UPC
193  BPU_gf2SparseQcMatrixGetRow(&row, &ctx->code_spec->qcmdpc->H, bit);
194  upc = BPU_gf2SparsePolyAndHW(&syndrom, &row);
195 
196  // check which bits to flip
197  if (upc > 0 && upc >= B_store[iter < BPU_QCMDPC_MAX_B_VALUES ? iter : (BPU_QCMDPC_MAX_B_VALUES-1)]-BPU_QCMDPC_PARAM_DELTA_B) {
198  flipped_bits++; flipped_bits_iter++;
199  // flip bit
200  BPU_gf2VecSetBit(error_vec, bit, !BPU_gf2VecGetBit(error_vec, bit));
201  // update syndrom
202  BPU_gf2SparsePolyAdd(&syndrom, &row);
203  // check the syndrom
204  if (BPU_gf2PolyIsZero(&syndrom)) {
205  isSyndromZero = 1;
206  BPU_gf2SparsePolyFree(&row, 0);
207  break;
208  }
209  }
210  BPU_gf2SparsePolyFree(&row, 0);
211  }
212 
213  if (flipped_bits_iter < 1) {
214  isSyndromZero = 0;
215  break;
216  }
217 
218  if (isSyndromZero)
219  break;
220  }
221  }
222  else {
223  isSyndromZero = 1;
224  }
225  //free
226  BPU_gf2PolyFree(&syndrom, 0);
227 
228  return isSyndromZero;
229 }
230 
231 void BPU_mecsQcmdpcCalcSyndrom(BPU_T_GF2_Vector *syndrom, const BPU_T_GF2_Vector *cipher_text, const struct _BPU_T_Code_Ctx *ctx) {
233  int i;
234 
235  BPU_gf2PolyMalloc(syndrom, ctx->code_spec->qcmdpc->H.n);
236  for (i = 0; i < cipher_text->len; i++) {
237  if (BPU_gf2VecGetBit(cipher_text, i) == 1ul) {
238  BPU_gf2SparseQcMatrixGetRow(&row, &ctx->code_spec->qcmdpc->H, i);
239  BPU_gf2SparsePolyAdd(syndrom, &row);
240  BPU_gf2SparsePolyFree(&row, 0);
241  }
242  }
243 }
244 #endif
245 
246 #ifdef BPU_CONF_KEY_GEN
248 
249  BPU_T_GF2_Poly H_temp[ctx->code_spec->qcmdpc->n0];
250  BPU_T_GF2_Poly G_temp[ctx->code_spec->qcmdpc->n0-1];
251  BPU_T_GF2_Poly H_last_inv, mod, test_inv;
252  BPU_T_GF2_QC_Matrix G_temp_mat, H_temp_mat;
253  BPU_T_GF2_Sparse_Qc_Matrix H_temp_sparse;
254  int wi[ctx->code_spec->qcmdpc->n0];
255  int ret = 0, i, err = 0;
256 
257  // init modulus like 1000000...0001
258  BPU_gf2PolyMalloc(&mod, ctx->code_spec->qcmdpc->m+1);
259  BPU_gf2VecSetBit(&mod, ctx->code_spec->qcmdpc->m, 1ul);
260  BPU_gf2VecSetBit(&mod, 0, 1ul);
261 
262  #if defined(DEBUG_L)
263  BPU_printDebug("modulus: ");
264 // BPU_printGf2Poly(&mod);
265  BPU_printDebug("generating H vectors");
266  #endif
267 
268  // alloc parity-check matrix
269  for (i = 0; i < ctx->code_spec->qcmdpc->n0; i++) {
270  // calc weight of polynomials (last poly must be odd)
271  if ((ctx->code_spec->qcmdpc->w/ctx->code_spec->qcmdpc->n0) % 2 == 1)
272  wi[i] = ctx->code_spec->qcmdpc->w/ctx->code_spec->qcmdpc->n0 + (int)(i < (ctx->code_spec->qcmdpc->w%ctx->code_spec->qcmdpc->n0));
273  else
274  wi[i] = ctx->code_spec->qcmdpc->w/ctx->code_spec->qcmdpc->n0 + (int)(i < (ctx->code_spec->qcmdpc->w%ctx->code_spec->qcmdpc->n0)) + (int)(i == 0) - (int)(i == ctx->code_spec->qcmdpc->n0-1);
275 
276  // generate random polynomials of given weight
277  err += BPU_gf2PolyInitRand(&H_temp[i], ctx->code_spec->qcmdpc->m, wi[i], 1);
278  #if defined(DEBUG_L)
279  BPU_printDebug("H[%i]: ", i);
280 // BPU_printGf2Poly(&H_temp[i]);
281  #endif
282  }
283 
284  if (!err) {
285  BPU_printDebug("generation successful");
286  }
287  else {
288  BPU_printError("generation failed");
289  }
290 
291  BPU_printDebug("finding inversion to H[%i]", ctx->code_spec->qcmdpc->n0-1);
292  // check if H[n0-1] has inversion
293  ret = 0;
294  while (!ret) {
295  BPU_gf2PolySetDeg(&H_temp[ctx->code_spec->qcmdpc->n0-1], -1);
296  // find inversion using XGCD
297  ret = BPU_gf2PolyInv(&H_last_inv, &H_temp[ctx->code_spec->qcmdpc->n0-1], &mod);
298 
299  // if inversion exists, test it (poly x inversion modulo = 1)
300  if (ret) {
301  BPU_printDebug("testing inversion");
302  BPU_gf2PolyMulMod(&H_last_inv, &H_temp[ctx->code_spec->qcmdpc->n0-1], &test_inv, &mod, 1);
303  if (test_inv.len != 1 || test_inv.elements[0] != 1ul) {
304  ret = 0;
305  BPU_printWarning("inversion failed");
306  }
307  else{
308  BPU_printDebug("inversion OK");
309  }
310  BPU_gf2PolyFree(&test_inv, 0);
311  }
312 
313  // inversion not found, regenerate last poly and try to find inversion again
314  if (!ret) {
315  BPU_printDebug("inversion not found");
316  BPU_printDebug("generating new H[%i]", ctx->code_spec->qcmdpc->n0-1);
317  BPU_gf2PolyFree(&H_temp[ctx->code_spec->qcmdpc->n0-1], 0);
318  ret += BPU_gf2PolyInitRand(&H_temp[ctx->code_spec->qcmdpc->n0-1], ctx->code_spec->qcmdpc->m, wi[ctx->code_spec->qcmdpc->n0-1], 1);
319  #if defined(DEBUG_L)
320  BPU_printGf2Poly(&H_temp[ctx->code_spec->qcmdpc->n0-1]);
321  #endif
322  BPU_gf2PolyFree(&H_last_inv, 0);
323  }
324  }
325 
326  #if defined(DEBUG_L)
327  BPU_printDebug("inversion to H[%i] found ", ctx->code_spec->qcmdpc->n0-1);
328 // BPU_printGf2Poly(&H_last_inv);
329  BPU_printDebug("creating H matrix");
330  #endif
331 
332  // create H temp matrix
333  BPU_gf2QcMatrixMalloc(&H_temp_mat, ctx->code_spec->qcmdpc->n0, ctx->code_spec->qcmdpc->m, 0, 0);
334  for (i = 0; i < ctx->code_spec->qcmdpc->n0; i++) {
335  H_temp[i].len = ctx->code_spec->qcmdpc->m;
336  BPU_gf2PolyCopy(&H_temp_mat.matrices[i], &H_temp[i]);
337  }
338 
339  BPU_gf2QcMatrixToSparse(&H_temp_sparse, &H_temp_mat, wi);
340 
341  #if defined(DEBUG_L)
342  BPU_printDebug("H: ");
343 // BPU_printGf2QcMatrix(&H_temp_mat);
344  BPU_printDebug("H sparse: ");
345 // BPU_printGf2SparseQcMatrix(&H_temp_sparse);
346  BPU_printDebug("creating G matrix");
347  #endif
348 
349  // create G temp matrix
350  for (i = 0; i < ctx->code_spec->qcmdpc->n0-1; i++) {
351  BPU_printDebug("multiplicating vectors H[%i]^-1 x H[%i]", ctx->code_spec->qcmdpc->n0-1, i);
352  BPU_gf2PolyMulMod(&H_last_inv, &H_temp[i], &G_temp[i], &mod, 0);
353  #if defined(DEBUG_L)
354 // BPU_printGf2Poly(&G_temp[i]);
355  #endif
356  }
357 
358  BPU_printDebug("creating temp G for GH^T test");
359  BPU_gf2QcMatrixMalloc(&G_temp_mat, ctx->code_spec->qcmdpc->n0-1, ctx->code_spec->qcmdpc->m, 0, 1);
360  for (i = 0; i < ctx->code_spec->qcmdpc->n0-1; i++) {
361  BPU_gf2PolyCopy(&G_temp_mat.matrices[i], &G_temp[i]);
362  }
363 
364  ret = 0;
365 
366  BPU_printDebug("testing GH^T");
367 
368  // test if G x H^T = 0
369  if (BPU_mecsQcmdpcTestGHmatrices(&G_temp_mat, &H_temp_sparse) != 0) {
370  BPU_printError("generator x parity check matrix ERROR");
371  ret = -1;
372  }
373  else {
374  BPU_printDebug("GH^t = 0");
375  }
376 
377  // transpose G matrix
378  if (ret == 0) {
379  BPU_gf2QcMatrixTransp(&ctx->code_spec->qcmdpc->G, &G_temp_mat);
380  #if defined(DEBUG_L)
381  BPU_printDebug("transposing G matrix");
382 // BPU_printGf2QcMatrix(&ctx->code_spec->qcmdpc->G);
383  #endif
384  }
385 
386  // transpose H matrix
387  if (ret == 0) {
388  BPU_gf2SparseQcMatrixTransp(&ctx->code_spec->qcmdpc->H, &H_temp_sparse);
389  #if defined(DEBUG_L)
390  BPU_printDebug("transposing H matrix");
391 // BPU_printGf2SparseQcMatrix(&ctx->code_spec->qcmdpc->H);
392  #endif
393  }
394 
395  BPU_printDebug("free and exit");
396 
397  // free
398  for (i = 0; i < ctx->code_spec->qcmdpc->n0-1; i++)
399  BPU_gf2PolyFree(&G_temp[i], 0);
400 
401  for (i = 0; i < ctx->code_spec->qcmdpc->n0; i++)
402  BPU_gf2PolyFree(&H_temp[i], 0);
403 
404  BPU_gf2PolyFree(&H_last_inv, 0);
405  BPU_gf2PolyFree(&mod, 0);
406  BPU_gf2QcMatrixFree(&G_temp_mat, 0);
407  BPU_gf2QcMatrixFree(&H_temp_mat, 0);
408  BPU_gf2SparseQcMatrixFree(&H_temp_sparse, 0);
409 
410  return ret;
411 }
412 
414  int i, element, err = 0;
415  BPU_T_GF2_Poly temp;
417 
418  // get I * H[0] + ... + I * H[n0-2]
419  BPU_gf2PolyMalloc(&temp, G->n);
420  for (i = 0; i < G->element_count; i++) {
421  BPU_gf2SparsePolyAdd(&temp, &H->matrices[i]);
422  }
423 
424  // get other rows
425  for (element = 0; element < G->element_count; element++) {
426  for (i = 0; i < G->element_size; i++) {
427  if (BPU_gf2VecGetBit(&G->matrices[element], i) == 1ul) {
429  BPU_gf2SparsePolyAdd(&temp, &row);
430  BPU_gf2SparsePolyFree(&row, 0);
431  }
432  }
433  }
434  // check result poly
435  for (i = 0; i < temp.elements_in_row; i++) {
436  if (temp.elements[i] != 0ul) {
437  err++;
438  break;
439  }
440  }
441 
442 #if defined(DEBUG_L)
443  BPU_T_GF2_QC_Matrix GH_result;
444  BPU_gf2QcMatrixMalloc(&GH_result, 1, G->element_size, 0, 0);
445  BPU_gf2PolyCopy(&GH_result.matrices[0], &temp);
446 // BPU_printGf2QcMatrix(&GH_result);
447  BPU_gf2QcMatrixFree(&GH_result, 0);
448 #endif
449 
450  BPU_gf2PolyFree(&temp, 0);
451 
452  return err;
453 }
454 
455 #endif
int BPU_gf2PolyIsZero(const BPU_T_GF2_Poly *a)
Definition: gf2.c:1087
BPU_T_Qcmdpc_Spec * qcmdpc
Definition: codectx.h:43
#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_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
int BPU_mecsQcmdpcDecrypt(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const struct _BPU_T_Code_Ctx *ctx)
Definition: qcmdpc.c:65
#define BPU_QCMDPC_PARAM_MAX_ITER
maximum count of iterations in decoding
Definition: qcmdpc.h:33
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
#define BPU_gf2PolyGetBit(poly, bit)
Definition: gf2.h:238
BPU_T_GF2_QC_Matrix G
generator matrix
Definition: qcmdpctypes.h:29
int BPU_gf2PolyInitRand(BPU_T_GF2_Poly *out, int l, int w, int set_deg)
Definition: gf2.c:626
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
#define BPU_printWarning(fmt,...)
print warning message with filename, line
Definition: debugio.h:55
uint16_t n0
number of cyclic matrices
Definition: qcmdpctypes.h:32
void BPU_gf2PolyShiftLeft(BPU_T_GF2_Poly *a, int shift_count)
Definition: gf2.c:681
int BPU_mecsQcmdpcTestGHmatrices(const BPU_T_GF2_QC_Matrix *G, const BPU_T_GF2_Sparse_Qc_Matrix *H)
Definition: qcmdpc.c:413
void BPU_gf2QcMatrixFree(BPU_T_GF2_QC_Matrix *v, int is_dyn)
Definition: gf2types.c:251
#define BPU_printError(fmt,...)
print error message with filename, line
Definition: debugio.h:47
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
void BPU_gf2SparseQcMatrixFree(BPU_T_GF2_Sparse_Qc_Matrix *v, int is_dyn)
Definition: gf2types.c:174
BPU_T_GF2 * elements
all element of matrix
Definition: gf2types.h:33
#define BPU_printDebug(fmt,...)
print debug message with filename, line
Definition: debugio.h:63
BPU_T_GF2_Vector * e
Error vector.
Definition: codectx.h:58
uint16_t element_count
number of cyclic matrices
Definition: gf2types.h:76
#define BPU_gf2VecSetBit(v_pointer, i, bit)
Definition: gf2.h:215
uint16_t w
weight of parity-check matrix row
Definition: qcmdpctypes.h:33
int BPU_gf2QcMatrixToSparse(BPU_T_GF2_Sparse_Qc_Matrix *out, const BPU_T_GF2_QC_Matrix *in, const int wi[])
Definition: gf2.c:599
uint16_t elements_in_row
number of elements in one row
Definition: gf2types.h:35
#define BPU_QCMDPC_MAX_B_VALUES
count of precalculated values for decode2 algorithm
Definition: qcmdpc.h:40
int BPU_mecsQcmdpcDecode1(BPU_T_GF2_Vector *error_vec, const BPU_T_GF2_Vector *cipher_text, int delta, const struct _BPU_T_Code_Ctx *ctx)
Definition: qcmdpc.c:110
void BPU_gf2SparsePolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Sparse_Poly *in)
Definition: gf2.c:830
int BPU_mecsQcmdpcEncode(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const struct _BPU_T_Code_Ctx *ctx)
Definition: qcmdpc.c:23
#define BPU_QCMDPC_PARAM_DELTA
starting param delta (threshold) for decode1 algorithm
Definition: qcmdpc.h:36
int BPU_gf2PolyInv(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *m)
Definition: gf2.c:1042
BPU_T_GF2_Sparse_Qc_Matrix H
parity-check matrix
Definition: qcmdpctypes.h:30
uint16_t m
size of cyclic matrix
Definition: qcmdpctypes.h:31
uint32_t len
cols
Definition: gf2types.h:36
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_gf2PolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in, int crop)
Definition: gf2.c:806
BPU_T_GF2_Poly * matrices
all cyclic matrices of matrix
Definition: gf2types.h:75
void BPU_mecsQcmdpcCalcSyndrom(BPU_T_GF2_Vector *syndrom, const BPU_T_GF2_Vector *cipher_text, const struct _BPU_T_Code_Ctx *ctx)
Definition: qcmdpc.c:231
void BPU_gf2SparsePolyFree(BPU_T_GF2_Sparse_Poly *p, int is_dyn)
Definition: gf2types.c:147
int BPU_mecsQcmdpcDecode2(BPU_T_GF2_Vector *error_vec, const BPU_T_GF2_Vector *cipher_text, const struct _BPU_T_Code_Ctx *ctx)
Definition: qcmdpc.c:175
#define BPU_QCMDPC_PARAM_DELTA_B
threshold for decode2
Definition: qcmdpc.h:39
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
int BPU_mecsQcmdpcGenKeys(BPU_T_Code_Ctx *ctx)
Definition: qcmdpc.c:247
#define BPU_gf2VecGetBit(v_pointer, i)
Check if is set bit at i-th position in vector.
Definition: gf2.h:192
void BPU_gf2PolyCopy(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in)
Definition: gf2.c:586
uint16_t code_len
Code len.
Definition: codectx.h:61
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
Definition: gf2types.h:34
BPU_T_UN_Code_Spec * code_spec
Code specific structure, like generator matrix, control matrix, gen. poly ...
Definition: codectx.h:59
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