summaryrefslogtreecommitdiff
path: root/nist/make-package.sh
blob: 124da4b411fc1e0e380090c0018c2d6832fa7f4c (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
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
#!/bin/bash

set -Eeu
shopt -s extglob

# Generate NIST's expected tree:
#
# crypto_aead
# │
# └── lilliputae${mode}${keylen}v1
#     │
#     ├── add_${someimplementation}
#     │   ├── api.h
#     │   └── encrypt.c
#     │
#     ├── add_${someplatform}
#     │   ├── api.h
#     │   └── encrypt.c
#     │
#     ├── ref
#     │   ├── api.h
#     │   └── encrypt.c
#     │
#     └── LWC_AEAD_KAT_${keylen}_120.txt

NIST_DIR=$(dirname $0)
ROOT=${NIST_DIR}/..
TMP_DIR=$(mktemp -d)

cleanup ()
{
    rm -r ${TMP_DIR}
}

trap cleanup ERR


list-implementation-files ()
{
    local mode=$1
    local key_length=$2
    local implem=$3

    # src/${implem} can contain arbitrary files; we need to copy
    # everything save for the unused AE mode.

    local f
    for f in ${ROOT}/src/${implem}/!(lilliput-i|lilliput-ii).[ch]
    do
        echo ${f}
    done

    echo ${ROOT}/src/${implem}/lilliput-${mode}.c
    echo ${ROOT}/src/${mode}-${key_length}/parameters.h
}

add-variant ()
{
    mode=$1
    key_length=$2
    variant=lilliputae${mode}${key_length}v1
    dest=${TMP_DIR}/crypto_aead/${variant}

    mkdir -p ${dest}

    implementations=(
        ref
        add_threshold
        add_tweakeyloop
    )

    for implem in ${implementations[@]}
    do
        mkdir ${dest}/${implem}

        list-implementation-files ${mode} ${key_length} ${implem} |
            xargs cp -t ${dest}/${implem}

        cp ${NIST_DIR}/{api.h,encrypt.c} ${dest}/${implem}
    done
}

test-variant ()
{
    mode=$1
    key_length=$2
    variant=lilliputae${mode}${key_length}v1
    dest=${TMP_DIR}/crypto_aead/${variant}
    src=${dest}/ref

    genkat=${TMP_DIR}/${variant}

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

    gcc ${nist_flags[@]} -Werror -I${src} -I${TMP_DIR} \
         ${src}/*.c ${TMP_DIR}/genkat_aead.c -o ${genkat}

    ${genkat}

    mv LWC_AEAD_KAT_${key_length}_120.txt ${dest}
}


cp ${NIST_DIR}/TestVectorGen/* ${TMP_DIR}

for mode in i ii
do
    for key_length in 128 192 256
    do
        add-variant ${mode} ${key_length}
        test-variant ${mode} ${key_length}
    done
done

cp -r ${TMP_DIR}/crypto_aead .

cleanup