diff options
Diffstat (limited to 'src/lib/pubkey/mce/binary_matrix.h')
-rw-r--r-- | src/lib/pubkey/mce/binary_matrix.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lib/pubkey/mce/binary_matrix.h b/src/lib/pubkey/mce/binary_matrix.h new file mode 100644 index 000000000..a5438666d --- /dev/null +++ b/src/lib/pubkey/mce/binary_matrix.h @@ -0,0 +1,61 @@ +/** + * (C) Copyright Projet SECRET, INRIA, Rocquencourt + * (C) Bhaskar Biswas and Nicolas Sendrier + * + * (C) 2014 cryptosource GmbH + * (C) 2014 Falko Strenzke [email protected] + * + * Distributed under the terms of the Botan license + * + */ + +#ifndef BOTAN_BINARY_MATRIX_H__ +#define BOTAN_BINARY_MATRIX_H__ + +#include <botan/secmem.h> + +namespace Botan { + +#define BITS_PER_U32 (8 * sizeof (u32bit)) + +struct binary_matrix + { + public: + binary_matrix(u32bit m_rown, u32bit m_coln); + + void row_xor(u32bit a, u32bit b); + secure_vector<int> row_reduced_echelon_form(); + + /** + * return the coefficient out of F_2 + */ + u32bit coef(u32bit i, u32bit j) + { + return (m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] >> (j % BITS_PER_U32)) & 1; + }; + + void set_coef_to_one(u32bit i, u32bit j) + { + m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] |= (1UL << ((j) % BITS_PER_U32)) ; + }; + + void toggle_coeff(u32bit i, u32bit j) + { + m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] ^= (1UL << ((j) % BITS_PER_U32)) ; + } + + void set_to_zero() + { + std::memset(&m_elem[0], 0, m_alloc_size); + } + + u32bit m_rown; // number of rows. + u32bit m_coln; // number of columns. + u32bit m_rwdcnt; // number of words in a row + u32bit m_alloc_size; // number of allocated bytes + std::vector<u32bit> m_elem; + }; + +} + +#endif |