]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Port of the openss-poratble arc4random code to our build environment
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 20 Jun 2023 09:17:00 +0000 (11:17 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 6 Jul 2023 13:46:42 +0000 (15:46 +0200)
ext/arc4random/.gitignore [new file with mode: 0644]
ext/arc4random/Makefile.am [new file with mode: 0644]
ext/arc4random/arc4random.c
ext/arc4random/arc4random.h
ext/arc4random/arc4random.hh [new file with mode: 0644]
ext/arc4random/includes.h [new file with mode: 0644]
ext/arc4random/log.h [new file with mode: 0644]

diff --git a/ext/arc4random/.gitignore b/ext/arc4random/.gitignore
new file mode 100644 (file)
index 0000000..24ad051
--- /dev/null
@@ -0,0 +1,5 @@
+*.la
+*.lo
+*.o
+Makefile
+Makefile.in
diff --git a/ext/arc4random/Makefile.am b/ext/arc4random/Makefile.am
new file mode 100644 (file)
index 0000000..ee46ad2
--- /dev/null
@@ -0,0 +1,6 @@
+noinst_LTLIBRARIES = libarc4random.la
+libarc4random_la_SOURCES = arc4random.c arc4random.h \
+       arc4random_uniform.c \
+       bsd-getentropy.c \
+       includes.h \
+       log.h
index ffd33734db5647250745b06a6b0afa7f886055c5..afcaa64720e2cc92e19f8879c468110d216b7557 100644 (file)
@@ -205,6 +205,9 @@ _rs_random_u32(uint32_t *val)
        rs->rs_have -= sizeof(*val);
 }
 
+#include <pthread.h>
+static pthread_mutex_t arc4mutex = PTHREAD_MUTEX_INITIALIZER;
+
 uint32_t
 arc4random(void)
 {
index 5af3a4492a826a1304b66c9e967a1d6611222e16..402b26312a46be4491bfb06fd0d87ef2cb48d173 100644 (file)
@@ -28,8 +28,8 @@
 #include <signal.h>
 
 /* OpenSSH isn't multithreaded */
-#define _ARC4_LOCK()
-#define _ARC4_UNLOCK()
+#define _ARC4_LOCK() pthread_mutex_lock(&arc4mutex);
+#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4mutex);
 #define _ARC4_ATFORK(f)
 
 static inline void
diff --git a/ext/arc4random/arc4random.hh b/ext/arc4random/arc4random.hh
new file mode 100644 (file)
index 0000000..72449fb
--- /dev/null
@@ -0,0 +1,9 @@
+#pragma once
+
+#include <inttypes.h>
+
+extern "C" {
+uint32_t arc4random(void);
+void arc4random_buf(void *buf, size_t nbytes);
+uint32_t arc4random_uniform(uint32_t upper_bound);
+}
diff --git a/ext/arc4random/includes.h b/ext/arc4random/includes.h
new file mode 100644 (file)
index 0000000..8914c12
--- /dev/null
@@ -0,0 +1,20 @@
+#include "config.h"
+
+#ifdef HAVE_GETRANDOM
+#include <sys/random.h>
+#endif
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+#define seed_from_prngd(a, b) -1
+
+uint32_t arc4random(void);
+void arc4random_buf(void *buf, size_t nbytes);
+uint32_t arc4random_uniform(uint32_t upper_bound);
+
+#define DEF_WEAK(x)
diff --git a/ext/arc4random/log.h b/ext/arc4random/log.h
new file mode 100644 (file)
index 0000000..51d7af2
--- /dev/null
@@ -0,0 +1 @@
+#define fatal(...) do { fprintf(stderr, __VA_ARGS__); abort(); } while (0)