diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-28 03:10:46 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-28 03:10:46 +0000 |
| commit | cec9a25c2acadb6d62d25d9a43c8641b6078bd7d (patch) | |
| tree | 4b40daad351c74659369deb7f928164829cec20f /util/libreboot-utils/lib/num.c | |
| parent | f4f167090964186d65d1ee8b9676b7123b015e3b (diff) | |
nvmutil: clamp rand (rejection sampling)
clamp rand to eliminate modulo sampling; high
values on the randomisation will bias the result.
not really critical for mac addresses, but there's
no reason not to have this. this patches reduces
the chance that two libreboot users will generate
the same mac addresses!
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib/num.c')
| -rw-r--r-- | util/libreboot-utils/lib/num.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index d297ab86..f53f0cee 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -41,10 +41,8 @@ hextonum(char ch_s) if ((unsigned int)(ch - 'a') <= 5) return ch - 'a' + 10; - if (ch == '?' || ch == 'x') { - rset(&rval, sizeof(rval)); - return rval & 0xf; - } + if (ch == '?' || ch == 'x') + return rsize(16); /* <-- with rejection sampling! */ return 16; } |
