Botan
1.11.15
|
#include <binary_matrix.h>
Public Member Functions | |
binary_matrix (u32bit m_rown, u32bit m_coln) | |
u32bit | coef (u32bit i, u32bit j) |
secure_vector< int > | row_reduced_echelon_form () |
void | row_xor (u32bit a, u32bit b) |
void | set_coef_to_one (u32bit i, u32bit j) |
void | set_to_zero () |
void | toggle_coeff (u32bit i, u32bit j) |
Public Attributes | |
u32bit | m_coln |
std::vector< u32bit > | m_elem |
u32bit | m_rown |
u32bit | m_rwdcnt |
Definition at line 21 of file binary_matrix.h.
Botan::binary_matrix::binary_matrix | ( | u32bit | m_rown, |
u32bit | m_coln | ||
) |
Definition at line 17 of file binary_matrix.cpp.
References BITS_PER_U32, m_coln, m_elem, m_rown, and m_rwdcnt.
u32bit Botan::binary_matrix::coef | ( | u32bit | i, |
u32bit | j | ||
) | [inline] |
return the coefficient out of F_2
Definition at line 32 of file binary_matrix.h.
References BITS_PER_U32, m_elem, and m_rwdcnt.
Referenced by row_reduced_echelon_form().
{ return (m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] >> (j % BITS_PER_U32)) & 1; };
secure_vector< int > Botan::binary_matrix::row_reduced_echelon_form | ( | ) |
Definition at line 35 of file binary_matrix.cpp.
References coef(), m_coln, m_rown, and row_xor().
{ u32bit i, failcnt, findrow, max=m_coln - 1; secure_vector<int> perm(m_coln); for(i=0;i<m_coln;i++) { perm[i]=i;//initialize permutation. } failcnt = 0; for(i=0;i<m_rown;i++,max--) { findrow=0; for(u32bit j=i;j<m_rown;j++) { if(coef(j,max)) { if (i!=j)//not needed as ith row is 0 and jth row is 1. row_xor(i,j);//xor to the row.(swap)? findrow=1; break; }//largest value found (end if) } if(!findrow)//if no row with a 1 found then swap last column and the column with no 1 down. { perm[m_coln - m_rown - 1 - failcnt] = max; failcnt++; if (!max) { //CSEC_FREE_MEM_CHK_SET_NULL(*p_perm); //CSEC_THR_RETURN(); perm.resize(0); } i--; } else { perm[i+m_coln - m_rown] = max; for(u32bit j=i+1;j<m_rown;j++)//fill the column downwards with 0's { if(coef(j,(max))) { row_xor(j,i);//check the arg. order. } } for(int j=i-1;j>=0;j--)//fill the column with 0's upwards too. { if(coef(j,(max))) { row_xor(j,i); } } } }//end for(i) return perm; }
void Botan::binary_matrix::row_xor | ( | u32bit | a, |
u32bit | b | ||
) |
Definition at line 25 of file binary_matrix.cpp.
References m_elem, and m_rwdcnt.
Referenced by row_reduced_echelon_form().
void Botan::binary_matrix::set_coef_to_one | ( | u32bit | i, |
u32bit | j | ||
) | [inline] |
Definition at line 37 of file binary_matrix.h.
References BITS_PER_U32, m_elem, and m_rwdcnt.
{ m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] |= (1UL << ((j) % BITS_PER_U32)) ; };
void Botan::binary_matrix::set_to_zero | ( | ) | [inline] |
Definition at line 47 of file binary_matrix.h.
References m_elem, and Botan::zeroise().
void Botan::binary_matrix::toggle_coeff | ( | u32bit | i, |
u32bit | j | ||
) | [inline] |
Definition at line 42 of file binary_matrix.h.
References BITS_PER_U32, m_elem, and m_rwdcnt.
{ m_elem[(i) * m_rwdcnt + (j) / BITS_PER_U32] ^= (1UL << ((j) % BITS_PER_U32)) ; }
Definition at line 53 of file binary_matrix.h.
Referenced by binary_matrix(), and row_reduced_echelon_form().
std::vector<u32bit> Botan::binary_matrix::m_elem |
Definition at line 55 of file binary_matrix.h.
Referenced by binary_matrix(), coef(), row_xor(), set_coef_to_one(), set_to_zero(), and toggle_coeff().
Definition at line 52 of file binary_matrix.h.
Referenced by binary_matrix(), and row_reduced_echelon_form().
Definition at line 54 of file binary_matrix.h.
Referenced by binary_matrix(), coef(), row_xor(), set_coef_to_one(), and toggle_coeff().