2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
5 * Subject to the GPL, version 2.
6 * Based on Bhaskar Biswas and Nicolas Sendrier McEliece
7 * implementation, LGPL 2.1.
15 #define BITS_PER_LONG __WORDSIZE
18 size_t rown
; /* Number of rows */
19 size_t coln
; /* Number of columns */
20 size_t rwdcnt
; /* Number of words in a row */
21 size_t alloc_size
; /* Number of allocated bytes */
22 uint32_t *elem
; /* Row index */
25 #define matrix_coeff(A, i, j) \
26 (((A)->elem[(i) * A->rwdcnt + \
27 (j) / BITS_PER_LONG] >> ((j) % BITS_PER_LONG)) & 1)
29 #define matrix_set_coeff_to_one(A, i, j) \
30 ((A)->elem[(i) * A->rwdcnt + \
31 (j) / BITS_PER_LONG] |= (1UL << ((j) % BITS_PER_LONG)))
33 #define matrix_change_coeff(A, i, j) \
34 ((A)->elem[(i) * A->rwdcnt + \
35 (j) / BITS_PER_LONG] ^= (1UL << ((j) % BITS_PER_LONG)))
37 #define matrix_set_to_zero(R) memset((R)->elem, 0, (R)->alloc_size);
39 extern struct matrix
*matrix_init(size_t rown
, size_t coln
);
40 extern struct matrix
*matrix_init_from_string(size_t rown
, size_t coln
,
41 const unsigned char *str
,
43 extern void matrix_free(struct matrix
*A
);
44 extern struct matrix
*matrix_copy(struct matrix
*A
);
45 extern struct matrix
*matrix_rowxor(struct matrix
*A
, int a
, int b
);
46 extern uint32_t *matrix_rref(struct matrix
*A
);
47 extern void matrix_vec_mul(uint32_t *cR
, uint8_t *x
, struct matrix
*A
);
48 extern struct matrix
*matrix_mul(struct matrix
*A
, struct matrix
*B
);