29 static const BYTE REVERSE_NIBBLE_ORDER[16] = { 0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF };
31 static const BYTE REVERSE_BYTE_ORDER[256] = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8,
32 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 0x0C, 0x8C,
33 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2,
34 0x72, 0xF2, 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96,
35 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1,
36 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 0x05, 0x85,
37 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD,
38 0x7D, 0xFD, 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B,
39 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF,
40 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF };
46 static const BYTE RESET_BIT_POSITIONS[9] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
51 static const BYTE RESET_BIT_POSITIONS_INV[9] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFF };
54 static const BYTE GET_BIT_POSITIONS[9] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 0x00 };
57 static const BYTE GET_BIT_POSITIONS_INV[9] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 };
60 static const int INT_MASK[8] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01 };
63 static const int FIRST_MASK_SHIFT[8] = { 0xFF00, 0x7F80, 0x3FC0, 0x1FE0, 0x0FF0, 0x07F8, 0x03FC, 0x01FE };
68 static const BYTE MASK_BIT[8] = { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };
74 static const BYTE BIT[8] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 };
80 static const BYTE CMASK_BIT[8] = { 0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe };
86 static const BYTE C_BIT[8] = { 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F };
88 static const BYTE MASK_SET_BIT[2][8] = { { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 } };
96 static const BYTE MASK_SET_BIT_C[2][8] = { { 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 }, { 0, 0, 0, 0, 0, 0, 0, 0 } };
102 static const BYTE SET_BIT_C[2][8] = { { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 }, { 0, 0, 0, 0, 0, 0, 0, 0 } };
104 const BYTE SELECT_BIT_POSITIONS[9] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
106 #ifdef MACHINE_SIZE_32
107 static const REGISTER_SIZE TRANSPOSITION_MASKS[6] =
108 { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};
109 static const REGISTER_SIZE TRANSPOSITION_MASKS_INV[6] =
110 { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000};
112 #ifdef MACHINE_SIZE_64
114 static const REGISTER_SIZE TRANSPOSITION_MASKS[6] = { 0x5555555555555555, 0x3333333333333333, 0x0F0F0F0F0F0F0F0F, 0x00FF00FF00FF00FF, 0x0000FFFF0000FFFF, 0x00000000FFFFFFFF };
115 static const REGISTER_SIZE TRANSPOSITION_MASKS_INV[6] = { 0xAAAAAAAAAAAAAAAA, 0xCCCCCCCCCCCCCCCC, 0xF0F0F0F0F0F0F0F0, 0xFF00FF00FF00FF00, 0xFFFF0000FFFF0000, 0xFFFFFFFF00000000 };
120 static const size_t SHIFTVAL = 3;
173 if (m_nByteSize > 0) {
204 void Create(uint64_t bits);
228 memset(m_pBits, 0, m_nByteSize);
248 void Create(uint64_t numelements, uint64_t elementlength);
258 void Create(uint64_t numelements, uint64_t elementlength,
crypto* crypt);
268 void Create(uint64_t numelementsDimA, uint64_t numelementsDimB, uint64_t elementlength);
278 void Create(uint64_t numelementsDimA, uint64_t numelementsDimB, uint64_t elementlength,
crypto* crypt);
299 memset(m_pBits, 0, m_nByteSize);
308 memset(m_pBits + frombyte, 0, tobyte - frombyte);
315 memset(m_pBits, 0xFF, m_nByteSize);
348 m_nElementLength = elelen;
357 return m_nElementLength;
392 void Copy(BYTE* p,
int pos,
int len);
398 unsigned int GetInt(
int bitPos,
int bitLen);
399 #define GetIntBitsFromLen(x, from, len) ( ( (x & ( ( (2<<(len))-1) << from )) >> from) & 0xFF)
400 #define GetMask(len) (( (1<<(len))-1))
408 void ORByte(
int pos, BYTE p);
422 return !!(m_pBits[idx >> 3] & MASK_BIT[idx & 0x7]);
432 m_pBits[idx >> 3] = (m_pBits[idx >> 3] & CMASK_BIT[idx & 0x7]) | MASK_SET_BIT_C[!(b & 0x01)][idx & 0x7];
443 m_pBits[idx >> 3] ^= MASK_SET_BIT_C[!(b & 0x01)][idx & 0x7];
456 m_pBits[idx >> 3] &= CMASK_BIT[idx & 0x7];
468 return !!(m_pBits[idx >> 3] & BIT[idx & 0x7]);
478 m_pBits[idx >> 3] = (m_pBits[idx >> 3] & C_BIT[idx & 0x7]) | SET_BIT_C[!(b & 0x01)][idx & 0x7];
488 m_pBits[idx >> 3] ^= SET_BIT_C[!(b & 0x01)][idx & 0x7];
500 m_pBits[idx >> 3] &= C_BIT[idx & 0x7];
554 void GetBits(BYTE* p,
int pos,
int len);
563 void GetBytes(BYTE* p,
int pos,
int len);
568 template<
class T>
void GetBytes(T* dst, T* src, T* lim);
577 template<
class T> T
Get(
int pos,
int len) {
579 GetBits((BYTE*) &val, pos, len);
593 void SetBits(BYTE* p, uint64_t pos, uint64_t len);
603 SetBits(p, (uint64_t) pos, (uint64_t) len);
622 void SetBytes(BYTE* p,
int pos,
int len);
628 template<
class T>
void SetBytes(T* dst, T* src, T* lim);
636 template<
class T>
void Set(T val,
int pos,
int len) {
637 SetBits((BYTE*) &val, (uint64_t) pos, (uint64_t) len);
658 void XORBytes(BYTE* p,
int pos,
int len);
685 template<
class T>
void XOR(T val,
int pos,
int len) {
686 XORBits((BYTE*) &val, pos, len);
696 void XORBits(BYTE* p,
int pos,
int len);
711 template<
class T>
void XORBytes(T* dst, T* src, T* lim);
737 void ANDBytes(BYTE* p,
int pos,
int len);
743 template<
class T>
void ANDBytes(T* dst, T* src, T* lim);
757 void SetXOR(BYTE* p, BYTE* q,
int pos,
int len);
768 void SetAND(BYTE* p, BYTE* q,
int pos,
int len);
820 void Print(
int fromBit,
int toBit);
832 void PrintHex(
int fromByte,
int toByte);
838 Print(0, m_nByteSize << 3);
864 template<
class T> T
Get(
int i) {
865 return Get<T>(i * m_nElementLength, m_nElementLength);
873 template<
class T>
void Set(T val,
int i) {
874 Set<T>(val, i * m_nElementLength, m_nElementLength);
885 template<
class T> T
Get2D(
int i,
int j) {
886 return Get<T>((i * m_nNumElementsDimB + j) * m_nElementLength, m_nElementLength);
896 template<
class T>
void Set2D(T val,
int i,
int j) {
897 Set<T>(val, (i * m_nNumElementsDimB + j) * m_nElementLength, m_nElementLength);
902 void EklundhBitTranspose(
int rows,
int columns);
903 void SimpleTranspose(
int rows,
int columns);
907 uint64_t m_nByteSize;
909 uint64_t m_nElementLength;
911 uint64_t m_nNumElements;
912 uint64_t m_nNumElementsDimB;
void XORBit(int idx, BYTE b)
Definition: cbitvector.h:442
CBitVector(uint32_t bits)
Definition: cbitvector.h:136
void XOR_no_mask(int p, int bitPos, int bitLen)
Definition: cbitvector.cpp:431
void SetXOR(BYTE *p, BYTE *q, int pos, int len)
Definition: cbitvector.cpp:337
void Create(uint64_t bits)
Definition: cbitvector.cpp:40
Definition: pk-crypto.h:59
void PrintBinary()
Definition: cbitvector.h:837
void SetAND(BYTE *p, BYTE *q, int pos, int len)
Definition: cbitvector.cpp:342
void XORBytesReverse(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:194
void SetElementLength(int elelen)
Definition: cbitvector.h:347
BYTE GetBitNoMask(int idx)
Definition: cbitvector.h:467
void ORByte(int pos, BYTE p)
Definition: cbitvector.cpp:245
void XORBytes(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:269
BYTE GetBit(int idx)
Definition: cbitvector.h:421
void FillRand(uint32_t bits, crypto *crypt)
Definition: cbitvector.cpp:22
void Copy(CBitVector &vec, int pos, int len)
Definition: cbitvector.h:381
void PrintBinaryMasked(int from, int to)
Definition: cbitvector.cpp:371
void Reset()
Definition: cbitvector.h:298
void SetBits(BYTE *p, int pos, int len)
Definition: cbitvector.h:602
void DetachBuf()
Definition: cbitvector.h:805
void SetByte(int idx, BYTE p)
Definition: cbitvector.h:512
int GetSize()
Definition: cbitvector.h:322
void delCBitVector()
Definition: cbitvector.h:172
void Init()
Definition: cbitvector.h:156
void XOR(T val, int pos, int len)
Definition: cbitvector.h:685
void XORBits(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:210
BYTE GetByte(int idx)
Definition: cbitvector.h:521
BOOL IsEqual(CBitVector &vec)
Definition: cbitvector.cpp:403
T Get(int pos, int len)
Definition: cbitvector.h:577
void SetToOne()
Definition: cbitvector.h:314
void XORBitNoMask(int idx, BYTE b)
Definition: cbitvector.h:487
void ANDBitNoMask(int idx, BYTE b)
Definition: cbitvector.h:498
void SetBytes(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:302
void SetBits(BYTE *p, uint64_t pos, uint64_t len)
Definition: cbitvector.cpp:103
void GetBytes(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:250
T Get2D(int i, int j)
Definition: cbitvector.h:885
void PrintContent()
Definition: cbitvector.cpp:380
void ANDBytes(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:321
void SetBit(int idx, BYTE b)
Definition: cbitvector.h:431
void XORRepeat(BYTE *p, int pos, int len, int num)
Definition: cbitvector.cpp:288
CBitVector(uint32_t bits, crypto *crypt)
Definition: cbitvector.h:145
void GetBits(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:162
void SetBitNoMask(int idx, BYTE b)
Definition: cbitvector.h:477
unsigned int GetInt(int bitPos, int bitLen)
Definition: cbitvector.cpp:444
~CBitVector()
Definition: cbitvector.h:165
void CreateBytes(uint64_t bytes)
Definition: cbitvector.h:216
T Get(int i)
Definition: cbitvector.h:864
uint64_t GetElementLength()
Definition: cbitvector.h:356
void XORBytes(BYTE *p, int len)
Definition: cbitvector.h:665
void ANDBit(int idx, BYTE b)
Definition: cbitvector.h:454
void CreateZeros(uint64_t bits)
Definition: cbitvector.h:226
void XORByte(int idx, BYTE b)
Definition: cbitvector.h:531
void Set(T val, int pos, int len)
Definition: cbitvector.h:636
void Print(int fromBit, int toBit)
Definition: cbitvector.cpp:347
void SetBitsToZero(int bitpos, int bitlen)
Definition: cbitvector.cpp:148
CBitVector()
Definition: cbitvector.h:129
void AttachBuf(BYTE *p, uint64_t size=-1)
Definition: cbitvector.h:796
void Set(T val, int i)
Definition: cbitvector.h:873
void XORVector(CBitVector &vec, int pos, int len)
Definition: cbitvector.h:677
void AttachBuf(BYTE *p, int size=-1)
Definition: cbitvector.h:786
BYTE * GetArr()
Definition: cbitvector.h:777
void ResizeinBytes(int newSizeBytes)
Definition: cbitvector.cpp:79
void XORBitsPosOffset(BYTE *p, int ppos, int pos, int len)
Definition: cbitvector.cpp:204
void ResetFromTo(int frombyte, int tobyte)
Definition: cbitvector.h:307
void SetBitsPosOffset(BYTE *p, int ppos, int pos, int len)
Definition: cbitvector.cpp:141
Definition: cbitvector.h:123
void ANDByte(int idx, BYTE b)
Definition: cbitvector.h:539
void PrintHex()
Definition: cbitvector.cpp:364
void Copy(CBitVector &vec)
Definition: cbitvector.h:369
void Set2D(T val, int i, int j)
Definition: cbitvector.h:896