Block Ciphers
186 RSA BSAFE Crypto-C Developers Guide
Step 3: Init
You need a key before you can initialize the algorithm object for encryption.
Step 3a: Creating a Key Object
Step 3b: Setting the Key Object
You are using 80 effective key bits. That does not mean you need exactly ten bytes of
key data, although for security reasons, it is important to use at least ten bytes. You
can generate 24 bytes (192 bits) of key data and the algorithm will still work at 80
effective bits. Thus, in the future, if you want to increase the effective key bits, you do
not have to change the code that generates key data, only the effective key bit
parameter.
Key generation is almost the same as with DES, but you will use a different KI. In the
Reference Manual Chapter 2 entry for AI_FeedbackCipher, you see you have a choice of
KIs. Because your key is going to be 24 bytes, you cannot use KI_8Byte, so choose
KI_Item. Looking up KI_Item in Chapter 3 of the Reference Manual, you find that the
info
you supply to B_SetKeyInfo is a pointer to an ITEM struct, which is:
rc2Params.effectiveKeyBits = 80;
ivItem.data = initVector;
ivItem.len = BLOCK_SIZE;
fbParams.encryptionMethodName = (unsigned char *)"rc2";
fbParams.encryptionParams = NULL_PTR;
fbParams.feedbackMethodName = (unsigned char *)"cbc";
fbParams.feedbackParams = (POINTER)&ivItem;
fbParams.paddingMethodName = (unsigned char *)"pad";
fbParams.paddingParams = NULL_PTR;
if ((status = B_SetAlgorithmInfo
(rc2Encrypter, AI_FeedbackCipher, (POINTER)&fbParams)) != 0)
break;
B_KEY_OBJ rc2Key = (B_KEY_OBJ)NULL_PTR;
if ((status = B_CreateKeyObject (&rc2Key)) != 0)
break