예제 #1
0
void CClient::Init()
{
	// circuit
	CConfig* cf = CConfig::GetInstance();
	
	// random
	sha1_context sha;
	sha1_starts(&sha);
	sha1_update(&sha, (BYTE*) cf->GetSeed().c_str(), cf->GetSeed().length());
	sha1_finish(&sha, m_aSeed);
	m_nCounter = 1;
	

	if( !cf->GetCircFileName().empty() )
	{
		m_pCircuit = LOAD_CIRCUIT_BIN(cf->GetCircFileName().c_str());

		if(!m_pCircuit)
		{
			cout << "failure in loading circuit " << cf->GetCircFileName() << endl;
			return;
		}
	}
	else
	{
		m_pCircuit = CREATE_CIRCUIT(cf->GetNumParties(), cf->GetCircCreateName(), cf->GetCircCreateParams() );
	}

	m_pGates = m_pCircuit->Gates();
	m_nNumGates = m_pCircuit->GetNumGates();
	m_nGateStart = m_pCircuit->GetGateStart();
	 
	// bind the constant
	m_pGates[0].val = 0;
	m_pGates[1].val = 1;
	
	// bind the input
	int nBits = m_pCircuit->GetNumVBits(ID_CLIENT);
	int nStart = m_pCircuit->GetInputStart(ID_CLIENT);
	int nEnd = m_pCircuit->GetInputEnd(ID_CLIENT);
	vector<int> vIn;
	CConfig::GetInstance()->GetInput(vIn);	
	int nInputs = vIn.size();	
 	
	int j=nStart;
	for( int i=0; i<nInputs && j <=nEnd; i++ ) 
	{
		for(int k=0; k<nBits && j<=nEnd; k++ )
		{
			int mask = (1 << k );
			m_pGates[j++].val = !!(vIn[i] & mask);
		}
	}
	 
	// yao
	m_pYaoKeys = new KEY[m_nNumGates];
	m_pYaoGates  = new YAO_GARBLED_GATE[m_nNumGates-m_nGateStart+1];
	m_nGatesDone = -1;
	m_bOTDone = FALSE;
	m_bOutKeysReady = FALSE;

	// batch
	m_nGateBatch = NUM_GATE_BATCH; 
	m_nKeyBatch = NUM_KEY_BATCH; 
	 
	// IKNP
	int nNumInputBits = m_pCircuit->GetInputEnd(ID_CLIENT) - m_pCircuit->GetInputStart(ID_CLIENT) + 1;
	m_T.resize(NUM_EXECS_NAOR_PINKAS);
	for(int i=0; i<NUM_EXECS_NAOR_PINKAS; i++)
		m_T[i].Create(nNumInputBits, m_aSeed, m_nCounter );
}
예제 #2
0
BOOL CServer::Init()
{
	// circuit
	CConfig* cf = CConfig::GetInstance();
	int nInputs = cf->GetNumInputs();
		
	if( !cf->GetCircFileName().empty() )
	{
		m_pCircuit = LOAD_CIRCUIT_BIN(cf->GetCircFileName().c_str());

		if(!m_pCircuit)
		{
			cout << "failure in loading circuit " << cf->GetCircFileName() << endl;
			return FALSE;
		}
	}
	else
	{
		m_pCircuit = CREATE_CIRCUIT(cf->GetNumParties(), cf->GetCircCreateName(), cf->GetCircCreateParams() );
	}

	m_pGates = m_pCircuit->Gates();
	m_nNumGates = m_pCircuit->GetNumGates();

	// bind the constant
	m_pGates[0].val = 0;
	m_pGates[1].val = 1;
	
	// bind the input
	int nBits = m_pCircuit->GetNumVBits(ID_SERVER);
	int nStart = m_pCircuit->GetInputStart(ID_SERVER);
	int nEnd = m_pCircuit->GetInputEnd(ID_SERVER);

	vector<int> vIn;
	CConfig::GetInstance()->GetInput(vIn);	
	//cout << "s=" << nStart << " e= " << nEnd << endl;
	
	int j=nStart;
	for( int i=0; i<nInputs && j <=nEnd; i++ ) 
	{
		for(int k=0; k<nBits && j<=nEnd; k++ )
		{
			int mask = (1 << k );
			m_pGates[j++].val = !!(vIn[i] & mask);
		}
	}
	 
	#ifdef _DEBUG
	
	if( nInputs == 10 )
	{
		j = nStart;
		for( int i=0; i<nInputs; i++ )
		{
			cout << "id[" << i << "]: ";
	
			for(int k=0; k<nBits; k++ )
			{
				cout << (int) m_pGates[j].val;
				j++;
			}
			cout << endl;
		}
		assert(j == nEnd+1);


		int i= m_pCircuit->GetInputStart(ID_CLIENT); 
		m_pGates[i++].val = 0;
		m_pGates[i++].val = 0;
		m_pGates[i++].val = 1;
		m_pGates[i++].val = 0;
		m_pGates[i++].val = 0;
		m_pGates[i++].val = 1;
		m_pGates[i++].val = 1;
		m_pGates[i++].val = 0;
		m_pGates[i++].val = 0;
		m_pGates[i++].val = 0;
 		m_pCircuit->Evaluate();
	}
	#endif

	// yao
	m_pYaoWires = new YAO_WIRE[m_nNumGates];
	m_pYaoGates  = new YAO_GARBLED_GATE[m_nNumGates - m_pCircuit->GetGateStart()];
	m_vOutGates.reserve(1024);
	m_nGatesDone = -1;
	m_nWiresDone = -1;

	// randomness
	sha1_context sha;
	sha1_starts(&sha);
	sha1_update(&sha, (BYTE*) cf->GetSeed().c_str(), cf->GetSeed().length());
	sha1_finish(&sha, m_aSeed);
	m_nCounter = 1;
	
	// batch parameters
 	m_nGateBatch = NUM_GATE_BATCH;
	m_nKeyBatch = NUM_KEY_BATCH; 
	 

	// IKNP
	m_S.Create(NUM_EXECS_NAOR_PINKAS, m_aSeed, m_nCounter );

	m_bStop = FALSE;

	return TRUE;
}