Multiple Updates

places them into the given buffer, and sets a flag indicating whether the bytes returned are the last ones in the file or not. Assume also that the subroutine AppendDataToFile appends output data to a file. Finally, assume we have already called B_CreateAlgorithmObject, B_SetAlgorithmInfo, and B_EncryptInit:

#define

UPDATE_SIZE

64

#define

UPDATE_OUTPUT_SIZE

(UPDATE_SIZE + 16)

FILE *inputFile = (FILE *)NULL_PTR;

FILE *outputFile = (FILE *)NULL_PTR;

unsigned char dataToEncrypt[UPDATE_SIZE];

unsigned char blockOfEncryptedData[UPDATE_OUTPUT_SIZE]; unsigned int dataToEncryptLen, totalBytesSoFar; unsigned int outputLenUpdate, outputLenFinal; unsigned int sizeToUpdate = UPDATE_SIZE;

int endFlag, status; do {

totalBytesSoFar = 0;

while ((status = GetDataFromFile

(inputFile, sizeToUpdate, dataToEncrypt, &dataToEncryptLen, &endFlag)) == 0) {

printf ("dataToEncryptLen = %i \n", dataToEncryptLen); PrintBuf (dataToEncrypt, dataToEncryptLen);

if ((status = B_EncryptUpdate (encryptionObject, blockOfEncryptedData, &outputLenUpdate, UPDATE_OUTPUT_SIZE, dataToEncrypt, dataToEncryptLen, (B_ALGORITHM_OBJ)NULL_PTR, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

/* Save the encrypted data. */ if ((status = AppendDataToFile

(outputFile, blockOfEncryptedData, outputLenUpdate)) != 0)

break;

totalBytesSoFar += outputLenUpdate; if (endFlag == 1)

break;

} /* end while */

3 0

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 52
Image 52
RSA Security 5.2.2 manual Updatesize, Break End while