1.60 CRYPT_SHA256_DataSizeSet Function

C

int CRYPT_SHA256_DataSizeSet(
    CRYPT_SHA256_CTX* sha256, 
    unsigned int msgSize
);

Description

The PIC32MZ hardware encryption module needs to know the size of the data before it starts processing. This function sets that value.

Preconditions

None.

Parameters

ParametersDescription
sha256Pointer to CRYPT_SHA256_CTX structure which holds the hash values.
msgSizeSize of the data (in bytes) that will be processed.

Returns

  • BAD_FUNC_ARG - An invalid pointer was passed to the function.

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

Remarks

All SHA256 hashes have to start at a particular value before adding new data to it. This function sets the necessary values for the structure.

Example

CRYPT_SHA256_CTX sha256;
uint8_t buffer[1024];
uint8_t sha256sum[SHA256_DIGEST_SIZE];

CRYPT_SHA256_Initialize(&sha256);
CRYPT_SHA256DataSizeSet(&sha256, sizeof(buffer));
CRYPT_SHA256_DataAdd(&sha256, buffer, sizeof(buffer));
CRYPT_SHA256_Finalize(&sha256, sha256sum);