void check_inv(struct svm_smo_model *m,int ndocs) { check_s(&(m->I0), c0, m); check_s(&(m->I1), c1, m); check_s(&(m->I2), c2, m); check_s(&(m->I3), c3, m); check_s(&(m->I4), c4, m); if (m->I0.ilength + m->I1.ilength + m->I2.ilength + m->I3.ilength + m->I4.ilength != ndocs) { abort(); } return; }
void testcase(int index , int size) { //printf("inside testcase"); int checkip=0; strcpy(testname,input_arra[index]); checkip=check_ip(size); if(checkip!=0) { strcpy(ip," "); strcpy(ip,input_arra[checkip+1]); } //printf("testcase name %s is checking on ip = %s and ",testname, ip); int checks=-1; checks=check_s(index,size); if(checks != -1) { teststream=atoi(input_arra[checks]); printf("stream number is %d \n",teststream); checks=teststream; } if( !strcmp(testname,"FR") || !strcmp(testname,"fr")) { //printf("inside fr"); tc_fr(checks , checkip); } }
// Perform the key expansion for AES-128 using key as 16-byte string in hexstring format void keyexpand(char* key_chars, FILE* table) { unsigned char* init_key = (unsigned char*)calloc(1,16); unsigned char round_key[Nb*(Nr+1)][4]; // Verify S values are valid if(!check_s(table)) { // S vals are invalid fprintf(stderr, "ERROR: tablecheck failed for S (Substitution) values.\n"); return; } // Check key length else if(strlen(key_chars) != 32) { fprintf(stderr, "ERROR: key must consist of 32 characters, all hex values.\n"); return; } // Read raw hexchars in and convert to bytes else { char temp_val[3]; for(int i=0; i<16; i++) { if(!is_hex_char(key_chars[i*2]) || !is_hex_char(key_chars[i*2+1])) { fprintf(stderr, "ERROR: all values in the polynomial must be hex values.\n"); return; } temp_val[0] = key_chars[i*2]; temp_val[1] = key_chars[i*2+1]; temp_val[2] = ' '; init_key[i] = strtol(temp_val, NULL, 16); } } // Perform the key expansion key_expansion(init_key, round_key, table); // Print round output for(int i=0; i<44; i++) { if(i >= 10) { printf("w[%d]: %02x%02x%02x%02x\n", i, round_key[i][0], round_key[i][1], round_key[i][2], round_key[i][3]); } else { printf("w[ %d]: %02x%02x%02x%02x\n", i, round_key[i][0], round_key[i][1], round_key[i][2], round_key[i][3]); } } free(init_key); // PSEUDO-CODE // - Initialize the S-box and Rcon // - For the S-box, read in the tablefile; incrementally assign the permutations to a 256-byte array // - For Rcon, starting with rcon[0]=0x8d, modularly mult rcon[i-1] by 0x02 until you have 256 vals // - (For AES-128: Nk=4, Nr=10, key is 16 bytes long) // - For the first 4 rounds, the round_key is one quarter of the init_key // - For the remainder of the rounds (4*(Nr+1) total): // - Every 4th round: // - Rotate the round_key circularly to the left and store in temp val // - Put the temp val through the s_box and XOR the MSB with the next val of Rcon // - For every round, XOR the current temp vals with the previous round_key, store as next round_key // - Print the output of each round_key }
void testcase(int index , int size) { //printf("inside testcase"); int checkip=0 , checkdel =0 ,checkd ; strcpy(testname,input_arra[index]); checkip=check_ip(size); checkd=check_d(size); checkdel=check_delta(size); if(checkdel != -1) { //strcpy(ip," "); delta=0; delta=atof(input_arra[checkdel]); //printf("delta is %f \n",delta); } else { delta=0.10; //printf("delta is %f we\n",delta); } if(checkd != -1) { //strcpy(ip," "); d_value=0; d_value=atof(input_arra[checkd]); //printf("delta is %f \n",delta); } else { d_value=2; //printf("delta is %f we\n",delta); } if(checkip != 0) { strcpy(ip," "); strcpy(ip,input_arra[checkip]); } //printf("testcase name %s is checking on ip = %s and ",testname, ip); int checks=-1; checks=check_s(index,size); if(checks != -1) { teststream=atoi(input_arra[checks]); //printf("stream number is %d \n",teststream); checks=teststream; if(checks>node_count) { printf(" \t stream number entered is out of range ! \n "); return; } } if( !strcmp(testname,"FR") || !strcmp(testname,"fr")) { tc_fr(checks , checkip ); } else if( !strcmp(testname,"RT") || !strcmp(testname,"rt")) { tc_rt(checks , checkip); } else { printf("wrong test case name \n"); } }
// Check the integrity of tablefile bool tablecheck(FILE *table) { // Check IP vals if(!check_ip(table)) { // IP vals are invalid fprintf(stderr, "ERROR: tablecheck failed for IP (Initial Permutation) values.\n"); return false; } // Check E vals if(!check_e(table)) { // E vals are invalid fprintf(stderr, "ERROR: tablecheck failed for E (Expansion) values.\n"); return false; } // Check P vals if(!check_p(table)) { // P vals are invalid fprintf(stderr, "ERROR: tablecheck failed for P (Permutation) values.\n"); return false; } // Check S# vals char header[3]; for(int i=1; i<=8; i++) { sprintf(header, "S%d=", i); if(!check_s(table, header)) { // S# vals are invalid fprintf(stderr, "ERROR: tablecheck failed for S%d (Substitution) values.\n", i); return false; } } // Check V vals if(!check_v(table)) { // V vals are invalid fprintf(stderr, "ERROR: tablecheck failed for V (Circular Rotation) values.\n"); return false; } // Check PC1 vals if(!check_pc1(table)) { // PC1 vals are invalid fprintf(stderr, "ERROR: tablecheck failed for PC1 (Permutated Choice 1) values.\n"); return false; } // Check PC2 vals if(!check_pc2(table)) { // PC2 vals are invalid fprintf(stderr, "ERROR: tablecheck failed for PC2 (Permutated Choice 2) values.\n"); return false; } return true; // PSEUDO-CODE // - Use read_line_vals method to search through file until finds a line starting with header // - Read each item in the line into an array of ints, using comma delimiters to separate // - Run whatever test is needed on the array to ensure that all the values are valid // - Usually something like counting the instances of each number to ensure correct permutation // - Repeat for all headers }