Exemple #1
0
int
INV_GF256(GarbledCircuit *garbledCircuit, GarblingContext *garblingContext,
          int* inputs, int* outputs)
{
	int i;
	int square0Inputs[8];
	int square0Outputs[8];
	int square1Inputs[8];
	int square1Outputs[8];

	int Mult0Inputs[8];
	int Mult1Inputs[8];
	int XOR0Inputs[8];
	int XOR0Outputs[8];
	int XOR1Inputs[8];
	int XOR1Outputs[8];
	int Mult0Outputs[8];
	int Mult1Outputs[8];

	int mapOutputs[16];

	MAP(garbledCircuit, garblingContext, inputs, mapOutputs);

	for (i = 0; i < 4; i++) {
		square0Inputs[i] = mapOutputs[i + 4];

		square1Inputs[i] = mapOutputs[i];

		Mult0Inputs[i] = mapOutputs[i + 4];

		Mult0Inputs[i + 4] = mapOutputs[i];

		XOR0Inputs[i] = mapOutputs[i + 4];

		XOR0Inputs[i + 4] = mapOutputs[i];
	}

	SquareCircuit(garbledCircuit, garblingContext, 4, square0Inputs,
			square0Outputs);
	SquareCircuit(garbledCircuit, garblingContext, 4, square1Inputs,
			square1Outputs);

	MULTGF16(garbledCircuit, garblingContext, Mult0Inputs, Mult0Outputs);

	XORCircuit(garbledCircuit, garblingContext, 8, XOR0Inputs, XOR0Outputs);

	int MultEInputs[8];
	int MultEOutputs[8];
	int XOR2Inputs[8];
	int XOR2Outputs[8];

	for (i = 0; i < 4; i++) {

		MultEInputs[i] = square0Outputs[i];
		XOR1Inputs[i] = square1Outputs[i];
	}

	MULTE_GF16(garbledCircuit, garblingContext, MultEInputs, MultEOutputs);

	for (i = 0; i < 4; i++) {
		XOR1Inputs[i + 4] = MultEOutputs[i];
	}

	XORCircuit(garbledCircuit, garblingContext, 8, XOR1Inputs, XOR1Outputs);
	for (i = 0; i < 4; i++) {
		XOR2Inputs[i] = Mult0Outputs[i];
		XOR2Inputs[i + 4] = XOR1Outputs[i];
	}
	XORCircuit(garbledCircuit, garblingContext, 8, XOR2Inputs, XOR2Outputs);

	int InvtInputs[8];
	int InvtOutputs[8];

	for (i = 0; i < 4; i++) {
		InvtInputs[i] = XOR2Outputs[i];
	}
	INV_GF16(garbledCircuit, garblingContext, InvtInputs, InvtOutputs);

	for (i = 0; i < 4; i++) {
		Mult1Inputs[i] = InvtOutputs[i];
	}
	for (i = 0; i < 4; i++) {
		Mult1Inputs[i + 4] = mapOutputs[i + 4];
	}
	MULTGF16(garbledCircuit, garblingContext, Mult1Inputs, Mult1Outputs);

	int Mult2Inputs[8];
	int Mult2Outputs[8];
	for (i = 0; i < 4; i++) {
		Mult2Inputs[i] = XOR0Outputs[i];
		Mult2Inputs[i + 4] = InvtOutputs[i];
	}
	MULTGF16(garbledCircuit, garblingContext, Mult2Inputs, Mult2Outputs);

	int InvMapInputs[8];
	int InvMapOutputs[8];

	for (i = 0; i < 4; i++) {
		InvMapInputs[i] = Mult2Outputs[i];
		InvMapInputs[i + 4] = Mult1Outputs[i];
	}

	INVMAP(garbledCircuit, garblingContext, InvMapInputs, InvMapOutputs);
	for (i = 0; i < 8; i++) {
		outputs[i] = InvMapOutputs[i];
	}
	return 0;
}
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;
}
Exemple #3
0
int
AddRoundKey(GarbledCircuit *gc, GarblingContext *garblingContext,
            int* inputs, int* outputs)
{
	return XORCircuit(gc, garblingContext, 256, inputs, outputs);
}