A SERVICE OF

logo

Chapter 5 Non-Cryptographic Operations 153
Message Digests
Step 3: Init
To initialize a message digest, call B_DigestInit. The Reference Manual Chapter 4
entry on
B_DigestInit shows that it requires four arguments. The first argument is
the algorithm object. The second is a key object. All Crypto-C message digest AIs call
for a properly cast
NULL_PTR as the key object; Crypto-C provides this argument for
algorithms, like HMAC, that require keys. The third argument is an algorithm
chooser. The fourth is a surrender context; this is a fast function, so it is reasonable to
pass a properly cast
NULL_PTR:
Refer to Saving State on page 120 for a discussion of how to save the state of the
algorithm object for future use.
Step 4: Update
Use B_DigestUpdate to enter the data to digest. If you have separate units of data (for
example, two or more files or several strings), make a call to
B_DigestUpdate for each
unit. Message digesting is quick, so unless you are digesting an extremely large
amount of data (a megabyte or more), it is reasonable to pass a properly cast
NULL_PTR
for the surrender context.
if ((status = B_SetAlgorithmInfo
(digester, AI_SHA1, NULL_PTR)) != 0)
break;
B_ALGORITHM_METHOD *DIGEST_CHOOSER[] = {
&AM_SHA,
(B_ALGORITHM_METHOD *)NULL_PTR
};
if ((status = B_DigestInit
(digester, (B_KEY_OBJ)NULL_PTR, DIGEST_CHOOSER,
(A_SURRENDER_CTX *)NULL_PTR)) != 0)
break;