#!/bin/sh
# Documentation-reviewed example. Requires OpenSSL >=3.5 with ML-KEM.
# This is a local round trip, not a cryptographic security test.
set -eu
OPENSSL_BIN=${OPENSSL_BIN:-openssl}
"$OPENSSL_BIN" version
"$OPENSSL_BIN" list -kem-algorithms | grep -q ML-KEM || {
  echo 'ML-KEM unavailable: select an OpenSSL 3.5+ build/provider.' >&2
  exit 1
}
umask 077
PQC_LAB_DIR=$(mktemp -d "${TMPDIR:-/tmp}/pqc-roundtrip.XXXXXX")
cd "$PQC_LAB_DIR"
"$OPENSSL_BIN" genpkey -algorithm ML-KEM-768 -out recipient.pem
"$OPENSSL_BIN" pkey -in recipient.pem -pubout -out recipient-public.pem
"$OPENSSL_BIN" pkeyutl -encap -pubin -inkey recipient-public.pem \
  -out encapsulation.bin -secret sender-secret.bin
"$OPENSSL_BIN" pkeyutl -decap -inkey recipient.pem \
  -in encapsulation.bin -secret recipient-secret.bin
cmp sender-secret.bin recipient-secret.bin
printf 'Local shared secrets match. Temporary fixture: %s\n' "$PQC_LAB_DIR"
# Do not print or commit private keys or shared secrets.
# Remove this temporary fixture after inspection; no production data is used.
