summaryrefslogtreecommitdiff
path: root/test/check-implementation.sh
blob: 985ff04506ecefd1aa3affc6d1fcb42772081704 (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
#!/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})