sha256.h
Functions
| Name | |
|---|---|
| int | wc_InitSha256(wc_Sha256 * sha) This function initializes SHA256. This is automatically called by wc_Sha256Hash. |
| int | wc_Sha256Update(wc_Sha256 * sha, const byte * data, word32 len) Can be called to continually hash the provided byte array of length len. |
| int | wc_Sha256Final(wc_Sha256 * sha256, byte * hash) Finalizes hashing of data. Result is placed into hash. Resets state of sha256 struct. |
| void | wc_Sha256Free(wc_Sha256 * sha256) Resets the Sha256 structure. Note: this is only supported if you have WOLFSSL_TI_HASH defined. |
| int | wc_Sha256GetHash(wc_Sha256 * sha256, byte * hash) Gets hash data. Result is placed into hash. Does not reset state of sha256 struct. |
| int | wc_InitSha224(wc_Sha224 * sha224) Used to initialize a Sha224 struct. |
| int | wc_Sha224Update(wc_Sha224 * sha224, const byte * data, word32 len) Can be called to continually hash the provided byte array of length len. |
| int | wc_Sha224Final(wc_Sha224 * sha224, byte * hash) Finalizes hashing of data. Result is placed into hash. Resets state of sha224 struct. |
| int | wc_InitSha256_ex(wc_Sha256 * sha, void * heap, int devId) Initializes SHA256 with heap and device ID. |
| int | wc_Sha256FinalRaw(wc_Sha256 * sha256, byte * hash) Gets raw hash without finalizing. |
| int | wc_Sha256Transform(wc_Sha256 * sha, const unsigned char * data) Transforms SHA256 block. |
| int | wc_Sha256HashBlock(wc_Sha256 * sha, const unsigned char * data, unsigned char * hash) Hashes single block and outputs result. |
| int | wc_Sha256_Grow(wc_Sha256 * sha256, const byte * in, int inSz) Grows SHA256 buffer with input data. This function is only available when WOLFSSL_HASH_KEEP is defined. It is used for keeping an internal buffer to hold all data to be hashed rather than iterating over update, which is necessary for some hardware acceleration platforms that have restrictions on streaming hash operations. |
| int | wc_Sha256Copy(wc_Sha256 * src, wc_Sha256 * dst) Copies SHA256 context. |
| void | wc_Sha256SizeSet(wc_Sha256 * sha256, word32 len) Sets SHA256 size. |
| int | wc_Sha256SetFlags(wc_Sha256 * sha256, word32 flags) Sets SHA256 flags. |
| int | wc_Sha256GetFlags(wc_Sha256 * sha256, word32 * flags) Gets SHA256 flags. |
| int | wc_InitSha224_ex(wc_Sha224 * sha224, void * heap, int devId) Initializes SHA224 with heap and device ID. |
| void | wc_Sha224Free(wc_Sha224 * sha224) Frees SHA224 resources. |
| int | wc_Sha224_Grow(wc_Sha224 * sha224, const byte * in, int inSz) Grows SHA224 buffer with input data. This function is only available when WOLFSSL_HASH_KEEP is defined. It is used for keeping an internal buffer to hold all data to be hashed rather than iterating over update, which is necessary for some hardware acceleration platforms that have restrictions on streaming hash operations. |
| int | wc_Sha224GetHash(wc_Sha224 * sha224, byte * hash) Gets SHA224 hash without finalizing. |
| int | wc_Sha224Copy(wc_Sha224 * src, wc_Sha224 * dst) Copies SHA224 context. |
| int | wc_Sha224SetFlags(wc_Sha224 * sha224, word32 flags) Sets SHA224 flags. |
| int | wc_Sha224GetFlags(wc_Sha224 * sha224, word32 * flags) Gets SHA224 flags. |
Functions Documentation
function wc_InitSha256
int wc_InitSha256(
wc_Sha256 * sha
)
This function initializes SHA256. This is automatically called by wc_Sha256Hash.
Parameters:
- sha256 pointer to the sha256 structure to use for encryption
See:
Return: 0 Returned upon successfully initializing
Example
Sha256 sha256[1];
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256Final(sha256, hash);
}
function wc_Sha256Update
int wc_Sha256Update(
wc_Sha256 * sha,
const byte * data,
word32 len
)
Can be called to continually hash the provided byte array of length len.
Parameters:
- sha256 pointer to the sha256 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
Sha256 sha256[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256Final(sha256, hash);
}
function wc_Sha256Final
int wc_Sha256Final(
wc_Sha256 * sha256,
byte * hash
)
Finalizes hashing of data. Result is placed into hash. Resets state of sha256 struct.
Parameters:
- sha256 pointer to the sha256 structure to use for encryption
- hash Byte array to hold hash value.
See:
Return: 0 Returned upon successfully finalizing.
Example
Sha256 sha256[1];
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256Final(sha256, hash);
}
function wc_Sha256Free
void wc_Sha256Free(
wc_Sha256 * sha256
)
Resets the Sha256 structure. Note: this is only supported if you have WOLFSSL_TI_HASH defined.
Parameters:
- sha256 Pointer to the sha256 structure to be freed.
See:
Return: none No returns.
Example
Sha256 sha256;
byte data[] = { Data to be hashed };
word32 len = sizeof(data);
if ((ret = wc_InitSha256(&sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(&sha256, data, len);
wc_Sha256Final(&sha256, hash);
wc_Sha256Free(&sha256);
}
function wc_Sha256GetHash
int wc_Sha256GetHash(
wc_Sha256 * sha256,
byte * hash
)
Gets hash data. Result is placed into hash. Does not reset state of sha256 struct.
Parameters:
- sha256 pointer to the sha256 structure to use for encryption
- hash Byte array to hold hash value.
See:
Return: 0 Returned upon successfully finalizing.
Example
Sha256 sha256[1];
if ((ret = wc_InitSha256(sha256)) != 0) {
WOLFSSL_MSG("wc_InitSha256 failed");
}
else {
wc_Sha256Update(sha256, data, len);
wc_Sha256GetHash(sha256, hash);
}
function wc_InitSha224
int wc_InitSha224(
wc_Sha224 * sha224
)
Used to initialize a Sha224 struct.
Parameters:
- sha224 Pointer to a Sha224 struct to initialize.
See:
Return:
- 0 Success
- 1 Error returned because sha224 is null.
Example
Sha224 sha224;
if(wc_InitSha224(&sha224) != 0)
{
// Handle error
}
function wc_Sha224Update
int wc_Sha224Update(
wc_Sha224 * sha224,
const byte * data,
word32 len
)
Can be called to continually hash the provided byte array of length len.
Parameters:
- sha224 Pointer to the Sha224 structure to use for encryption.
- data Data to be hashed.
- len Length of data to be hashed.
See:
Return:
- 0 Success
- 1 Error returned if function fails.
- BAD_FUNC_ARG Error returned if sha224 or data is null.
Example
Sha224 sha224;
byte data[]; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitSha224(&sha224)) != 0) {
WOLFSSL_MSG("wc_InitSha224 failed");
}
else {
wc_Sha224Update(&sha224, data, len);
wc_Sha224Final(&sha224, hash);
}
function wc_Sha224Final
int wc_Sha224Final(
wc_Sha224 * sha224,
byte * hash
)
Finalizes hashing of data. Result is placed into hash. Resets state of sha224 struct.
Parameters:
- sha224 pointer to the sha224 structure to use for encryption
- hash Byte array to hold hash value.
See:
Return:
- 0 Success
- <0 Error
Example
Sha224 sha224;
byte data[]; // Data to be hashed
word32 len = sizeof(data);
if ((ret = wc_InitSha224(&sha224)) != 0) {
WOLFSSL_MSG("wc_InitSha224 failed");
}
else {
wc_Sha224Update(&sha224, data, len);
wc_Sha224Final(&sha224, hash);
}
function wc_InitSha256_ex
int wc_InitSha256_ex(
wc_Sha256 * sha,
void * heap,
int devId
)
Initializes SHA256 with heap and device ID.
Parameters:
- sha SHA256 structure
- heap Heap hint
- devId Device ID
See: wc_InitSha256
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
int ret = wc_InitSha256_ex(&sha, NULL, INVALID_DEVID);
function wc_Sha256FinalRaw
int wc_Sha256FinalRaw(
wc_Sha256 * sha256,
byte * hash
)
Gets raw hash without finalizing.
Parameters:
- sha256 SHA256 structure
- hash Output hash buffer
See: wc_Sha256Final
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
byte hash[WC_SHA256_DIGEST_SIZE];
int ret = wc_Sha256FinalRaw(&sha, hash);
function wc_Sha256Transform
int wc_Sha256Transform(
wc_Sha256 * sha,
const unsigned char * data
)
Transforms SHA256 block.
Parameters:
- sha SHA256 structure
- data Block data
See: wc_Sha256Update
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
unsigned char block[WC_SHA256_BLOCK_SIZE];
int ret = wc_Sha256Transform(&sha, block);
function wc_Sha256HashBlock
int wc_Sha256HashBlock(
wc_Sha256 * sha,
const unsigned char * data,
unsigned char * hash
)
Hashes single block and outputs result.
Parameters:
- sha SHA256 structure
- data Block data
- hash Output hash buffer
See: wc_Sha256Transform
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
unsigned char block[WC_SHA256_BLOCK_SIZE];
unsigned char hash[WC_SHA256_DIGEST_SIZE];
int ret = wc_Sha256HashBlock(&sha, block, hash);
function wc_Sha256_Grow
int wc_Sha256_Grow(
wc_Sha256 * sha256,
const byte * in,
int inSz
)
Grows SHA256 buffer with input data. This function is only available when WOLFSSL_HASH_KEEP is defined. It is used for keeping an internal buffer to hold all data to be hashed rather than iterating over update, which is necessary for some hardware acceleration platforms that have restrictions on streaming hash operations.
Parameters:
- sha256 SHA256 structure
- in Input data
- inSz Input size
See: wc_Sha256Update
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
byte data[100];
int ret = wc_Sha256_Grow(&sha, data, sizeof(data));
function wc_Sha256Copy
int wc_Sha256Copy(
wc_Sha256 * src,
wc_Sha256 * dst
)
Copies SHA256 context.
Parameters:
- src Source SHA256 structure
- dst Destination SHA256 structure
See: wc_InitSha256
Return:
- 0 on success
- negative on error
Example
wc_Sha256 src, dst;
int ret = wc_Sha256Copy(&src, &dst);
function wc_Sha256SizeSet
void wc_Sha256SizeSet(
wc_Sha256 * sha256,
word32 len
)
Sets SHA256 size.
Parameters:
- sha256 SHA256 structure
- len Size to set
See: wc_Sha256Update
Return: none No returns
Example
wc_Sha256 sha;
wc_Sha256SizeSet(&sha, 1000);
function wc_Sha256SetFlags
int wc_Sha256SetFlags(
wc_Sha256 * sha256,
word32 flags
)
Sets SHA256 flags.
Parameters:
- sha256 SHA256 structure
- flags Flags to set
See: wc_InitSha256
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
int ret = wc_Sha256SetFlags(&sha, WC_HASH_FLAG_WILLCOPY);
function wc_Sha256GetFlags
int wc_Sha256GetFlags(
wc_Sha256 * sha256,
word32 * flags
)
Gets SHA256 flags.
Parameters:
- sha256 SHA256 structure
- flags Pointer to store flags
See: wc_Sha256SetFlags
Return:
- 0 on success
- negative on error
Example
wc_Sha256 sha;
word32 flags;
int ret = wc_Sha256GetFlags(&sha, &flags);
function wc_InitSha224_ex
int wc_InitSha224_ex(
wc_Sha224 * sha224,
void * heap,
int devId
)
Initializes SHA224 with heap and device ID.
Parameters:
- sha224 SHA224 structure
- heap Heap hint
- devId Device ID
See: wc_InitSha224
Return:
- 0 on success
- negative on error
Example
wc_Sha224 sha;
int ret = wc_InitSha224_ex(&sha, NULL, INVALID_DEVID);
function wc_Sha224Free
void wc_Sha224Free(
wc_Sha224 * sha224
)
Frees SHA224 resources.
Parameters:
- sha224 SHA224 structure
See: wc_InitSha224
Return: none No returns
Example
wc_Sha224 sha;
wc_InitSha224(&sha);
wc_Sha224Free(&sha);
function wc_Sha224_Grow
int wc_Sha224_Grow(
wc_Sha224 * sha224,
const byte * in,
int inSz
)
Grows SHA224 buffer with input data. This function is only available when WOLFSSL_HASH_KEEP is defined. It is used for keeping an internal buffer to hold all data to be hashed rather than iterating over update, which is necessary for some hardware acceleration platforms that have restrictions on streaming hash operations.
Parameters:
- sha224 SHA224 structure
- in Input data
- inSz Input size
See: wc_Sha224Update
Return:
- 0 on success
- negative on error
Example
wc_Sha224 sha;
byte data[100];
int ret = wc_Sha224_Grow(&sha, data, sizeof(data));
function wc_Sha224GetHash
int wc_Sha224GetHash(
wc_Sha224 * sha224,
byte * hash
)
Gets SHA224 hash without finalizing.
Parameters:
- sha224 SHA224 structure
- hash Output hash buffer
See: wc_Sha224Final
Return:
- 0 on success
- negative on error
Example
wc_Sha224 sha;
byte hash[WC_SHA224_DIGEST_SIZE];
int ret = wc_Sha224GetHash(&sha, hash);
function wc_Sha224Copy
int wc_Sha224Copy(
wc_Sha224 * src,
wc_Sha224 * dst
)
Copies SHA224 context.
Parameters:
- src Source SHA224 structure
- dst Destination SHA224 structure
See: wc_InitSha224
Return:
- 0 on success
- negative on error
Example
wc_Sha224 src, dst;
int ret = wc_Sha224Copy(&src, &dst);
function wc_Sha224SetFlags
int wc_Sha224SetFlags(
wc_Sha224 * sha224,
word32 flags
)
Sets SHA224 flags.
Parameters:
- sha224 SHA224 structure
- flags Flags to set
See: wc_InitSha224
Return:
- 0 on success
- negative on error
Example
wc_Sha224 sha;
int ret = wc_Sha224SetFlags(&sha, WC_HASH_FLAG_WILLCOPY);
function wc_Sha224GetFlags
int wc_Sha224GetFlags(
wc_Sha224 * sha224,
word32 * flags
)
Gets SHA224 flags.
Parameters:
- sha224 SHA224 structure
- flags Pointer to store flags
See: wc_Sha224SetFlags
Return:
- 0 on success
- negative on error
Example
wc_Sha224 sha;
word32 flags;
int ret = wc_Sha224GetFlags(&sha, &flags);
Source code
int wc_InitSha256(wc_Sha256* sha);
int wc_Sha256Update(wc_Sha256* sha, const byte* data, word32 len);
int wc_Sha256Final(wc_Sha256* sha256, byte* hash);
void wc_Sha256Free(wc_Sha256* sha256);
int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash);
int wc_InitSha224(wc_Sha224* sha224);
int wc_Sha224Update(wc_Sha224* sha224, const byte* data, word32 len);
int wc_Sha224Final(wc_Sha224* sha224, byte* hash);
int wc_InitSha256_ex(wc_Sha256* sha, void* heap, int devId);
int wc_Sha256FinalRaw(wc_Sha256* sha256, byte* hash);
int wc_Sha256Transform(wc_Sha256* sha, const unsigned char* data);
int wc_Sha256HashBlock(wc_Sha256* sha, const unsigned char* data,
unsigned char* hash);
int wc_Sha256_Grow(wc_Sha256* sha256, const byte* in, int inSz);
int wc_Sha256Copy(wc_Sha256* src, wc_Sha256* dst);
void wc_Sha256SizeSet(wc_Sha256* sha256, word32 len);
int wc_Sha256SetFlags(wc_Sha256* sha256, word32 flags);
int wc_Sha256GetFlags(wc_Sha256* sha256, word32* flags);
int wc_InitSha224_ex(wc_Sha224* sha224, void* heap, int devId);
void wc_Sha224Free(wc_Sha224* sha224);
int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz);
int wc_Sha224GetHash(wc_Sha224* sha224, byte* hash);
int wc_Sha224Copy(wc_Sha224* src, wc_Sha224* dst);
int wc_Sha224SetFlags(wc_Sha224* sha224, word32 flags);
int wc_Sha224GetFlags(wc_Sha224* sha224, word32* flags);
Updated on 2025-12-31 at 01:16:04 +0000