util/nvmutil: mitigate fast calls to rand

if someone calls rhex fast enough, the timestamp
may not change. this mitigates that by adding
a counter value to the mix

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-12 14:13:55 +00:00
parent 53c5a40007
commit 922344e81e
+3 -1
View File
@@ -1032,13 +1032,15 @@ fallback_rand(void)
{
struct timeval tv;
unsigned long mix;
static unsigned long counter = 0;
gettimeofday(&tv, NULL);
mix = (unsigned long)tv.tv_sec
^ (unsigned long)tv.tv_usec
^ (unsigned long)getpid()
^ (unsigned long)(uintptr_t)&mix;
^ (unsigned long)&mix
^ counter++;
return (uint16_t)(mix & 0xf);
}