Botan  1.11.15
src/lib/pubkey/mce/binary_matrix.h
Go to the documentation of this file.
00001 /**
00002  * (C) Copyright Projet SECRET, INRIA, Rocquencourt
00003  * (C) Bhaskar Biswas and  Nicolas Sendrier
00004  *
00005  * (C) 2014 cryptosource GmbH
00006  * (C) 2014 Falko Strenzke fstrenzke@cryptosource.de
00007  *
00008  * Botan is released under the Simplified BSD License (see license.txt)
00009  *
00010  */
00011 
00012 #ifndef BOTAN_BINARY_MATRIX_H__
00013 #define BOTAN_BINARY_MATRIX_H__
00014 
00015 #include <botan/secmem.h>
00016 
00017 namespace Botan {
00018 
00019 #define BITS_PER_U32 (8 * sizeof (u32bit))
00020 
00021 struct binary_matrix
00022    {
00023    public:
00024       binary_matrix(u32bit m_rown, u32bit m_coln);
00025 
00026       void row_xor(u32bit a, u32bit b);
00027       secure_vector<int> row_reduced_echelon_form();
00028 
00029       /**
00030       * return the coefficient out of F_2
00031       */
00032       u32bit coef(u32bit i, u32bit j)
00033          {
00034          return (m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] >> (j % BITS_PER_U32)) & 1;
00035          };
00036 
00037       void set_coef_to_one(u32bit i, u32bit j)
00038          {
00039          m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] |= (1UL << ((j) % BITS_PER_U32)) ;
00040          };
00041 
00042       void toggle_coeff(u32bit i, u32bit j)
00043          {
00044          m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] ^= (1UL << ((j) % BITS_PER_U32)) ;
00045          }
00046 
00047       void set_to_zero()
00048          {
00049          zeroise(m_elem);
00050          }
00051 
00052       u32bit m_rown;  // number of rows.
00053       u32bit m_coln; // number of columns.
00054       u32bit m_rwdcnt; // number of words in a row
00055       std::vector<u32bit> m_elem;
00056    };
00057 
00058 }
00059 
00060 #endif