SPB Git

Repository Public

README.md 4.9 KB

# Differential oracles

Independent reference implementations used by security/tests/Tests/DifferentialAuditTests. They run in the test environment only; nothing here is linked into, or shipped with, the wallet.

# How a campaign works

  1. A Swift test draws its cases from AuditRNG(seed:). The seed comes from the system (or from QY_AUDIT_SEED) and is written with the result. To replay one campaign exactly, give its recorded seed: QY_AUDIT_REPLAY_SEED=<seed> swift test -c release --package-path security/tests --filter <test name> (filter down to the single campaign: the variable applies to every campaign that runs).
  2. The QYVORA result is compared with the reference: in process for CryptoKit and CommonCrypto, through oracle.py for everything else (one JSON array of cases on stdin, one JSON array of answers on stdout, byte strings in hexadecimal; the script is started with python3 -I).
  3. One record per (algorithm, parameter set, oracle) is appended to $QY_AUDIT_OUT/records.jsonl with the number of cases, the number of mismatches and the seed. The inputs of the first mismatches go to $QY_AUDIT_OUT/differential-failures.jsonl. Campaigns over altered inputs also record how many inputs the engine accepted and refused, so a comparison where everything is refused cannot pass unnoticed.
  4. A missing optional oracle is recorded as NOT RUN with the reason. It is never counted as passed.

Case counts: AuditMode.cases(quick:full:); QY_AUDIT_MODE=full multiplies the quick counts by ten, QY_AUDIT_SCALE scales both.

# References

Reference Used for Where
Apple CryptoKit (corecrypto) SHA-2, SHA-3, HMAC, HKDF, AES-GCM (128/192/256), ChaCha20-Poly1305, ML-KEM-768/1024, ML-DSA-65/87 in process
Apple CommonCrypto PBKDF2-HMAC-SHA-256/512, SHA-2, HMAC in process
spb-quantum-crypto 1.0.0-alpha.1 (the owner's Rust library; separate code base and language) ML-KEM-512/768/1024, ML-DSA-44/65/87, the twelve SLH-DSA sets (C FFI of libspb_pqc.dylib, loaded by oracle.py with ctypes); SHA-2 incl. SHA-512/224 and /256, SHA-3, SHAKE (command-line tool spbqc) security/.tools/lib, security/.tools/bin
libsecp256k1 through coincurve secp256k1 keys, RFC 6979 ECDSA, verification, recovery, tweaks, BIP-340 venv
BIP-340 reference.py BIP-340 signing with messages of any length, verification third_party/bip340
segwit_addr.py Bech32, Bech32m, SegWit addresses third_party/bech32
embit BIP-32, Bitcoin transaction parsing, BIP-143 digests, addresses venv
mnemonic (Trezor) BIP-39 venv
argon2-cffi (reference C code) Argon2d / Argon2i / Argon2id with key and associated data venv
pycryptodome RIPEMD-160, Keccak-256 venv
CPython hashlib / hmac (OpenSSL) SHA-2, SHA-3, SHAKE, BLAKE2b, HMAC, PBKDF2 venv
written in oracle.py HKDF (RFC 5869), X25519 (RFC 7748), ECDSA verification on integers, strict SEC 1 parsing, RLP, Base58Check, EIP-55, EIP-1559 payloads, BIP-32 (second derivation), 256-bit integers oracle.py

The Rust library is copied, not built, from the existing release build of ~/Desktop/Cluster/projets/SP/spb-quantum-crypto (read-only): target/release/libspb_pqc.dylib → security/.tools/lib/, target/release/spbqc → security/.tools/bin/ (or set QY_SPBPQC_DYLIB / QY_SPBQC). It is itself labelled "EXPERIMENTAL / NOT AUDITED" and was written by the same owner: agreement with it is evidence of conformance to the same reading of FIPS 203/204/205, not an external validation. CryptoKit is the externally maintained oracle for ML-KEM-768/1024 and ML-DSA-65/87; the NIST ACVP vectors remain the reference for all parameter sets.

# Limits (stated, not hidden)

  • The FFI of the Rust library has no seeded key generation. ML-KEM-512 and ML-DSA-44 key generation from a seed is therefore compared only indirectly (the Rust library validates our keys, re-derives our ML-DSA public key from our private key, and both sides agree on every secret and deterministic signature). For SLH-DSA the seeds of a Rust key pair are fed to our key generation and must give the Rust public key.
  • X25519 in QyvoraIdentity is a wrapper around CryptoKit, not code written from scratch; it is compared with RFC 7748 written in the oracle.
  • Random testing finds systematic errors; it says little about inputs that occur with negligible probability (carry chains in field arithmetic, for instance). Those are the business of the edge-case vectors (Wycheproof) and of the property tests.
  • No Ethereum library (eth-account) is installed: the EIP-1559 reference is the oracle's own RLP and payload code on top of libsecp256k1 and pycryptodome's Keccak-256.

# Self-tests

DifferentialHarnessSelfTests feeds deliberately wrong values through the same path and requires the mismatch to be detected, checks that an oracle error is never read as a match, and that a seed reproduces its cases.

Files main
Menu

Theme