RSA Security 5.2.2 manual Update, Unsigned int outputBufferSize

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 204
Image 204

Block Ciphers

Now that you have a key, you need an algorithm chooser and a surrender context. This is a speedy function, so you can use a properly cast NULL_PTR for the surrender context; but you do want to build a chooser:

B_ALGORITHM_METHOD *DES_CBC_CHOOSER[] = { &AM_CBC_ENCRYPT,

&AM_DES_ENCRYPT,

&AM_SHA_RANDOM,

(B_ALGORITHM_METHOD *)NULL_PTR

};

if ((status = B_EncryptInit (encryptionObject, desKey, DES_CBC_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 4: Update

Enter the data to encrypt with B_EncryptUpdate. The Reference Manual Chapter 2 entry for AI_FeedbackCipher states that you may pass (B_ALGORITHM_OBJ)NULL_PTR for all randomAlgorithm arguments. Once you have your input, call B_EncryptUpdate.

Remember that DES is a block cipher and requires input that is a multiple of eight bytes. Because you set fbParams.paddingMethodName to "pad" (see page 180), Crypto- C will pad to make the input a multiple of eight bytes. That means that the output buffer should be at least eight bytes longer than the input length. DES is a fast algorithm, so for small amounts of data it is reasonable to pass a properly cast NULL_PTR for the surrender context. If you want to pass a surrender context, refer to the following code sample:

static char *dataToEncrypt = "Encrypt this sentence."; unsigned char *encryptedData = NULL_PTR;

unsigned int outputBufferSize;

unsigned int outputLenUpdate, outputLenFinal; unsigned int encryptedDataLen;

encryptedDataLen = dataToEncryptLen + 8; encryptedData = T_malloc (encryptedDataLen);

if ((status = (encryptedData == NULL_PTR)) != 0) break;

1 8 2

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 204
Image 204
RSA Security 5.2.2 manual Update, Unsigned int outputBufferSize