mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-21 19:26:22 +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;
|
struct timeval tv;
|
||||||
unsigned long mix;
|
unsigned long mix;
|
||||||
|
static unsigned long counter = 0;
|
||||||
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
mix = (unsigned long)tv.tv_sec
|
mix = (unsigned long)tv.tv_sec
|
||||||
^ (unsigned long)tv.tv_usec
|
^ (unsigned long)tv.tv_usec
|
||||||
^ (unsigned long)getpid()
|
^ (unsigned long)getpid()
|
||||||
^ (unsigned long)(uintptr_t)&mix;
|
^ (unsigned long)&mix
|
||||||
|
^ counter++;
|
||||||
|
|
||||||
return (uint16_t)(mix & 0xf);
|
return (uint16_t)(mix & 0xf);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user