summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-25 10:36:50 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-25 10:38:37 +0000
commita6da25ad0bbbd23d72c0043735af58aa68e59424 (patch)
treea3e7d5bd5e40b2dd46f8599d5c39a28c7ce42fc7 /util
parentf7f1856969df44c47deca559a1b77b82d4f42cb3 (diff)
libreboot-utils: remove 1989 rand
added as an academic exercise, but pointless in the year 2026. or even the year 1989. Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/libreboot-utils/include/common.h8
-rw-r--r--util/libreboot-utils/lib/num.c8
-rw-r--r--util/libreboot-utils/lib/rand.c79
3 files changed, 1 insertions, 94 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h
index 97bbdf0c..0bab30de 100644
--- a/util/libreboot-utils/include/common.h
+++ b/util/libreboot-utils/include/common.h
@@ -26,7 +26,7 @@
#endif
#if !defined(HAVE_GETRANDOM)
#include <sys/syscall.h>
-#if defined(SYS_getrandom)
+#if !defined(SYS_getrandom)
#define HAVE_GETRANDOM_SYSCALL 1
#endif
#endif
@@ -396,18 +396,12 @@ int dcat(const char *s, size_t n,
unsigned short hextonum(char ch_s);
size_t rlong(void);
-#if !(defined(FALLBACK_RAND_1989) && \
- ((FALLBACK_RAND_1989) > 0))
#if defined(__linux__)
#if defined(HAVE_GETRANDOM) || \
defined(HAVE_GETRANDOM_SYSCALL)
int fallback_rand_getrandom(void *buf, size_t len);
#endif
#endif
-#else
-size_t fallback_rand_1989(void);
-size_t entropy_jitter(void);
-#endif
/* Helper functions for command: dump
*/
diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c
index c02b6722..41a08f0b 100644
--- a/util/libreboot-utils/lib/num.c
+++ b/util/libreboot-utils/lib/num.c
@@ -13,10 +13,6 @@ TODO: properly handle errno in this file
#include <sys/param.h>
#endif
#include <sys/types.h>
-#if defined(FALLBACK_RAND_1989) && \
- (FALLBACK_RAND_1989) > 0
-#include <sys/time.h>
-#endif
#include <errno.h>
#if !((defined(__OpenBSD__) && (OpenBSD) >= 201) || \
@@ -27,10 +23,6 @@ TODO: properly handle errno in this file
#include <limits.h>
#include <stddef.h>
#include <string.h>
-#if defined(FALLBACK_RAND_1989) && \
- (FALLBACK_RAND_1989) > 0
-#include <time.h>
-#endif
#include <unistd.h>
#include "../include/common.h"
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index c84664fa..900c3ed3 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -11,10 +11,6 @@
#include <sys/param.h>
#endif
#include <sys/types.h>
-#if defined(FALLBACK_RAND_1989) && \
- (FALLBACK_RAND_1989) > 0
-#include <sys/time.h>
-#endif
#include <errno.h>
#if !((defined(__OpenBSD__) && (OpenBSD) >= 201) || \
@@ -25,10 +21,6 @@
#include <limits.h>
#include <stddef.h>
#include <string.h>
-#if defined(FALLBACK_RAND_1989) && \
- (FALLBACK_RAND_1989) > 0
-#include <time.h>
-#endif
#include <unistd.h>
#include "../include/common.h"
@@ -54,8 +46,6 @@
size_t
rlong(void)
{
-#if !(defined(FALLBACK_RAND_1989) && \
- ((FALLBACK_RAND_1989) > 0))
#if (defined(__OpenBSD__) && (OpenBSD) >= 201) || \
defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__APPLE__)
@@ -278,74 +268,5 @@ fallback_rand_getrandom(void *buf, size_t len)
}
#endif
#endif
-#else
-size_t
-fallback_rand_1989(void)
-{
- static size_t mix = 0;
- static size_t counter = 0;
-
- struct timeval tv;
-
- /* nobody should use this
- * (not crypto-safe)
- */
-
- gettimeofday(&tv, NULL);
-
- mix ^= (size_t)tv.tv_sec
- ^ (size_t)tv.tv_usec
- ^ (size_t)getpid()
- ^ (size_t)&mix
- ^ counter++
- ^ entropy_jitter();
-
- /*
- * Stack addresses can vary between
- * calls, thus increasing entropy.
- */
- mix ^= (size_t)&mix;
- mix ^= (size_t)&tv;
- mix ^= (size_t)&counter;
-
- return mix;
-}
-
-size_t
-entropy_jitter(void)
-{
- size_t mix;
-
- struct timeval a, b;
- ssize_t mix_diff;
-
- int c;
-
- mix = 0;
-
- gettimeofday(&a, NULL);
-
- for (c = 0; c < 32; c++) {
-
- getpid();
- gettimeofday(&b, NULL);
-
- /*
- * prevent negative numbers to prevent overflow,
- * which would bias rand to large numbers
- */
- mix_diff = (ssize_t)(b.tv_usec - a.tv_usec);
- if (mix_diff < 0)
- mix_diff = -mix_diff;
-
- mix ^= (size_t)(mix_diff);
-
- mix ^= (size_t)&mix;
-
- }
-
- return mix;
-}
-#endif
#endif