A SERVICE OF

logo

Block Ciphers
178 RSA BSAFE Crypto-C Developers Guide
Block Ciphers
DES with CBC
The example in this section corresponds to the file descbc.c.
Step 1: Creating an Algorithm Object
Declare a variable to be a B_ALGORITHM_OBJ. As defined in the function prototype in
Chapter 4 of the Reference Manual, its address is the argument for
B_CreateAlgorithmObject:
Step 2: Setting the Algorithm Object
There are a number of DES AIs from which to choose. See Table 4-6 on page 105 for a
summary. For this example, choose
AI_FeedbackCipher. AI_FeedbackCipher is a
general-purpose AI that allows you to choose different block cipher methods, such as
DES, the RC2 cipher, and the RC5 cipher. It also allows you to choose different
feedback methods for your cipher. This makes updating your program to use a
different block cipher or feedback method easy: you simply have to replace the
arguments.
See Block Ciphers on page 37 of this manual for an overview of block cipher
algorithms and feedback methods. We will implement DES in CBC mode using the
padding scheme defined in PKCS V#5.
The description of
AI_FeedbackCipher in Chapter 2 of the Reference Manual says that
the format of the
info
supplied to B_SetAlgorithmInfo is a pointer to a
B_BLK_CIPHER_W_FEEDBACK_PARAMS structure:
B_ALGORITHM_OBJ encryptionObject = (B_ALGORITHM_OBJ)NULL_PTR;
if ((status = B_CreateAlgorithmObject (&encryptionObject)) != 0)
break;