-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtvtest.sh
executable file
·134 lines (120 loc) · 3.61 KB
/
tvtest.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# set -x
# Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
#
# An OpenSSL-based HPKE implementation of RFC9180
#
# run through all the ciphesuite and mode options and see
# what happens
# just in case...
BINDIR=$HOME/code/happykey
# LD_LIBRARY_PATH...
. $BINDIR/env
if [ ! -f $BINDIR/hpkemain ]
then
echo "You probably need to run make first ..."
exit 1
fi
# check hpkemain is built with testvectors
$BINDIR/hpkemain -T -h >/dev/null 2>&1
res=$?
if [[ "$res" != "0" ]]
then
echo "You need to build hpkemain with testvectors - see README.md"
exit 2
fi
function usage()
{
echo "$0 [-hvV] - test HPKE test vectors"
echo " -t <file> to use the given test vector file"
echo " -h means print this"
echo " -v means be verbose"
echo " -s means be super-verbose"
echo " -V means run with valgrind"
exit 99
}
# default values for parameters
verbose="no"
superverbose="no"
VG="no"
# test vectors file
TVFILE="test-vectors-08.json"
# options may be followed by one colon to indicate they have a required argument
if ! options=$(/usr/bin/getopt -s bash -o hst:vV -l help,super,testvectors:,verbose,valgrind -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi
#echo "|$options|"
eval set -- "$options"
while [ $# -gt 0 ]
do
case "$1" in
-h|--help) usage;;
-s|--super) superverbose="yes" ;;
-t|--testvectors) TVFILE=$2; shift ;;
-v|--verbose) verbose="yes" ;;
-V|--valgrind) VG="yes" ;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
goodcnt=0
badcnt=0
notvcnt=0
for mode in base psk auth pskauth
do
for kem in 0x10 0x11 0x12 0x20 0x21
do
for kdf in 1 2 3
do
for aead in 1 2 3
do
if [[ "$VG" == "yes" ]]
then
VALGRIND="valgrind --leak-check=full --show-leak-kinds=all"
$VALGRIND $BINDIR/hpkemain -T$TVFILE -m $mode -c $kem,$kdf,$aead
else
if [[ "$superverbose" == "yes" ]]
then
echo "====="
echo "Running: $BINDIR/hpkemain -T$TVFILE -m $mode -c $kem,$kdf,$aead"
$BINDIR/hpkemain -T$TVFILE -m $mode -c $kem,$kdf,$aead
else
$BINDIR/hpkemain -T$TVFILE -m $mode -c $kem,$kdf,$aead >/dev/null 2>&1
fi
fi
res=$?
if [[ "$res" == "0" ]]
then
if [[ "$verbose" == "yes" ]]
then
echo "$mode,$kem,$kdf,$aead is good"
fi
goodcnt=$((goodcnt+1))
elif [[ "$res" == "2" ]]
then
if [[ "$verbose" == "yes" ]]
then
echo "No test vector for: $mode,$kem,$kdf,$aead"
fi
notvcnt=$((notvcnt+1))
else
if [[ "$verbose" == "yes" ]]
then
echo "$mode,$kem,$kdf,$aead is BAD!"
fi
badcnt=$((badcnt+1))
fi
done
done
done
done
echo "Good: $goodcnt, Bad: $badcnt, No test vector: $notvcnt"