Edit: I extracted the SHA3 code from this question(Generate SHA-3 hash in C++ using OpenSSL library) and SHA3 is in the openssl 1.0.2q(but not 1.0.2r) version.
I am trying to generate SHA3 with the openssl library.
#include <stdio.h>
#include <openssl/evp.h>
unsigned int SHALEN=32;
void sha3(unsigned char *digest, const unsigned char *message, size_t message_len)
{
EVP_MD_CTX *mdctx;
mdctx = EVP_MD_CTX_create();
EVP_DigestInit_ex(mdctx, EVP_sha3_256(), NULL);
EVP_DigestUpdate(mdctx, message, message_len);
EVP_DigestFinal_ex(mdctx, digest, &SHALEN);
EVP_MD_CTX_destroy(mdctx);
}
int main()
{
unsigned char digest[32];
unsigned char message[32];
for(int i=0;i<32;i++)
message[i]=0;
sha3(digest,message,32);
}
The above code works on my personal Mac (with openssl 1.0.2q 2018Nov) but not on the server(Ubuntu 16.04, openssl version=1.1.1a). When compiled with
g++ test.cpp -lcrypto
It gives
/tmp/ccXTFrzC.o: In function `sha3(unsigned char*, unsigned char const*, unsigned long)':
test.cpp:(.text+0x1e): undefined reference to `EVP_sha3_256'
collect2: error: ld returned 1 exit status
I looked up the openssl manual but it is not very helpful. Is there anything I missed here? Thanks in advance.
BTW, I am advised not to downgrade openssl to solve the problem.