Chapter 6 Symmetric-Key Operations 185
Block Ciphers
Once again,
encryptionMethodName
is the block cipher that you will use; in this
example, use
“rc2”. All the other parameters are the same as for DES, except
encryptionParams
. For the RC2 cipher, the Reference Manual indicates that you need to
supply an
A_RC2_PARAMS structure for the RC2 encryption algorithm:
There is a distinction between key size and effective key bits. The RC2 algorithm
begins by building a 128-byte table based on the key. The total number of possible
tables is limited by the number of effective key bits. Using 80 effective key bits is
generally sufficient for most applications.
Use Cipher Block Chaining (CBC) for your feedback method. Once again, for this
method, you need an initialization vector; use a random number generator to produce
one. Remember, the IV is not secret and will not assist anyone in breaking the
encryption. Its size will be eight bytes, because the RC2 cipher encrypts blocks of eight
bytes. The Reference Manual says that
feedbackParams
is an ITEM structure containing
the initialization vector:
Now you can set your algorithm object as follows:
typedef struct {
unsigned int effectiveKeyBits; /* effective key size in bits */
} A_RC2_PARAMS;
typedef struct {
unsigned char *data;
unsigned int len;
} ITEM;
ITEM ivItem;
unsigned char initVector[BLOCK_SIZE];
A_RC2_PARAMS rc2Params;
B_BLK_CIPHER_W_FEEDBACK_PARAMS fbParams;
/* Complete steps 1 - 4 of Generating Random Numbers,
then call B_GenerateRandomBytes. */
if ((status = B_GenerateRandomBytes
(randomAlgorithm, (unsigned char *)initVector, 8,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;