sfinx

sphincs+ inspired signing utility
git clone git://git.finwo.net/app/sfinx
Log | Files | Refs | README | LICENSE

test_sign_verify.sh (2722B)


      1 #!/bin/sh
      2 set -eu
      3 HERE=$(cd "$(dirname "$0")" && pwd)
      4 ROOT=$(cd "${HERE}/.." && pwd)
      5 . "${HERE}/_tap.sh"
      6 
      7 BIN=$(ensure_bin "${ROOT}")
      8 TMP=$(mktemp -d)
      9 trap 'rm -rf "${TMP}"' EXIT
     10 
     11 tap_begin "cli: sign and verify"
     12 
     13 "${BIN}" seed -o "${TMP}/seed.bin"
     14 "${BIN}" printkey --in-fmt raw -k "${TMP}/seed.bin" -p 2 -o "${TMP}/key.hdr"
     15 "${BIN}" printkey -k "${TMP}/key.hdr" --public-only -o "${TMP}/pub.hdr"
     16 
     17 "${BIN}" sign -k "${TMP}/key.hdr" -m hello -P 0011 -o "${TMP}/sig.bin"
     18 "${BIN}" verify -k "${TMP}/pub.hdr" -m hello -S "${TMP}/sig.bin" >/dev/null && ok=1 || ok=0
     19 tap "${ok}" "raw signature file round trip" "failed"
     20 
     21 "${BIN}" sign -k "${TMP}/key.hdr" -m hello -P 0011 -o "${TMP}/a.bin"
     22 "${BIN}" sign -k "${TMP}/key.hdr" -m hello -P 0011 -o "${TMP}/b.bin"
     23 cmp -s "${TMP}/a.bin" "${TMP}/b.bin" && ok=1 || ok=0
     24 tap "${ok}" "fixed path is deterministic" "differs"
     25 
     26 HEX=$("${BIN}" sign -k "${TMP}/key.hdr" -m hello -P 0011)
     27 "${BIN}" verify -k "${TMP}/pub.hdr" -m hello -s "${HEX}" >/dev/null && ok=1 || ok=0
     28 tap "${ok}" "hex signature with -s" "failed"
     29 
     30 "${BIN}" sign -k "${TMP}/key.hdr" -m hello -P 0011 --sig-fmt hdr |
     31   "${BIN}" verify -k "${TMP}/pub.hdr" -m hello >/dev/null && ok=1 || ok=0
     32 tap "${ok}" "hdr signature auto-detected from stdin" "failed"
     33 
     34 "${BIN}" printkey -k "${TMP}/key.hdr" --public-only --out-fmt rawpub >"${TMP}/pub.bin"
     35 "${BIN}" sign --key-fmt raw -k "${TMP}/seed.bin" -m hello -P 0011 --sig-fmt hex -o "${TMP}/sig.hex"
     36 "${BIN}" verify --key-fmt rawpub -k "${TMP}/pub.bin" -p 2 --sig-fmt hex -m hello -S "${TMP}/sig.hex" >/dev/null &&
     37   ok=1 || ok=0
     38 tap "${ok}" "explicit key-fmt and sig-fmt round trip" "failed"
     39 
     40 "${BIN}" printkey -k "${TMP}/key.hdr" --public-only --out-fmt hexpub >"${TMP}/pub.hex"
     41 "${BIN}" verify --key-fmt hexpub -k "${TMP}/pub.hex" -p 2 -m hello -S "${TMP}/sig.bin" >/dev/null && ok=1 || ok=0
     42 tap "${ok}" "hexpub key reads back" "failed"
     43 
     44 printf 'hello' >"${TMP}/msg"
     45 "${BIN}" verify -k "${TMP}/pub.hdr" -M "${TMP}/msg" -S "${TMP}/sig.bin" >/dev/null && ok=1 || ok=0
     46 tap "${ok}" "message from a file" "failed"
     47 
     48 printf 'hello' | "${BIN}" verify -k "${TMP}/pub.hdr" -S "${TMP}/sig.bin" >/dev/null && ok=1 || ok=0
     49 tap "${ok}" "message from stdin" "failed"
     50 
     51 rc=0
     52 "${BIN}" verify -k "${TMP}/pub.hdr" -m nope -S "${TMP}/sig.bin" >/dev/null 2>&1 || rc=$?
     53 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "tampered message fails" "exit ${rc}"
     54 
     55 rc=0
     56 "${BIN}" verify -k "${TMP}/pub.hdr" -m hello -L 512 -S "${TMP}/sig.bin" >/dev/null 2>&1 || rc=$?
     57 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "hash mismatch fails" "exit ${rc}"
     58 
     59 rc=0
     60 "${BIN}" verify -k "${TMP}/pub.hdr" >/dev/null 2>&1 || rc=$?
     61 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "both inputs on stdin fails" "exit ${rc}"
     62 
     63 tap_plan