19 #ifndef __OT_EXTENSION_H_
20 #define __OT_EXTENSION_H_
22 #include "../util/typedefs.h"
23 #include "../util/socket.h"
24 #include "../util/thread.h"
25 #include "../util/cbitvector.h"
26 #include "../util/crypto/crypto.h"
30 #define FIXED_KEY_AES_HASHING
38 const BYTE G_OT = 0x01;
39 const BYTE C_OT = 0x02;
40 const BYTE R_OT = 0x03;
42 #define NUMOTBLOCKS 4096
51 #ifdef FIXED_KEY_AES_HASHING
52 static const uint8_t fixed_key_aes_seed[32] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
53 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
56 static void InitAESKey(AES_KEY_CTX* ctx, BYTE* keybytes, uint32_t numkeys,
crypto* crypt) {
57 BYTE* pBufIdx = keybytes;
58 uint32_t aes_key_bytes = crypt->get_aes_key_bytes();
59 for (uint32_t i = 0; i < numkeys; i++) {
60 crypt->init_aes_key(ctx + i, pBufIdx);
61 pBufIdx += aes_key_bytes;
65 #define OWF_BYTES AES_BYTES
77 OTExtSnd(uint32_t nSndVals, uint32_t nOTs, uint32_t bitlength,
crypto* crypt,
CSocket* sock,
CBitVector& U, BYTE* keybytes,
CBitVector& x0,
CBitVector& x1, BYTE type,
78 int nbaseOTs = -1,
int nchecks = -1,
int nbaseseeds = -1) {
79 Init(nSndVals, crypt, sock, U, keybytes, nbaseOTs, nchecks, nbaseseeds);
83 m_nBitLength = bitlength;
89 Init(nSndVals, crypt, sock, U, keybytes, nbaseOTs, nchecks, nbaseseeds);
93 void Init(uint32_t nSndVals,
crypto* crypt,
CSocket* sock,
CBitVector& U, BYTE* keybytes,
int nbaseOTs,
int nchecks,
int nbaseseeds) {
94 m_nSndVals = nSndVals;
98 m_nSymSecParam = m_cCrypt->get_seclvl().symbits;
99 m_nBaseOTs = m_nSymSecParam;
102 m_nBaseOTs = nbaseOTs;
104 int keyseeds = m_nBaseOTs;
105 if (nbaseseeds != -1)
106 keyseeds = nbaseseeds;
109 m_vU.
Copy(U.
GetArr(), 0, ceil_divide(keyseeds, 8));
110 for (
int i = keyseeds; i < PadToMultiple(keyseeds, 8); i++)
114 m_vKeySeeds = (AES_KEY_CTX*) malloc(
sizeof(AES_KEY_CTX) * keyseeds);
115 m_lSendLock =
new CLock;
117 InitAESKey(m_vKeySeeds, keybytes, keyseeds, m_cCrypt);
119 #ifdef FIXED_KEY_AES_HASHING
120 m_kCRFKey = (AES_KEY_CTX*) malloc(
sizeof(AES_KEY_CTX));
121 m_cCrypt->init_aes_key(m_kCRFKey, (uint8_t*) fixed_key_aes_seed);
131 BOOL send(uint32_t numThreads);
133 BOOL OTSenderRoutine(uint32_t
id, uint32_t myNumOTs);
136 void ProcessAndEnqueue(
CBitVector* snd_buf, uint32_t
id, uint32_t progress, uint32_t processedOTs);
137 void SendBlocks(uint32_t numThreads);
139 BOOL verifyOT(uint32_t myNumOTs);
145 uint32_t m_nBitLength;
148 uint32_t m_nSymSecParam;
157 AES_KEY_CTX* m_vKeySeeds;
163 #ifdef FIXED_KEY_AES_HASHING
164 AES_KEY_CTX* m_kCRFKey;
180 success = callback->OTSenderRoutine(senderID, numOTs);
205 int nbaseOTs = -1,
int nbaseseeds = -1) {
206 Init(nSndVals, crypt, sock, keybytes, nbaseOTs, nbaseseeds);
208 m_nChoices = choices;
210 m_nBitLength = bitlength;
211 m_eOTFlav = protocol;
214 OTExtRec(uint32_t nSndVals,
crypto* crypt,
CSocket* sock, BYTE* keybytes,
int nbaseOTs = -1,
int nbaseseeds = -1) {
215 Init(nSndVals, crypt, sock, keybytes, nbaseOTs, nbaseseeds);
219 void Init(uint32_t nSndVals,
crypto* crypt,
CSocket* sock, BYTE* keybytes,
int nbaseOTs,
int nbaseseeds) {
220 m_nSndVals = nSndVals;
223 m_nSymSecParam = m_cCrypt->get_seclvl().symbits;
224 m_nBaseOTs = m_nSymSecParam;
226 m_nBaseOTs = nbaseOTs;
227 int keyseeds = m_nBaseOTs;
228 if (nbaseseeds != -1)
229 keyseeds = nbaseseeds;
232 m_vKeySeedMtx = (AES_KEY_CTX*) malloc(
sizeof(AES_KEY_CTX) * keyseeds * nSndVals);
233 InitAESKey(m_vKeySeedMtx, keybytes, keyseeds * nSndVals, m_cCrypt);
235 #ifdef FIXED_KEY_AES_HASHING
236 m_kCRFKey = (AES_KEY_CTX*) malloc(
sizeof(AES_KEY_CTX));
237 m_cCrypt->init_aes_key(m_kCRFKey, (uint8_t*) fixed_key_aes_seed);
248 BOOL receive(uint32_t numThreads);
249 BOOL OTReceiverRoutine(uint32_t
id, uint32_t myNumOTs);
250 void ReceiveAndProcess(uint32_t numThreads);
251 void BuildMatrices(
CBitVector& T,
CBitVector& SndBuf, uint32_t numblocks, uint32_t ctr, BYTE* ctr_buf);
253 BOOL verifyOT(uint32_t myNumOTs);
259 uint32_t m_nBitLength;
261 uint32_t m_nSymSecParam;
271 AES_KEY_CTX* m_vKeySeedMtx;
273 #ifdef FIXED_KEY_AES_HASHING
274 AES_KEY_CTX* m_kCRFKey;
290 success = callback->OTReceiverRoutine(receiverID, numOTs);
302 #ifdef FIXED_KEY_AES_HASHING
303 inline void FixedKeyHashing(AES_KEY_CTX* aeskey, BYTE* outbuf, BYTE* inbuf, BYTE* tmpbuf, uint64_t
id, uint32_t bytessecparam,
crypto* crypt) {
304 #ifdef HIGH_SPEED_ROT_LT
305 ((uint64_t*) tmpbuf)[0] =
id ^ ((uint64_t*) inbuf)[0];
306 ((uint64_t*) tmpbuf)[1] = ((uint64_t*) inbuf)[1];
308 memset(tmpbuf, 0, AES_BYTES);
309 memcpy(tmpbuf, (BYTE*) (&
id),
sizeof(
int));
311 for (
int i = 0; i < bytessecparam; i++) {
312 tmpbuf[i] = tmpbuf[i] ^ inbuf[i];
316 crypt->encrypt(aeskey, outbuf, tmpbuf, AES_BYTES);
318 #ifdef HIGH_SPEED_ROT_LT
319 ((uint64_t*) outbuf)[0] ^= ((uint64_t*) inbuf)[0];
320 ((uint64_t*) outbuf)[1] ^= ((uint64_t*) inbuf)[1];
322 for (
int i = 0; i < bytessecparam; i++) {
323 outbuf[i] = outbuf[i] ^ inbuf[i];
void Create(uint64_t bits)
Definition: cbitvector.cpp:40
Definition: ot-extension.h:167
Definition: ot-extension.h:192
Definition: ot-extension.h:67
void SetBit(int idx, BYTE b)
Definition: cbitvector.h:431
BYTE * GetArr()
Definition: cbitvector.h:777
Definition: ot-extension.h:44
Definition: maskingfunction.h:25
Masking Function implementation.
Definition: cbitvector.h:123
void Copy(CBitVector &vec)
Definition: cbitvector.h:369
Definition: ot-extension.h:277