SPB Git

Repository Public

QYV-CRY-004.json 6.0 KB 25 lines json

1{2  "id": "QYV-CRY-004",3  "title": "Constant-time behaviour rests on source-level discipline only: no compiler guarantee, DIT not enabled",4  "severity": "low",5  "cvss_vector": "",6  "cvss_score": null,7  "cwe": "CWE-208",8  "masvs": "MASVS-CRYPTO-1",9  "area": "crypto",10  "location": "Sources/QyvoraSecp256k1/U256.swift:193",11  "tool": "manual-review",12  "rule": "constant-time-not-guaranteed",13  "status": "fixed",14  "fix_commit": "b806c00",15  "regression_test": "QyvoraMathTests.DataIndependentTimingTests (theFlagIsSetInsideAScopeAndRestoredAfterIt, nestedScopesLeaveTheFlagToTheOutermostOne, aThrowingScopeRestoresTheFlag, constantTimeComparisonStillAnswersAndRestoresTheFlag); QyvoraMLDSATests.MLDSAPrivateKeyValidationTests.theFlagOfTheProcessorIsRestoredAfterValidation; audit steps ct-machine-code and dudect-timing (security/audit/runners/timing.py), binary-checks source scan against the reviewed list",16  "description": "The review found no secret-dependent branch, table index or division in the secp256k1, ML-KEM, AES, GHASH, ChaCha20-Poly1305, HMAC and comparison code beyond what the standards themselves allow (rejection sampling in ML-DSA, data-dependent addressing in Argon2id; full list in security/audit/review/crypto-primitives.json). Two limits remain: (1) Swift has no constant-time attribute - the optimiser may turn mask selections into branches, and the machine code was not inspected in this audit; (2) on ARM64 the timing of instructions such as multiplications is guaranteed data-independent only when the processor's DIT bit (PSTATE.DIT) is set, which the system libraries do for their own cryptography and this engine does not (it cannot be set from pure Swift). ECDSA signing also has no verify-after-sign check against computation faults (Schnorr has one). Impact: a co-located attacker able to time many signing or decapsulation operations precisely could, in principle, learn key bits; the wallet exposes no remote signing or decapsulation oracle.",17  "recommendation": "Before production: add a minimal C or assembly shim that sets DIT around secret-key operations (requires a new target in Package.swift: owner decision, it breaks the 'Swift only' property but not the zero-dependency one); inspect the release machine code of Point.multiply, montMul, ML-KEM decapsulation and ConstantTime.equal for branches; keep the dudect-style timing test in the audit pipeline; add verify-after-sign to Secp256k1.sign. The statistical timing results are reported separately by the audit run.",18  "evidence": "no reference to DIT, msr or sysctl hw.optional.arm.FEAT_DIT in Sources/",19  "fingerprint": "8c089ff74bad",20  "fixed": "2026-12-04",21  "resolution_note": "Fixed: The four actions recommended are done. (1) New C target `QyvoraCSupport` (Sources/QyvoraCSupport/dit.c, about forty lines, no dependency): capability read from hw.optional.arm.FEAT_DIT, PSTATE.DIT read with mrs and set / cleared with msr; `DataIndependentTiming` (QyvoraMath) wraps it. The flag is set, and restored on exit, around secp256k1 public-key derivation, key tweak, ECDSA and Schnorr signing, ML-KEM key generation / encapsulation / decapsulation, ML-DSA key generation / signing / private-key validation, SLH-DSA key generation / signing, HMAC, HKDF, PBKDF2, Argon2, AES-GCM and ChaCha20-Poly1305 seal / open, `ConstantTime.equal`, BIP-32 derivation and the BIP-39 seed. (2) The release machine code of the listed functions is inspected at every audit (ct-machine-code: conditional branches per function against a reviewed maximum). (3) The dudect-style timing test stays in the pipeline. (4) `Secp256k1.sign` verifies the signature it produced before returning it. Verification: Package tests on M4M64c and on the laptop. `./Scripts/security-audit.sh --only timing --timing-node M4M64a` at commit 6ac0546: ct-machine-code RUN, 23 functions in the policy, 12 visible and checked, 0 above its maximum (ConstantTime.equal 10 for a maximum of 10, Modulus.montMul 4 / 4, U256.add / sub 0), 11 not visible (inlined; reported as NOT RUN, never as passed); dudect-timing RUN on M4M64a at 15 % of the sample counts, 21 targets, none above |t| = 4.5 (ECDSA sign key 0.96, secp256k1 k*G 2.02 / 2.00 / 1.38, Schnorr sign 2.24). Application target compiled for iphoneos on M3U96a (the C target builds for arm64 iOS). Residual risk: Swift still has no constant-time attribute: the optimiser may turn a mask selection into a branch in a future toolchain (the machine-code check exists to notice it), and functions inlined into their callers are not visible to that check. DIT covers the instructions ARM and Apple list, nothing else; it was verified on Apple silicon Macs, and read back on an iPhone by no test. The engine is no longer 'Swift only': it has one C file, on the reviewed list of the binary checks. Cost: about 30 ns per scope on M4M64a (the two writes of the flag), visible only on `ConstantTime.equal`.",22  "verification": "Package tests on M4M64c and on the laptop. `./Scripts/security-audit.sh --only timing --timing-node M4M64a` at commit 6ac0546: ct-machine-code RUN, 23 functions in the policy, 12 visible and checked, 0 above its maximum (ConstantTime.equal 10 for a maximum of 10, Modulus.montMul 4 / 4, U256.add / sub 0), 11 not visible (inlined; reported as NOT RUN, never as passed); dudect-timing RUN on M4M64a at 15 % of the sample counts, 21 targets, none above |t| = 4.5 (ECDSA sign key 0.96, secp256k1 k*G 2.02 / 2.00 / 1.38, Schnorr sign 2.24). Application target compiled for iphoneos on M3U96a (the C target builds for arm64 iOS).",23  "residual_risk": "Swift still has no constant-time attribute: the optimiser may turn a mask selection into a branch in a future toolchain (the machine-code check exists to notice it), and functions inlined into their callers are not visible to that check. DIT covers the instructions ARM and Apple list, nothing else; it was verified on Apple silicon Macs, and read back on an iPhone by no test. The engine is no longer 'Swift only': it has one C file, on the reviewed list of the binary checks. Cost: about 30 ns per scope on M4M64a (the two writes of the flag), visible only on `ConstantTime.equal`."24}25
Files main
Menu

Theme