
Introductory Example
14 RSA BSAFE Crypto-C Developer’s Guide
object as an RC4 key, we need to use B_SetKeyInfo. See Chapter 4 of the Reference
Manual for this function’s description and prototype:
This function is similar to
B_SetAlgorithmInfo. The first argument is the key object
just created,
rc4Key
. The second argument is a key info type (KI), and the third
argument is information that must accompany the given KI. We want to use a KI
compatible with RC4 encryption, so we return to the entry for our AI,
AI_RC4, in
Chapter 2 of the Reference Manual:
Key info types are described in Chapter 3 of the Reference Manual. Under the entry for
KI_ITEM we find that the format of
info
supplied to B_SetKeyInfo is a pointer to an
ITEM structure:
len
is the length of the key in bytes. The RC4 cipher takes key sizes of 1 to 256 bytes. A
10-byte key is generally sufficient for most applications.
data
is the key data. A real
application would use a random number generator to produce 10 bytes for the key
(see “Generating Random Numbers” on page 165). For this example, we can simply
use:
int B_SetKeyInfo (
B_KEY_OBJ keyObject, /* key object */
B_INFO_TYPE infoType, /* type of key information */
POINTER info /* key information */
);
Key info types for keyObject in B_EncryptInit or B_DecryptInit:
KI_Item that gives the address and length of the RC4 key.
typedef struct {
unsigned char *data;
unsigned int len;
} ITEM;