hash.h
Functions
| Name | |
|---|---|
| int | wc_HashGetOID(enum wc_HashType hash_type) This function will return the OID for the wc_HashType provided. |
| int | wc_HashGetDigestSize(enum wc_HashType hash_type) This function returns the size of the digest (output) for a hash_type. The returns size is used to make sure the output buffer provided to wc_Hash is large enough. |
| int | wc_Hash(enum wc_HashType hash_type, const byte * data, word32 data_len, byte * hash, word32 hash_len) This function performs a hash on the provided data buffer and returns it in the hash buffer provided. |
| int | wc_HashUpdate(wc_HashAlg * hash, enum wc_HashType type, const byte * data, word32 dataSz) This function updates the hash in a wc_HashAlg object with the provided data. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). |
| int | wc_HashFinal(wc_HashAlg * hash, enum wc_HashType type, byte * out) This function finalizes the hash in a wc_HashAlg object and writes the resulting digest to out. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). |
| int | wc_HashFree(wc_HashAlg * hash, enum wc_HashType type) This function frees any resources held by a wc_HashAlg object. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). The wc_HashAlg object itself is not freed. |
| int | wc_HashSetFlags(wc_HashAlg * hash, enum wc_HashType type, word32 flags) This function sets the flags of the underlying hash object in a wc_HashAlg object. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). Available when WOLFSSL_HASH_FLAGS is defined. |
| int | wc_HashGetFlags(wc_HashAlg * hash, enum wc_HashType type, word32 * flags) This function gets the flags of the underlying hash object in a wc_HashAlg object. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). Available when WOLFSSL_HASH_FLAGS is defined. |
| int | wc_Md5Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_ShaHash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha224Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha256Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha384Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha512Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha3_224Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha3_256Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha3_384Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Sha3_512Hash(const byte * data, word32 len, byte * hash) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Shake128Hash(const byte * data, word32 len, byte * hash, word32 hashLen) Convenience function, handles all the hashing and places the result into hash. |
| int | wc_Shake256Hash(const byte * data, word32 len, byte * hash, word32 hashLen) Convenience function, handles all the hashing and places the result into hash. |
Functions Documentation
function wc_HashGetOID
int wc_HashGetOID(
enum wc_HashType hash_type
)
This function will return the OID for the wc_HashType provided.
Parameters:
- hash_type A hash type from the “enum wc_HashType” such as “WC_HASH_TYPE_SHA256”.
See:
Return:
- OID returns value greater than 0
- HASH_TYPE_E hash type not supported.
- BAD_FUNC_ARG one of the provided arguments is incorrect.
Example
enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
int oid = wc_HashGetOID(hash_type);
if (oid > 0) {
// Success
}
function wc_HashGetDigestSize
int wc_HashGetDigestSize(
enum wc_HashType hash_type
)
This function returns the size of the digest (output) for a hash_type. The returns size is used to make sure the output buffer provided to wc_Hash is large enough.
Parameters:
- hash_type A hash type from the “enum wc_HashType” such as “WC_HASH_TYPE_SHA256”.
See: wc_Hash
Return:
- Success A positive return value indicates the digest size for the hash.
- Error Returns HASH_TYPE_E if hash_type is not supported.
- Failure Returns BAD_FUNC_ARG if an invalid hash_type was used.
Example
int hash_len = wc_HashGetDigestSize(hash_type);
if (hash_len <= 0) {
WOLFSSL_MSG("Invalid hash type/len");
return BAD_FUNC_ARG;
}
function wc_Hash
int wc_Hash(
enum wc_HashType hash_type,
const byte * data,
word32 data_len,
byte * hash,
word32 hash_len
)
This function performs a hash on the provided data buffer and returns it in the hash buffer provided.
Parameters:
- hash_type A hash type from the “enum wc_HashType” such as “WC_HASH_TYPE_SHA256”.
- data Pointer to buffer containing the data to hash.
- data_len Length of the data buffer.
- hash Pointer to buffer used to output the final hash to.
- hash_len Length of the hash buffer.
See: wc_HashGetDigestSize
Return: 0 Success, else error (such as BAD_FUNC_ARG or BUFFER_E).
Example
enum wc_HashType hash_type = WC_HASH_TYPE_SHA256;
int hash_len = wc_HashGetDigestSize(hash_type);
if (hash_len > 0) {
int ret = wc_Hash(hash_type, data, data_len, hash_data, hash_len);
if(ret == 0) {
// Success
}
}
function wc_HashUpdate
int wc_HashUpdate(
wc_HashAlg * hash,
enum wc_HashType type,
const byte * data,
word32 dataSz
)
This function updates the hash in a wc_HashAlg object with the provided data. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex().
Parameters:
- hash Pointer to the wc_HashAlg object, previously initialized with wc_HashInit() or wc_HashInit_ex().
- type Must be either WC_HASH_TYPE_NONE or the same hash type that was used to initialize the hash object. The hash type stored in the hash object during initialization is always used to select the algorithm. Any other value results in BAD_FUNC_ARG.
- data Pointer to buffer containing the data to hash. May be NULL only if dataSz is 0.
- dataSz Length of the data buffer in bytes.
See:
Return:
- 0 Success.
- BAD_FUNC_ARG hash is NULL, data is NULL while dataSz is greater than 0, the hash object was not initialized with a valid hash type, or type is not WC_HASH_TYPE_NONE and does not match the hash type used during initialization.
- HASH_TYPE_E the hash type stored in the hash object is not supported or not compiled in.
- Other negative error codes may be returned by the underlying hash algorithm's update function.
Example
wc_HashAlg hash;
byte digest[WC_SHA256_DIGEST_SIZE];
byte data[] = { 0x61, 0x62, 0x63 };
int ret;
ret = wc_HashInit(&hash, WC_HASH_TYPE_SHA256);
if (ret == 0) {
ret = wc_HashUpdate(&hash, WC_HASH_TYPE_SHA256, data, sizeof(data));
if (ret == 0) {
ret = wc_HashFinal(&hash, WC_HASH_TYPE_SHA256, digest);
}
wc_HashFree(&hash, WC_HASH_TYPE_SHA256);
}
function wc_HashFinal
int wc_HashFinal(
wc_HashAlg * hash,
enum wc_HashType type,
byte * out
)
This function finalizes the hash in a wc_HashAlg object and writes the resulting digest to out. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex().
Parameters:
- hash Pointer to the wc_HashAlg object, previously initialized with wc_HashInit() or wc_HashInit_ex().
- type Must be either WC_HASH_TYPE_NONE or the same hash type that was used to initialize the hash object. The hash type stored in the hash object during initialization is always used to select the algorithm. Any other value results in BAD_FUNC_ARG.
- out Pointer to the buffer to receive the digest. It must be at least as large as the digest size of the hash type the object was initialized with (see wc_HashGetDigestSize()).
See:
Return:
- 0 Success.
- BAD_FUNC_ARG hash or out is NULL, the hash object was not initialized with a valid hash type, or type is not WC_HASH_TYPE_NONE and does not match the hash type used during initialization.
- HASH_TYPE_E the hash type stored in the hash object is not supported or not compiled in.
- Other negative error codes may be returned by the underlying hash algorithm's final function.
Example
wc_HashAlg hash;
byte digest[WC_SHA256_DIGEST_SIZE];
byte data[] = { 0x61, 0x62, 0x63 };
int ret;
ret = wc_HashInit(&hash, WC_HASH_TYPE_SHA256);
if (ret == 0) {
ret = wc_HashUpdate(&hash, WC_HASH_TYPE_SHA256, data, sizeof(data));
if (ret == 0) {
ret = wc_HashFinal(&hash, WC_HASH_TYPE_SHA256, digest);
}
wc_HashFree(&hash, WC_HASH_TYPE_SHA256);
}
function wc_HashFree
int wc_HashFree(
wc_HashAlg * hash,
enum wc_HashType type
)
This function frees any resources held by a wc_HashAlg object. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). The wc_HashAlg object itself is not freed.
Parameters:
- hash Pointer to the wc_HashAlg object, previously initialized with wc_HashInit() or wc_HashInit_ex().
- type Must be either WC_HASH_TYPE_NONE or the same hash type that was used to initialize the hash object. The hash type stored in the hash object during initialization is always used to select the algorithm. Any other value results in BAD_FUNC_ARG.
See:
Return:
- 0 Success.
- BAD_FUNC_ARG hash is NULL, the hash object was not initialized with a valid hash type, or type is not WC_HASH_TYPE_NONE and does not match the hash type used during initialization.
- HASH_TYPE_E the hash type stored in the hash object is not supported or not compiled in.
Example
wc_HashAlg hash;
if (wc_HashInit(&hash, WC_HASH_TYPE_SHA256) == 0) {
// use hash
wc_HashFree(&hash, WC_HASH_TYPE_SHA256);
}
function wc_HashSetFlags
int wc_HashSetFlags(
wc_HashAlg * hash,
enum wc_HashType type,
word32 flags
)
This function sets the flags of the underlying hash object in a wc_HashAlg object. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). Available when WOLFSSL_HASH_FLAGS is defined.
Parameters:
- hash Pointer to the wc_HashAlg object, previously initialized with wc_HashInit() or wc_HashInit_ex().
- type Must be either WC_HASH_TYPE_NONE or the same hash type that was used to initialize the hash object. The hash type stored in the hash object during initialization is always used to select the algorithm. Any other value results in BAD_FUNC_ARG.
- flags Flags to set (for example WC_HASH_FLAG_ISCOPY).
See: wc_HashGetFlags
Return:
- 0 Success.
- BAD_FUNC_ARG hash is NULL, the hash object was not initialized with a valid hash type, or type is not WC_HASH_TYPE_NONE and does not match the hash type used during initialization.
- HASH_TYPE_E the hash type stored in the hash object is not supported or not compiled in.
Example
wc_HashAlg hash;
if (wc_HashInit(&hash, WC_HASH_TYPE_SHA256) == 0) {
wc_HashSetFlags(&hash, WC_HASH_TYPE_SHA256, WC_HASH_FLAG_NONE);
wc_HashFree(&hash, WC_HASH_TYPE_SHA256);
}
function wc_HashGetFlags
int wc_HashGetFlags(
wc_HashAlg * hash,
enum wc_HashType type,
word32 * flags
)
This function gets the flags of the underlying hash object in a wc_HashAlg object. The hash algorithm used is the one stored in the wc_HashAlg object when it was initialized with wc_HashInit() or wc_HashInit_ex(). Available when WOLFSSL_HASH_FLAGS is defined.
Parameters:
- hash Pointer to the wc_HashAlg object, previously initialized with wc_HashInit() or wc_HashInit_ex().
- type Must be either WC_HASH_TYPE_NONE or the same hash type that was used to initialize the hash object. The hash type stored in the hash object during initialization is always used to select the algorithm. Any other value results in BAD_FUNC_ARG.
- flags Pointer to receive the current flags. If NULL, no flags are returned.
See: wc_HashSetFlags
Return:
- 0 Success.
- BAD_FUNC_ARG hash is NULL, the hash object was not initialized with a valid hash type, or type is not WC_HASH_TYPE_NONE and does not match the hash type used during initialization.
- HASH_TYPE_E the hash type stored in the hash object is not supported or not compiled in.
Example
wc_HashAlg hash;
word32 flags = 0;
if (wc_HashInit(&hash, WC_HASH_TYPE_SHA256) == 0) {
wc_HashGetFlags(&hash, WC_HASH_TYPE_SHA256, &flags);
wc_HashFree(&hash, WC_HASH_TYPE_SHA256);
}
function wc_Md5Hash
int wc_Md5Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
- hashLen Number of bytes to write to hash.
See:
Return:
- 0 Returned upon successfully hashing the data.
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
const byte* data;
word32 data_len;
byte* hash;
int ret;
...
ret = wc_Md5Hash(data, data_len, hash);
if (ret != 0) {
// Md5 Hash Failure Case.
}
function wc_ShaHash
int wc_ShaHash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully ….
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha224Hash
int wc_Sha224Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Success
- <0 Error
Example
none
function wc_Sha256Hash
int wc_Sha256Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully …
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha384Hash
int wc_Sha384Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha512Hash
int wc_Sha512Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the inputted data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha3_224Hash
int wc_Sha3_224Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha3_256Hash
int wc_Sha3_256Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha3_384Hash
int wc_Sha3_384Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Sha3_512Hash
int wc_Sha3_512Hash(
const byte * data,
word32 len,
byte * hash
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the inputted data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Shake128Hash
int wc_Shake128Hash(
const byte * data,
word32 len,
byte * hash,
word32 hashLen
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
See:
Return:
- 0 Returned upon successfully hashing the inputted data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
function wc_Shake256Hash
int wc_Shake256Hash(
const byte * data,
word32 len,
byte * hash,
word32 hashLen
)
Convenience function, handles all the hashing and places the result into hash.
Parameters:
- data the data to hash
- len the length of data
- hash Byte array to hold hash value.
- hashLen Number of bytes to write to hash.
See:
Return:
- 0 Returned upon successfully hashing the inputted data
- Memory_E memory error, unable to allocate memory. This is only possible with the small stack option enabled.
Example
none
Source code
int wc_HashGetOID(enum wc_HashType hash_type);
int wc_HashGetDigestSize(enum wc_HashType hash_type);
int wc_Hash(enum wc_HashType hash_type,
const byte* data, word32 data_len,
byte* hash, word32 hash_len);
int wc_HashUpdate(wc_HashAlg* hash, enum wc_HashType type, const byte* data,
word32 dataSz);
int wc_HashFinal(wc_HashAlg* hash, enum wc_HashType type, byte* out);
int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type);
int wc_HashSetFlags(wc_HashAlg* hash, enum wc_HashType type, word32 flags);
int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags);
int wc_Md5Hash(const byte* data, word32 len, byte* hash);
int wc_ShaHash(const byte* data, word32 len, byte* hash);
int wc_Sha224Hash(const byte* data, word32 len, byte* hash);
int wc_Sha256Hash(const byte* data, word32 len, byte* hash);
int wc_Sha384Hash(const byte* data, word32 len, byte* hash);
int wc_Sha512Hash(const byte* data, word32 len, byte* hash);
int wc_Sha3_224Hash(const byte* data, word32 len, byte* hash);
int wc_Sha3_256Hash(const byte* data, word32 len, byte* hash);
int wc_Sha3_384Hash(const byte* data, word32 len, byte* hash);
int wc_Sha3_512Hash(const byte* data, word32 len, byte* hash);
int wc_Shake128Hash(const byte* data, word32 len, byte* hash,
word32 hashLen);
int wc_Shake256Hash(const byte* data, word32 len, byte* hash,
word32 hashLen);
Updated on 2026-10-28 at 01:13:04 +0000