Is this not supposed to work in OpenSSL 3.0.x+?

24 views
Skip to first unread message

Karl Denninger

unread,
May 11, 2025, 2:55:03 PM5/11/25
to openssl-users
[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.

Herbert

unread,
May 11, 2025, 5:55:16 PM5/11/25
to openss...@openssl.org


On 11/05/2025 20:55, Karl Denninger wrote:
> [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

The following seems to work:

$ cc -lcrypto -o test test.c


Karl Denninger

unread,
May 11, 2025, 5:58:32 PM5/11/25
to openss...@openssl.org

Ah so its not in the -lssl library, its in -lcrypto.  Thank you.

--
Karl Denninger
ka...@denninger.net
The Market Ticker
[S/MIME encrypted email preferred]
Reply all
Reply to author
Forward
0 new messages