summaryrefslogtreecommitdiff
path: root/test/check-implementation.sh
blob: f2c32eddd3ddfd4f7059b9ef55a258044e2bac4d (plain)
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
#!/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_DIR=${TEST_DIR}/..

implem=$1


run-genkat ()
{
    local tmp_dir=$1
    local implem=$2
    local mode=$3
    local keylen=$4
    echo "Testing mode ${mode}-${keylen}…"

    local src_dir=${ROOT_DIR}/src
    local vectors_dir=${tmp_dir}/vectors/${implem}
    local genkat_dir=${tmp_dir}/genkat/${implem}/${mode}-${keylen}
    local genkat=${genkat_dir}/genkat

    local source_files=(
        cipher.{c,h}
        constants.h
        lilliput-ae{.h,-utils.h,-${mode}.c}
        tweakey.{c,h}
    )

    mkdir -p ${genkat_dir}  # "-p" to allow comparing ref against ref.

    local f
    for f in ${source_files[@]}
    do
        cp ${src_dir}/${implem}/${f} ${genkat_dir}
    done

    cp ${src_dir}/${mode}-${keylen}/parameters.h ${genkat_dir}
    cp ${ROOT_DIR}/nist/{api.h,encrypt.c} ${genkat_dir}
    cp ${ROOT_DIR}/nist/TestVectorGen/* ${genkat_dir}

    local nist_flags=(-std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2)

    gcc ${nist_flags[@]} -Werror -I${genkat_dir} ${genkat_dir}/*.c -o ${genkat}

    ${genkat}
    mv LWC_AEAD_KAT*.txt ${vectors_dir}/${mode}-${keylen}
}


test-implem ()
{
    local tmp_dir=$1
    local implem=$2
    echo "Testing implementation ${implem}…"

    mkdir -p ${tmp_dir}/{genkat,vectors}/${implem}

    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
}


tmp_dir=$(mktemp -d)

test-implem ${tmp_dir} ref
test-implem ${tmp_dir} ${implem}

diff --brief --new-file --recursive ${tmp_dir}/vectors/ref ${tmp_dir}/vectors/${implem}