mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user