Cryptography Reference
In-Depth Information
else
{
des_block_operate( input_block, output, key, operation );
}
xor( output, iv, DES_BLOCK_SIZE );
memcpy( ( void * ) iv, ( void * ) input, DES_BLOCK_SIZE ); // CBC
}
input += DES_BLOCK_SIZE;
output += DES_BLOCK_SIZE;
input_len -= DES_BLOCK_SIZE;
}
}
If you were paying close attention in the previous section, you may have
noticed that des_block_operate accepts a key as an array of a fi xed size, whereas
des_operate accepts a pointer of indeterminate size. Now you can see why it
was designed this way.
Two new functions, des3_encrypt and des3_decrypt , are clones of des_encrypt
and des_decrypt , other than the passing of a new fl ag into des_operate , shown
in Listing 2-27.
Listing 2-27: “des.c” des3_encrypt
void des_encrypt( const unsigned char *plaintext,
{
des_operate( plaintext, plaintext_len, ciphertext,
iv, key, OP_ENCRYPT, 0 );
}
void des3_encrypt( const unsigned char *plaintext,...
{
des_operate( padded_plaintext, plaintext_len + padding_len, ciphertext,
iv, key, OP_ENCRYPT, 1 );
}
void des_decrypt( const unsigned char *ciphertext,
...
{
des_operate( ciphertext, ciphertext_len, plaintext, iv, key, OP_DECRYPT, 0 );
}
void des3_decrypt( const unsigned char *ciphertext,
...
{
des_operate( ciphertext, ciphertext_len, plaintext, iv, key, OP_DECRYPT, 1 );
}
You may be wondering why you created two new functions that are
essentially clones of the others instead of just adding a triplicate fl ag to
 
Search WWH ::




Custom Search