Example #1
0
int
MULTE_GF16(GarbledCircuit *garbledCircuit, GarblingContext *garblingContext,
           int* inputs, int* outputs)
{
	int outputA = getNextWire(garblingContext);
	int outputB = getNextWire(garblingContext);
	int outputq0 = getNextWire(garblingContext);
	int outputq2 = getNextWire(garblingContext);
	int outputq3 = getNextWire(garblingContext);

	XORGate(garbledCircuit, garblingContext, inputs[0], inputs[1], outputA);

	XORGate(garbledCircuit, garblingContext, inputs[2], inputs[3], outputB);

	XORGate(garbledCircuit, garblingContext, outputB, inputs[1], outputq0);

	XORGate(garbledCircuit, garblingContext, outputA, inputs[2], outputq2);

	XORGate(garbledCircuit, garblingContext, outputB, outputA, outputq3);

	outputs[0] = outputq0;
	outputs[1] = outputA;
	outputs[2] = outputq2;
	outputs[3] = outputq3;
	return 0;

}
Example #2
0
int
MAP(GarbledCircuit *gc, GarblingContext *garblingContext, int* inputs,
    int* outputs)
{
	unsigned char A = 0;
	unsigned char B = 1;
	unsigned char C = 2;
	unsigned char L0 = 3;
	unsigned char L1 = 4;
	unsigned char L3 = 5;
	unsigned char H0 = 6;
	unsigned char H1 = 7;
	unsigned char H2 = 8;

	int i;
	int tempW[10];
	for (i = 0; i < 10; i++)
		tempW[i] = getNextWire(garblingContext);

	XORGate(gc, garblingContext, inputs[1], inputs[7], tempW[A]);

	XORGate(gc, garblingContext, inputs[5], inputs[7], tempW[B]);

	XORGate(gc, garblingContext, inputs[4], inputs[6], tempW[C]);

	int temp = getNextWire(garblingContext);
	XORGate(gc, garblingContext, tempW[C], inputs[0], temp);
	XORGate(gc, garblingContext, temp, inputs[5], tempW[L0]);

	XORGate(gc, garblingContext, inputs[1], inputs[2], tempW[L1]);

	XORGate(gc, garblingContext, inputs[4], inputs[2], tempW[L3]);

	XORGate(gc, garblingContext, inputs[5], tempW[C], tempW[H0]);

	XORGate(gc, garblingContext, inputs[A], inputs[C], tempW[H1]);

	int temp2 = getNextWire(garblingContext);
	XORGate(gc, garblingContext, tempW[B], inputs[2], temp2);
	XORGate(gc, garblingContext, temp2, inputs[3], tempW[H2]);

	outputs[0] = tempW[L0];
	outputs[1] = tempW[L1];
	outputs[2] = tempW[A];
	outputs[3] = tempW[L3];
	outputs[4] = tempW[H0];
	outputs[5] = tempW[H1];
	outputs[6] = tempW[H2];
	outputs[7] = tempW[B];
	return 0;
}
Example #3
0
int
SquareCircuit(GarbledCircuit *garbledCircuit,
              GarblingContext *garblingContext, int n, int* inputs, int* outputs)
{
	outputs[0] = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[0], inputs[2], outputs[0]);

	outputs[1] = inputs[2];
	outputs[2] = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[1], inputs[3], outputs[2]);

	outputs[3] = inputs[3];
	return 0;
}
int fixedOneWire(GarbledCircuit *garbledCircuit,
		GarblingContext *garblingContext) {
	int ind = getNextWire(garblingContext);
	garblingContext->fixedWires[ind] = FIXED_ONE_GATE;
	Wire *wire = &garbledCircuit->wires[ind];
	wire->id = ind;
	wire->label0 = randomBlock();
	wire->label1 = xorBlocks(garblingContext->R, wire->label0);
	return ind;
}
Example #5
0
int fixedZeroWire(GarbledCircuit *garbledCircuit,
		GarblingContext *garblingContext) {
	int ind = getNextWire(garblingContext);
	garblingContext->fixedWires[ind] = FIXED_ZERO_GATE;
	Wire *wire = &garbledCircuit->wires[ind];
	if (wire->id != 0)
		printf("ERROR: Reusing output at wire %d\n", ind);
	wire->id = ind;
	wire->label0 = randomBlock();
	wire->label1 = xorBlocks(garblingContext->R, wire->label0);
	return ind;

}
int main() {

	char* refId = "rs1048659";
	char* name = "HG00372";

	// CI part

    int i,j;
    read_names();
    read_ids();
    int size_names = size_of_names();
    int size_ids = size_of_ids();

    int refId_id = find_ids_id(refId);
    int name_id = find_name_id(name);


    read_encs();
    char encC = get_char_in_enc((size_names*refId_id)+name_id);

    read_skeys();
    char skeyC = get_char_in_skeys((size_names*refId_id)+name_id);
    // SPU -> GC building part

	GarbledCircuit garbledCircuit;
	GarblingContext garblingContext;

	int inputsNb = 32;
	int wiresNb = 50000;
	int gatesNb = 50000;
	int outputsNb = 32;

	//Create a circuit.
	block labels[2 * inputsNb];
	createInputLabels(labels, inputsNb);
	InputLabels inputLabels = labels;
	createEmptyGarbledCircuit(&garbledCircuit, inputsNb, outputsNb, gatesNb,
			wiresNb, inputLabels);
	startBuilding(&garbledCircuit, &garblingContext);

	// Transform generator's input into fixed wire
	int zero = fixedZeroWire(&garbledCircuit,&garblingContext);
	int one = fixedOneWire(&garbledCircuit,&garblingContext);

	int onewire = getNextWire(&garblingContext);
	NOTGate(&garbledCircuit,&garblingContext,zero,onewire);

	int zerowire = getNextWire(&garblingContext);
	NOTGate(&garbledCircuit,&garblingContext,one,zerowire);

	int outputs[outputsNb];
	int *inp = (int *) malloc(sizeof(int) * inputsNb*2);
	countToN(inp, inputsNb);
	//countToN(outputs, inputsNb);

	int bits[inputsNb];
	int_into_ints(encC,bits);
	for (i = 0; i < inputsNb; i++) {
		if (bits[i]) {
			inp[inputsNb+i] = onewire;
		} else {
			inp[inputsNb+i] = zerowire;
		}
	}
	int tempOutput[2*outputsNb];
	XORCircuit(&garbledCircuit, &garblingContext, inputsNb*2, inp, outputs);

	block *outputbs = (block*) malloc(sizeof(block) * outputsNb);
	OutputMap outputMap = outputbs;
	finishBuilding(&garbledCircuit, &garblingContext, outputMap, outputs);
	garbleCircuit(&garbledCircuit, inputLabels, outputMap);

	// MU -> Evaluation part
	block extractedLabels[inputsNb];

	int extractedInputs[inputsNb];
	int_into_ints(skeyC,extractedInputs);

	extractLabels(extractedLabels, inputLabels, extractedInputs, inputsNb);
	block computedOutputMap[outputsNb];
	evaluate(&garbledCircuit, extractedLabels, computedOutputMap);
	int outputVals[outputsNb];
	mapOutputs(outputMap, computedOutputMap, outputVals, outputsNb);
	//TODO
	int res = ints_into_int(outputVals);
	printf("RESULT IS : %d\n",res);
	return 0;
}
Example #7
0
int
AFFINE(GarbledCircuit *garbledCircuit, GarblingContext *garblingContext,
       int* inputs, int* outputs)
{
	int AOutput = getNextWire(garblingContext);
	int BOutput = getNextWire(garblingContext);
	int COutput = getNextWire(garblingContext);
	int DOutput = getNextWire(garblingContext);

	int q0Output = getNextWire(garblingContext);
	int q1Output = getNextWire(garblingContext);
	int q2Output = getNextWire(garblingContext);
	int q3Output = getNextWire(garblingContext);
	int q4Output = getNextWire(garblingContext);
	int q5Output = getNextWire(garblingContext);
	int q6Output = getNextWire(garblingContext);
	int q7Output = getNextWire(garblingContext);

	int a0barOutput = getNextWire(garblingContext);
	int a1barOutput = getNextWire(garblingContext);
	int a5barOutput = getNextWire(garblingContext);
	int a6barOutput = getNextWire(garblingContext);

	XORGate(garbledCircuit, garblingContext, inputs[0], inputs[1], AOutput);

	XORGate(garbledCircuit, garblingContext, inputs[2], inputs[3], BOutput);

	XORGate(garbledCircuit, garblingContext, inputs[4], inputs[5], COutput);

	XORGate(garbledCircuit, garblingContext, inputs[6], inputs[7], DOutput);

	NOTGate(garbledCircuit, garblingContext, inputs[0], a0barOutput);

	NOTGate(garbledCircuit, garblingContext, inputs[1], a1barOutput);

	NOTGate(garbledCircuit, garblingContext, inputs[5], a5barOutput);

	NOTGate(garbledCircuit, garblingContext, inputs[6], a6barOutput);

	int tempWireq0 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, a0barOutput, COutput, tempWireq0);
	XORGate(garbledCircuit, garblingContext, tempWireq0, DOutput, q0Output);

	int tempWireq1 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, a5barOutput, AOutput, tempWireq1);
	XORGate(garbledCircuit, garblingContext, tempWireq1, DOutput, q1Output);

	int tempWireq2 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[2], AOutput, tempWireq2);
	XORGate(garbledCircuit, garblingContext, tempWireq2, DOutput, q2Output);

	int tempWireq3 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[7], AOutput, tempWireq3);
	XORGate(garbledCircuit, garblingContext, tempWireq3, BOutput, q3Output);

	int tempWireq4 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[4], AOutput, tempWireq4);
	XORGate(garbledCircuit, garblingContext, tempWireq4, BOutput, q4Output);

	int tempWireq5 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, a1barOutput, BOutput, tempWireq5);
	XORGate(garbledCircuit, garblingContext, tempWireq5, COutput, q5Output);

	int tempWireq6 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, a6barOutput, BOutput, tempWireq6);
	XORGate(garbledCircuit, garblingContext, tempWireq6, COutput, q6Output);

	int tempWireq7 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[3], COutput, tempWireq7);
	XORGate(garbledCircuit, garblingContext, tempWireq7, DOutput, q7Output);

	outputs[0] = q0Output;
	outputs[1] = q1Output;
	outputs[2] = q2Output;
	outputs[3] = q3Output;
	outputs[4] = q4Output;
	outputs[5] = q5Output;
	outputs[6] = q6Output;
	outputs[7] = q7Output;

	return 0;
}
Example #8
0
int
INV_GF16(GarbledCircuit *garbledCircuit, GarblingContext *garblingContext,
         int* inputs, int* outputs)
{
	int AOutput = getNextWire(garblingContext);
	int q0Output = getNextWire(garblingContext);
	int q1Output = getNextWire(garblingContext);
	int q2Output = getNextWire(garblingContext);
	int q3Output = getNextWire(garblingContext);

	int and01Output = getNextWire(garblingContext);
	int and02Output = getNextWire(garblingContext);
	int and03Output = getNextWire(garblingContext);
	int and12Output = getNextWire(garblingContext);
	int and13Output = getNextWire(garblingContext);
	int and23Output = getNextWire(garblingContext);
	int and012Output = getNextWire(garblingContext);
	int and123Output = getNextWire(garblingContext);
	int and023Output = getNextWire(garblingContext);
	int and013Output = getNextWire(garblingContext);

	ANDGate(garbledCircuit, garblingContext, inputs[0], inputs[1], and01Output);

	ANDGate(garbledCircuit, garblingContext, inputs[0], inputs[2], and02Output);

	ANDGate(garbledCircuit, garblingContext, inputs[0], inputs[3], and03Output);

	ANDGate(garbledCircuit, garblingContext, inputs[2], inputs[1], and12Output);

	ANDGate(garbledCircuit, garblingContext, inputs[3], inputs[1], and13Output);

	ANDGate(garbledCircuit, garblingContext, inputs[2], inputs[3], and23Output);

	ANDGate(garbledCircuit, garblingContext, inputs[2], and01Output,
			and012Output);

	ANDGate(garbledCircuit, garblingContext, inputs[3], and12Output,
			and123Output);

	ANDGate(garbledCircuit, garblingContext, inputs[3], and02Output,
			and023Output);

	ANDGate(garbledCircuit, garblingContext, inputs[3], and01Output,
			and013Output);

	int tempXORA1 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[1], inputs[2], tempXORA1);
	int tempXORA2 = getNextWire(garblingContext);
	XORGate(garbledCircuit, garblingContext, inputs[3], and123Output,
			tempXORA2);
	XORGate(garbledCircuit, garblingContext, tempXORA1, tempXORA2, AOutput);

	int tempXORq01 = getNextWire(garblingContext);
	int tempXORq02 = getNextWire(garblingContext);
	int tempXORq03 = getNextWire(garblingContext);

	XORGate(garbledCircuit, garblingContext, inputs[0], AOutput, tempXORq01);
	XORGate(garbledCircuit, garblingContext, and02Output, tempXORq01,
			tempXORq02);
	XORGate(garbledCircuit, garblingContext, and12Output, tempXORq02,
			tempXORq03);
	XORGate(garbledCircuit, garblingContext, and012Output, tempXORq03,
			q0Output);

	int tempXORq11 = getNextWire(garblingContext);
	int tempXORq12 = getNextWire(garblingContext);
	int tempXORq13 = getNextWire(garblingContext);
	int tempXORq14 = getNextWire(garblingContext);
	/* int tempXORq15 = */ getNextWire(garblingContext);

	XORGate(garbledCircuit, garblingContext, and01Output, and02Output,
			tempXORq11);
	XORGate(garbledCircuit, garblingContext, and12Output, tempXORq11,
			tempXORq12);
	XORGate(garbledCircuit, garblingContext, inputs[3], tempXORq12, tempXORq13);
	XORGate(garbledCircuit, garblingContext, and13Output, tempXORq13,
			tempXORq14);
	XORGate(garbledCircuit, garblingContext, and013Output, tempXORq14,
			q1Output);

	int tempXORq21 = getNextWire(garblingContext);
	int tempXORq22 = getNextWire(garblingContext);
	int tempXORq23 = getNextWire(garblingContext);
	int tempXORq24 = getNextWire(garblingContext);
	/* int tempXORq25 = */ getNextWire(garblingContext);

	XORGate(garbledCircuit, garblingContext, and01Output, inputs[2],
			tempXORq21);
	XORGate(garbledCircuit, garblingContext, and02Output, tempXORq21,
			tempXORq22);
	XORGate(garbledCircuit, garblingContext, inputs[3], tempXORq22, tempXORq23);
	XORGate(garbledCircuit, garblingContext, and03Output, tempXORq23,
			tempXORq24);
	XORGate(garbledCircuit, garblingContext, and023Output, tempXORq24,
			q2Output);

	int tempXORq31 = getNextWire(garblingContext);
	int tempXORq32 = getNextWire(garblingContext);
	/* int tempXORq33 = */ getNextWire(garblingContext);
	/* int tempXORq34 = */ getNextWire(garblingContext);
	/* int tempXORq35 = */ getNextWire(garblingContext);

	XORGate(garbledCircuit, garblingContext, AOutput, and03Output, tempXORq31);
	XORGate(garbledCircuit, garblingContext, and13Output, tempXORq31,
			tempXORq32);
	XORGate(garbledCircuit, garblingContext, and23Output, tempXORq32, q3Output);

	outputs[0] = q0Output;
	outputs[1] = q1Output;
	outputs[2] = q2Output;
	outputs[3] = q3Output;

	return 0;
}
Example #9
0
int
MULTGF16(GarbledCircuit *gc, GarblingContext *garblingContext, int* inputs,
         int* outputs)
{
	unsigned char A = 0;
	unsigned char B = 1;
	unsigned char C = 2;
	unsigned char q0 = 3;
	unsigned char q1 = 4;
	unsigned char q2 = 5;
	unsigned char q3 = 6;

	unsigned char and00 = 7;
	unsigned char and31 = 8;
	unsigned char and22 = 9;
	unsigned char and13 = 10;
	unsigned char and10 = 11;
	unsigned char andA1 = 12;
	unsigned char andB2 = 13;
	unsigned char andC3 = 14;
	unsigned char and20 = 15;
	unsigned char and11 = 16;
	unsigned char andA2 = 17;
	unsigned char andB3 = 18;
	unsigned char and30 = 19;
	unsigned char and21 = 20;
	unsigned char and12 = 21;
	unsigned char andA3 = 22;

	unsigned char b0 = 0;
	unsigned char b1 = 1;
	unsigned char b2 = 2;
	unsigned char b3 = 3;
	unsigned char a0 = 4;
	unsigned char a1 = 5;
	unsigned char a2 = 6;
	unsigned char a3 = 7;

	int tempW[24];
	int i;
	for (i = 0; i < 24; i++)
		tempW[i] = getNextWire(garblingContext);

	XORGate(gc, garblingContext, inputs[a3], inputs[a0], tempW[A]);

	XORGate(gc, garblingContext, inputs[a3], inputs[a2], tempW[B]);

	XORGate(gc, garblingContext, inputs[a1], inputs[a2], tempW[C]);

	ANDGate(gc, garblingContext, inputs[a0], inputs[b0], tempW[and00]);

	ANDGate(gc, garblingContext, inputs[a3], inputs[b1], tempW[and31]);

	ANDGate(gc, garblingContext, inputs[a2], inputs[b2], tempW[and22]);

	ANDGate(gc, garblingContext, inputs[a1], inputs[b3], tempW[and13]);

	int temp1 = getNextWire(garblingContext);
	int temp2 = getNextWire(garblingContext);
	XORGate(gc, garblingContext, tempW[and00], tempW[and31], temp1);

	XORGate(gc, garblingContext, tempW[and13], tempW[and22], temp2);
	XORGate(gc, garblingContext, temp1, temp2, tempW[q0]);

	ANDGate(gc, garblingContext, inputs[a1], inputs[b0], tempW[and10]);

	ANDGate(gc, garblingContext, tempW[A], inputs[b1], tempW[andA1]);

	ANDGate(gc, garblingContext, tempW[B], inputs[b2], tempW[andB2]);

	ANDGate(gc, garblingContext, tempW[C], inputs[b3], tempW[andC3]);

	temp1 = getNextWire(garblingContext);
	temp2 = getNextWire(garblingContext);

	XORGate(gc, garblingContext, tempW[and10], tempW[andA1], temp1);

	XORGate(gc, garblingContext, tempW[andB2], tempW[andC3], temp2);

	XORGate(gc, garblingContext, temp1, temp2, tempW[q1]);

	ANDGate(gc, garblingContext, inputs[a2], inputs[b0], tempW[and20]);

	ANDGate(gc, garblingContext, inputs[a1], inputs[b1], tempW[and11]);

	ANDGate(gc, garblingContext, tempW[A], inputs[b2], tempW[andA2]);

	ANDGate(gc, garblingContext, tempW[B], inputs[b3], tempW[andB3]);

	temp1 = getNextWire(garblingContext);
	temp2 = getNextWire(garblingContext);

	XORGate(gc, garblingContext, tempW[and20], tempW[and11], temp1);

	XORGate(gc, garblingContext, tempW[andA2], tempW[andB3], temp2);

	XORGate(gc, garblingContext, temp1, temp2, tempW[q2]);

	ANDGate(gc, garblingContext, inputs[a3], inputs[b0], tempW[and30]);

	ANDGate(gc, garblingContext, inputs[a2], inputs[b1], tempW[and21]);

	ANDGate(gc, garblingContext, inputs[a1], inputs[b2], tempW[and12]);

	ANDGate(gc, garblingContext, tempW[A], inputs[b3], tempW[andA3]);

	temp1 = getNextWire(garblingContext);
	temp2 = getNextWire(garblingContext);

	XORGate(gc, garblingContext, tempW[and30], tempW[and21], temp1);

	XORGate(gc, garblingContext, tempW[andA3], tempW[and12], temp2);

	XORGate(gc, garblingContext, temp1, temp2, tempW[q3]);

	outputs[0] = tempW[q0];
	outputs[1] = tempW[q1];
	outputs[2] = tempW[q2];
	outputs[3] = tempW[q3];
	return 0;

}
Example #10
0
int
INVMAP(GarbledCircuit *gc, GarblingContext *garblingContext, int* inputs,
       int* outputs)
{
	unsigned char A = 0;
	unsigned char B = 1;
	unsigned char a0 = 2;
	unsigned char a1 = 3;
	unsigned char a2 = 4;
	unsigned char a3 = 5;
	unsigned char a4 = 6;
	unsigned char a5 = 7;
	unsigned char a6 = 8;
	unsigned char a7 = 9;

	unsigned char l0 = 0;
	unsigned char l1 = 1;
	unsigned char l2 = 2;
	unsigned char l3 = 3;
	unsigned char h0 = 4;
	unsigned char h1 = 5;
	unsigned char h2 = 6;
	unsigned char h3 = 7;

	int i;
	for (i = 0; i < 8; i++)
		outputs[i] = getNextWire(garblingContext);
	int tempW[16];
	for (i = 0; i < 16; i++)
		tempW[i] = getNextWire(garblingContext);

	XORGate(gc, garblingContext, inputs[l1], inputs[h3], tempW[A]);

	XORGate(gc, garblingContext, inputs[h1], inputs[h0], tempW[B]);

	XORGate(gc, garblingContext, inputs[l0], inputs[h0], tempW[a0]);

	XORGate(gc, garblingContext, inputs[h3], tempW[B], tempW[a1]);

	XORGate(gc, garblingContext, tempW[A], tempW[B], tempW[a2]);

	int temp = getNextWire(garblingContext);
	XORGate(gc, garblingContext, tempW[B], inputs[l1], temp);

	XORGate(gc, garblingContext, temp, inputs[h2], tempW[a3]);

	temp = getNextWire(garblingContext);
	XORGate(gc, garblingContext, tempW[A], tempW[B], temp);

	XORGate(gc, garblingContext, inputs[l3], temp, tempW[a4]);

	XORGate(gc, garblingContext, inputs[l2], tempW[B], tempW[a5]);

	temp = getNextWire(garblingContext);
	XORGate(gc, garblingContext, tempW[A], inputs[l2], temp);

	int temp2 = getNextWire(garblingContext);
	XORGate(gc, garblingContext, temp, inputs[l3], temp2);
	XORGate(gc, garblingContext, temp2, inputs[h0], tempW[a6]);

	temp2 = getNextWire(garblingContext);

	XORGate(gc, garblingContext, tempW[B], inputs[l2], temp2);

	XORGate(gc, garblingContext, temp2, inputs[h3], tempW[a7]);

	outputs[0] = tempW[a0];
	outputs[1] = tempW[a1];
	outputs[2] = tempW[a2];
	outputs[3] = tempW[a3];
	outputs[4] = tempW[a4];
	outputs[5] = tempW[a5];
	outputs[6] = tempW[a6];
	outputs[7] = tempW[a7];
	return 0;

}