-
Notifications
You must be signed in to change notification settings - Fork 17
/
build-and-test.sh
executable file
·42 lines (32 loc) · 1.11 KB
/
build-and-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
41
42
#!/bin/sh -e
printf 'Building... '
for bin in encrypt decrypt; do
gcc -Wall -nostdlib -o $bin $bin.s
done
printf 'done.\n'
n=$(wc -l < test-vectors)
i=1
# Read test vectors from a file and test them.
#
# This includes the NIST test vectors [1] as well as some multiblock
# test cases generated by me.
#
# These are stored as octal escapes because POSIX printf(1) lacks
# \x syntax. Never mind that the binaries are for amd64 Linux
# only; the test script must be as portable as possible!
#
# [1] http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip
cat test-vectors | while read -r key plaintext ciphertext; do
printf "\rTesting %3d of %3d" $i $n
# Using process substitution with <(...) would be nicer
# here, but it doesn't work reliably (FIXME: why?)
printf "$plaintext" > expected_pt
printf "$ciphertext" > expected_ct
printf "$key$plaintext" | ./encrypt > actual_ct
printf "$key$ciphertext" | ./decrypt > actual_pt
cmp expected_pt actual_pt
cmp expected_ct actual_ct
i=$(expr $i + 1)
done
printf '\rTesting... done. \n'
rm expected_pt expected_ct actual_pt actual_ct