[karl@NewFS ~/tmp]$ cat test.c
#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
int main() {
const char *key = "secretkey";
const char *msg = "This is the message";
unsigned char hmac_result[EVP_MAX_MD_SIZE];
unsigned int hmac_len;
HMAC(EVP_sha256(), key, strlen(key), (unsigned char*)msg, strlen(msg), hmac_result, &hmac_len);
printf("HMAC-SHA256: ");
for (int i = 0; i < hmac_len; i++) {
printf("%02x", hmac_result[i]);
}
printf("\n");
return 0;
}
[karl@NewFS ~/tmp]$ cc -o test test.c -lssl
ld: error: undefined symbol: EVP_sha256
>>> referenced by test.c
>>> /tmp/test-8e4787.o:(main)
ld: error: undefined symbol: HMAC
>>> referenced by test.c
>>> /tmp/test-8e4787.o:(main)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
[karl@NewFS ~/tmp]$ openssl version
OpenSSL 3.0.16 11 Feb 2025 (Library: OpenSSL 3.0.16 11 Feb 2025)
[karl@NewFS ~/tmp]$
If I do a "strings" on /usr/lib/libssl.so I do indeed see an HMAC function -- but not the EVP_sha256() one.
This is on FreeBSD 14.2-STABLE if that matters. I only need a one-shot HMAC computation so doing the entire EVP setup is a waste.