Block Ciphers

Step 3: Init

The next step is to make a call to You will first create a key object,

B_EncryptInit. To do this, you need a key object. and then set the key data.

Step 3a: Creating a Key Object

B_KEY_OBJ rc6Key = (B_KEY_OBJ)NULL_PTR;

if ((status = B_CreateKeyObject (&rc6Key)) != 0) break;

Step 3b: Setting the Key Data

Now you need to set the key size and pass the bytes of key data. According to the Reference Manual entry for AI_RC6_CBCPad, the compatible KI type is KI_Item. A key anywhere from 1-255 bytes is supported. Here, you can use a random 24-byte key. For most applications, a 128-bit key should be sufficient.]

#define KEY_SIZE 24 /* number of bytes in the key */

ITEM rc6KeyItem = {NULL, 0};

/* Step 3b: Set the key object with a random RC6 key */ rc6KeyItem.len = KEY_SIZE;

rc6KeyItem.data = T_malloc (rc6KeyItem.len);

if ((status = (rc6KeyItem.data == NULL_PTR)) != 0) break;

At this point, you can write the key data to rc6KeyItem.data. In the sample code, we fill rc6KeyItem.data with random bytes:

if ((status = B_GenerateRandomBytes

(randomAlgorithm, rc6KeyItem.data, rc6KeyItem.len, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

if ((status = B_SetKeyInfo (rc6Key, KI_Item, (POINTER)&rc6KeyItem)) != 0) break;

Once you have passed in the key data, dispose of rc6KeyItem, because it is no longer necessary. Crypto-C has already initialized the key object with the necessary data.

1 9 8

R S A B S A F E C r y p t o - C D e v e l o p e r ’s G u i d e

Page 220
Image 220
RSA Security 5.2.2 manual Init, Setting the Key Data