Files
wolfssl/doc/dox_comments/header_files/sha.h
T

266 lines
5.0 KiB
C
Raw Normal View History

/*!
\ingroup SHA
2018-06-27 16:22:12 -06:00
\brief This function initializes SHA. This is automatically called
by wc_ShaHash.
2018-06-27 16:22:12 -06:00
\return 0 Returned upon successfully initializing
2018-06-27 16:22:12 -06:00
\param sha pointer to the sha structure to use for encryption
2018-06-27 16:22:12 -06:00
_Example_
\code
Sha sha[1];
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaFinal(sha, hash);
}
\endcode
2018-06-27 16:22:12 -06:00
\sa wc_ShaHash
\sa wc_ShaUpdate
\sa wc_ShaFinal
*/
2025-11-21 17:43:55 +00:00
int wc_InitSha(wc_Sha* sha);
/*!
\ingroup SHA
2018-06-27 16:22:12 -06:00
\brief Can be called to continually hash the provided byte array of
length len.
2018-06-27 16:22:12 -06:00
\return 0 Returned upon successfully adding the data to the digest.
2018-06-27 16:22:12 -06:00
\param sha pointer to the sha structure to use for encryption
\param data the data to be hashed
\param len length of data to be hashed
2018-06-27 16:22:12 -06:00
_Example_
\code
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);
}
\endcode
2018-06-27 16:22:12 -06:00
\sa wc_ShaHash
\sa wc_ShaFinal
\sa wc_InitSha
*/
2022-04-06 16:17:36 +01:00
int wc_ShaUpdate(wc_Sha* sha, const byte* data, word32 len);
/*!
\ingroup SHA
2018-06-27 16:22:12 -06:00
\brief Finalizes hashing of data. Result is placed into hash.
Resets state of sha struct.
2018-06-27 16:22:12 -06:00
\return 0 Returned upon successfully finalizing.
2018-06-27 16:22:12 -06:00
\param sha pointer to the sha structure to use for encryption
\param hash Byte array to hold hash value.
2018-06-27 16:22:12 -06:00
_Example_
\code
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);
}
\endcode
2018-06-27 16:22:12 -06:00
\sa wc_ShaHash
\sa wc_InitSha
\sa wc_ShaGetHash
*/
2022-04-06 16:17:36 +01:00
int wc_ShaFinal(wc_Sha* sha, byte* hash);
/*!
\ingroup SHA
2018-06-27 16:22:12 -06:00
\brief Used to clean up memory used by an initialized Sha struct.
2018-06-27 16:22:12 -06:00
\return No returns.
2018-06-27 16:22:12 -06:00
\param sha Pointer to the Sha struct to free.
2018-06-27 16:22:12 -06:00
_Example_
\code
Sha sha;
wc_InitSha(&sha);
// Use sha
wc_ShaFree(&sha);
\endcode
2018-06-27 16:22:12 -06:00
\sa wc_InitSha
\sa wc_ShaUpdate
\sa wc_ShaFinal
*/
2025-11-21 17:43:55 +00:00
void wc_ShaFree(wc_Sha* sha);
/*!
\ingroup SHA
2018-06-27 16:22:12 -06:00
\brief Gets hash data. Result is placed into hash. Does not reset state
of sha struct.
2018-06-27 16:22:12 -06:00
\return 0 Returned upon successfully finalizing.
2018-06-27 16:22:12 -06:00
\param sha pointer to the sha structure to use for encryption
\param hash Byte array to hold hash value.
2018-06-27 16:22:12 -06:00
_Example_
\code
Sha sha[1];
if ((ret = wc_InitSha(sha)) != 0) {
WOLFSSL_MSG("wc_InitSha failed");
}
else {
wc_ShaUpdate(sha, data, len);
wc_ShaGetHash(sha, hash);
}
\endcode
2018-06-27 16:22:12 -06:00
\sa wc_ShaHash
\sa wc_ShaFinal
\sa wc_InitSha
*/
2022-04-06 16:17:36 +01:00
int wc_ShaGetHash(wc_Sha* sha, byte* hash);
2025-12-26 08:00:20 -08:00
/*!
\ingroup SHA
\brief Initializes SHA with heap and device ID.
\return 0 on success
\return negative on error
\param sha SHA structure
\param heap Heap hint
\param devId Device ID
_Example_
\code
wc_Sha sha;
int ret = wc_InitSha_ex(&sha, NULL, INVALID_DEVID);
\endcode
\sa wc_InitSha
*/
int wc_InitSha_ex(wc_Sha* sha, void* heap, int devId);
/*!
\ingroup SHA
\brief Gets raw hash without finalizing.
\return 0 on success
\return negative on error
\param sha SHA structure
\param hash Output hash buffer
_Example_
\code
wc_Sha sha;
byte hash[WC_SHA_DIGEST_SIZE];
int ret = wc_ShaFinalRaw(&sha, hash);
\endcode
\sa wc_ShaFinal
*/
int wc_ShaFinalRaw(wc_Sha* sha, byte* hash);
/*!
\ingroup SHA
\brief Copies SHA context.
\return 0 on success
\return negative on error
\param src Source SHA structure
\param dst Destination SHA structure
_Example_
\code
wc_Sha src, dst;
int ret = wc_ShaCopy(&src, &dst);
\endcode
\sa wc_InitSha
*/
int wc_ShaCopy(wc_Sha* src, wc_Sha* dst);
/*!
\ingroup SHA
\brief Transforms SHA block.
\return 0 on success
\return negative on error
\param sha SHA structure
\param data Block data
_Example_
\code
wc_Sha sha;
unsigned char block[WC_SHA_BLOCK_SIZE];
int ret = wc_ShaTransform(&sha, block);
\endcode
\sa wc_ShaUpdate
*/
int wc_ShaTransform(wc_Sha* sha, const unsigned char* data);
/*!
\ingroup SHA
\brief Sets SHA size.
\return none No returns
\param sha SHA structure
\param len Size to set
_Example_
\code
wc_Sha sha;
wc_ShaSizeSet(&sha, 1000);
\endcode
\sa wc_ShaUpdate
*/
void wc_ShaSizeSet(wc_Sha* sha, word32 len);
/*!
\ingroup SHA
\brief Sets SHA flags.
\return 0 on success
\return negative on error
\param sha SHA structure
\param flags Flags to set
_Example_
\code
wc_Sha sha;
int ret = wc_ShaSetFlags(&sha, WC_HASH_FLAG_WILLCOPY);
\endcode
\sa wc_InitSha
*/
int wc_ShaSetFlags(wc_Sha* sha, word32 flags);