]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
compat: use OpenSSL RAND_priv_bytes() for entropy (#248)
authorTobias Heider <tobias.heider@canonical.com>
Fri, 29 Sep 2023 07:57:41 +0000 (09:57 +0200)
committerGitHub <noreply@github.com>
Fri, 29 Sep 2023 07:57:41 +0000 (08:57 +0100)
* compat: use OpenSSL RAND_priv_bytes() for entropy

Use OpenSSL random number generator to seed arc4random() if available,
if it fails fall back to /dev/urandom.

* tests: link eloop-bench against LDADD lib

arc4random might depend on libcrypto so we need to link it.

compat/arc4random.c
tests/eloop-bench/Makefile

index edc5fff94ff8cf688e57f3314a35fe2fb6e50f77..8f28f616d2fec9d7d36fca161a11dc5382bc2b7d 100644 (file)
 #include <sys/types.h>
 #include <sys/time.h>
 
+#if defined(HAVE_OPENSSL)
+#include <openssl/rand.h>
+#endif
+
 #define KEYSTREAM_ONLY
 #include "chacha_private.h"
 
@@ -93,6 +97,11 @@ _dhcpcd_getentropy(void *buf, size_t length)
        struct timeval   tv;
        uint8_t         *rand = (uint8_t *)buf;
 
+#if defined (HAVE_OPENSSL)
+       if (RAND_priv_bytes(buf, (int)length) == 1)
+               return (0);
+#endif
+
        if (length < sizeof(tv)) {
                gettimeofday(&tv, NULL);
                memcpy(buf, &tv, sizeof(tv));
index 2827c60704222e93e4dd9d16fc2cd3d6cf56a9e9..a0ebafd9c0f981575478da28f8f81990d0836673 100644 (file)
@@ -39,7 +39,7 @@ distclean: clean
 depend:
 
 ${PROG}: ${DEPEND} ${OBJS}
-       ${CC} ${LDFLAGS} -o $@ ${OBJS}
+       ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD}
 
 test: ${PROG}
        ./${PROG}