39 void init(uint32_t bitlength) {
40 m_nBitLength = bitlength;
43 void Mask(uint32_t progress, uint32_t processedOTs,
CBitVector* values,
CBitVector* snd_buf, BYTE protocol) {
44 uint32_t nsndvals = 2;
46 if (protocol == G_OT) {
47 snd_buf[0].
XORBytes(values[0].GetArr() + ceil_divide(progress * m_nBitLength, 8), 0, ceil_divide(processedOTs * m_nBitLength, 8));
48 snd_buf[1].
XORBytes(values[1].GetArr() + ceil_divide(progress * m_nBitLength, 8), 0, ceil_divide(processedOTs * m_nBitLength, 8));
49 }
else if (protocol == C_OT) {
50 values[0].
SetBytes(snd_buf[0].GetArr(), ceil_divide(progress * m_nBitLength, 8), ceil_divide(processedOTs * m_nBitLength, 8));
51 int bitPos = progress * m_nBitLength;
52 int length = processedOTs * m_nBitLength;
53 int bytePos = ceil_divide(bitPos, 8);
55 values[1].
SetBits(values[0].GetArr() + bytePos, bitPos, length);
56 values[1].
XORBits(m_vDelta->
GetArr() + bytePos, bitPos, length);
57 snd_buf[1].
XORBits(values[1].GetArr() + bytePos, 0, length);
59 else if (protocol == R_OT) {
60 values[0].
SetBytes(snd_buf[0].GetArr(), ceil_divide(progress * m_nBitLength, 8), ceil_divide(processedOTs * m_nBitLength, 8));
61 values[1].
SetBytes(snd_buf[1].GetArr(), ceil_divide(progress * m_nBitLength, 8), ceil_divide(processedOTs * m_nBitLength, 8));
68 uint32_t bytelen = ceil_divide(m_nBitLength, 8);
69 uint32_t gprogress = progress * bytelen;
70 uint32_t lim = progress + processedOTs;
72 if (protocol == G_OT) {
73 for (uint32_t u, i = progress, offset = processedOTs * bytelen, l = 0; i < lim; i++, gprogress += bytelen, l += bytelen) {
76 output.
SetXOR(rcv_buf.
GetArr() + (u * offset) + l, tmpmask.
GetArr() + gprogress, gprogress, bytelen);
79 }
else if (protocol == C_OT)
81 int gprogress = progress * bytelen;
82 output.
Copy(tmpmask.
GetArr() + gprogress, gprogress, bytelen * processedOTs);
83 for (
int i = progress, l = 0; i < lim; i++, l += bytelen, gprogress += bytelen) {
89 }
else if (protocol == R_OT) {
95 void expandMask(
CBitVector& out, BYTE* sbp, uint32_t offset, uint32_t processedOTs, uint32_t bitlength,
crypto* crypt) {
97 if (bitlength <= AES_KEY_BITS) {
98 for (uint32_t i = 0; i < processedOTs; i++, sbp += AES_KEY_BYTES) {
99 out.
SetBits(sbp, (uint64_t) (offset + i) * bitlength, (uint64_t) bitlength);
102 BYTE m_bBuf[AES_BYTES];
103 BYTE ctr_buf[AES_BYTES] = { 0 };
104 uint32_t counter = *((uint32_t*) ctr_buf);
106 for (uint32_t i = 0, rem; i < processedOTs; i++, sbp += AES_KEY_BYTES) {
107 crypt->init_aes_key(&tkey, sbp);
108 for (counter = 0; counter < bitlength / AES_BITS; counter++) {
109 crypt->encrypt(&tkey, m_bBuf, ctr_buf, AES_BYTES);
110 out.
SetBits(m_bBuf, ((uint64_t) offset + i) * bitlength + (counter * AES_BITS), (uint64_t) AES_BITS);
113 if ((rem = bitlength - (counter * AES_BITS)) > 0) {
114 crypt->encrypt(&tkey, m_bBuf, ctr_buf, AES_BYTES);
115 out.
SetBits(m_bBuf, ((uint64_t) offset + i) * bitlength + (counter * AES_BITS), (uint64_t) rem);
123 uint32_t m_nBitLength;
void SetXOR(BYTE *p, BYTE *q, int pos, int len)
Definition: cbitvector.cpp:337
BYTE GetBitNoMask(int idx)
Definition: cbitvector.h:467
void XORBytes(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:269
void XORBits(BYTE *p, int pos, int len)
Definition: cbitvector.cpp:210
Definition: xormasking.h:24
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
BYTE * GetArr()
Definition: cbitvector.h:777
Definition: maskingfunction.h:25
Masking Function implementation.
Definition: cbitvector.h:123
void Copy(CBitVector &vec)
Definition: cbitvector.h:369