Cryptography Reference
In-Depth Information
The independent rotations of the two key-halves are shown in Listing 2-9:
Listing 2-9: “des.c” rotate left
/**
* Perform the left rotation operation on the key. This is made fairly
* complex by the fact that the key is split into two 28-bit halves, each
* of which has to be rotated independently (so the second rotation operation
* starts in the middle of byte 3).
*/
static void rol( unsigned char *target )
{
int carry_left, carry_right;
carry_left = ( target[ 0 ] & 0x80 ) >> 3;
target[ 0 ] = ( target[ 0 ] << 1 ) | ( ( target[ 1 ] & 0x80 ) >> 7 );
target[ 1 ] = ( target[ 1 ] << 1 ) | ( ( target[ 2 ] & 0x80 ) >> 7 );
target[ 2 ] = ( target[ 2 ] << 1 ) | ( ( target[ 3 ] & 0x80 ) >> 7 );
// special handling for byte 3
carry_right = ( target[ 3 ] & 0x08 ) >> 3;
target[ 3 ] = ( ( ( target[ 3 ] << 1 ) |
( ( target[ 4 ] & 0x80 ) >> 7 ) ) & ~0x10 ) | carry_left;
target[ 4 ] = ( target[ 4 ] << 1 ) | ( ( target[ 5 ] & 0x80 ) >> 7 );
target[ 5 ] = ( target[ 5 ] << 1 ) | ( ( target[ 6 ] & 0x80 ) >> 7 );
target[ 6 ] = ( target[ 6 ] << 1 ) | carry_right;
}
Here you see that each byte of the key, which is in a 7-byte array, is left-shifted
by one place, and the MSB of the next byte is used as the LSB. The only com-
plicating factor here is that the key is in a 7-byte array, but the dividing point
between the two halves is in the middle of the third byte.
DES Expansion Function
Notice in the previous section that the subkeys are 48-bits long, but the input
halves that are to be XORed are 32 bits long. Now, you can't properly XOR
a 32-bit input with a 48-bit key, so the input is expanded — some bits are
duplicated — before being XORed. The output of the expansion function is
illustrated in Figure 2-6.
The output is split into eight six-bit blocks (which works out to six eight-bit
bytes), with the fi rst and last bits of each block overlapping the preceding and
following blocks. Note that the fi rst and last block wrap around and use the
last bit of the input as the fi rst bit of output and the fi rst bit of input as the last
Search WWH ::




Custom Search