Message Digests

Table 5-1Code Sample: DigestDataSavedState()

int DigestDataSavedState (ITEM *stateInfo, B_INFO_TYPE digestAI, ITEM *dataToDigest)

{

int status = 0;

B_ALGORITHM_OBJ digestObj = NULL;

ITEM newStateInfo = {NULL, 0}, bsfStateInfo = {NULL, 0}; do {

if ((status = B_CreateAlgorithmObject (&digestObj)) != 0) break;

if ((status = B_SetAlgorithmState (digestObj, digestAI, stateInfo, DIGEST_CHOOSER)) != 0)

break;

if ((status = B_DigestUpdate (digestObj, dataToDigest->data, dataToDigest->len, NULL)) != 0)

break;

if ((status = B_GetAlgorithmState (&bsfStateInfo, digestObj)) != 0) break;

/* Make a copy of the information pointed to by bsfStateInfo for local use, since the info pointed to by bsfStateInfo could be changed or reclaimed by the Crypto-C library during subsequent calls. */

newStateInfo.len = bsfStateInfo.len; newStateInfo.data = T_malloc (newStateInfo.len); if (newStateInfo.data == NULL) {

status = RSA_DEMO_E_ALLOC; break;

}

C h a p t e r 5 N o n - C r y p t o g r a p h i c O p e r a t i o n s

1 5 9

Page 181
Image 181
RSA Security 5.2.2 manual 1Code Sample DigestDataSavedState, Status = Rsademoealloc break