Exemplo n.º 1
0
//Initialize and start numThreads OTSenderThread
BOOL OTExtSnd::start_send(uint32_t numThreads) {
	if (m_nOTs == 0)
		return true;

	if(numThreads * m_nBlockSizeBits > m_nOTs && numThreads > 1) {
		cerr << "Decreasing nthreads from " << numThreads << " to " << max(m_nOTs / m_nBlockSizeBits, (uint64_t) 1) << " to fit window size" << endl;
		numThreads = max(m_nOTs / m_nBlockSizeBits, (uint64_t) 1);
	}

	//The total number of OTs that is performed has to be a multiple of numThreads*Z_REGISTER_BITS
	uint32_t wd_size_bits = m_nBlockSizeBits;//pad_to_power_of_two(m_nBaseOTs);//1 << (ceil_log2(m_nBaseOTs));
	//uint64_t numOTs = ceil_divide(PadToMultiple(m_nOTs, wd_size_bits), numThreads);
	uint64_t internal_numOTs = PadToMultiple(ceil_divide(m_nOTs, numThreads), wd_size_bits);
	vector<OTSenderThread*> sThreads(numThreads);

	for (uint32_t i = 0; i < numThreads; i++) {
		sThreads[i] = new OTSenderThread(i, internal_numOTs, this);
		sThreads[i]->Start();
	}

	for (uint32_t i = 0; i < numThreads; i++) {
		sThreads[i]->Wait();
	}

	m_nCounter += m_nOTs;

	for (uint32_t i = 0; i < numThreads; i++) {
		delete sThreads[i];
	}

#ifdef VERIFY_OT
	verifyOT(m_nOTs);
#endif
	return true;
}
Exemplo n.º 2
0
void KKOTExtSnd::KKHashValues(CBitVector &Q, CBitVector *seedbuf,
                              CBitVector *snd_buf, uint64_t OT_ptr,
                              uint64_t OT_len, uint64_t **mat_mul) {
    uint64_t numhashiters =
        ceil_divide(m_nBitLength, m_cCrypt->get_hash_bytes());
    uint32_t rowbytelen = bits_in_bytes(m_nBaseOTs);
    uint32_t hashinbytelen = rowbytelen + sizeof(uint64_t);
    uint32_t hashoutbitlen = ceil_log2(m_nSndVals);
    uint64_t wd_size_bytes =
        m_nBlockSizeBytes; // 1 << (ceil_log2(m_nBaseOTs) - 3);
    uint32_t u;
    uint32_t aes_key_bytes = m_cCrypt->get_aes_key_bytes();
    uint32_t choicebitlen = ceil_log2(m_nSndVals);

    uint64_t *Qptr = (uint64_t *)Q.GetArr();

    uint8_t **sbp = (uint8_t **)malloc(sizeof(uint8_t *) * m_nSndVals);
    uint8_t *inbuf = (uint8_t *)calloc(hashinbytelen, 1);
    uint8_t *resbuf = (uint8_t *)calloc(m_cCrypt->get_hash_bytes(), 1);
    uint8_t *hash_buf = (uint8_t *)calloc(m_cCrypt->get_hash_bytes(), 1);

    uint64_t *tmpbuf = (uint64_t *)calloc(
        PadToMultiple(bits_in_bytes(m_nBitLength), sizeof(uint64_t)), 1);
    uint8_t *tmpbufb = (uint8_t *)calloc(bits_in_bytes(m_nBitLength), 1);

    uint64_t global_OT_ptr = OT_ptr + m_nCounter;
    CBitVector mask(m_nCodeWordBits);

    for (u = 0; u < m_nSndVals; u++) {
        sbp[u] = seedbuf[u].GetArr();
    }

    for (uint64_t i = 0; i < OT_len; global_OT_ptr++, i++, Qptr += 2) {
        for (u = 0; u < m_nSndVals; u++) {
            mask.Copy(m_vU, 0, rowbytelen);
            mask.ANDBytes((uint8_t *)m_vCodeWords[u], 0, rowbytelen);
            mask.XORBytes(Q.GetArr() + i * rowbytelen, rowbytelen);

#ifdef DEBUG_OT_HASH_IN
            cout << "Hash-In for i = " << global_OT_ptr << ", u = " << u << ": "
                 << (hex);
            for (uint32_t p = 0; p < rowbytelen; p++)
                cout << setw(2) << setfill('0') << (uint32_t)mask.GetArr()[p];
            cout << (dec) << endl;
// cout << "Using codeword " << (hex) << m_vCodeWords[u][0] <<
// m_vCodeWords[u][1] << (hex) << m_vCodeWords[u][2] << m_vCodeWords[u][3] <<
// (dec) << endl;

#endif

            if (m_eSndOTFlav != Snd_GC_OT) {
#ifdef FIXED_KEY_AES_HASHING
                FixedKeyHashing(m_kCRFKey, sbp[u], (BYTE *)Qptr, hash_buf, i,
                                hashinbytelen, m_cCrypt);
#else
                memcpy(inbuf, &global_OT_ptr, sizeof(uint64_t));
                // memcpy(inbuf+sizeof(uint64_t), Q.GetArr() + i *
                // wd_size_bytes, rowbytelen);
                memcpy(inbuf + sizeof(uint64_t), mask.GetArr(), rowbytelen);
                m_cCrypt->hash_buf(resbuf, aes_key_bytes, inbuf, hashinbytelen,
                                   hash_buf);
                memcpy(sbp[u], resbuf, aes_key_bytes);
                // snd_buf[u].SetBits(resbuf, i * hashoutbitlen, hashoutbitlen);
            } else {
                // TODO: mecr has not been tested with KK-OT!!
                BitMatrixMultiplication(tmpbufb, bits_in_bytes(hashoutbitlen),
                                        mask.GetArr(), m_nBaseOTs, mat_mul,
                                        tmpbuf);
                // BitMatrixMultiplication(tmpbufb, bits_in_bytes(m_nBitLength),
                // Q.GetArr() + i * wd_size_bytes, m_nBaseOTs, mat_mul, tmpbuf);
                // m_vValues[u].SetBits(tmpbufb, (OT_ptr + i)* m_nBitLength,
                // m_nBitLength);
                snd_buf[u].SetBits(tmpbufb, i * hashoutbitlen, hashoutbitlen);
                // m_vTempOTMasks.SetBytes(tmpbufb, (uint64_t) (OT_ptr + i) *
                // aes_key_bytes, (uint64_t) aes_key_bytes);
                // m_vValues[u].SetBytes(Q.GetArr() + i * wd_size_bytes, (OT_ptr
                // + i)* wd_size_bytes, rowbytelen);
            }
#endif

#ifdef DEBUG_OT_HASH_OUT
                cout << "Hash-Out for i = " << global_OT_ptr << ", u = " << u
                     << ": " << (hex);
                for (uint32_t p = 0; p < aes_key_bytes; p++)
                    cout << setw(2) << setfill('0') << (uint32_t)sbp[u][p];
                cout << (dec) << endl;
#endif
                sbp[u] += m_cCrypt->get_aes_key_bytes();
            }
        }

        // TODO: difference is in here!! (could be solved by giving the
        // bit-length as parameter in the function call)
        for (uint32_t u = 0; u < m_nSndVals; u++) {
            m_fMaskFct->expandMask(&snd_buf[u], seedbuf[u].GetArr(), 0, OT_len,
                                   m_nBitLength * choicebitlen, m_cCrypt);
            // cout << "Mask " << u << ": ";
            // snd_buf[u].PrintHex();
        }

        // m_vValues[0].PrintHex();
        // m_vValues[1].PrintHex();

        free(resbuf);
        free(inbuf);
        free(sbp);
        free(hash_buf);
        free(tmpbuf);
        free(tmpbufb);
    }
