SPB Git

Repository Public

QYV-AUD-005.json 10.7 KB 21 lines json

1{2 "id": "QYV-AUD-005",3 "title": "Timing harness artefact reported as a leak: ML-KEM decapsulation, one repeated ciphertext against many (QY-TIMING-MLKEM-DECAPS-MESSAGE-ML-KEM-768); qytiming did not isolate the timed operation from where and how each class's inputs were prepared",4 "severity": "high",5 "cvss_vector": "CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:N/A:N",6 "cvss_score": 4.7,7 "cwe": "CWE-208",8 "masvs": "MASVS-CRYPTO-1",9 "area": "crypto",10 "location": "security/tests/Sources/qytiming/main.swift",11 "tool": "dudect-timing",12 "rule": "mlkem-decaps-message-ML-KEM-768",13 "status": "fixed",14 "fix_commit": "972721e, f175054, da2d3b2",15 "regression_test": "security/tests/Sources/qytiming/main.swift: control-negative-mlkem-ciphertexts-ML-KEM-512/768/1024, control-negative-aes-random-keys and control-same-class (same distribution in both classes, must stay below the threshold: the per-class storage that failed them at --scale 10 is reproduced by diag-aes-random-vs-random), info-former-preparation-ML-KEM-512/768/1024 (the target exactly as it was written, one buffer against a pool, reported without verdict; reproduces the artefact with --no-barrier), control-positive-mlkem-leak-ML-KEM-768 and control-leaky-compare (must be detected), and the corrected mlkem-decaps-message-ML-KEM-512/768/1024; security/policies/constant-time-functions.json: 21 entries for the compiled ML-KEM decapsulation path (commit c8f0d6a); security/policies/timing-known.json reports a new exceedance of the three targets under this identifier, severity high",16 "description": "What the audit reported (full run on commit 60c944c, node M4M64a): the target mlkem-decaps-message-ML-KEM-768 (one key; class A = one valid ciphertext repeated, class B = 512 other valid ciphertexts) exceeded the threshold twice, max |t| = 4.7 then 4.5 with 40 000 measurements per class; with 400 000 per class |t| = 10.7 and 12.8, and 8.1 with --dit. Rated high: unanalysed timing difference on an operation that uses a private key. All measurements below: M4M64a (Mac Studio M4 Max, macOS 26.5.1, Swift 6.3.3), 2026-12-04, 1-minute load between 1.3 and 3 (3 to 7 during the very first series, while Spotlight indexed the copied tree), 400 000 measurements per class for ML-KEM and 1 000 000 for AES unless stated; each value is one run. Reproduction with the harness as it was: ML-KEM-768 max |t| = 12.5, 11.4, 12.0, 9.3; ML-KEM-512 9.7, 8.9, 6.0, 4.8; ML-KEM-1024 5.5, 8.8, 8.3, 12.7. The excess is in the cropped distributions (median crop), class A the slower one; difference of the means between -1 and +12 ns (typically 5 to 8) on 14 to 31 microseconds; uncropped statistic 0.6 to 3.5. Root cause: the measurement, not the decapsulation. The harness let two things differ between the classes besides the contents of the inputs. (1) The timed region was not separated from the preparation. The clock reading is not a serialising instruction; the copy of the ciphertext into the working buffer, made just before, could still be completing when the timed region started, and that copy was not the same for the two classes (class A: from one buffer, always in the first-level cache, by a direct reference; class B: from one of 512 buffers, 0.4 to 0.8 MB, by an indexed access). (2) Each class kept its inputs in its own memory. Even with identical preparation code, a class whose values live in their own buffers differs from the other by a constant of 1 to 3 ns for the whole run, the sign changing from one process to the next. Evidence separating this from a dependence on the ciphertext or on the decrypted message: (a) SAME ciphertext in both classes, one buffer against 512 buffers holding copies of it, former harness: ML-KEM-768 |t| = 8.4, 8.2; ML-KEM-1024 5.7, 7.1 (ML-KEM-512: 1.0, 2.5 in this form, where both classes use the same indexed access). Identical inputs cannot differ because of the engine. (b) Contents varied, storage identical (one ciphertext in 512 buffers against 512 ciphertexts), former harness: 768: 1.3, 2.0; 512: 1.9, 1.4; 1024: 2.6, 2.5. Pool against another pool 2.7; one buffer against another buffer holding a different ciphertext 1.9; ciphertexts differing from the repeated one in u only 1.3, 2.6; in v only 1.8, 1.6. (c) The former target unchanged, plus a serialising barrier (dsb sy; isb) between the preparation and the first clock reading: 768: 1.3, 1.2, 2.0, 1.9, 2.3, 4.35; 512: 2.1, 1.8, 2.2, 1.2, 2.0, 0.6; 1024: 1.2, 1.7, 0.9, 1.5, 0.7, 1.5 (same binary without the barrier in the last series: 768: 5.8, 8.3; 512: 4.7, 6.2; 1024: 6.9, 6.5). The barrier is outside the timed region. The 4.35 shows that the barrier alone does not remove everything from an asymmetric preparation; point (2) is the rest. (d) Making class A read the pool entry class B would have read before copying from its single buffer did not remove the difference (7.6, 4.0): the cache footprint of the pool is not the cause by itself. (e) Point (2) was found when the first correction (barrier, repeated value kept in 512 buffers of its own) made aes-key-dependence fail in the audit run (4.5 then 13.4 at 100 000 per class). With a million per class, AES-256-GCM seal (10 microseconds), two classes drawn from the SAME distribution, each in its own pool: random keys against random keys |t| = 56.7, 21.0, 48.1, 37.9, 43.8 (the last with the opposite sign); all-zero against all-zero 20.3, 24.9, 44.1, 44.2; pools exchanged between the classes 48.2, 76.2; the former form (zero key in one buffer against a pool) 12.8, 15.0 with the barrier and 24.8, 21.9 without. In the run that was dumped the offset was constant (1.9 to 2.4 ns in each tenth of the run) and did not depend on the previous class. A preparation that ignores the class: 1.9, 1.1 (the measuring loop itself is unbiased). Making the loop branch-free on the class changed nothing (hypothesis of a branch-history effect: rejected). With both classes in one block of memory whose slots are dealt to the classes at random: random against random 2.4, 2.1, 1.5, 2.0, 1.5; all-zero key against random keys 0.7, 1.9, 1.2. (f) Machine code of the decapsulation path (decapsCore, pkeDecrypt, pkeEncrypt, NTT forward/inverse/multiply, samplePolyCBD, compressEncode, decodeDecompress, decode12, messageToPoly, the Field reductions, ConstantTime.select, Keccak permutation, absorb and squeeze), read branch by branch in the release builds of Swift 6.3.3 and 6.4.2: every conditional branch tests a loop counter, a public length or parameter (k, eta, d, accumulate), a bounds or overflow trap on such values, a buffer-overlap check of the vectoriser, array uniqueness or a one-time initialisation; the only data-dependent ones are the three of the rejection sampling of the matrix, on bytes expanded from the public seed (same key in both classes). No division instruction in the ML-KEM objects or in Keccak.swift (those of QyvoraMath are in SystemRandom.uniform and permutation, the one of QyvoraKeccak in SP800185.bytepad; none on this path); the only table is the zeta table, indexed by loop counters. Not established: the microarchitectural mechanisms themselves (why the class with the cached source is the slower one in (1); which property of the storage, alignment, cache sets or pages, produces the constant offset in (2)). No performance counter was read. The conclusion rests on (a), (b), (c), (e) and (f). Limits: statistical evidence on one machine and one build; a shift of about 3 ns in 21 microseconds is the smallest the ML-KEM target sees at 400 000 per class; no measurement on an iPhone; no power or electromagnetic analysis. A leak that exists only through the branch predictor is partly hidden by a pool of 512 values, which the predictor learns: 32 branches on bits of the shared secret added after a decapsulation gave a difference of 18 ns with 512 values and 57 ns with 8192 (both detected, |t| = 36.8 and 30.5), and inside the first audit run only 2.4 at 40 000 per class. That is why the positive control is now a loop whose length is a secret byte, and why the machine-code review (f) matters. Scope beyond ML-KEM: every target of qytiming used per-class buffers and the unseparated timed region (AES, secp256k1, ECDSA, BIP-340, ConstantTime.equal, AEAD tags, the informational ML-KEM targets); all now go through the same storage and barrier. Earlier passes of those targets remain valid as 'no difference seen at that sample count', with a sensitivity limited by the same 1 to 3 ns floor. ML-DSA and SLH-DSA signing have no timing target, so the artefact could not affect them; their code was not re-examined here.",17 "recommendation": "Fixed in the harness; the engine is unchanged, so its performance is unchanged (no engine file modified). (1) qytiming serialises the processor (dsb sy; isb) between the preparation and the first clock reading and before the last one; --no-barrier restores the former timed region. (2) Both classes of every target keep their inputs in one block of memory whose slots are dealt to the classes at random (ClassStore); a repeated value occupies as many slots as the other class has values. (3) The measuring loop uses the class as an index and splits the measurements afterwards. (4) Controls at every run: control-negative-mlkem-ciphertexts-<set>, control-negative-aes-random-keys, control-same-class (same distribution in both classes; an exceedance invalidates the run); control-positive-mlkem-leak-ML-KEM-768 (measured 62 and 71 with 40 000 per class, 20.7 with 6 000) and control-leaky-compare must be detected. After the fix (400 000 per class, two runs each, load 1.9 to 2.6): mlkem-decaps-message-ML-KEM-512 max |t| = 1.2 and 1.9; ML-KEM-768 1.4 and 0.5 (1.8 and 1.1 with 8192 ciphertexts per class); ML-KEM-1024 2.0 and 2.1. aes-key-dependence at 1 000 000 per class: 0.7, 1.9, 1.2. The former asymmetric form of the target is kept as info-former-preparation-<set>, without verdict: it is protected by the barrier only, each class still has its own memory, and it reached 4.35 once in twelve runs at 400 000 per class and 4.1 once at 40 000; it could not serve as a pass/fail control. Disposition proposed to the owner: measurement artefact of the audit tooling; no dependence of the decapsulation time on the ciphertext or on the decrypted message found at this sensitivity, and none in the compiled code. The severity recorded at detection (high) is kept in this entry and is the owner's to reclassify. Remaining recommendations: include the ML-KEM decapsulation path and this harness in the independent cryptographic review; time on an iPhone if a device harness becomes available.",18 "evidence": "qytiming runs of 2026-12-04 on M4M64a (qytiming --only <target> --scale 10 [--no-barrier] [--pool N]; targets diag-* reproduce the former per-class storage); disassembly with otool -tV of the release objects (Swift 6.3.3 on M4M64a, Swift 6.4.2 on the laptop) and of the iOS archive built from 60c944c (same branch counts as 6.4.2).",19 "fingerprint": ""20}21
Files main
Menu

Theme