// ======================================================================================================== // ======================================================================================================== // **************************************** verifier_regeneration.c *************************************** // ======================================================================================================== // ======================================================================================================== #include "common.h" #include "verifier_common.h" #include "verifier_regen_funcs.h" // ======================================================================================================== // ======================================================================================================== // ======================================================================================================== // ======================================================================================================== unsigned char *first_vecs_b[MAX_VECS]; unsigned char *second_vecs_b[MAX_VECS]; unsigned char *masks[MAX_VECS]; float fPND[MAX_PNDIFFS]; float fPNDc[MAX_PNDIFFS]; float fPNDco[MAX_PNDIFFS]; float fmodPNDco[MAX_PNDIFFS]; unsigned char Offsets_binary[MAX_PNDIFFS]; unsigned char verifier_SBS[MAX_PNDIFFS/8]; unsigned char verifier_SHD[MAX_PNDIFFS/8]; unsigned char token_SBS[MAX_PNDIFFS/8]; unsigned char token_SHD[MAX_PNDIFFS/8]; // ============================================================================ // ============================================================================ int main(int argc, char *argv[]) { char verifier_IP[MAX_STRING_LEN]; char vec_file_path[MAX_STRING_LEN]; char mask_file_path[MAX_STRING_LEN]; int num_vecs, num_rise_vecs; // Prepare the sockaddr_in structure for the verifier; struct sockaddr_in token_addr; int verifier_socket_desc = 0; int token_socket_desc = 0; int port_number; float **PNR, **PNF; float *MedianPNR, *MedianPNF; int first_time; char database_path[MAX_STRING_LEN]; int database_has_samples; int has_masks; int num_chips; struct timeval t1, t2; long elapsed; int RANDOM; int chip_num; // unsigned int LFSR_seed_low, LFSR_seed_high; // float reference_mean, reference_range; // unsigned short Modulus, Margin; // unsigned char XOR_nonce[MAX_NONCE_BYTES]; int DUMP_BITSTRINGS; int DEBUG; // =============================================================================== if ( argc != 4 ) { printf("ERROR: verifier_regeneration : verifier IP (129.24.28.170) -- VecFilePath -- DataBase\n"); fflush(stdout); exit(EXIT_FAILURE); } strcpy(verifier_IP, argv[1]); strcpy(vec_file_path, argv[2]); strcpy(database_path, argv[3]); // ====================================================== PARAMETERS ==================================================== port_number = 8888; database_has_samples = 1; has_masks = 1; DEBUG = 0; DUMP_BITSTRINGS = 1; // ====================================================================================================================== // ====================================================================================================================== // When we save output file, this tells us what we used. strcat(database_path, ".txt"); printf("PARAMETERS: Has Masks %d\tDatabase has samples %d\tVec File %s\tDatabase File %s\n\n", has_masks, database_has_samples, vec_file_path, database_path); fflush(stdout); // arrays. 'max_PNs' should be set to 2048 in common.h but can be bigger. // The rising and falling PNs beyond 2048 are not used currently. if ( MAX_PNS != 2048 || MAX_PNDIFFS != 2048 ) { printf("ERROR: MAX_PNS and MAX_PNDIFFS must be 2048!\n"); fflush(stdout); exit(EXIT_FAILURE); } // Allocate storage if ( (PNR = (float **)malloc(sizeof(float *)*MAX_CHIPS)) == NULL ) { printf("ERROR: Failed to allocate storage for PNR outside!\n"); fflush(stdout); exit(EXIT_FAILURE); } if ( (PNF = (float **)malloc(sizeof(float *)*MAX_CHIPS)) == NULL ) { printf("ERROR: Failed to allocate storage for PNF outside!\n"); fflush(stdout); exit(EXIT_FAILURE); } for ( chip_num = 0; chip_num < MAX_CHIPS; chip_num++ ) { if ( (PNR[chip_num] = (float *)malloc(sizeof(float)*MAX_PNS)) == NULL ) { printf("ERROR: Failed to allocate storage for PNR inside!\n"); fflush(stdout); exit(EXIT_FAILURE); } if ( (PNF[chip_num] = (float *)malloc(sizeof(float)*MAX_PNS)) == NULL ) { printf("ERROR: Failed to allocate storage for PNR inside!\n"); fflush(stdout); exit(EXIT_FAILURE); } } if ( (MedianPNR = (float *)malloc(sizeof(float)*MAX_PNS)) == NULL ) { printf("ERROR: Failed to allocate storage for MedianPNR!\n"); fflush(stdout); exit(EXIT_FAILURE); } if ( (MedianPNF = (float *)malloc(sizeof(float)*MAX_PNS)) == NULL ) { printf("ERROR: Failed to allocate storage for MedianPNF!\n"); fflush(stdout); exit(EXIT_FAILURE); } // Set filenames. strcpy(mask_file_path, vec_file_path); strcat(mask_file_path, "_masks.txt"); strcat(vec_file_path, ".txt"); // Read vector and masks to be used in authentication operation. num_vecs = ReadVectorAndMaskFiles(MAX_STRING_LEN, vec_file_path, MAX_VECS, VEC_LEN_BITS, &num_rise_vecs, first_vecs_b, second_vecs_b, has_masks, mask_file_path, MAX_OUTPUTS, masks); printf("\tNumber of vectors read %d\tNumber of rising vectors %d\tHas masks? %d\n", num_vecs, num_rise_vecs, has_masks); // Read timing data from database. Timing data has a blank line that separates the rising and falling PN and a blank line that // separates the chips. if ( (num_chips = ReadDatabasePNsExact(MAX_STRING_LEN, database_path, MAX_CHIPS, MAX_PNS, PNR, PNF, database_has_samples, DEBUG)) == 0 ) { printf("ERROR: Number of chips MUST be non-zero!\n"); fflush(stdout); exit(EXIT_FAILURE); } // if ( (num_chips = ReadDatabasePNsFromMaster(MAX_STRING_LEN, database_path, MAX_CHIPS, MAX_PNS, PNR, PNF, database_has_samples, session_vec_nums, // session_PO_nums, DEBUG)) == 0 ) // { printf("ERROR: Number of chips MUST be non-zero!\n"); fflush(stdout); exit(EXIT_FAILURE); } printf("\tNumber of chips read %d\n\n", num_chips); fflush(stdout); // Compute the Median values across all chips for population offset method. printf("\tComputing Median values for population offset method\n"); fflush(stdout); ComputeEnrollmentMedianPUFNums(MAX_CHIPS, MAX_PNS, num_chips, PNR, PNF, MedianPNR, MedianPNF); // **************************************** // Open up the random source for token to generate nonce bytes that will be used to SelectParams for authentication. if ( (RANDOM = open("/dev/urandom", O_RDONLY)) == -1 ) { printf("ERROR: Could not open /dev/urandom\n"); fflush(stdout); exit(EXIT_FAILURE); } printf("\tSuccessfully open '/dev/urandom'\n"); first_time = 1; while (1) { // Serve-up a socket connection to wait for connection requests from any tokens. printf("Waiting for incoming connections from clients ....\n\n"); fflush(stdout); OpenSocketServer(MAX_STRING_LEN, &verifier_socket_desc, verifier_IP, port_number, &token_socket_desc, &token_addr, !first_time, 0); first_time = 0; #ifdef DEBUG printf("Client has connected\n"); fflush(stdout); #endif gettimeofday(&t2, 0); GoSendVectors(MAX_STRING_LEN, MAX_VECS, MAX_OUTPUTS, VEC_LEN_BITS, token_socket_desc, num_vecs, num_rise_vecs, has_masks, first_vecs_b, second_vecs_b, masks, DEBUG); gettimeofday(&t1, 0); elapsed = (t1.tv_sec-t2.tv_sec)*1000000 + t1.tv_usec-t2.tv_usec; printf("\tElapsed %ld us\n\n", (long)elapsed); } // Close the socket close(verifier_socket_desc); return 0; }