diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-12 14:35:01 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-12 14:36:01 +0000 |
| commit | f04b796dcce93be266234a9220ab0f42c5eec5ff (patch) | |
| tree | 956d6ca7b8d8af41f1ebb523abef74a1cdc9e859 | |
| parent | 38c3889f67d91d9b4d4295514a08603b7db9f9c7 (diff) | |
util/nvmutil: add jitter to fallback_rand entropy
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 846eb2c3..3608c439 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -164,6 +164,7 @@ static void set_mac_nib(size_t mac_str_pos, static uint16_t hextonum(char ch_s); static uint16_t rhex(void); static uint16_t fallback_rand(void); +static unsigned long entropy_jitter(void); static void write_mac_part(size_t partnum); /* @@ -1034,7 +1035,8 @@ fallback_rand(void) ^ (unsigned long)tv.tv_usec ^ (unsigned long)getpid() ^ (unsigned long)&mix - ^ counter++; + ^ counter++ + ^ entropy_jitter(); /* * Stack addresses can vary between @@ -1047,6 +1049,25 @@ fallback_rand(void) return (uint16_t)(mix & 0xf); } +static unsigned long +entropy_jitter(void) +{ + struct timeval a, b; + unsigned long mix = 0; + int i; + + for (i = 0; i < 8; i++) { + gettimeofday(&a, NULL); + getpid(); + gettimeofday(&b, NULL); + + mix ^= (unsigned long)(b.tv_usec - a.tv_usec); + mix ^= (unsigned long)&mix; + } + + return mix; +} + static void write_mac_part(size_t partnum) { |
