From 8d4001096b346ac8d962f68c9a938cb725fc53b1 Mon Sep 17 00:00:00 2001 From: Alexander Wagner Date: Tue, 7 Mar 2023 16:18:07 +0100 Subject: [PATCH] cryptolib/botan: Add DES scripts --- cryptolib/botan/algo_des/.gitignore | 1 + cryptolib/botan/algo_des/data_run.sh | 24 +++++ cryptolib/botan/algo_des/framework.sh | 139 ++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 cryptolib/botan/algo_des/.gitignore create mode 100755 cryptolib/botan/algo_des/data_run.sh create mode 100755 cryptolib/botan/algo_des/framework.sh diff --git a/cryptolib/botan/algo_des/.gitignore b/cryptolib/botan/algo_des/.gitignore new file mode 100644 index 0000000..fbca225 --- /dev/null +++ b/cryptolib/botan/algo_des/.gitignore @@ -0,0 +1 @@ +results/ diff --git a/cryptolib/botan/algo_des/data_run.sh b/cryptolib/botan/algo_des/data_run.sh new file mode 100755 index 0000000..cad78b7 --- /dev/null +++ b/cryptolib/botan/algo_des/data_run.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +PINFLAGS="--phase1 --phase2 --export --parallel" +export RESULTDIR=results + + +pushd ${BASH_SOURCE%/*} + +if [[ $1 == "clean" || $2 == "clean" ]]; then + rm -rf results +fi + +./framework.sh ${PINFLAGS} DES 64 CBC + +if [[ $1 == "test" || $2 == "test" ]]; then + popd + exit 0 +fi + +./framework.sh ${PINFLAGS} 3DES 192 CBC + +popd diff --git a/cryptolib/botan/algo_des/framework.sh b/cryptolib/botan/algo_des/framework.sh new file mode 100755 index 0000000..7f65ad8 --- /dev/null +++ b/cryptolib/botan/algo_des/framework.sh @@ -0,0 +1,139 @@ + + +######################################################################### +# DO NOT CHANGE: Preparing DATA +#------------------------------------------------------------------------ +source "${DATA_COMMON}/DATA_init.sh" || { echo "source data.sh first!" && exit 1; } +######################################################################### + +#------------------------------------------------------------------------ +# Specify your framework settings used by DATA +#------------------------------------------------------------------------ + +# The name of the framework. Do not use spaces or special characters. +export FRAMEWORK=botan + +# The file containing all supported algorithms +export TARGETFILE=targets.txt + +# The number of measurements for difference detection (phase1) +export PHASE1_TRACES=3 + +# The number of constant keys for generic tests (phase2) +# Make sure that PHASE2_FIXEDKEYS <= PHASE1_TRACES +export PHASE2_FIXEDKEYS=3 + +# The number of measurements per constant key for generic tests (phase2) +export PHASE2_TRACES=100 + +# The number of measurements for specific tests (phase3) +export PHASE3_TRACES=300 + +# (Optional) Additional flags for the pintool. Supported flags are: +# -main
Start recording at function
. Note that the
+# symbol must exist, otherwise this will yield empty traces! +# -heap Trace heap allocations and replace heap addresses with +# relative offset +export PINTOOL_ARGS="-heap" + +#------------------------------------------------------------------------ +# Implement your framework-specific callbacks +#------------------------------------------------------------------------ +# +# Globally available environment variables: +# $FRAMEWORK The framework name +# $BASEDIR The absolute directory path of this script +# $DATA_COMMON The absolute directory for common DATA scripts +# $DATA_LEAKAGE_MODELS The absolute directory for DATA leakage models +# +# Available for cb_genkey, cb_pre_run, cb_run_command, cb_post_run +# $ALGO The currently tested algo +# +# Available for cb_pre_run, cb_run_command, cb_post_run +# $ENVFILE + +export BINARY=${PWD}/../botan/botan + +# The leakage model of phase 3. +# See ${DATA_LEAKAGE_MODELS} for all options. +export SPECIFIC_LEAKAGE_CALLBACK=${DATA_LEAKAGE_MODELS}/sym_byte_value.py + +# DATA callback for setting up the framework to analyze. This callback +# is invoked once inside the current directory before analysis starts. +# Implement framework-specific tasks here like framework compilation. +function cb_prepare_framework { + : +} + +# DATA callback for generating keys. This callback is invoked every +# time a new key is needed. Implement key generation according to +# your algorithm and store the generated key inside a file named $2. +# +# $1 ... key file name +function cb_genkey { + "${DATA_COMMON}"/genkey.py "${KEYBYTES}" > "$1" + RES=$((RES + $?)) +} + +# DATA callback for custom commands that are executed immediately before +# the algorithm is profiled. It is executed in a temporary directory +# which contains the keyfile $1 and ${ENVFILE}. +# +# If 'cb_run_command' needs any other files, copy them to ${PWD}. +# +# $1 ... key file name +function cb_pre_run { + log_verbose "running with key $1" + echo "hello" > input.bin + echo "LD_LIBRARY_PATH=${BINARY}" >> ${ENVFILE} +} + +# DATA callback for the main invocation of the tested algorithm. +# It shall return the bash command to execute as string. It is +# executed inside a temporary directory with a clean environment. +# If you need special files or environment variables set, specify +# them in cb_pre_run. +# +# $1 ... key file name +function cb_run_command { + HEXKEY=$(cat "$1") + echo "${BINARY} cipher --cipher=${ALGO}/${MODE} --key=${HEXKEY} input.bin" +} + +# DATA callback for custom commands that are executed immediately after +# the algorithm is profiled. It is executed in a temporary directory. +# You can cleanup any custom files generated by your algorithm. +# +# $1 ... key file name +function cb_post_run { + : +} + +# DATA callback for preparing an individual algorithm. It shall: +# 1. Parse the next algorithm from the commandline string of all algorithms +# and set up anything necessary for analyzing this algorithm. +# If the algorithm needs additional parameters (like key sizes), +# increase $SHIFT accordingly. +# 2. Configure $WORKDIR, which will create a subdirectory holding all +# intermediate files generated by the algorithm and the results. +# Do not use an absolute path! +# +# $* ... algorithm string from the commandline +function cb_prepare_algo { + ALGO=$1 + # key bits + PARAM=$2 + MODE=$3 + SHIFT=$((SHIFT+2)) + KEYBYTES=$(( PARAM / 8 )) + + WORKDIR="$ALGO-$MODE-$PARAM" +} + +######################################################################### +# DO NOT CHANGE: Running DATA's commandline parser +#------------------------------------------------------------------------ +DATA_parse "$@" +#------------------------------------------------------------------------ +# DO NOT ADD CODE AFTER THIS LINE +#########################################################################