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); }