Cryptography Reference
In-Depth Information
for ( c = 0; c < 4; c++ )
{
state[ r ][ c ] = input_block[ r + ( 4 * c ) ];
}
}
// rounds = key size in 4-byte words + 6
nr = ( key_size >> 2 ) + 6;
compute_key_schedule( key, key_size, w );
add_round_key( state, &w[ 0 ] );
for ( round = 0; round < nr; round++ )
{
sub_bytes( state );
shift_rows( state );
if ( round < ( nr - 1 ) )
{
mix_columns( state );
}
add_round_key( state, &w[ ( round + 1 ) * 4 ] );
}
for ( r = 0; r < 4; r++ )
{
for ( c = 0; c < 4; c++ )
{
output_block[ r + ( 4 * c ) ] = state[ r ][ c ];
}
}
}
Notice this same routine handles 128-, 192-, or 256-bit key sizes; the only
difference between the three is the number of rounds, and the amount of key
material that therefore needs to be computed. Rather than computing the size
of w — the key schedule array — dynamically, it just statically allocates enough
space for a 256-bit key schedule (60 * 4). It then copies the input into the state
matrix, applies the fi rst round key, and starts iterating. Also, it skips column
mixing on the very last iteration. Finally, it copies from state array back into the
output, and the block is encrypted.
AES Decryption
Unlike DES, AES's decryption operation isn't the same as encryption. You have
to go back and undo everything that you did during the encryption step. This
starts, of course, with re-applying the round keys in reverse order, unmixing
the columns, unshifting the rows, and unsubstituting the bytes.
Search WWH ::




Custom Search