Commit | Line | Data |
---|---|---|
a98bca79 MW |
1 | #! /bin/bash |
2 | ||
3 | set -e -o pipefail | |
b2e9fb7e | 4 | prog=${0##*/} |
a98bca79 | 5 | |
b2e9fb7e | 6 | case $# in 1) ;; *) echo >&2 "usage: $prog DEV"; exit 127 ;; esac |
a98bca79 MW |
7 | dev=$1 |
8 | ||
9 | typeset -i sz; sz=$(blockdev --getsize64 "$dev") | |
10 | k=$(gorp -fhex 256) | |
11 | ||
12 | ## Figure out a useful block size. | |
13 | typeset -i bsz=1 nb=$sz | |
14 | for i in 2 3 5 7; do | |
15 | while :; do | |
16 | case $((nb%i)) in | |
17 | 0) bsz=$((bsz*i)) nb=$((nb/i)) ;; | |
18 | *) break ;; | |
19 | esac | |
20 | if (( bsz >= 65536 )); then break 2; fi | |
21 | done | |
22 | done | |
b2e9fb7e | 23 | echo >&2 "$prog: using $nb blocks of size $bsz" |
a98bca79 MW |
24 | |
25 | ## Write the initial stream. | |
b2e9fb7e | 26 | echo >&2 "$prog: writing pseudorandom pattern..." |
a98bca79 MW |
27 | rspit salsa20/8 -H$k -z$sz -pT | \ |
28 | dd status=none iflag=fullblock oflag=direct bs=$bsz count=$nb of="$dev" | |
b2e9fb7e | 29 | echo >&2 "$prog: writing pseudorandom pattern... done" |
a98bca79 MW |
30 | |
31 | ## Read the stream back, and check against the reference. | |
b2e9fb7e | 32 | echo >&2 "$prog: checking pseudorandom pattern..." |
a98bca79 MW |
33 | cmp <(rspit salsa20/8 -H$k -z$sz -pT) \ |
34 | <(dd status=none iflag=direct bs=$bsz count=$nb if="$dev") | |
b2e9fb7e MW |
35 | echo >&2 "$prog: checking pseudorandom pattern... done" |
36 | echo >&2 "$prog: all ok" |