Cryptography Reference
In-Depth Information
2, 8, 24, 14,
32, 27, 3, 9,
19, 13, 30, 6,
22, 11, 4, 25 };
All of this is performed on the right-half of the input, which is then XORed
with the left half, becoming the new right-half, and the old right-half, before
any transformation, becomes the new left half.
Finally, the code to implement this is shown in Listing 2-13. This code accepts
a single eight-byte block of input and an eight-byte key and returns an encrypted
eight-byte output block. The input block is not modifi ed. This is the DES algo-
rithm itself.
Listing 2-13: “des.c” des_block_operate
#define DES_BLOCK_SIZE 8 // 64 bits, defined in the standard
#define DES_KEY_SIZE 8 // 56 bits used, but must supply 64 (8 are ignored)
#define EXPANSION_BLOCK_SIZE 6
#define PC1_KEY_SIZE 7
#define SUBKEY_SIZE 6
static void des_block_operate( const unsigned char plaintext[ DES_BLOCK_SIZE ],
unsigned char ciphertext[ DES_BLOCK_SIZE ],
const unsigned char key[ DES_KEY_SIZE ] )
{
// Holding areas; result flows from plaintext, down through these,
// finally into ciphertext. This could be made more memory efficient
// by reusing these.
unsigned char ip_block[ DES_BLOCK_SIZE ];
unsigned char expansion_block[ EXPANSION_BLOCK_SIZE ];
unsigned char substitution_block[ DES_BLOCK_SIZE / 2 ];
unsigned char pbox_target[ DES_BLOCK_SIZE / 2 ];
unsigned char recomb_box[ DES_BLOCK_SIZE / 2 ];
unsigned char pc1key[ PC1_KEY_SIZE ];
unsigned char subkey[ SUBKEY_SIZE ];
int round;
// Initial permutation
permute( ip_block, plaintext, ip_table, DES_BLOCK_SIZE );
// Key schedule computation
permute( pc1key, key, pc1_table, PC1_KEY_SIZE );
for ( round = 0; round < 16; round++ )
{
// “Feistel function” on the first half of the block in 'ip_block'
// “Expansion”. This permutation only looks at the first
// four bytes (32 bits of ip_block); 16 of these are repeated
// in “expansion_table”.
permute( expansion_block, ip_block + 4, expansion_table, 6 );
(Continued)
 
Search WWH ::




Custom Search