void decode_block(BYTE* counter, BYTE* dst, BYTE round_key[ROUND_KEY_SIZE][BLOCK_SIZE]){ unsigned char temp[BLOCK_SIZE]; xor_key(counter,temp,round_key[ROUNDS]); //memcpy(dst, round_key[ROUNDS], 16); shift_rows_inv(temp,dst); sub_bytes_inv(dst,temp); for(int i = ROUNDS-1; i > 0; i--){ xor_key(temp, dst, round_key[i]); mix_columns_inv(dst, temp); shift_rows_inv(temp, dst); sub_bytes_inv(dst, temp); } xor_key(temp, dst, round_key[0]); }
static void aes_main_inv(aes_key *key, uint8_t *state) { int i = 0; uint8_t rk[16]; create_round_key(key->data + 16 * key->nbr, rk); add_round_key(state, rk); for (i = key->nbr - 1; i > 0; i--) { create_round_key(key->data + 16 * i, rk); shift_rows_inv(state); add_round_key(state, rk); mix_columns_inv(state); } create_round_key(key->data, rk); shift_rows_inv(state); add_round_key(state, rk); }
void Aes256::decrypt(unsigned char* buffer) { unsigned char i, rcon = 1; copy_key(); for (i = NUM_ROUNDS / 2; i > 0; --i) expand_enc_key(&rcon); add_round_key(buffer, NUM_ROUNDS); shift_rows_inv(buffer); sub_bytes_inv(buffer); for (i = NUM_ROUNDS, rcon = 0x80; --i;) { if ((i & 1)) expand_dec_key(&rcon); add_round_key(buffer, i); mix_columns_inv(buffer); shift_rows_inv(buffer); sub_bytes_inv(buffer); } add_round_key(buffer, i); }
// Decrypt a single 128 bit block by a 128 bit key using AES // http://en.wikipedia.org/wiki/Advanced_Encryption_Standard void AES_Decrypt(unsigned char *data, unsigned char *key) { int i; // To count the rounds // Key expansion unsigned char keys[176]; expand_key(key,keys); // Reverse the final Round xor_round_key(data,keys,10); shift_rows_inv(data); sub_bytes_inv(data, 16); // Reverse the middle rounds for (i=0; i<9; i++) { xor_round_key(data,keys,9-i); mix_cols_inv(data); shift_rows_inv(data); sub_bytes_inv(data, 16); } // Reverse the first Round xor_round_key(data, keys, 0); }
// Decrypt a single 128 bit block by a 128 bit key using AES // http://en.wikipedia.org/wiki/Advanced_Encryption_Standard void DecryptAES(byte *c, byte *key, byte *m) { int i; // To count the rounds // Key expansion byte keys[176]; expand_key(key,keys); // Reverse the final Round memcpy(m,c,16); xor_round_key(m,keys,10); shift_rows_inv(m); sub_bytes_inv(m, 16); // Reverse the middle rounds for (i=0; i<9; i++) { xor_round_key(m,keys,9-i); mix_cols_inv(m); shift_rows_inv(m); sub_bytes_inv(m, 16); } // Reverse the first Round xor_round_key(m, keys, 0); }