From a92d247884468d37ede093391a4ac54293d74863 Mon Sep 17 00:00:00 2001 From: Eneas U de Queiroz Date: Mon, 27 May 2024 16:40:53 -0300 Subject: [PATCH] gost_engine: add CI test Thi adds one MD and one cipher test from upstream, adapted to a shell script. Signed-off-by: Eneas U de Queiroz --- libs/gost_engine/test.sh | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 libs/gost_engine/test.sh diff --git a/libs/gost_engine/test.sh b/libs/gost_engine/test.sh new file mode 100644 index 0000000000..b2cef4b33f --- /dev/null +++ b/libs/gost_engine/test.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# shellcheck disable=SC2059 + +run_md_test () { + [ $# -ge 3 ] || { + echo "Error: insufficient args to run_md_test()" >&2 + exit 1 + } + DGST="$1"; shift + INP="$1"; shift + EXP="$1"; shift + printf "Testing digest %s: " "$DGST" >&2 + OUT="$(printf "$INP" | openssl dgst -"$DGST" "$@")" || exit 1 + [ -z "${OUT%%*"$EXP"}" ] || { + printf "Failure: expected: '%s', got '%s'\n" "$EXP" "$OUT" >&2 + exit 1 + } + echo OK >&2 || true +} + +run_cipher_test() { + [ $# -ge 5 ] || { + echo "Error: insufficient args to run_cipher_test()" >&2 + exit 1 + } + ALG="$1"; shift + KEY="$1"; shift + IV="$1"; shift + CLEAR_TEXT="$1"; shift + CIPHER_TEXT="$1"; shift + printf "Testing %s encryption: " "$ALG" >&2 + OUT="$(printf "$CLEAR_TEXT" | openssl enc -e -"$ALG" -K "$KEY" -iv "$IV" "$@" -a -A)" || exit 1 + [ -z "${OUT%"$CIPHER_TEXT"}" ] || { + printf "Encryption failure: expected: '%s', got '%s'\n" "$CIPHER_TEXT" "$OUT" >&2 + exit 1 + } + echo OK >&2 + printf "Testing %s decryption: " "$ALG" >&2 + OUT="$(printf "$CIPHER_TEXT" | openssl enc -d -"$ALG" -K "$KEY" -iv "$IV" "$@" -a -A)" || exit 1 + [ -z "${OUT%"$(printf "$CLEAR_TEXT")"}" ] || { + echo "Decryption failure!" >&2 + echo "----------- expected hexdump -------------" >&2 + printf "$CLEAR_TEXT" | hexdump -C + echo "------------ result hexdump --------------" >&2 + echo "$OUT" | hexdump -C >&2 + exit 1 + } + echo OK >&2 || true +} + +case "$1" in + libopenssl-gost_engine) + opkg install openssl-util + run_md_test \ + md_gost12_256 \ + 012345678901234567890123456789012345678901234567890123456789012 \ + 9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500 + export CRYPT_PARAMS="1.2.643.2.2.31.1" + run_cipher_test \ + gost89 \ + 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF \ + 0000000000000000 \ + "The quick brown fox jumps over the lazy dog\n" \ + "B/QQLGGFxKCeZ24mm/pLycXfZXWRa4eb0TqJOiKF7maQEHze73oxXS61S/o=" + ;; + gost_engine-util) + printf "Testing gost12sum: " + EXP=9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500 + OUT=$(printf 012345678901234567890123456789012345678901234567890123456789012 | gost12sum) + [ -z "${OUT##"$EXP"*}" ] || { + printf "Failure: expected: '%s', got '%s'\n" "$EXP" "$OUT" >&2 + exit 1 + } + echo OK >&2 || true + ;; + *) + echo "Unexpected package '$1'" >&2 + exit 1 + ;; +esac -- 2.30.2