Repository Public
1# Differential oracles23Independent reference implementations used by `security/tests/Tests/DifferentialAuditTests`. They run in4the test environment only; nothing here is linked into, or shipped with, the wallet.56## How a campaign works781. A Swift test draws its cases from `AuditRNG(seed:)`. The seed comes from the system (or from9 `QY_AUDIT_SEED`) and is written with the result. To replay one campaign exactly, give its recorded seed:10 `QY_AUDIT_REPLAY_SEED=<seed> swift test -c release --package-path security/tests --filter <test name>`11 (filter down to the single campaign: the variable applies to every campaign that runs).122. The QYVORA result is compared with the reference: in process for CryptoKit and CommonCrypto, through13 `oracle.py` for everything else (one JSON array of cases on stdin, one JSON array of answers on stdout,14 byte strings in hexadecimal; the script is started with `python3 -I`).153. One record per (algorithm, parameter set, oracle) is appended to `$QY_AUDIT_OUT/records.jsonl` with the16 number of cases, the number of mismatches and the seed. The inputs of the first mismatches go to17 `$QY_AUDIT_OUT/differential-failures.jsonl`. Campaigns over altered inputs also record how many inputs18 the engine accepted and refused, so a comparison where everything is refused cannot pass unnoticed.194. A missing optional oracle is recorded as `NOT RUN` with the reason. It is never counted as passed.2021Case counts: `AuditMode.cases(quick:full:)`; `QY_AUDIT_MODE=full` multiplies the quick counts by ten,22`QY_AUDIT_SCALE` scales both.2324## References2526| Reference | Used for | Where |27|---|---|---|28| 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 |29| Apple CommonCrypto | PBKDF2-HMAC-SHA-256/512, SHA-2, HMAC | in process |30| `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` |31| libsecp256k1 through `coincurve` | secp256k1 keys, RFC 6979 ECDSA, verification, recovery, tweaks, BIP-340 | venv |32| BIP-340 `reference.py` | BIP-340 signing with messages of any length, verification | `third_party/bip340` |33| `segwit_addr.py` | Bech32, Bech32m, SegWit addresses | `third_party/bech32` |34| `embit` | BIP-32, Bitcoin transaction parsing, BIP-143 digests, addresses | venv |35| `mnemonic` (Trezor) | BIP-39 | venv |36| `argon2-cffi` (reference C code) | Argon2d / Argon2i / Argon2id with key and associated data | venv |37| `pycryptodome` | RIPEMD-160, Keccak-256 | venv |38| CPython `hashlib` / `hmac` (OpenSSL) | SHA-2, SHA-3, SHAKE, BLAKE2b, HMAC, PBKDF2 | venv |39| 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` |4041The Rust library is copied, not built, from the existing release build of42`~/Desktop/Cluster/projets/SP/spb-quantum-crypto` (read-only):43`target/release/libspb_pqc.dylib` → `security/.tools/lib/`, `target/release/spbqc` → `security/.tools/bin/`44(or set `QY_SPBPQC_DYLIB` / `QY_SPBQC`). It is itself labelled "EXPERIMENTAL / NOT AUDITED" and was written45by the same owner: agreement with it is evidence of conformance to the same reading of FIPS 203/204/205,46not an external validation. CryptoKit is the externally maintained oracle for ML-KEM-768/1024 and47ML-DSA-65/87; the NIST ACVP vectors remain the reference for all parameter sets.4849## Limits (stated, not hidden)5051- The FFI of the Rust library has no seeded key generation. ML-KEM-512 and ML-DSA-44 key generation52 *from a seed* is therefore compared only indirectly (the Rust library validates our keys, re-derives our53 ML-DSA public key from our private key, and both sides agree on every secret and deterministic signature).54 For SLH-DSA the seeds of a Rust key pair are fed to our key generation and must give the Rust public key.55- X25519 in `QyvoraIdentity` is a wrapper around CryptoKit, not code written from scratch; it is compared with56 RFC 7748 written in the oracle.57- Random testing finds systematic errors; it says little about inputs that occur with negligible probability58 (carry chains in field arithmetic, for instance). Those are the business of the edge-case vectors59 (Wycheproof) and of the property tests.60- No Ethereum library (`eth-account`) is installed: the EIP-1559 reference is the oracle's own RLP and payload61 code on top of libsecp256k1 and pycryptodome's Keccak-256.6263## Self-tests6465`DifferentialHarnessSelfTests` feeds deliberately wrong values through the same path and requires the mismatch66to be detected, checks that an oracle error is never read as a match, and that a seed reproduces its cases.67