Message Digests
154 RSA BSAFE Crypto-C Developers Guide
Your call will be the following:
Step 5: Final
An MD2 or M D5 dige st is alw ays 16 b ytes; a n SHA1 di gest is always 20 bytes . Becau se
you are using SHA1, create a 20-byte buffer to hold the output and call
B_DigestFinal. The Reference Manual gives the prototype for this function in Chapter
4.
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:
/* 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;
#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;