RSA Security 5.2.2 manual Update

Models: 5.2.2

1 376
Download 376 pages 13.91 Kb
Page 210
Image 210
(B_ALGORITHM_OBJ)NULL_PTR input, call B_EncryptUpdate.

Block Ciphers

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. However, you do want to build a chooser:

B_ALGORITHM_METHOD *RC2_CHOOSER[] = { &AM_CBC_ENCRYPT, &AM_RC2_ENCRYPT, &AM_SHA_RANDOM, (B_ALGORITHM_METHOD *)NULL_PTR

};

if ((status = B_EncryptInit (rc2Encrypter, rc2Key, RC2_CHOOSER, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 4: Update

Enter the data to encrypt through B_EncryptUpdate. From the Reference Manual Chapter 2 entry on AI_FeedbackCipher, you see that you can pass

for all randomAlgorithm arguments. Once you have your

Remember that the RC2 cipher is a block cipher and requires that the input be a multiple of eight bytes. Because you set fbParams.paddingMethodName to "pad" (see page 184), 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 larger than the input length.

The RC2 cipher 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, you can:

/* Assume dataToEncrypt points to already set data and dataToEncryptLen has been set to the number of bytes in dataToEncrypt. */

unsigned char *dataToEncrypt;

unsigned char *encryptedData = NULL_PTR; unsigned int dataToEncryptLen; unsigned int encryptedDataLen; unsigned int outputLenUpdate; encryptedDataLen = dataToEncryptLen + 8; encryptedData = T_malloc (encryptedDataLen);

1 8 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 210
Image 210
RSA Security 5.2.2 manual Update