Cryptography Reference
In-Depth Information
{
output[ ( i % 2 ) ? ( ( i - 1 ) >> 1 ) : ( ( 4 + ( i >> 1 ) ) ) ] |=
( ( ( input[ j ] & ( 0x80 >> i ) ) >> ( 7 - i ) ) << j );
}
}
However, the specifi cation is given in terms of permutations, so you do the
same, using the permute routine. The permute_table for the initial permutation
is shown in Listing 2-5.
Listing 2-5: “des.c” initial permutation table
static const int ip_table[] = {
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6,
64, 56, 48, 40, 32, 24, 16, 8,
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7 };
This specifi es that the 58 th bit of the input is the fi rst bit of the output; the
50 th bit of the input is the second bit of the output; and so on. You may want to
convince yourself that this is the same as described above.
NOTE When examining the permutation table above, remember the struc-
ture of the GET_BIT and SET_BIT macros. The fi rst bit, bit 58, works out to
be byte #58/8 = 7, bit #58%8 = 2. Remember that DES considers bytes to be
ordered according to big endian conventions, which means that bit 2 is the
next-to-the-most signifi cant bit.
After the input has been so permuted, it is combined with the key in a series
of 16 rounds, each of which consists of the following:
1. Expand bits 32-64 of the input to 48 bits (described in the expansion func-
tion in Listing 2-10).
2. XOR the expanded right half of the input with the key.
3. Use the output of this XOR to look up eight entries in the s-box table and
overwrite the input with these contents.
4. Permute this output according to a specifi c p-table.
5. XOR this output with the left half of the input (bits 1-32) and swap sides so
that the XORed left half becomes the right half, and the (as of yet untouched)
right-half becomes the left half. On the next round, the same series of opera-
tions are applied again, but this time on what used to be the right half.
 
Search WWH ::




Custom Search