From: Otto Moerbeek Date: Tue, 20 Jun 2023 09:17:00 +0000 (+0200) Subject: Port of the openss-poratble arc4random code to our build environment X-Git-Tag: rec-5.0.0-alpha1~125^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8be2b8385cd1cf1ccd53d941087101f4547670ff;p=thirdparty%2Fpdns.git Port of the openss-poratble arc4random code to our build environment --- diff --git a/ext/arc4random/.gitignore b/ext/arc4random/.gitignore new file mode 100644 index 0000000000..24ad051c6e --- /dev/null +++ b/ext/arc4random/.gitignore @@ -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 index 0000000000..ee46ad2a57 --- /dev/null +++ b/ext/arc4random/Makefile.am @@ -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 diff --git a/ext/arc4random/arc4random.c b/ext/arc4random/arc4random.c index ffd33734db..afcaa64720 100644 --- a/ext/arc4random/arc4random.c +++ b/ext/arc4random/arc4random.c @@ -205,6 +205,9 @@ _rs_random_u32(uint32_t *val) rs->rs_have -= sizeof(*val); } +#include +static pthread_mutex_t arc4mutex = PTHREAD_MUTEX_INITIALIZER; + uint32_t arc4random(void) { diff --git a/ext/arc4random/arc4random.h b/ext/arc4random/arc4random.h index 5af3a4492a..402b26312a 100644 --- a/ext/arc4random/arc4random.h +++ b/ext/arc4random/arc4random.h @@ -28,8 +28,8 @@ #include /* 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 index 0000000000..72449fb248 --- /dev/null +++ b/ext/arc4random/arc4random.hh @@ -0,0 +1,9 @@ +#pragma once + +#include + +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 index 0000000000..8914c12aa9 --- /dev/null +++ b/ext/arc4random/includes.h @@ -0,0 +1,20 @@ +#include "config.h" + +#ifdef HAVE_GETRANDOM +#include +#endif + +#include +#include +#include + +#include +#include + +#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 index 0000000000..51d7af2799 --- /dev/null +++ b/ext/arc4random/log.h @@ -0,0 +1 @@ +#define fatal(...) do { fprintf(stderr, __VA_ARGS__); abort(); } while (0)