Considering the amount of bit twiddling in DES, it probably comes as no surprise that it is frequently implemented in hardware. Even the figures and terminology associated with DES (diagrams drawn with boxes and lines, and terms such as S-boxes and P-boxes) tend to suggest a certain affinity toward hardware implementations. Nevertheless, software implementations have their place as well. In software, it is helpful to have several basic operations to assist in carrying out the numerous permutations, transformations, and substitutions that DES requires. For this purpose, the implementation presented here makes use of the bit operations presented in Chapter 14. The details of each permutation, transformation, and substitution are defined by the tables at the beginning of Example 15.2. These match the tables presented earlier in the text.
The des_encipher operation (see Example
15.2) enciphers a 64-bit block of plaintext using DES. Since
one of the nice properties of DES is that the same process can be
used both to encipher and decipher data,
des_encipher simply calls
des_decipher calls as well. The
des_main function uses its
argument to determine whether to encipher or decipher the data
direction argument simply alters the
order in which subkeys are applied. In the case of
des_encipher, we set
The des_main function begins by testing
key is NULL. This allows ...