Topic: wc_Sha256Final(sha256, hash) - who frees hash?

I'm using this function when creating a sha256 hash.  my questions is, who frees the memory for hash, which is a byte*?

The examples in the doc don't show how this is allocated.  Would I be OK assuming that if I do the following, it will be allocated on the stack and deleted when it goes out of scope?

Sha256 sha256[1];
// call init and update here
char hash[32];
int ret = wc_Sha256Final(sha256, hash);

Share

Re: wc_Sha256Final(sha256, hash) - who frees hash?

Hi gawiz,

Yes, that's correct.  wc_Sha256Final() just takes a pointer to a memory location from the user.  This means that your application is responsible for managing that memory - whether it be on the stack as above, or dynamically if you allocated it with malloc().

Best Regards,
Chris

Re: wc_Sha256Final(sha256, hash) - who frees hash?

Hi gawiz,

As a follow-up, we have examples of using SHA-256 in our wolfCrypt test application.  This can be found in the wolfSSL package at the following location:

<wolfssl_root>/wolfcrypt/test/test.c

Specifically, inside of the sha256_test() function.  Do you mind if I ask what you are working on?

Thanks,
Chris

Re: wc_Sha256Final(sha256, hash) - who frees hash?

Hi Chris -
We're developing a secure messenger called Sesame.  All messages and attachments are encrypted from client to client and pass through the server ephemerally.  http://sesame.chat

Share