p_session_entry tc_retrieve_session(uint64_t key) { uint32_t h = supplemental_hash((uint32_t) key); uint32_t index = table_index(h, s_table->size); p_session_entry e = NULL, last = NULL; for(e = s_table->entries[index]; e != NULL; e = e->next) { if (e->key == key) { last = e; } } return last; }
void tc_add_session(p_session_entry entry) { uint32_t h = supplemental_hash((uint32_t) entry->key); uint32_t index = table_index(h, s_table->size); p_session_entry e = NULL, last = NULL; for(e = s_table->entries[index]; e != NULL; e = e->next) { last = e; } if (last == NULL) { s_table->entries[index] = entry; } else { last->next = entry; } s_table->num_of_sessions++; tc_log_debug2(LOG_DEBUG, 0, "index:%d,sessions in table:%d", index, s_table->num_of_sessions); }
// This COULD just be Rijndael key expansion, but with a different set of S-boxes void generate_key_schedule(unsigned char* key_material, uint32_t key_schedule[11][4]) { uint32_t key_data[4]; int i; for (i = 0; i < 11; i++) { key_schedule[i][0] = 0xdeadbeef; key_schedule[i][1] = 0xdeadbeef; key_schedule[i][2] = 0xdeadbeef; key_schedule[i][3] = 0xdeadbeef; } unsigned char* buffer = (unsigned char*)key_data; int ti = 0; printf("Generating key schedule\n"); // G print_block("Raw key material: ", key_material); t_xor(key_material, buffer); print_block("G has produced: ", buffer); for (int round = 0; round < 11; round++) { printf("Starting round %d\n", round); // H key_schedule[round][0] = key_data[0]; printf("H has set chunk 1 of round %d %08X\n", round, key_schedule[round][0]); printf("H complete\n"); // I unsigned char* table1 = table_index(ti); unsigned char* table2 = table_index(ti+1); unsigned char* table3 = table_index(ti+2); unsigned char* table4 = table_index(ti+3); ti += 4; //buffer[0] = (buffer[0] - (4 & (buffer[0] << 1)) + 2) ^ 2 ^ index_mangle[round] ^ table1[buffer[0x0d]]; printf("S-box: 0x%02x -> 0x%02x\n", buffer[0x0d], table1[buffer[0x0d]]); printf("S-box: 0x%02x -> 0x%02x\n", buffer[0x0e], table2[buffer[0x0e]]); printf("S-box: 0x%02x -> 0x%02x\n", buffer[0x0f], table3[buffer[0x0f]]); printf("S-box: 0x%02x -> 0x%02x\n", buffer[0x0c], table4[buffer[0x0c]]); buffer[0] ^= table1[buffer[0x0d]] ^ index_mangle[round]; buffer[1] ^= table2[buffer[0x0e]]; buffer[2] ^= table3[buffer[0x0f]]; buffer[3] ^= table4[buffer[0x0c]]; print_block("After I, buffer is now: ", buffer); printf("I complete\n"); // H key_schedule[round][1] = key_data[1]; printf("H has set chunk 2 to %08X\n", key_schedule[round][1]); printf("H complete\n"); // J key_data[1] ^= key_data[0]; printf("J complete\n"); print_block("Buffer is now ", buffer); // H key_schedule[round][2] = key_data[2]; printf("H has set chunk3 to %08X\n", key_schedule[round][2]); printf("H complete\n"); // J key_data[2] ^= key_data[1]; printf("J complete\n"); // K and L // Implement K and L to fill in other bits of the key schedule key_schedule[round][3] = key_data[3]; // J again key_data[3] ^= key_data[2]; printf("J complete\n"); } for (i = 0; i < 11; i++) print_block("Schedule: ", (unsigned char*)key_schedule[i]); }