lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

check-implementation.sh (2153B)


      1 #!/bin/bash
      2 
      3 set -eu
      4 shopt -s extglob
      5 
      6 # Run NIST's genkat_aead.c against the reference implementation as
      7 # well as another one, and compare vectors.
      8 
      9 TEST_DIR=$(dirname $0)
     10 ROOT_DIR=${TEST_DIR}/..
     11 
     12 implem=$1
     13 
     14 
     15 list-implementation-files ()
     16 {
     17     local mode=$1
     18     local key_length=$2
     19     local src_dir=${ROOT_DIR}/src
     20 
     21     # src/${implem} can contain arbitrary files; we need to copy
     22     # everything save for the unused AE mode.
     23 
     24     for f in ${src_dir}/${implem}/!(lilliput-i|lilliput-ii).[ch]
     25     do
     26         echo ${f}
     27     done
     28 
     29     echo ${src_dir}/${implem}/lilliput-${mode}.c
     30     echo ${src_dir}/${mode}-${key_length}/parameters.h
     31 }
     32 
     33 run-genkat ()
     34 {
     35     local tmp_dir=$1
     36     local implem=$2
     37     local mode=$3
     38     local keylen=$4
     39     echo -e "    ${mode}-${keylen}…"
     40 
     41     local src_dir=${ROOT_DIR}/src
     42     local vectors_dir=${tmp_dir}/vectors/${implem}
     43     local genkat_dir=${tmp_dir}/genkat/${implem}/${mode}-${keylen}
     44     local genkat=${genkat_dir}/genkat
     45 
     46     local source_files=(
     47         cipher.{c,h}
     48         constants.h
     49         lilliput-ae{.h,-utils.h}
     50         lilliput-${mode}.c
     51         tweakey.{c,h}
     52     )
     53 
     54     mkdir -p ${genkat_dir}  # "-p" allows comparing ref against ref.
     55 
     56     list-implementation-files ${mode} ${keylen} | xargs cp -t ${genkat_dir}
     57 
     58     cp ${ROOT_DIR}/nist/{api.h,encrypt.c} ${genkat_dir}
     59     cp ${ROOT_DIR}/nist/TestVectorGen/* ${genkat_dir}
     60 
     61     local nist_flags=(-std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2)
     62 
     63     gcc ${nist_flags[@]} -I${genkat_dir} ${genkat_dir}/*.c -o ${genkat}
     64 
     65     ${genkat}
     66     mv LWC_AEAD_KAT*.txt ${vectors_dir}/${mode}-${keylen}
     67 }
     68 
     69 
     70 test-implem ()
     71 {
     72     local tmp_dir=$1
     73     local implem=$2
     74     echo "Generating vectors for implementation ${implem}…"
     75 
     76     mkdir -p ${tmp_dir}/{genkat,vectors}/${implem}
     77 
     78     local mode
     79     local keylen
     80 
     81     for mode in i ii
     82     do
     83         for keylen in 128 192 256
     84         do
     85             run-genkat ${tmp_dir} ${implem} ${mode} ${keylen}
     86         done
     87     done
     88 }
     89 
     90 
     91 tmp_dir=$(mktemp -d)
     92 
     93 test-implem ${tmp_dir} ref
     94 test-implem ${tmp_dir} ${implem}
     95 
     96 diff --brief --new-file --recursive ${tmp_dir}/vectors/ref ${tmp_dir}/vectors/${implem}