Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 1.17 KB

GUID-A73DC762-0144-466E-88C9-75E76ADE7F03.md

File metadata and controls

51 lines (32 loc) · 1.17 KB

CRYPT_SHA_Finalize Function

Parent topic:MPLAB® Harmony Crypto Library

C

int CRYPT_SHA_Finalize(
    CRYPT_SHA_CTX* sha, 
    unsigned char* digest
);

Description

This function finalizes the hash and puts the result into digest.

Preconditions

The SHA context must be initialized prior to calling this function. The context must not be modified by code outside of this function.

Parameters

Parameters Description
sha Pointer to CRYPT_SHA_CTX structure which holds the hash values.
digest Pointer to byte array to store hash result.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function. either sha or digest.

  • 0 - An invalid pointer was not passed to the function.

Remarks

In order to preserve the validity of the SHA hash, nothing must modify the context hoding variable between calls to CRYPT_SHA_DataAdd and CRYPT_SHA_Finalize.

Example

CRYPT_SHA_CTX sha;
uint8_t buffer[1024];
uint8_t shaSum[SHA_DIGEST_SIZE];

CRYPT_SHA_Initialize(&sha);
CRYPT_SHA_DataAdd(&sha, buffer, sizeof(buffer));
CRYPT_SHA_Finalize(&sha, shaSum);