Chapter 6 Symmetric-Key Operations 209
Block Ciphers
secure; it is used for illustrative purposes only. It is not for duplication:
You should zeroize any sensitive data after leaving the do-while. In fact, you might
want to zeroize the memory immediately after you set the key:
Now that you have a key, you need an algorithm chooser and a surrender context.
This is a speedy function, so it is reasonable to use a properly cast NULL_PTR for the
surrender context. You do want to build a chooser:
unsigned char enteredPassword[MAX_PW_LEN];
ITEM pbeKeyItem;
puts ("Enter the password, then press Return or Enter");
gets ((char *)enteredPassword);
pbeKeyItem.data = enteredPassword;
pbeKeyItem.len = strlen (enteredPassword);
if ((status = B_SetKeyInfo
(pbeKey, KI_Item, (POINTER)&pbeKeyItem)) != 0)
break;
T_memset (pbeKeyItem.data, 0, MAX_PW_LEN);
B_ALGORITHM_METHOD *PBE_CHOOSER[] = {
&AM_MD5,
&AM_RC2_CBC_ENCRYPT,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_EncryptInit
(pbEncrypter, pbeKey, PBE_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;