I would like to create a whirlpool-digest with a program like this:
#include <openssl/evp.h>
#include <cstdio>
char sData[] = "test string";
int main(int argc, char *argv[]) {
const EVP_MD *digest_type = EVP_whirlpool();
EVP_MD_CTX *mdctx = EVP_MD_CTX_new();
int res = EVP_DigestInit_ex(mdctx, digest_type, NULL);
if (res == 1) {
res = EVP_DigestUpdate(mdctx, (unsigned char *)sData, 12);
if (res == 1) {
unsigned char *pOut = (unsigned char *)OPENSSL_malloc(EVP_MD_size(digest_type));
if (pOut != NULL) {
unsigned int len = 0;
res = EVP_DigestFinal_ex(mdctx, pOut, &len);
if (res == 1) {
for (int i = 0; i < len; i++) {
printf("%02x", pOut[i]);
}
printf("\n");
} else {
printf("EVP_DigestFinal_ex() failed\n");
}
} else {
printf("Couldn't allocate array\n");
}
} else{
printf("EVP_DigestUpdate() failed\n");
}
} else {
printf("EVP_DigestInit_ex() failed\n");
}
return 0;
}
When i run this, the call to EVP_DigestInit_ex()
fails.
On the other hand, when i replace EVP_whirlpool()
with EVP_sha512()
in the above code, the program runs through and displays the digest.
Is there some particular parameter i have to pass to EVP_DigestInit_ex()
to make this work?