Files
RCM-Emulator/tests/se/run.sh
T
Claude 1aa0ee9f23 Model the SE's RSA and random number generator
Both ops finished with OP_DONE and produced nothing. se_rng_pseudo()
left its buffer as it was, so Nyx's partition manager wrote whatever
was on the stack into GPT partition GUIDs, and the SD benchmark drew
its random offsets from uninitialised memory. se_rsa_exp_mod() read
back zeros.

- RSA, as Lockpick's bdk drives it: two keyslots of up to 2048 bits
  loaded through SE_RSA_KEYTABLE_ADDR/DATA, KEY_SIZE in 512-bit steps,
  EXP_SIZE in words, the input a little-endian number over DMA and the
  result in SE_RSA_OUTPUT (or memory). Montgomery multiplication on
  32-bit words; an even modulus fails the op.
- RNG into memory or a keyslot quad, LAST_BLOCK + 1 blocks cut to the
  buffer. The bytes come from SplitMix64 with a fixed seed, reset with
  the SE, so runs stay reproducible.

tests/se/ is a new make test payload: RSA-2048 and RSA-1024 in the two
slots, each m^d and s^e checked against Python (gen_vectors.py writes
vectors.h), SHA-256 one-shot and in two parts, AES-128 ECB, and the
RNG filling a zeroed buffer, changing between calls and stopping at
the size asked for. Run against the previous binary it fails the RSA
and RNG checks. The README's "RSA, RNG and chunked SHA are stubs" is
gone; chunked SHA was already modelled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
2026-09-25 22:40:08 +00:00

27 lines
944 B
Bash
Executable File

#!/bin/sh
# Security Engine regression test: run tests/se/payload.c and check what it
# reports. Usage: tests/se/run.sh [rcm_emu] [payload]
EMU=${1:-./rcm_emu}
PAYLOAD=${2:-tests/se/payload.bin}
LOG=${LOG:-tests/se/out.log}
SDL_VIDEODRIVER=dummy RCM_EMU_NO_AUDIO=1 timeout 60 "$EMU" "$PAYLOAD" \
> "$LOG" 2>&1
status=$?
echo "se test (emulator exit $status):"
# The payload's lines arrive through the UART-B log, tagged [uartB].
grep '^\[uartB\] se test: \(ok\|FAIL\) ' "$LOG" |
sed -e 's/^.*se test: ok */ ok /' -e 's/^.*se test: FAIL */ FAIL /'
fail=0
grep -q 'se test: FAIL' "$LOG" && fail=1
if ! grep -q '^\[uartB\] se test: done$' "$LOG"; then
echo " FAIL the payload did not finish cleanly"
fail=1
fi
if [ "$status" -ne 0 ]; then
echo " FAIL the emulator exited with status $status (124 = timed out)"
fail=1
fi
[ $fail -eq 0 ] && echo "se test: PASS" || { echo "se test: FAIL (log: $LOG)"; exit 1; }