From 743f16fb3fed9a05e601226f184be236614efe9a Mon Sep 17 00:00:00 2001 From: Fabrice Fontaine Date: Fri, 12 Aug 2022 23:35:52 +0200 Subject: [PATCH] fix build with libressl Fix the following build failure with libressl: /home/buildroot/autobuild/instance-0/output-1/host/lib/gcc/armeb-buildroot-linux-gnueabi/11.3.0/../../../../armeb-buildroot-linux-gnueabi/bin/ld: libntp/libntp.a(ntp_random.c.1.o): in function `ntp_RAND_priv_bytes': ntp_random.c:(.text+0xac): undefined reference to `RAND_priv_bytes' Fixes: - http://autobuild.buildroot.org/results/a6a825b7f0efc7c82e8ecf792a1f9951ffb047c5 Signed-off-by: Fabrice Fontaine [Upstream status: https://gitlab.com/NTPsec/ntpsec/-/merge_requests/1285] --- attic/cmac-timing.c | 2 ++ attic/random.c | 8 ++++++++ libntp/ntp_random.c | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/attic/cmac-timing.c b/attic/cmac-timing.c index 464daa76b..4f2fd3338 100644 --- a/attic/cmac-timing.c +++ b/attic/cmac-timing.c @@ -204,7 +204,9 @@ static void DoPKEY( printf("## Oops, EVP_MD_CTX_new() failed.\n"); return; } +#ifdef EVP_MD_CTX_FLAG_FINALISE EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_FINALISE); +#endif clock_gettime(CLOCK_MONOTONIC, &start); for (int i = 0; i < SAMPLESIZE; i++) { diff --git a/attic/random.c b/attic/random.c index 446c68535..8530ecd25 100644 --- a/attic/random.c +++ b/attic/random.c @@ -127,7 +127,11 @@ static int do_avg_priv(unsigned int bytes) { clock_gettime(CLOCK_REALTIME, &start); for (int i = 0; i < BATCHSIZE; i++) { +#ifdef LIBRESSL_VERSION_NUMBER + err += RAND_bytes((unsigned char *)&rnd, bytes); +#else err += RAND_priv_bytes((unsigned char *)&rnd, bytes); +#endif } clock_gettime(CLOCK_REALTIME, &stop); @@ -209,7 +213,11 @@ static int do_fast_priv(unsigned bytes) { for (int i = 0; i < BATCHSIZE; i++) { clock_gettime(CLOCK_REALTIME, &start); +#ifdef LIBRESSL_VERSION_NUMBER + err += RAND_bytes((unsigned char *)&rnd, bytes); +#else err += RAND_priv_bytes((unsigned char *)&rnd, bytes); +#endif clock_gettime(CLOCK_REALTIME, &stop); sec = (stop.tv_sec-start.tv_sec); nanos = sec*BILLION + (stop.tv_nsec-start.tv_nsec); diff --git a/libntp/ntp_random.c b/libntp/ntp_random.c index 9304a790d..adb375b24 100644 --- a/libntp/ntp_random.c +++ b/libntp/ntp_random.c @@ -29,7 +29,7 @@ void ntp_RAND_bytes(unsigned char *buf, int num) { void ntp_RAND_priv_bytes(unsigned char *buf, int num) { int err; -#if (OPENSSL_VERSION_NUMBER > 0x1010100fL) +#if (OPENSSL_VERSION_NUMBER > 0x1010100fL) && !defined(LIBRESSL_VERSION_NUMBER) err = RAND_priv_bytes(buf, num); #else err = RAND_bytes(buf, num); -- 2.35.1