A SERVICE OF

logo

Chapter 6 Symmetric-Key Operations 191
Block Ciphers
Step 2: Setting The Algorithm Object
There are a number of RC5 AIs from which to choose. Table 4-6 on page 105 describes
the AIs. For this example, you will use a different cipher from
AI_FeedbackCipher.
Choose
AI_RC5_CBCPad. The Reference Manual Chapter 2 entry for this AI indicates that
the format of
info
supplied to B_SetAlgorithmInfo is:
As a provision for future revisions of the RC5 algorithm, Crypto-C includes a version
number. So that the version number can be one byte, it is two hex digits. Version 1.0 is
therefore
0x10. Version 3.8, if there ever is one, would be 0x38. The hex number 0x10
is the decimal number 16. Both are valid, but it is probably better to use
0x10 because
it is easier to see as a version number.
For this example, you will use 12 rounds with a word size of 32.
Because you have chosen an AI that uses Cipher Block Chaining (CBC), you need an
initialization vector. Use a random number generator to produce an IV. Because the
word size is 32, the block size is 64 bits or eight bytes, and your IV must be eight bytes
long. Remember, the IV is not secret and will not assist anyone in breaking the
encryption. Its size will be eight bytes, because the RC5 cipher encrypts blocks of eight
bytes. Remember, the IV is related to the block, not the key:
B_ALGORITHM_OBJ rc5Encrypter = (B_ALGORITHM_OBJ)NULL_PTR;
if ((status = B_CreateAlgorithmObject (&rc5Encrypter)) != 0)
break;
typedef struct {
unsigned int version; /* currently 1.0 defined 0x10 */
unsigned int rounds; /* number of rounds (0 - 255) */
unsigned int wordSizeInBits; /*
AI_RC5_CBCPad
requires 32 */
unsigned char *iv; /* initialization vector */
} A_RC5_CBC_PARAMS;