Block Ciphers
184 RSA BSAFE Crypto-C Developer’s Guide
The RC2 Cipher
The RC2 cipher is a variable-key-size block cipher. Whereas a DES key requires eight
bytes — no more, no less — an RC2 key can be anywhere between one and 128 bytes.
The larger the key, the greater the security. The RC2 cipher is called a block cipher
because it encrypts 8-byte blocks. Recall that DES also is a block cipher that encrypts
8-byte blocks. That means the RC2 cipher can serve as a drop-in replacement for DES.
The steps for using
AI_FeedbackCipher with the RC2 cipher are almost identical to
those for DES.
The example in this section corresponds to the file
rc2.c.
Step 1: Creating An Algorithm Object
Declare a variable to be 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 RC2 AIs from which to choose. Table 4-6 on page 105 gives a
summary of AIs. Choose
AI_FeedbackCipher; as in the previous example, the format
of the
info
supplied to B_SetAlgorithmInfo is a pointer to a
B_BLK_CIPHER_W_FEEDBACK_PARAMS structure:
B_ALGORITHM_OBJ rc2Encrypter = (B_ALGORITHM_OBJ)NULL_PTR;
if ((status = B_CreateAlgorithmObject (&rc2Encrypter)) != 0)
break;
typedef struct {
unsigned char *encryptionMethodName; /* examples include “des”, “rc5” */
POINTER encryptionParams; /* e.g., RC5 parameters */
unsigned char *feedbackMethodName;
POINTER feedbackParams; /* Points at init vector ITEM */
/* for all feedback modes except cfb */
unsigned char *paddingMethodName;
POINTER paddingParams; /* Ignored for now, but may be used */
/* for new padding schemes */
} B_BLK_CIPHER_W_FEEDBACK_PARAMS;