Exemplo n.º 1
0
void Aes256::encrypt(unsigned char* buffer)
{
    unsigned char i, rcon;

    copy_key();
    add_round_key(buffer, 0);
    for (i = 1, rcon = 1; i < NUM_ROUNDS; ++i)
    {
        sub_bytes(buffer);
        shift_rows(buffer);
        mix_columns(buffer);
        if (!(i & 1))
            expand_enc_key(&rcon);
        add_round_key(buffer, i);
    }
    sub_bytes(buffer);
    shift_rows(buffer);
    expand_enc_key(&rcon);
    add_round_key(buffer, i);
}
Exemplo n.º 2
0
void Aes256Encoder::Encrypt(MemoryData& rkey, const MemoryData& key,const MemoryData& salt, unsigned char* buffer)
{
	unsigned char i, rcon;

	copy_key(rkey, key, salt);
	add_round_key(rkey.MutableData(), buffer, 0);
	for (i = 1, rcon = 1; i < RoundCount; ++i)
	{
		sub_bytes(buffer);
		shift_rows(buffer);
		mix_columns(buffer);
		if (!(i & 1))
			expand_enc_key(rkey.MutableData(), &rcon);
		add_round_key(rkey.MutableData(), buffer, i);
	}
	sub_bytes(buffer);
	shift_rows(buffer);
	expand_enc_key(rkey.MutableData(), &rcon);
	add_round_key(rkey.MutableData(), buffer, i);
}
Exemplo n.º 3
0
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);
}