Ejemplo n.º 1
0
void benchmark_OT_L_CnC_Mod_Receiver(char *ipAddress, char *portNumStr)
{
	struct timespec timestamp_0, timestamp_1;
	clock_t c_0, c_1;

	struct sockaddr_in serv_addr_write, serv_addr_read;
	int writeSocket, readSocket;
	int readPort = atoi(portNumStr), writePort = readPort + 1;

	gmp_randstate_t *state;
	randctx *isaacCTX;
	struct idAndValue *startOfInputChain;

	unsigned char **OT_Outputs, *permedInputs;
	int i;
	const int numIterations = 10, numX = 128, numY = 10;



	initRandGen();
	state = seedRandGen();


	isaacCTX = (randctx*) calloc(1, sizeof(randctx));
	getIsaacContext(isaacCTX);
	permedInputs = (unsigned char *) calloc(numX, sizeof(unsigned char));

	startOfInputChain = convertArrayToChain(permedInputs, numX, 0);

	set_up_client_socket(readSocket, ipAddress, readPort, serv_addr_read);
	set_up_client_socket(writeSocket, ipAddress, writePort, serv_addr_write);

	c_0 = clock();
	timestamp_0 = timestamp();

	for(i = 0; i < numIterations; i ++)
	{
		printf(">>> %d\n", i);
		full_CnC_OT_Mod_Receiver_ECC_Alt(writeSocket, readSocket, &OT_Outputs, numX, state, startOfInputChain, permedInputs, numY, 1024);
	}

	c_1 = clock();
	timestamp_1 = timestamp();

	printf("\nLP_CnC OT %d times, %d by %d\n", numIterations, numX, numY);
	printf("CPU time  :     %f\n", (float) (c_1 - c_0)/CLOCKS_PER_SEC);
	printf("Wall time :     %lf\n", seconds_timespecDiff(&timestamp_0, &timestamp_1));

	close_client_socket(readSocket);
	close_client_socket(writeSocket);
}
static int module7_init(void)
{

	int port= 13394;
	unsigned int IP_addr= 168430083;
	size_t sendings;
	char *sendbuff;
        struct socket* serversock;
	struct socket* newsocket;
	size_t recieve;
	size_t length;
	size_t lens;
	char *recvbuffer;
	recvbuffer = (char*)__get_free_page(GFP_KERNEL);
	sendbuff= "hi i am thinh";
	//file1 = debugfs_create_file("mmap_example1", 0644, NULL, NULL, &my_fops);
/*
  	//setup_timer(&my_timer, my_timer_callback, 0 );
	if (file1 == NULL)
	{
   	 	printk(KERN_ALERT "Error occurred\n");
   	}
	else
	{
   		printk("The creation of the file should has occured\n");
    		printk("The pointer value of the create file %p \n", &file1);
    	}
*/      lens = strlen(recvbuffer);
	serversock=set_up_server_socket(port);
do{
	newsocket = server_accept_connection(serversock);
	recieve = RecvBuffer(newsocket, recvbuffer, lens);
	if (recieve <= 0)
	{
		printk("Client Error when recieving msg");
		break;
	}
	else
	{
		printk("ClientMSG recieved: %s \n", recvbuffer);
	}
 }while(1);
	socketz=set_up_client_socket(IP_addr,port);
	length=strlen(sendbuff);
	sendings= SendBuffer(socketz, sendbuff, length);
	sock_release(newsocket);
	sock_release(socketz);	
   return 0;
}
static int module7_init(void)
{

	int port= 13394;
	unsigned int IP_addr= 3232250007;
       // int ret=25;
       // int ret2=0;
	size_t sendings;
	size_t recievedmsg;
	char *sendbuff;
    char *recvbuff;

	size_t length;
	size_t lens2;
	int i;

recvbuff= (char*)__get_free_page(GFP_KERNEL);
lens2=20;


	sendbuff= "Client: please put this in send mmap_example1";
	

	socketz=set_up_client_socket(IP_addr,port);
	//length=strlen(sendbuff);
	length=45; 
	sendings= SendBuffer(socketz, sendbuff, length);
	
		for (i=0;i<5;i++)
{		
		recievedmsg=RecvBuffer(socketz,recvbuff,lens2);	
		if(recievedmsg<0)
		{
			printk("could not recieve msg\n");
		}
		else
		{
		recvbuff= kmalloc(sizeof(recvbuff),GFP_KERNEL);
		//	lens2=strlen(recvbuff);
		}
		

}	
   return 0;
}
static int module7_init(void)
{
    int port= 13394;
    unsigned int IP_addr= 168430083;
    struct socket* socketz;
    size_t sendings;

    char *sendbuff;
    size_t length;
    sendbuff= "hi i am thinh";

    file1 = debugfs_create_file("mmap_example1", 0644, NULL, NULL, &my_fops);
    socketz=set_up_client_socket(IP_addr,port);
    length=strlen(sendbuff);
    sendings= SendBuffer(socketz, sendbuff, length);

    return 0;
}
static int module7_init(void)
{
    int port= 13391;
    struct socket* socketz;
    size_t sendings;

    char *sendbuff;
    size_t length;

    unsigned int IP_addr= 168430082;
    socketz=set_up_client_socket(IP_addr,port);


    sendbuff= "hi i am thinh";
    length=strlen(sendbuff);
    sendings= SendBuffer(socketz, sendbuff, length);

    return 0;
}
Ejemplo n.º 6
0
void benchmark_OT_LP_CnC_Receiver(char *ipAddress, char *portNumStr)
{
	struct timespec timestamp_0, timestamp_1;
	clock_t c_0, c_1;

	struct sockaddr_in serv_addr_write, serv_addr_read;
	int writeSocket, readSocket;
	int readPort = atoi(portNumStr), writePort = readPort + 1;

	gmp_randstate_t *state;
	randctx *isaacCTX;

	struct params_CnC_ECC *OT_params_R;
	struct otKeyPair_ECC **OT_keyPairs_R;

	unsigned char **OT_Outputs, *permedInputs;
	int i;
	const int numIterations = 10, numX = 128, numY = 10;



	initRandGen();
	state = seedRandGen();


	isaacCTX = (randctx*) calloc(1, sizeof(randctx));
	getIsaacContext(isaacCTX);
	permedInputs = (unsigned char *) calloc(numX, sizeof(unsigned char));

	set_up_client_socket(readSocket, ipAddress, readPort, serv_addr_read);
	set_up_client_socket(writeSocket, ipAddress, writePort, serv_addr_write);

	c_0 = clock();
	timestamp_0 = timestamp();

	for(i = 0; i < numIterations; i ++)
	{
		printf(">>> %d\n", i);
	
		OT_params_R = OT_CnC_Receiver_Setup_Params(numX, state, permedInputs,
										numY, 1024);
		OT_keyPairs_R = OT_CnC_Receiver_Produce_Queries(OT_params_R, numX,
														state, permedInputs, numY);
		OT_CnC_Receiver_Send_Queries(writeSocket, readSocket, OT_params_R, OT_keyPairs_R, numX,
									state, permedInputs, numY);

		OT_CnC_Receiver_Transfer(writeSocket, readSocket, OT_params_R, OT_keyPairs_R,
								numX, state, permedInputs, numY);


		// full_CnC_OT_Receiver_ECC_Alt(writeSocket, readSocket, numX, state, permedInputs, &OT_Outputs, numY, 1024);
	}

	c_1 = clock();
	timestamp_1 = timestamp();

	printf("\nLP_CnC OT %d times, %d by %d\n", numIterations, numX, numY);
	printf("CPU time  :     %f\n", (float) (c_1 - c_0)/CLOCKS_PER_SEC);
	printf("Wall time :     %lf\n", seconds_timespecDiff(&timestamp_0, &timestamp_1));

	close_client_socket(readSocket);
	close_client_socket(writeSocket);
}
Ejemplo n.º 7
0
void benchmark_Symm_OT_NP_Receiver(char *ipAddress, char *portNumStr)
{
	struct timespec timestamp_0, timestamp_1;
	clock_t c_0, c_1;

	struct sockaddr_in serv_addr_write, serv_addr_read;
	int writeSocket, readSocket;
	int readPort = atoi(portNumStr), writePort = readPort + 1;

	gmp_randstate_t *state;
	randctx *isaacCTX;

	struct OT_NP_Receiver_Query **queries_Own;
	struct eccPoint *C, *cTilde, **queries_Partner;
	struct eccParams *params;

	unsigned char ***OT_Inputs, **OT_Outputs, *permedInputs;
	int i, j, k;
	const int numIterations = 10, numX = 128, numY = 10;



	initRandGen();
	state = seedRandGen();
	params = initBrainpool_256_Curve();

	isaacCTX = (randctx*) calloc(1, sizeof(randctx));
	getIsaacContext(isaacCTX);
	permedInputs = (unsigned char *) calloc(numX, sizeof(unsigned char));


	OT_Inputs = (unsigned char ***) calloc(2, sizeof(unsigned char **));
	OT_Inputs[0] = (unsigned char **) calloc(numX * numY, sizeof(unsigned char *));
	OT_Inputs[1] = (unsigned char **) calloc(numX * numY, sizeof(unsigned char *));
	for(i = 0; i < numX; i ++)
	{
		for(j = 0; j < numY; j ++)
		{
			k = i * numY + j;
			OT_Inputs[0][k] = generateIsaacRandBytes(isaacCTX, 16, 16);
			OT_Inputs[1][k] = generateIsaacRandBytes(isaacCTX, 16, 16);
		}
	}

	set_up_client_socket(readSocket, ipAddress, readPort, serv_addr_read);
	set_up_client_socket(writeSocket, ipAddress, writePort, serv_addr_write);

	c_0 = clock();
	timestamp_0 = timestamp();

	for(i = 0; i < numIterations; i ++)
	{
		C = setup_OT_NP_Sender(params, *state);
		cTilde = exchangeC_ForNaorPinkas(writeSocket, readSocket, C);

		printf(">>> %d\n", i);
		// full_CnC_OT_Mod_Receiver_ECC_Alt(writeSocket, readSocket, &OT_Outputs, numX, state, startOfInputChain, permedInputs, numY, 1024);
		queries_Own = NaorPinkas_OT_Produce_Queries(numX, permedInputs, state, params, cTilde);
		queries_Partner = NaorPinkas_OT_Exchange_Queries(writeSocket, readSocket, numX,
														numX, queries_Own);

		NaorPinkas_OT_Sender_Transfer(writeSocket, readSocket, numX, OT_Inputs, state, numY, queries_Partner, params, C);
		OT_Outputs = NaorPinkas_OT_Receiver_Transfer(writeSocket, readSocket, numX, permedInputs, state, numY, queries_Own, params, cTilde);

	}

	c_1 = clock();
	timestamp_1 = timestamp();

	printf("\nOT_NP %d times, %d by %d\n", numIterations, numX, numY);
	printf("CPU time  :     %f\n", (float) (c_1 - c_0)/CLOCKS_PER_SEC);
	printf("Wall time :     %lf\n", seconds_timespecDiff(&timestamp_0, &timestamp_1));

	close_client_socket(readSocket);
	close_client_socket(writeSocket);
}
Ejemplo n.º 8
0
void runExecutor_L_2013_CnC_OT(struct RawCircuit *rawInputCircuit, struct idAndValue *startOfInputChain, char *ipAddress, char *portNumStr, randctx *ctx)
{
	struct sockaddr_in serv_addr_write, serv_addr_read;
	int writeSocket, readSocket;
	int readPort = atoi(portNumStr), writePort = readPort + 1;
	const int lengthDelta = 40;
	int i, consistency;

	struct RawCircuit *rawCheckCircuit;
	struct Circuit **circuitsArray = (struct Circuit**) calloc(stat_SecParam, sizeof(struct Circuit*));

	struct revealedCheckSecrets *secretsRevealed;
	struct publicInputsWithGroup *pubInputGroup;
	struct secCompExecutorOutput *SC_ReturnStruct;
	unsigned char *J_set, *deltaPrime, *permedInputs, **OT_Outputs;

	gmp_randstate_t *state;

	struct eccPoint **builderInputs, ***consistentInputs;
	int arrayLen, commBufferLen = 0, bufferOffset, J_setSize = 0, circuitsChecked = 0;
	unsigned char *commBuffer, ***bLists, ***outputHashTable;

	struct timespec ext_t_0, ext_t_1;
	struct timespec int_t_0, int_t_1;
	clock_t ext_c_0, ext_c_1;
	clock_t int_c_0, int_c_1;


	set_up_client_socket(readSocket, ipAddress, readPort, serv_addr_read);
	set_up_client_socket(writeSocket, ipAddress, writePort, serv_addr_write);

	ext_t_0 = timestamp();
	ext_c_0 = clock();

	printf("Connected to builder.\n");

	rawCheckCircuit = createRawCheckCircuit(rawInputCircuit -> numInputs_P1);

	state = seedRandGen();
	permedInputs = convertChainIntoArray(startOfInputChain, rawInputCircuit -> numInputs_P2);


	int_t_0 = timestamp();
	int_c_0 = clock();

	J_set = full_CnC_OT_Mod_Receiver_ECC_Alt(writeSocket, readSocket, &OT_Outputs, rawInputCircuit -> numInputs_P2,
											state, startOfInputChain, permedInputs, stat_SecParam, 1024);

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "OT - Receiver");
	printAndZeroBothCounters();



	int_t_0 = timestamp();
	int_c_0 = clock();
	pubInputGroup = receivePublicCommitments(writeSocket, readSocket);

	for(i = 0; i < stat_SecParam; i ++)
	{
		circuitsArray[i] = receiveFullCircuit(writeSocket, readSocket);
	}

	commBufferLen = 0;
	bufferOffset = 0;
	commBuffer = receiveBoth(readSocket, commBufferLen);
	outputHashTable = deserialise3D_UChar_Array(commBuffer, rawInputCircuit -> numOutputs, 16, &bufferOffset);
	free(commBuffer);

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Received Circuits + Hash tables + Public inputs");
	printAndZeroBothCounters();


	// Input our own bit values.
	for(i = 0; i < stat_SecParam; i ++)
	{
		setCircuitsInputs_Values(startOfInputChain, circuitsArray[i], 0x00);
	}
	setInputsFromCharArray(circuitsArray, OT_Outputs, stat_SecParam);


	int_t_0 = timestamp();
	int_c_0 = clock();

	// Here we do the decommit...
	secretsRevealed = executor_decommitToJ_Set(writeSocket, readSocket, circuitsArray, pubInputGroup -> public_inputs,
							pubInputGroup -> params, J_set, &J_setSize, stat_SecParam);

	commBufferLen = 0;
	bufferOffset = 0;
	commBuffer = receiveBoth(readSocket, commBufferLen);
	builderInputs = deserialise_ECC_Point_Array(commBuffer, &arrayLen, &bufferOffset);
	free(commBuffer);

	commBuffer = receiveBoth(readSocket, commBufferLen);
	setBuilderInputs(builderInputs, commBuffer, J_set, J_setSize, circuitsArray,
					pubInputGroup -> public_inputs, pubInputGroup -> params);
	free(commBuffer);

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Decommit to and receive check circuit secrets.");
	printAndZeroBothCounters();


	int_t_0 = timestamp();
	int_c_0 = clock();

	printf("\nEvaluating Circuits ");
	fflush(stdout);

	for(i = 0; i < stat_SecParam; i ++)
	{
		if(0x00 == J_set[i])
		{
			printf("%d, ", i);
			fflush(stdout);
			runCircuitExec( circuitsArray[i], writeSocket, readSocket );
		}
	}

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Evaluating all circuits");
	printAndZeroBothCounters();


	int_t_0 = timestamp();
	int_c_0 = clock();

	// Perform the cheating detection function.
	deltaPrime = expandDeltaPrim(circuitsArray, J_set, stat_SecParam);
	SC_ReturnStruct = SC_DetectCheatingExecutor(writeSocket, readSocket, rawCheckCircuit,
	 											deltaPrime, lengthDelta, 3 * stat_SecParam, state );

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Full sub-computation");
	printAndZeroBothCounters();

	int_t_0 = timestamp();
	int_c_0 = clock();

	commBufferLen = 0;
	bufferOffset = 0;
	commBuffer = receiveBoth(readSocket, commBufferLen);
	bLists = deserialise3D_UChar_Array(commBuffer, rawInputCircuit -> numOutputs, 16, &bufferOffset);
	free(commBuffer);

	printf("\nVerified B_Lists = %d\n", verifyB_Lists(outputHashTable, bLists, circuitsArray[0] -> numInputsExecutor));

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Verifying B Lists");
	printAndZeroBothCounters();


	int_t_0 = timestamp();
	int_c_0 = clock();


	consistentInputs = getAllConsistentInputsAsPoints(secretsRevealed -> revealedSecrets, pubInputGroup -> public_inputs -> public_keyPairs, pubInputGroup -> params, J_set, stat_SecParam, rawInputCircuit -> numInputs_P1);
	circuitsChecked = secretInputsToCheckCircuitsConsistentOutputs(circuitsArray, rawInputCircuit, consistentInputs, 
																secretsRevealed -> revealedCircuitSeeds, bLists[0], bLists[1], pubInputGroup -> params,
																J_set, J_setSize, stat_SecParam);

	printf("Circuits Correct = %d\n", circuitsChecked);

	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Checking Circuits Correct");
	printAndZeroBothCounters();


	int_t_0 = timestamp();
	int_c_0 = clock();

	proveConsistencyEvaluationKeys_Exec_L_2013(writeSocket, readSocket, J_set, J_setSize,
											builderInputs, pubInputGroup -> public_inputs,
											pubInputGroup -> params,
											SC_ReturnStruct, state);
	
	int_c_1 = clock();
	int_t_1 = timestamp();
	printTiming(&int_t_0, &int_t_1, int_c_0, int_c_1, "Builder Inputs consistency checked");
	printAndZeroBothCounters();

	clearPublicInputsWithGroup(pubInputGroup);

	#pragma omp parallel for private(i) schedule(auto)
	for(i = 0; i < arrayLen; i ++)
	{
		clearECC_Point(builderInputs[i]);
	}
	free(builderInputs);


	ext_c_1 = clock();
	ext_t_1 = timestamp();
	printTiming(&ext_t_0, &ext_t_1, ext_c_0, ext_c_1, "Total time without connection setup");
	printBothTotalCounters();

	close_client_socket(readSocket);
	close_client_socket(writeSocket);


	// If the secure computation to detect cheating returned NULL it means everything is fine.
	// Just use the normal majority output. Else the Secure Comp. to detect cheating returned X.
	// Then we use the Raw Binary Circuit to compute the true answer. 
	if(NULL == SC_ReturnStruct -> output)
	{
		printMajorityOutputAsBinary(circuitsArray, stat_SecParam, J_set);
	}
	else
	{
		setRawCircuitsInputs_Hardcode(startOfInputChain, rawInputCircuit -> gates);
		setRawCircuitsInputs_Hardcode(SC_ReturnStruct -> output, 0, rawInputCircuit -> numInputs_P1, rawInputCircuit -> gates);
		evaluateRawCircuit(rawInputCircuit);
		printOutputHexString_Raw(rawInputCircuit);
	}

	
	/*
	for(i = 0; i < stat_SecParam; i ++)
	{
		freeCircuitStruct(circuitsArray[i], 1);
	}
	*/
	freeRawCircuit(rawInputCircuit);
	free_idAndValueChain(startOfInputChain);

}