wownero/src/crypto/sha3.c
wowario 87dcc37776
switch to SHA-3 PoW
Co-authored-by: fuwa <fuwa0529@users.noreply.github.com>
2020-05-15 08:37:36 +03:00

30 lines
582 B
C

#include <stddef.h>
#include <openssl/evp.h>
void handleErrors(void) {
printf("sha3 error, wow is ded\n");
exit(1);
}
void sha3(const void *data, size_t length, char *hash)
{
EVP_MD_CTX *mdctx;
if((mdctx = EVP_MD_CTX_new()) == NULL) {
handleErrors();
}
if(1 != EVP_DigestInit_ex(mdctx, EVP_sha3_256(), NULL)) {
handleErrors();
}
if(1 != EVP_DigestUpdate(mdctx, data, length)) {
handleErrors();
}
/* the digest context ctx is automatically cleaned up. */
if(1 != EVP_DigestFinal(mdctx, (unsigned char*)hash, NULL)) {
handleErrors();
}
}