interplane.Get Omega
Read in your language

spark-rsi-mv

Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger

Brought by drakestapleton

branch main Branches Tags History

spark-rsi-mv / om / p256 / README.md

182 lines · 11500 bytes Raw Blame History Source

om/p256: the #67 judge signature scheme in seeded .om (library only)

p256.om is ECDSA over NIST P-256 with SHA-256 and RFC 6979 deterministic nonces. It reproduces the signatures of the spark-rsi judge signer byte for byte. It is a parity-proven library and nothing more:

Refs spark-rsi-mv #67 (judge signer, ".om throughout") and #73 (REUSE-1, whose receipt is unsigned because no .om signer existed).

The scheme it matches

PropertyRust judgeSource
Curve, crateNIST P-256, RustCrypto p256 0.14.0 (ecdsa 0.17.0, rfc6979 0.6.0)Cargo.toml:41, Cargo.lock
Key32-byte big-endian scalar, SigningKey::from_slice (0 and >= n refused)src/actor/judge.rs:1070-1082
Messagethe 32 raw bytes of receipt_digest (hex-decoded)src/evaluator/mod.rs:259-264
HashSigner::sign hashes the message once with SHA-256; ECDSA signs that hashecdsa-0.17.0/src/signing.rs:155-172
NonceRFC 6979 section 3.2 HMAC-DRBG over (d, bits2octets(h)), no extra entropy (ad = [])ecdsa-0.17.0/src/signing.rs:171-172, rfc6979-0.6.0/src/lib.rs:73-100
Outputr \|\| s, 64 bytes, big endian; the judge prefixes tpm2-p256: and hexsrc/evaluator/mod.rs:263
Low-Snot applied: p256 sets NORMALIZE_S = false, so s is whatever the equation gives and verification accepts both s and n - sp256-0.14.0/src/ecdsa.rs:60, ecdsa-0.17.0/src/hazmat.rs:85,142
Public keyuncompressed SEC1, 0x04 \|\| X \|\| Y (65 bytes)src/actor/judge.rs:1088

The low-S row is also checked by data: every parity vector carries a V line with s replaced by n - s, and Rust accepted all 2048 of them (parity-rust.txt); p2vrfy gives the same verdict.

Files

FileWhat it is
p256.omThe library (682 lines): field and scalar arithmetic, points, HMAC-SHA-256, RFC 6979, sign, verify, public key. Functions and constants only.
sha256.omByte copy of aien-dev/omega-mv om/sha256/sha256.om at main acb3f15c (last change a1cfb4a3), sha256 7f034814303a8a40b4bc56383ddd55ab2ae8460291f80793340bc3b0ac024e21. The same bytes as om/reuse-eval/sha256.om on the REUSE-1 branch. Not modified.
tests/run.omThe runner: self tests, then every vector file named on the command line. Exit 0 only when every check passed.
tests/rfc6979-a25.txtRFC 6979 A.2.5, P-256 with SHA-256: the public key, both nonces k and both signatures ("sample", "test"), copied from the RFC text.
tests/parity-rust.txtRecorded from Rust p256 0.14.0: 2 public keys, 2048 signatures (1024 digests per key), 4864 verify verdicts.
tests/edge-rust.txtRecorded from Rust: 3 signatures and 3 verdicts for a message whose SHA-256 is >= n.
tests/interplane.txt3 real judge receipts from aien-dev/interplane-mv a68300c2, each followed by a tampered copy, with Rust's verdicts.

API

Callers own four arrays and pass them in: w ulong 1024 (workspace), c uchar 104 (SHA-256 context), b uchar 4096 (byte buffer), s ulong 64 (SHA-256 schedule). Call p2init w once.

CallInputsResult
p2sign w c b s mlenkey d at b[3264..3296), message at b[2048..2048+mlen), mlen <= 10240 and r \|\| s at b[3200..3264); 1 when d is 0 or >= n
p2vrfy w c b s mlenpublic key at b[3072..3137), r \|\| s at b[3200..3264), message as above1 valid, 0 refused
p2pub w bkey d at b[3264..3296)0 and 0x04 \|\| X \|\| Y at b[3072..3137); 1 when d is refused

p2vrfy refuses a key that is not 0x04 || X || Y with X, Y < p on the curve, r or s outside 1..n-1, a sum u1 G + u2 Q equal to the identity, or x mod n different from r. These are the checks of VerifyingKey::from_sec1_bytes, Signature::from_slice and verify_prehashed (ecdsa-0.17.0/src/hazmat.rs:136-159).

