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

make-package.sh (2428B)


      1 #!/bin/bash
      2 
      3 set -Eeu
      4 shopt -s extglob
      5 
      6 # Generate NIST's expected tree:
      7 #
      8 # crypto_aead
      9 # │
     10 # └── lilliputae${mode}${keylen}v${VERSION}
     11 #     │
     12 #     ├── add_${someimplementation}
     13 #     │   ├── api.h
     14 #     │   └── encrypt.c
     15 #     │
     16 #     ├── add_${someplatform}
     17 #     │   ├── api.h
     18 #     │   └── encrypt.c
     19 #     │
     20 #     ├── ref
     21 #     │   ├── api.h
     22 #     │   └── encrypt.c
     23 #     │
     24 #     └── LWC_AEAD_KAT_${keylen}_120.txt
     25 
     26 NIST_DIR=$(dirname $0)
     27 ROOT=${NIST_DIR}/..
     28 TMP_DIR=$(mktemp -d)
     29 
     30 VERSION=$(${NIST_DIR}/version.sh)
     31 
     32 
     33 cleanup ()
     34 {
     35     rm -r ${TMP_DIR}
     36 }
     37 
     38 trap cleanup ERR
     39 
     40 
     41 list-implementation-files ()
     42 {
     43     local mode=$1
     44     local key_length=$2
     45     local implem=$3
     46 
     47     # src/${implem} can contain arbitrary files; we need to copy
     48     # everything save for the unused AE mode.
     49 
     50     local f
     51     for f in ${ROOT}/src/${implem}/!(lilliput-i|lilliput-ii).[ch]
     52     do
     53         echo ${f}
     54     done
     55 
     56     echo ${ROOT}/src/${implem}/lilliput-${mode}.c
     57     echo ${ROOT}/src/${mode}-${key_length}/parameters.h
     58 }
     59 
     60 add-variant ()
     61 {
     62     mode=$1
     63     key_length=$2
     64     variant=lilliputae${mode}${key_length}v${VERSION}
     65     dest=${TMP_DIR}/crypto_aead/${variant}
     66 
     67     mkdir -p ${dest}
     68 
     69     implementations=(
     70         ref
     71         add_felicsref
     72         add_threshold
     73         add_tweakeyloop
     74     )
     75 
     76     for implem in ${implementations[@]}
     77     do
     78         mkdir ${dest}/${implem}
     79 
     80         list-implementation-files ${mode} ${key_length} ${implem} |
     81             xargs cp -t ${dest}/${implem}
     82 
     83         cp ${NIST_DIR}/{api.h,encrypt.c} ${dest}/${implem}
     84     done
     85 }
     86 
     87 test-variant ()
     88 {
     89     mode=$1
     90     key_length=$2
     91     variant=lilliputae${mode}${key_length}v${VERSION}
     92     dest=${TMP_DIR}/crypto_aead/${variant}
     93     src=${dest}/ref
     94 
     95     genkat=${TMP_DIR}/${variant}
     96 
     97     nist_flags=(-std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2)
     98 
     99     gcc ${nist_flags[@]} -Werror -I${src} -I${TMP_DIR} \
    100          ${src}/*.c ${TMP_DIR}/genkat_aead.c -o ${genkat}
    101 
    102     ${genkat}
    103 
    104     mv LWC_AEAD_KAT_${key_length}_120.txt ${dest}
    105 }
    106 
    107 
    108 cp ${NIST_DIR}/TestVectorGen/* ${TMP_DIR}
    109 
    110 for mode in i ii
    111 do
    112     for key_length in 128 192 256
    113     do
    114         add-variant ${mode} ${key_length}
    115         test-variant ${mode} ${key_length}
    116     done
    117 done
    118 
    119 ${NIST_DIR}/package-python.sh ${TMP_DIR}
    120 ${NIST_DIR}/package-vhdl.sh ${TMP_DIR}
    121 
    122 cp -r ${TMP_DIR}/crypto_aead .
    123 
    124 cleanup
    125