crypto_HandlerType_E Crypto_Hash_Sha_Final(
st_Crypto_Sha_Hash_Ctx *ptr_shaCtx_st,
uint8_t *ptr_digest
);
Description
This API is used to get the calculated hash/digest for different variants of SHA-1,
SHA-2, and SHA-3 (Excluding SHAKE) algorithms in multi-steps. Initialize context by
calling Crypto_Hash_Sha_Init function and calculate hash using
Crypto_Hash_Sha_Update and then call this function.
Parameters
No. | Argument Type | Argument Name | Type | Description |
---|
1 | st_Crypto_Sha_Hash_Ctx | ptr_shaCtx_st | Input/out | Hash algorithm
and crypto handler selection |
2 | uint8_t* | ptr_digest | Output | Pointer to
store calculated digest |
Returns
Return Type | Description |
---|
crypto_Hash_Status_E | Function
returns the status of the API. |
Prerequisites
- To use the HW handler, the
algorithm must be enabled in Crypto v4 in MPLAB® Code Configurator.
- To use the SW handler, the
algorithm must be enabled in wolfCrypt, and linked to Crypto V4 in MPLAB® Code
Configurator.
- Crypto_Hash_Sha_Init and Crypto_Hash_Sha_Update must be called before calling
Crypto_Hash_Sha_Final.
Example
#define sessionID 1
crypto_Hash_Status_E status;
crypto_HandlerType_E handlerType_en = CRYPTO_HANDLER_HW_INTERNAL;
st_Crypto_Hash_Sha_Ctx Hash_Ctx;
crypto_Hash_Algo_E shaAlgorithm_en = CRYPTO_HASH_SHA2_224;
uint8_t inputData[32] = {/*data*/};
uint32_t dataLen = sizeof(inputData);
uint8_t digest[28];
status = Crypto_Hash_Sha_Init(
&Hash_Ctx,
shaAlgorithm_en,
handlerType_en,
sessionID
);
status = Crypto_Hash_Sha_Update(
&Hash_Ctx,
inputData,
dataLen
);
status = Crypto_Hash_Sha_Final(
&Hash_Ctx,
digest
);