31 #ifdef BPU_CONF_ENCRYPTION
62 #endif // BPU_CONF_ENCRYPTION
65 #ifdef BPU_CONF_DECRYPTION
109 inv_syndrome->
coef[1] = inv_syndrome->
coef[1] ^ 1;
165 #ifdef BPU_CONF_GOPPA_WO_H
170 #ifdef BPU_CONF_GOPPA_WO_H
171 for(column = 0; column < z->
len; column++) {
180 syndrome->
coef[syndrome->
max_deg - row] ^= element;
185 for (column = 0; column < z->
len; column++) {
196 int end_deg = mod->
deg / 2;
202 #endif // BPU_CONF_DECRYPTION
205 #ifdef BPU_CONF_KEY_GEN
207 int bit, bit_in_element = -1, act_element = 0;
209 int k, row, column,
e;
217 #ifndef BPU_CONF_GOPPA_WO_H
224 for(column = 0; column < h2->
n; column++) {
238 #ifndef BPU_CONF_GOPPA_WO_H
239 hx->
elements[row][column] = element;
241 for (bit = 0; bit < element_bit_size; bit++) {
242 h2->
elements[row*element_bit_size + bit][act_element] ^=
BPU_getBit(element, bit) << (bit_in_element);
256 #ifdef BPU_CONF_GOPPA_WO_H
274 while (permute != 0) {
286 #ifdef BPU_CONF_PRINT
295 #endif // BPU_CONF_KEY_GEN
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.
int BPU_gf2VecMalloc(BPU_T_GF2_Vector **v, int len)
#define BPU_gf2VecNull(v_pointer)
Null GF2 vector.
#define BPU_getBit(w, n)
Check if is set bit at n-th index.
int BPU_gf2VecXor(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in)
Xor two Vectors GF2 and store result in first vector.
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)
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_GF2_16x mod
polynomial modulus
int BPU_goppaInitMatH2(BPU_T_GF2_Matrix *h2, BPU_T_GF2_16x_Matrix *hx, const BPU_T_Code_Ctx *ctx)
BPU_goppaInitMatH2 Initialize control matrix.
BPU_T_Math_Ctx * math_ctx
Math context.
void BPU_permFree(BPU_T_Perm_Vector **p)
Free dynamically or statically alocated permutation vector.
void BPU_gf2VecFree(BPU_T_GF2_Vector **v)
Free dynamically or statically allocated vector.
#define BPU_gf2xPolyNull(d_pointer)
Copy Polynomial.
int BPU_permPermute(BPU_T_Perm_Vector *to_permute, const BPU_T_Perm_Vector *permutation)
int BPU_gf2xMatMalloc(BPU_T_GF2_16x_Matrix **m, int rows, int cols)
Allocate memory for matrix.
BPU_T_GF2_Matrix * g_mat
Generator matrix.
int BPU_goppaGetError(BPU_T_GF2_Vector *error, const BPU_T_GF2_Vector *encoded, const BPU_T_Code_Ctx *ctx)
void BPU_printGf2Mat(const BPU_T_GF2_Matrix *m)
BPU_T_GF2_16x ** elements
all element of matrix
int BPU_gf2xPolyMalloc(BPU_T_GF2_16x_Poly **p, int16_t max_deg)
uint16_t elements_in_row
number of elements in one row
BPU_T_Perm_Vector * permutation
permutation "matrix"
int BPU_gf2MatPermute(BPU_T_GF2_Matrix *inout, BPU_T_Perm_Vector *permutation)
int BPU_gf2xPolyGetDeg(BPU_T_GF2_16x_Poly *poly)
Get degree of polynomial over GF2x.
int BPU_permRandomize(BPU_T_Perm_Vector *permutation)
BPU_T_GF2_16x_Matrix * h_mat
Control matrix H.
int BPU_goppaDecode(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const struct _BPU_T_Code_Ctx *ctx)
uint16_t msg_len
Code dimenzion.
#define BPU_printError(fmt,...)
print error message with filename, line
uint16_t support_len
number of elements in support
void BPU_goppaFindPolyAB(BPU_T_GF2_16x_Poly *a, BPU_T_GF2_16x_Poly *b, const BPU_T_GF2_16x_Poly *tau, const BPU_T_GF2_16x_Poly *mod, const BPU_T_Math_Ctx *math_ctx)
Find polynomials a, b of degree <= (t div 2)
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.
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
BPU_T_GF2 * elements
all element of matrix
int BPU_gf2VecResize(BPU_T_GF2_Vector *v, int len)
BPU_gf2VecResize Resize vecor.
BPU_T_Perm_Element size
permutation size
BPU_T_GF2_Vector * e
Error vector.
#define BPU_gf2VecSetBit(v_pointer, i, bit)
int BPU_gf2MatMakeSystematic(BPU_T_GF2_Matrix *inout)
It brings Matrix GF2 into the systematic form -> with I on the left side.
void BPU_gf2VecCopy(BPU_T_GF2_Vector *dest, const BPU_T_GF2_Vector *src)
Copy VectorGF2.
int BPU_gf2MatCrop(BPU_T_GF2_Matrix *m, uint16_t width)
Crop matrix GF2 from left.
void BPU_gf2xPolyGenGoppa(BPU_T_GF2_16x_Poly *p, int t, const BPU_T_Math_Ctx *math_ctx)
int BPU_gf2MatMalloc(BPU_T_GF2_Matrix **m, int rows, int cols)
int BPU_gf2VecPermute(BPU_T_GF2_Vector *vec, const BPU_T_Perm_Vector *permutation)
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)
int BPU_permGetInv(BPU_T_Perm_Vector *out, const BPU_T_Perm_Vector *in)
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.
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.
int BPU_gf2VecCrop(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const int start, const int length)
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_goppaEncode(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const struct _BPU_T_Code_Ctx *ctx)
BPU_goppaEncode Encode message using goppa code.
int ord
group ord, number of elements
uint8_t BPU_getParity(BPU_T_GF2 dword)
BPU_getParity Get parity of word.
uint8_t t
Error code correction capability.
int BPU_permMalloc(BPU_T_Perm_Vector **p, int size)
Allocate permutation vector elements of size size.
int BPU_goppaGenCode(BPU_T_Code_Ctx *ctx)
BPU_goppaGenCode Generate random code based on params.
#define BPU_gf2VecGetBit(v_pointer, i)
Check if is set bit at i-th position in vector.
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.
uint8_t mod_deg
modulo degree, galois finite field GF(2^m)
void BPU_goppaDetSyndrome(BPU_T_GF2_16x_Poly *syndrome, const BPU_T_GF2_Vector *z, const BPU_T_Code_Ctx *ctx)
BPU_goppaDetSyndrome.
BPU_T_UN_Code_Spec * code_spec
Code specific structure, like generator matrix, control matrix, gen. poly ...
BPU_T_GF2_16x_Poly * g
gen. polynomial
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.