diff options
author | 2017-06-26 17:00:49 +0000 | |
---|---|---|
committer | 2017-06-26 17:00:49 +0000 | |
commit | f1a3b71a2102e9f7987b4dc589a4639c09526c93 (patch) | |
tree | 35afd0c5c2b53092b88b9a2282bee508b4ee761f /sys | |
parent | Arrange a phandle for the "ciu" node. (diff) | |
download | wireguard-openbsd-f1a3b71a2102e9f7987b4dc589a4639c09526c93.tar.xz wireguard-openbsd-f1a3b71a2102e9f7987b4dc589a4639c09526c93.zip |
RANDOM1 was subject to rather bad modulus bias. Improve the situation a bit
by implementing an arc4random_uniform(3) clone with beloved jot(1) and
using it.
discussed with and ok deraadt
Diffstat (limited to 'sys')
-rw-r--r-- | sys/conf/makegap.sh | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/sys/conf/makegap.sh b/sys/conf/makegap.sh index ddf16ffe7e6..e104163fb48 100644 --- a/sys/conf/makegap.sh +++ b/sys/conf/makegap.sh @@ -1,16 +1,28 @@ #!/bin/sh - +random_uniform() { + local _upper_bound + + if [[ $1 -gt 0 ]]; then + _upper_bound=$(($1 - 1)) + else + _upper_bound=0 + fi + + echo `jot -r 1 0 $_upper_bound 2>/dev/null` +} + umask 007 PAGE_SIZE=`sysctl -n hw.pagesize` PAD=$1 GAPDUMMY=$2 -RANDOM1=$((RANDOM % (3 * PAGE_SIZE))) -RANDOM2=$((RANDOM % PAGE_SIZE)) -RANDOM3=$((RANDOM % PAGE_SIZE)) -RANDOM4=$((RANDOM % PAGE_SIZE)) -RANDOM5=$((RANDOM % PAGE_SIZE)) +RANDOM1=`random_uniform $((3 * PAGE_SIZE))` +RANDOM2=`random_uniform $PAGE_SIZE` +RANDOM3=`random_uniform $PAGE_SIZE` +RANDOM4=`random_uniform $PAGE_SIZE` +RANDOM5=`random_uniform $PAGE_SIZE` cat > gap.link << __EOF__ |