Topic: ShaHash - how to select SHA-256 for hash?

Is there any way to select SHA-256 when using ShaHash? I was not able to get the SHA-256 functions to work correctly - kept giving me key collisions on different sets of data - so I figured I'd use ShaHash (which works perfectly).

Thanks in advance!

Share

Re: ShaHash - how to select SHA-256 for hash?

Hi n7ekg,

The API for performing a full hash on SHA-256 data is "wc_Sha256Hash". This wraps our internal calls and allows you to provide an input/size and get a hash output (32-bytes for SHA-256).

int wc_Sha256Hash(const byte* data, word32 len, byte* hash);

Also you can call the wolfCrypt API's directly using something like:

#include "wolfssl/wolfcrypt/sha256.h"

Sha256 sha256;
unsigned char hash[SHA256_DIGEST_SIZE];
wc_InitSha256(&sha256);
wc_Sha256Update(&sha256, data, len);
wc_Sha256Final(&sha256, hash);

Of course make sure and check the return code from these, which should be 0 on success.

Here is another example for our wolfCrypt test:
https://github.com/wolfSSL/wolfssl/blob … st.c#L1234

Let me know if that helps.
David Garske, wolfSSL

Share