Repository Public
1{2 "id": "QYV-AUD-003",3 "title": "ConstantTime.equal: a sub-nanosecond dependence on the compared contents is statistically detectable when the processor's DIT flag is not set",4 "severity": "low",5 "cvss_vector": "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:L/I:N/A:N",6 "cvss_score": 2.5,7 "cwe": "CWE-208",8 "masvs": "MASVS-CRYPTO-1",9 "area": "crypto",10 "location": "Sources/QyvoraMath/ConstantTime.swift:50",11 "tool": "dudect-timing",12 "rule": "ct-equal-hamming",13 "status": "fixed",14 "fix_commit": "b806c00",15 "regression_test": "security/tests/Sources/qytiming/main.swift (target ct-equal-hamming, without --dit: the engine now sets the flag itself); QyvoraMathTests.DataIndependentTimingTests",16 "description": "Observation: comparing a 64-byte reference with a buffer that differs by one bit, against a buffer with random contents (both comparisons return false, same buffers at the same addresses in both classes), gives a Welch t statistic that grows with the number of measurements: max |t| = 4.6 and 6.3 with 200 000 measurements per class, 11.7, 13.6 and 12.2 with 1 000 000 (node M4M64a, Swift 6.3.3, 32 calls per measurement). The means are equal to the displayed precision (6.0–6.3 ns per call): the difference is below 0.1 ns. The position of a single differing byte shows no effect (max |t| = 1.6–2.4 with the same sample sizes). The machine code of ConstantTime.equal contains no data-dependent branch (vectorised XOR/OR accumulation, branches on the length only). With the processor's data-independent-timing flag set (PSTATE.DIT, `qytiming --dit`), three runs of 1 000 000 measurements per class gave max |t| = 6.3 (opposite sign, at the median crop), 1.7 and 3.2, against 12.6 and 7.6 without the flag in the same session: the systematic effect is consistent with processor-level data-dependent timing that DIT suppresses. This is statistical evidence from one machine, not a proof of the cause. Impact: negligible in practice — telling 'almost equal' from 'different' would need on the order of a million isolated, sub-nanosecond-precise measurements of the same comparison, which no interface of the wallet offers (AEAD tags are compared once per attempt, and the tag-position targets show no difference: max |t| = 1.5 and 1.7). Recorded because the audit must not hide a reproducible measurement, and because it gives a measured basis to the recommendation of QYV-CRY-004.",17 "recommendation": "Set PSTATE.DIT around the operations that process secrets (signing, decapsulation, AEAD open, comparisons): Apple's guidance for constant-time code on Apple silicon. Pure Swift cannot set it; it needs a small C or assembly shim (as security/tests/Sources/CAuditDIT does for the measurement) and therefore a change of Package.swift — an owner decision, tracked with QYV-CRY-004. Until then the residual risk is rated low.",18 "evidence": "qytiming --only ct-equal-hamming --scale 5 (1 000 000 per class): without DIT max |t| = 11.69, 13.61, 12.21, 12.59, 7.64; with --dit max |t| = 6.34 (crop p50, negative), 1.73, 3.22.",19 "fingerprint": "",20 "fixed": "2026-12-04",21 "resolution_note": "Fixed: `ConstantTime.equal` sets the processor's data-independent-timing flag for the comparison and restores it afterwards (see QYV-CRY-004). Verification: Measured on M4M64a (Swift 6.3.3, release build of commit 6ac0546) with `qytiming --only ct-equal-hamming --scale 5`, 1 000 000 measurements per class, without --dit, three runs: max |t| = 2.50 (crop p95), 0.90 (crop p99), 2.22 (crop p95), raw t = -1.23, -0.31, -2.15; threshold 4.5. Before the fix, same node and sample size: 11.69, 13.61, 12.21, 12.59, 7.64. Position target (`ct-equal-position`, same size): max |t| = 0.96. Mean per measurement 35.4 to 35.9 ns for both classes. Statistical evidence from one machine and one build, not a proof. Residual risk: The measurement is statistical and was made on one Mac; it was not repeated on an iPhone.",22 "verification": "Measured on M4M64a (Swift 6.3.3, release build of commit 6ac0546) with `qytiming --only ct-equal-hamming --scale 5`, 1 000 000 measurements per class, without --dit, three runs: max |t| = 2.50 (crop p95), 0.90 (crop p99), 2.22 (crop p95), raw t = -1.23, -0.31, -2.15; threshold 4.5. Before the fix, same node and sample size: 11.69, 13.61, 12.21, 12.59, 7.64. Position target (`ct-equal-position`, same size): max |t| = 0.96. Mean per measurement 35.4 to 35.9 ns for both classes. Statistical evidence from one machine and one build, not a proof.",23 "residual_risk": "The measurement is statistical and was made on one Mac; it was not repeated on an iPhone."24}25