Skip to content

sha.h

Functions

Name
int wc_InitSha(wc_Sha * )
This function initializes SHA. This is automatically called by wc_ShaHash.
int wc_ShaUpdate(wc_Sha * sha, const byte * data, word32 len)
Can be called to continually hash the provided byte array of length len.
int wc_ShaFinal(wc_Sha * sha, byte * hash)
Finalizes hashing of data. Result is placed into hash. Resets state of sha struct.
void wc_ShaFree(wc_Sha * )
Used to clean up memory used by an initialized Sha struct. Note: this is only supported if you have WOLFSSL_TI_HASH defined.
int wc_ShaGetHash(wc_Sha * sha, byte * hash)
Gets hash data. Result is placed into hash. Does not reset state of sha struct.

Functions Documentation

function wc_InitSha

int wc_InitSha(
    wc_Sha * 
)

This function initializes SHA. This is automatically called by wc_ShaHash.

Parameters:

  • sha pointer to the sha structure to use for encryption

See:

Return: 0 Returned upon successfully initializing

Example

Sha sha[1];
if ((ret = wc_InitSha(sha)) != 0) {
   WOLFSSL_MSG("wc_InitSha failed");
}
else {
   wc_ShaUpdate(sha, data, len);
   wc_ShaFinal(sha, hash);
}

function wc_ShaUpdate

int wc_ShaUpdate(
    wc_Sha * sha,
    const byte * data,
    word32 len
)

Can be called to continually hash the provided byte array of length len.

Parameters:

  • sha pointer to the sha structure to use for encryption
  • data the data to be hashed
  • len length of data to be hashed

See:

Return: 0 Returned upon successfully adding the data to the digest.

Example

Sha sha[1];
byte data[] = { // Data to be hashed };
word32 len = sizeof(data);

if ((ret = wc_InitSha(sha)) != 0) {
   WOLFSSL_MSG("wc_InitSha failed");
}
else {
   wc_ShaUpdate(sha, data, len);
   wc_ShaFinal(sha, hash);
}

function wc_ShaFinal

int wc_ShaFinal(
    wc_Sha * sha,
    byte * hash
)

Finalizes hashing of data. Result is placed into hash. Resets state of sha struct.

Parameters:

  • sha pointer to the sha structure to use for encryption
  • hash Byte array to hold hash value.

See:

Return: 0 Returned upon successfully finalizing.

Example

Sha sha[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);

if ((ret = wc_InitSha(sha)) != 0) {
   WOLFSSL_MSG("wc_InitSha failed");
}
else {
   wc_ShaUpdate(sha, data, len);
   wc_ShaFinal(sha, hash);
}

function wc_ShaFree

void wc_ShaFree(
    wc_Sha * 
)

Used to clean up memory used by an initialized Sha struct. Note: this is only supported if you have WOLFSSL_TI_HASH defined.

Parameters:

  • sha Pointer to the Sha struct to free.

See:

Return: No returns.

Example

Sha sha;
wc_InitSha(&sha);
// Use sha
wc_ShaFree(&sha);

function wc_ShaGetHash

int wc_ShaGetHash(
    wc_Sha * sha,
    byte * hash
)

Gets hash data. Result is placed into hash. Does not reset state of sha struct.

Parameters:

  • sha pointer to the sha structure to use for encryption
  • hash Byte array to hold hash value.

See:

Return: 0 Returned upon successfully finalizing.

Example

Sha sha[1];
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
    wc_ShaUpdate(sha, data, len);
    wc_ShaGetHash(sha, hash);
}

Source code


int wc_InitSha(wc_Sha*);

int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len);

int wc_ShaFinal(wc_Sha* sha, byte* hash);

void wc_ShaFree(wc_Sha*);

int wc_ShaGetHash(wc_Sha* sha, byte* hash);

Updated on 2022-05-18 at 08:30:58 +0000