sfinx

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

test_single_mode.sh (2631B)


      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 bytes() {
     12   wc -c <"$1" | tr -d '[:space:]'
     13 }
     14 
     15 tap_begin "cli: single-key mode"
     16 
     17 "${BIN}" generate --single --out-fmt raw -o "${TMP}/s.key"
     18 tap "$([ "$(bytes "${TMP}/s.key")" = 32 ] && [ "$(bytes "${TMP}/s.pub")" = 32 ] && echo 1 || echo 0)" \
     19   "single generate writes a seed and a public key" "key $(bytes "${TMP}/s.key") pub $(bytes "${TMP}/s.pub")"
     20 
     21 "${BIN}" sign --single -k "${TMP}/s.key" -m hello -o "${TMP}/sig.bin"
     22 tap "$([ "$(bytes "${TMP}/sig.bin")" = 1090 ] && echo 1 || echo 0)" "single signature is size(0) bytes" \
     23   "got $(bytes "${TMP}/sig.bin")"
     24 
     25 "${BIN}" verify -k "${TMP}/s.pub" -m hello -S "${TMP}/sig.bin" >/dev/null && ok=1 || ok=0
     26 tap "${ok}" "single signature verifies with the public key" "failed"
     27 
     28 "${BIN}" sign --single -k "${TMP}/s.key" -m hello -o "${TMP}/a.bin"
     29 "${BIN}" sign --single -k "${TMP}/s.key" -m hello -o "${TMP}/b.bin"
     30 cmp -s "${TMP}/a.bin" "${TMP}/b.bin" && ok=1 || ok=0
     31 tap "${ok}" "single signing is deterministic" "differs"
     32 
     33 "${BIN}" printkey --in-fmt raw -k "${TMP}/s.key" --out-fmt rawpub --public-only >"${TMP}/tree.pub"
     34 cmp -s "${TMP}/tree.pub" "${TMP}/s.pub" && ok=0 || ok=1
     35 tap "${ok}" "single and tree public keys differ for one seed" "same key"
     36 
     37 rc=0
     38 "${BIN}" verify -k "${TMP}/tree.pub" -m hello -S "${TMP}/sig.bin" >/dev/null 2>&1 || rc=$?
     39 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "a tree public key rejects a single signature" "exit ${rc}"
     40 
     41 "${BIN}" printkey --in-fmt raw -k "${TMP}/s.key" --single --out-fmt rawpub --public-only >"${TMP}/single.pub"
     42 cmp -s "${TMP}/single.pub" "${TMP}/s.pub" && ok=1 || ok=0
     43 tap "${ok}" "printkey --single matches the generated public key" "differs"
     44 
     45 "${BIN}" generate --single -o "${TMP}/h.hdr"
     46 "${BIN}" sign --single -k "${TMP}/h.hdr" -m hello -o "${TMP}/h.sig"
     47 "${BIN}" verify -k "${TMP}/h.hdr" -m hello -S "${TMP}/h.sig" >/dev/null && ok=1 || ok=0
     48 tap "${ok}" "verify derives the single key from a seed-bearing hdr" "failed"
     49 
     50 rc=0
     51 "${BIN}" sign --single -k "${TMP}/s.key" -m hi -P 0011 >/dev/null 2>&1 || rc=$?
     52 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "--single refuses --path" "exit ${rc}"
     53 
     54 rc=0
     55 "${BIN}" sign --single -k "${TMP}/s.key" -m hi -p 8 >/dev/null 2>&1 || rc=$?
     56 tap "$([ "${rc}" != 0 ] && echo 1 || echo 0)" "--single refuses --path-len" "exit ${rc}"
     57 
     58 out=$("${BIN}" sign -p 0 -k "${TMP}/s.key" -m hi 2>&1 || true)
     59 case "${out}" in *--single*) ok=1 ;; *) ok=0 ;; esac
     60 tap "${ok}" "-p 0 names --single in the error" "${out}"
     61 
     62 tap_plan