diff options
Diffstat (limited to 'test/check-implementation.sh')
| -rwxr-xr-x | test/check-implementation.sh | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/check-implementation.sh b/test/check-implementation.sh new file mode 100755 index 0000000..985ff04 --- /dev/null +++ b/test/check-implementation.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +set -eu + +# Run NIST's genkat_aead.c against the reference implementation as +# well as another one, and compare vectors. + +TEST_DIR=$(dirname $0) +ROOT=${TEST_DIR}/.. + +implem=$1 + + +run-genkat () +{ + local tmp_dir=$1 + local implem=$2 + local mode=$3 + local keylen=$4 + + local src_dir=${ROOT}/src/ + + local source_files=( + ae-common.h + cipher.{c,h} + lilliput-ae{.h,-${mode}.c} + parameters.h + tweakey.{c,h} + ) + + local f + for f in ${source_files[@]} + do + cp ${src_dir}/${implem}/${f} ${tmp_dir} + done + + cp ${src_dir}/${mode}-${keylen}/_parameters.h ${tmp_dir} + cp ${ROOT_DIR}/nist/{api.h,encrypt.c} ${tmp_dir} + + local nist_flags=(-std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2) + + gcc ${nist_flags[@]} -Werror -I${tmp_dir} -o ${tmp_dir}/genkat + ( + cd ${tmp_dir} + ./genkat + cat LWC_AEAD_KAT*.txt + ) +} + + +test-implem () +{ + local implem=$1 + local tmp_dir=$(mktemp -d) + + local mode + local keylen + + for mode in i ii + do + for keylen in 128 192 256 + do + run-genkat ${tmp_dir} ${implem} ${mode} ${keylen} + done + done + + rm -r ${tmp_dir} +} + + +diff -u <(test-implem ref) <(test-implem ${implem}) |
