B_DigestFinal 4.

Message Digests

Your call will be the following:

/* The variable dataToDigest should already point to allocated memory and contain the data, dataToDigestLen should already be set to the number of bytes to digest. */

unsigned char *dataToDigest; unsigned int dataToDigestLen;

if ((status = B_DigestUpdate

(digester, dataToDigest, dataToDigestLen, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

Step 5: Final

An MD2 or MD5 digest is always 16 bytes; an SHA1 digest is always 20 bytes. Because you are using SHA1, create a 20-byte buffer to hold the output and call

. The Reference Manual gives the prototype for this function in Chapter

The first argument is the algorithm object. The second is the buffer where Crypto-C will deposit the digest. The third is an address for Crypto-C to return the number of bytes in the digest. Because this value should always be 20, you can use this as a check on the algorithm if you like. The fourth argument is the size of the output buffer. If Crypto-C needs a bigger buffer, this function will return an error. The fifth argument is the surrender context; this is a fast function, so there should be no problem with using a properly cast NULL_PTR:

#define DIGEST_LEN 20

unsigned char digestedData[DIGEST_LEN]; unsigned int digestedDataLen;

if ((status = B_DigestFinal

(digester, digestedData, &digestedDataLen, DIGEST_LEN, (A_SURRENDER_CTX *)NULL_PTR)) != 0)

break;

1 5 4

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 176
Image 176
RSA Security 5.2.2 manual Your call will be the following, If status = BDigestUpdate, #define Digestlen