// ======================================================================================================== // ======================================================================================================== // **************************************** verifier_enrollment.c ***************************************** // ======================================================================================================== // ======================================================================================================== #include "common.h" #include "verifier_common.h" // ======================================================================================================== // ======================================================================================================== // Receive timing values and write them to an outfile. THIS IS ONLY ALLOWED during enrollment. void ReceiveTimingVals(int str_length, int token_socket_desc) { char outfile_name[str_length]; char buffer[str_length]; FILE *OUTFILE; // Received outfile_name. if ( SockGetB((unsigned char *)outfile_name, str_length, token_socket_desc) < 0 ) { printf("ERROR: ReceiveTimingVals(): Error receiving outfile_name '%s'\n", outfile_name); fflush(stdout); exit(EXIT_FAILURE); } printf("ReceiveTimingVals(): Saving values to '%s'\n", outfile_name); fflush(stdout); // Open output file and write the outfile_name info into it. if ( (OUTFILE = fopen(outfile_name, "w")) == NULL ) { printf("ERROR: ReceiveTimingVals(): Could NOT open output filename '%s'\n", outfile_name); fflush(stdout); exit(EXIT_FAILURE); } // Receive timing values and write them into the OUTFILE. while (1) { if ( SockGetB((unsigned char *)buffer, str_length, token_socket_desc) < 0 ) { printf("ERROR: ReceiveTimingVals(): Error receiving timing value line\n"); fflush(stdout); exit(EXIT_FAILURE); } if ( strcmp(buffer, "DONE") == 0 ) { // Write a final in output file. fprintf(OUTFILE, "\n"); break; } fprintf(OUTFILE, "%s\n", buffer); } fclose(OUTFILE); return; } // ======================================================================================================== // ======================================================================================================== // ======================================================================================================== // ======================================================================================================== // For enrollment, the token is the 'server' while the verifier is the 'client' unsigned char *first_vecs_b[MAX_VECS]; unsigned char *second_vecs_b[MAX_VECS]; unsigned char *masks[MAX_VECS]; int main(int argc , char *argv[]) { char vec_file_path[MAX_STRING_LEN]; char mask_file_path[MAX_STRING_LEN]; int num_vecs, num_rise_vecs; char verifier_IP[MAX_STRING_LEN]; // Prepare the sockaddr_in structure for the server; struct sockaddr_in token_addr; int token_socket_desc = 0; int verifier_socket_desc = 0; int port_number; int first_time; int has_masks; // =============================================================================== // COMMAND LINE. if ( argc != 3 ) { printf("ERROR: Verifier_Enrollment : verifier_IP -- vec_file\n"); fflush(stdout); exit(EXIT_FAILURE); } strcpy(verifier_IP, argv[1]); strcpy(vec_file_path, argv[2]); // ============================================ PARAMETERS ===================================================== port_number = 8888; // ============================================ PARAMETERS ===================================================== //Vector Set provided in Reference Design must need mask file to generate exactly 4096 PNs. These Masks help to //select glitch-free and less noise Paths which are least affected by Temperature- Voltage Variation. "has_masks" must be set to 1 //for this vector file to generate exactly 4096 PNs. has_masks=0; // ReadVectorAndMaskFiles and store them in the first_vecs[MAX_VECS] and second_vecs[MAX_VECS] strcpy(mask_file_path, vec_file_path); strcat(mask_file_path, "_masks.txt"); strcat(vec_file_path, ".txt"); // Note that we ASSUME that an analysis was done in advance regarding how many rising and falling PNs are generated by the // vectors and EXACTLY that many (rising) vectors vectors are applied, and NO MORE than that -- current token code does NOT // check for rising PN overflow and no assumptions are made regarding the number of rising or falling vectors that are applied. 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); // Server is infinite loop first_time = 1; while (1) { // Serve-up a socket connection to wait for connection requests from any tokens. On subsequent iterations, accept only connections. printf("\nWaiting for incoming connections from clients for Enrollment ....\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; // Send num_vecs and vector pairs to the token. SendVectorsAndMasks(MAX_STRING_LEN, num_vecs, MAX_VECS, token_socket_desc, num_rise_vecs, VEC_LEN_BITS, first_vecs_b, second_vecs_b, has_masks, MAX_OUTPUTS, masks); // Receive timing values from token write to an output file. ReceiveTimingVals(MAX_STRING_LEN, token_socket_desc); close(token_socket_desc); } close(verifier_socket_desc); return 0; }