How it is built

Side-channel limits

This is stated for a future signer deployment; nothing in this PR deploys one.

Results (DGX Spark, Cortex-X925/A725, nice -n 19, one run)

self tests: 3 pass, 0 fail
file om/p256/tests/rfc6979-a25.txt: K 1/1 N 2/2 S 2/2 V 0/0 malformed 0
file om/p256/tests/parity-rust.txt: K 2/2 N 0/0 S 2048/2048 V 4864/4864 malformed 0
file om/p256/tests/edge-rust.txt: K 0/0 N 0/0 S 3/3 V 3/3 malformed 0
file om/p256/tests/interplane.txt: K 0/0 N 0/0 S 0/0 V 6/6 malformed 0
timing p2sign: calls 2053 mean_us 1230 min_us 1224 max_us 2694
timing p2vrfy (S lines, valid): calls 2053 mean_us 2337 min_us 2327 max_us 5086
timing p2vrfy (V lines, mixed): calls 4873 mean_us 2151 min_us 0 max_us 2433
p256: PASS
wall_s 20.22 user_s 20.22 sys_s 0.00 maxrss_kb 2080

What the lines mean:

Mutants (throwaway copies under /tmp, not committed)

Every mutant was run over the four vector files. A mutant counts as detected only when the runner printed at least one MISMATCH line and exited nonzero.

MutantExitMISMATCH linesDetected
M1: HMAC-DRBG V initialised to 0x02 instead of 0x0112055yes
M2: one limb of Gy changed by 114110 (self tests 0/3)yes
M3: final conditional subtraction removed104 (trap 4 on the first N line)1 (the RFC K line)yes, then trapped
M4: low-S normalisation added to signing11059yes
M5: verification compares x with itself12435yes
M6: Montgomery reduction step removed14110yes
M7: h mod n removed before RFC 6979 and z13, all in edge-rust.txt (0 in the other files)yes, only by edge-rust.txt
M8: on-curve check of the public key removed00no (see below)
M9: HMAC opad 0x5d instead of 0x5c12055yes

M8 survives. Every off-curve key in the vectors is still refused without the check, because the verification equation fails anyway.

Reproduce

OMC=/path/to/omc   # the pinned seeded omc, sha256 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
cat om/p256/sha256.om om/p256/p256.om om/p256/tests/run.om | "$OMC" > /tmp/p256-run.elf
chmod +x /tmp/p256-run.elf
/tmp/p256-run.elf om/p256/tests/rfc6979-a25.txt om/p256/tests/parity-rust.txt \
  om/p256/tests/edge-rust.txt om/p256/tests/interplane.txt

Run it from the repo root. Exit 0 means every check passed; 1 means a mismatch or a malformed line; 2 means a file could not be read.

How the Rust data was recorded

The Rust data came from a throwaway program under /tmp, never committed. It uses p256 0.14.0 with spark-rsi-mv's Cargo.lock and signs with SigningKey::from_slice(key).sign(&msg), the same call as src/evaluator/mod.rs:262. It verifies with VerifyingKey::from_sec1_bytes + Signature::from_slice + verify.

What remains (not in this PR)

  1. Key custody. The real signing key lives with the judge account (docs/RECEIPT-V2.md, "Key separation"; /var/lib/aien-judge), and policy says atlas-vault. A .om signer has to load it there, under that account, without copying it. Nothing here touches it.
  2. RECEIPT-V2 digest in .om. compute_digest_v2 (src/evaluator/mod.rs:143-201) is still Rust only. A .om successor needs it byte-equal before it can sign what the Rust judge signs.
  3. REUSE-1 receipt mapping. The REUSE-1 FINAL receipt (om/reuse-eval/receipt.om, identity domain spark-rsi.reuse1-receipt.v2-unsigned) is not a RECEIPT-V2 receipt. Signing it needs either a RECEIPT-V2-shaped record or a versioned companion domain (#67 item 6), plus the operator action in item 1.
    • Any such signature is written after FINAL and must be labelled so.
  4. Cutover. The Rust signer is removed only after a .om signer is qualified and the judge and the promotion gate call it.
  5. Further vectors. Wycheproof and NIST CAVP vectors, and an invalid-curve vector that kills M8.