Exemplo n.º 3
0
void OTExtSnd::HashValues(CBitVector& Q, CBitVector* seedbuf, CBitVector* snd_buf, uint64_t OT_ptr, uint64_t OT_len, uint64_t** mat_mul) {
	uint64_t numhashiters = ceil_divide(m_nBitLength, m_cCrypt->get_hash_bytes());
	uint32_t rowbytelen = bits_in_bytes(m_nBaseOTs);
	uint32_t hashinbytelen = rowbytelen + sizeof(uint64_t);
	uint64_t wd_size_bytes = m_nBlockSizeBytes;//1 << (ceil_log2(m_nBaseOTs) - 3);
	uint32_t u;
	uint32_t aes_key_bytes = m_cCrypt->get_aes_key_bytes();


	uint64_t* Qptr = (uint64_t*) Q.GetArr();
	uint64_t* Uptr = (uint64_t*) m_vU.GetArr();

	uint8_t** sbp = (uint8_t**) malloc(sizeof(uint8_t*) * m_nSndVals);
	uint8_t* inbuf = (uint8_t*) calloc(hashinbytelen, 1);
	uint8_t* resbuf = (uint8_t*) calloc(m_cCrypt->get_hash_bytes(), 1);
	uint8_t* hash_buf = (uint8_t*) calloc(m_cCrypt->get_hash_bytes(), 1);

	uint64_t* tmpbuf = (uint64_t*) calloc(PadToMultiple(bits_in_bytes(m_nBitLength), sizeof(uint64_t)), 1);
	uint8_t* tmpbufb = (uint8_t*) calloc(bits_in_bytes(m_nBitLength), 1);

	uint64_t global_OT_ptr = OT_ptr + m_nCounter;

	for (u = 0; u < m_nSndVals; u++)
		sbp[u] = seedbuf[u].GetArr();

	for (uint64_t i = 0; i < OT_len; global_OT_ptr++, i++, Qptr += 2) {
		for (u = 0; u < m_nSndVals; u++) {

#ifdef HIGH_SPEED_ROT_LT
			if(u == 1) {
				Qptr[0]^=Uptr[0];
				Qptr[1]^=Uptr[1];
			}
#else
			if (u == 1)
				Q.XORBytes((uint8_t*) Uptr, i * wd_size_bytes, rowbytelen);
#endif

#ifdef DEBUG_OT_HASH_IN
			cout << "Hash-In for i = " << global_OT_ptr << ", u = " << u << ": " << (hex);
			for(uint32_t p = 0; p < rowbytelen; p++)
				cout << setw(2) << setfill('0') << (uint32_t) (Q.GetArr() + i * wd_size_bytes)[p];
			cout << (dec) << endl;
#endif

			if(m_eSndOTFlav != Snd_GC_OT) {
#ifdef FIXED_KEY_AES_HASHING
				FixedKeyHashing(m_kCRFKey, sbp[u], (BYTE*) Qptr, hash_buf, i, hashinbytelen, m_cCrypt);
#else
				memcpy(inbuf, &global_OT_ptr, sizeof(uint64_t));
				memcpy(inbuf+sizeof(uint64_t), Q.GetArr() + i * wd_size_bytes, rowbytelen);
				m_cCrypt->hash_buf(resbuf, aes_key_bytes, inbuf, hashinbytelen, hash_buf);
				memcpy(sbp[u], resbuf, aes_key_bytes);

			} else {

				BitMatrixMultiplication(tmpbufb, bits_in_bytes(m_nBitLength), Q.GetArr() + i * wd_size_bytes, m_nBaseOTs, mat_mul, tmpbuf);
				//m_vValues[u].SetBits(tmpbufb, (OT_ptr + i)* m_nBitLength, m_nBitLength);
				snd_buf[u].SetBits(tmpbufb, i * m_nBitLength, m_nBitLength);
					//m_vTempOTMasks.SetBytes(tmpbufb, (uint64_t) (OT_ptr + i) * aes_key_bytes, (uint64_t) aes_key_bytes);
				//m_vValues[u].SetBytes(Q.GetArr() + i * wd_size_bytes, (OT_ptr + i)* wd_size_bytes, rowbytelen);
			}
#endif

#ifdef DEBUG_OT_HASH_OUT
			cout << "Hash-Out for i = " << global_OT_ptr << ", u = " << u << ": " << (hex);
			for(uint32_t p = 0; p < aes_key_bytes; p++)
				cout << setw(2) << setfill('0') << (uint32_t) sbp[u][p];
			cout << (dec) << endl;
#endif
			sbp[u] += aes_key_bytes;

		}
	}
	//m_vValues[0].PrintHex();
	//m_vValues[1].PrintHex();

#ifndef HIGH_SPEED_ROT_LT
	if(m_eSndOTFlav != Snd_GC_OT) {
	//Two calls to expandMask, both writing into snd_buf
		for (uint32_t u = 0; u < m_nSndVals; u++)
			m_fMaskFct->expandMask(snd_buf[u], seedbuf[u].GetArr(), 0, OT_len, m_nBitLength, m_cCrypt);
	}
#endif

	free(resbuf);
	free(inbuf);
	free(sbp);
	free(hash_buf);
	free(tmpbuf);
	free(tmpbufb);
}