-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.sh
executable file
·40 lines (32 loc) · 917 Bytes
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /bin/bash
test_hmac() {
opensslhmac=`echo -n "$1" | openssl sha256 -hmac "$2" | cut -d ' ' -f 2`
mymac=`echo -n "$1" | ./hmacsha256 "$2"`
if [[ "$opensslhmac" != "$mymac" ]]; then
echo "openssl disagrees!"
echo "$1" > baddata.txt
echo "$2" > badkey.txt
exit 1
fi
}
echo "Testing short keys"
for i in {0..960}; do
data=`dd if=/dev/urandom bs=1 count=$i 2> /dev/null`
keylen=$(($i / 16))
key=`dd if=/dev/urandom bs=1 count=$keylen 2> /dev/null`
test_hmac "$data" "$key"
done
echo "Testing 64 byte keys"
for i in {0..1024}; do
data=`dd if=/dev/urandom bs=1 count=$i 2> /dev/null`
keylen=64
key=`dd if=/dev/urandom bs=1 count=$keylen 2> /dev/null`
test_hmac "$data" "$key"
done
echo "Testing long keys"
for i in {0..1024}; do
data=`dd if=/dev/urandom bs=1 count=$i 2> /dev/null`
keylen=$(($i + 64))
key=`dd if=/dev/urandom bs=1 count=$keylen 2> /dev/null`
test_hmac "$data" "$key"
done