summaryrefslogtreecommitdiff
path: root/util/libreboot-utils/lib/rand.c
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/libreboot-utils/lib/rand.c
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/libreboot-utils/lib/rand.c')
-rw-r--r--util/libreboot-utils/lib/rand.c79
1 files changed, 0 insertions, 79 deletions
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