SPB Git

Repository Public

crypto-primitives.json 44.1 KB 805 lines json

1{2  "schema": "qyvora-review/1",3  "title": "Manual source review of the cryptographic primitives: timing, validation, entropy",4  "reviewed_revision_base": "b3e95a0",5  "method": "Every source file of QyvoraMath, QyvoraKeccak, QyvoraSymmetric, QyvoraMLKEM, QyvoraMLDSA, QyvoraSLHDSA, QyvoraSecp256k1 and QyvoraCrypto read in full by the audit agent (no tool); each construct that touches a secret, or that validates untrusted input, is listed with a verdict. Source-level review only: Swift gives no constant-time guarantee and the generated machine code was not inspected; statistical timing tests are run separately (security/tests, qytiming).",6  "verdicts": {7    "constant-time by construction": "no secret-dependent branch, memory index or variable-time instruction at source level",8    "variable-time, public data only": "data-dependent timing on values that are public",9    "variable-time on secret-derived data, inherent to the algorithm": "data-dependent timing on secret-derived values that the algorithm's specification itself requires",10    "variable-time, rejection of values independent of the released secret": "rejection sampling or retry whose timing reveals only discarded values or an iteration count the standard allows to leak",11    "conforms": "validation or parameter handling matches the cited standard",12    "residual risk (documented)": "not a defect of this code; limit of the platform, documented",13    "finding (fixed)": "defect, fixed, see finding_id"14  },15  "entropy": {16    "source": "SystemRandom.bytes (SecRandomCopyBytes) is the only generator referenced in Sources/ (grep for arc4random, SystemRandomNumberGenerator, .random(, drand48, SecRandom: no other use outside QyvoraMath/SystemRandom.swift at the reviewed revision).",17    "failure_mode": "precondition failure (process stops) if SecRandomCopyBytes does not return errSecSuccess",18    "key_generation_paths": [19      "MLKEM.generateKeyPair (d, z)",20      "MLKEM.encapsulate (m)",21      "MLDSA.generateKeyPair (xi)",22      "MLDSA.sign hedged (rnd)",23      "SLHDSA.generateKeyPair (SK.seed, SK.prf, PK.seed)",24      "SLHDSA.sign hedged (opt_rand)",25      "AES256GCM.seal / ChaCha20Poly1305.seal (96-bit nonce)"26    ],27    "secp256k1": "no key generation in the module (keys come from BIP-32 derivation in QyvoraCore); ECDSA nonces are deterministic (RFC 6979), Schnorr takes caller-supplied auxiliary randomness",28    "aead_random_nonce_birthday_bound": {29      "nonce_bits": 96,30      "collision_probability": "about q^2 / 2^97 after q seals under one key",31      "examples": {32        "2^16 seals": "2^-65",33        "2^20 seals": "2^-57",34        "2^24 seals": "2^-49",35        "2^32 seals (SP 800-38D limit)": "2^-33"36      },37      "consequence_of_reuse": "XOR of the two plaintexts revealed and, for GCM, the authentication key recoverable (forgeries)",38      "enforced_by_engine": false39    }40  },41  "entries": [42    {43      "module": "QyvoraMath",44      "file": "Sources/QyvoraMath/ConstantTime.swift",45      "line": 50,46      "construct": "ConstantTime.equal: length guard, then OR-accumulated XOR over the whole length, result through isZeroMask",47      "secret_involved": true,48      "verdict": "constant-time by construction",49      "rationale": "No early exit on content; the only early return is on the lengths, which are public in every caller (tags of fixed size, 32-byte hashes). The accumulator is a plain UInt8: the Swift optimiser is free to vectorise the loop but has no semantic licence to short-circuit an OR-reduction; nothing in the language forbids it either (no constant-time guarantee in Swift), which is why fork TIMING measures it."50    },51    {52      "module": "QyvoraMath",53      "file": "Sources/QyvoraMath/ConstantTime.swift",54      "line": 64,55      "construct": "ConstantTime.select: byte-wise (a & mask) | (b & ~mask); precondition on equal lengths",56      "secret_involved": true,57      "verdict": "constant-time by construction",58      "rationale": "Mask arithmetic only. The precondition is on public lengths; the single caller in the reviewed modules (ML-KEM decapsulation) passes two 32-byte arrays. A compiler could in theory turn the mask expression into a conditional move (still constant time) but not into a branch on secret data without a miscompilation-level transformation; not guaranteed by the language."59    },60    {61      "module": "QyvoraMath",62      "file": "Sources/QyvoraMath/ConstantTime.swift",63      "line": 75,64      "construct": "SecureMemory.zero: memset_s over the array's own storage",65      "secret_involved": true,66      "verdict": "residual risk (documented)",67      "rationale": "memset_s may not be removed by the optimiser. Limits verified by reading: (1) it erases `count` bytes, not the spare capacity of the array; (2) if the array shares its storage with another value (copy-on-write) withUnsafeMutableBytes first copies it, and the copy is what gets erased - the other reference keeps the bytes; (3) earlier reallocations of a growing array are not reachable. See memory-hygiene-crypto.json."68    },69    {70      "module": "QyvoraMath",71      "file": "Sources/QyvoraMath/SystemRandom.swift",72      "line": 53,73      "construct": "SystemRandom.bytes: SecRandomCopyBytes, precondition on errSecSuccess",74      "secret_involved": true,75      "verdict": "conforms",76      "rationale": "Only entropy source of the engine. A generator failure traps the process (fail closed) instead of returning zeros or partial output. A negative count traps in Array(repeating:count:) - programming error, every caller passes a constant or a parameter-set size."77    },78    {79      "module": "QyvoraMath",80      "file": "Sources/QyvoraMath/Bytes.swift",81      "line": 74,82      "construct": "Hex.nibble: switch on the character; Hex.encode: table indexed by the nibble",83      "secret_involved": false,84      "verdict": "variable-time, public data only",85      "rationale": "Hex coding is variable-time (branch per character, table lookup per nibble). No reviewed crypto module hex-decodes or hex-encodes a secret; a caller that prints or parses a private key in hexadecimal goes through it (reported to REVIEW-B scope, not a primitive finding)."86    },87    {88      "module": "QyvoraSecp256k1",89      "file": "Sources/QyvoraSecp256k1/U256.swift",90      "line": 101,91      "construct": "U256.add / U256.sub: addingReportingOverflow chains, carries converted with `c ? 1 : 0`",92      "secret_involved": true,93      "verdict": "constant-time by construction",94      "rationale": "Fixed sequence of four limb additions; the carry is a Bool turned into 0/1, which the ARM64 backend emits as ADCS/CSET, not as a branch. Source-level constant time; code generation not guaranteed by the language."95    },96    {97      "module": "QyvoraSecp256k1",98      "file": "Sources/QyvoraSecp256k1/U256.swift",99      "line": 75,100      "construct": "U256.limb(i) / bit(i): switch on the limb index",101      "secret_involved": false,102      "verdict": "variable-time, public data only",103      "rationale": "The index is the loop counter of the scalar multiplication or the exponentiation (public). The value read is secret but the access pattern is not: every bit position is read exactly once in a fixed order."104    },105    {106      "module": "QyvoraSecp256k1",107      "file": "Sources/QyvoraSecp256k1/U256.swift",108      "line": 90,109      "construct": "U256.zeroMask / isZero: (v | -v) >> 63 - 1, no branch on the value",110      "secret_involved": true,111      "verdict": "constant-time by construction",112      "rationale": "Mask computation; isZero compares the mask with 0, a branch on a one-bit result that callers only use for validity checks."113    },114    {115      "module": "QyvoraSecp256k1",116      "file": "Sources/QyvoraSecp256k1/U256.swift",117      "line": 124,118      "construct": "U256.select: limb-wise mask selection",119      "secret_involved": true,120      "verdict": "constant-time by construction",121      "rationale": "Used by modular add/sub/reduce, by the Montgomery final subtraction and by the scalar multiplication."122    },123    {124      "module": "QyvoraSecp256k1",125      "file": "Sources/QyvoraSecp256k1/U256.swift",126      "line": 130,127      "construct": "U256.lessThan: full 256-bit subtraction, borrow returned",128      "secret_involved": true,129      "verdict": "constant-time by construction",130      "rationale": "Documented as 'variable time: public values only' but implemented as a complete subtraction: constant time in fact. Called on secret values in three places (private-key range check, RFC 6979 candidate check, low-s test), where only the one-bit result is branched on."131    },132    {133      "module": "QyvoraSecp256k1",134      "file": "Sources/QyvoraSecp256k1/U256.swift",135      "line": 193,136      "construct": "Modulus.montMul: CIOS Montgomery product, fixed 4x4 limb schedule, final subtraction by mask",137      "secret_involved": true,138      "verdict": "constant-time by construction",139      "rationale": "No branch, no secret index; multipliedFullWidth is a single UMULH/MUL pair on ARM64 (constant time on Apple silicon; data-independent timing is not architecturally guaranteed for every CPU unless DIT is set - see residual risks). Correct for an odd modulus above 2^255 and operands below the modulus: both moduli (p and n) satisfy this and every caller reduces its operands first.",140      "finding_id": "QYV-CRY-004"141    },142    {143      "module": "QyvoraSecp256k1",144      "file": "Sources/QyvoraSecp256k1/U256.swift",145      "line": 228,146      "construct": "Modulus.montPow: square-and-multiply branching on the exponent bit",147      "secret_involved": false,148      "verdict": "variable-time, public data only",149      "rationale": "The exponent is always a public constant (p-2, n-2, (p+1)/4). The base may be secret (the nonce k in order.inverse(k), the Z coordinate): the sequence of operations depends on the exponent only."150    },151    {152      "module": "QyvoraSecp256k1",153      "file": "Sources/QyvoraSecp256k1/U256.swift",154      "line": 238,155      "construct": "Modulus.inverse: Fermat inversion a^(m-2)",156      "secret_involved": true,157      "verdict": "constant-time by construction",158      "rationale": "Used for k^-1 in ECDSA signing. No extended Euclid (which would be variable time on the nonce). inverse(0) = 0, never reached with a valid nonce."159    },160    {161      "module": "QyvoraSecp256k1",162      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",163      "line": 82,164      "construct": "Point.add / Point.double: complete projective formulas (Renes-Costello-Batina 2016, a = 0)",165      "secret_involved": true,166      "verdict": "constant-time by construction",167      "rationale": "No exceptional case: identity, doubling and inverse points go through the same field operations, so the scalar multiplication needs no special-case branch. Checked against the paper's algorithms 7 and 9 line by line; b3 = 21."168    },169    {170      "module": "QyvoraSecp256k1",171      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",172      "line": 154,173      "construct": "Point.multiply: 256 iterations of double, add, mask-select on the scalar bit",174      "secret_involved": true,175      "verdict": "constant-time by construction",176      "rationale": "Double-and-add-always from the identity over all 256 bits: no leading-zero skip (no Minerva-style nonce bit-length leak), no table, no secret index. Slow (no window) but simple. The same routine is used for public scalars in verification."177    },178    {179      "module": "QyvoraSecp256k1",180      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",181      "line": 165,182      "construct": "Point.affine: `if isIdentity { return nil }`, then inversion of Z",183      "secret_involved": true,184      "verdict": "variable-time, public data only",185      "rationale": "Branches on whether the result is the identity. For k*G with 1 <= k < n the result is never the identity; the branch outcome is therefore constant on every secret path (public key derivation, ECDSA nonce point, Schnorr)."186    },187    {188      "module": "QyvoraSecp256k1",189      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",190      "line": 205,191      "construct": "scalar(): rejects 0 and values >= n",192      "secret_involved": true,193      "verdict": "variable-time, public data only",194      "rationale": "Validity of a private key is not a secret; the comparison itself is a full subtraction."195    },196    {197      "module": "QyvoraSecp256k1",198      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",199      "line": 289,200      "construct": "rfc6979Nonce: HMAC-SHA256 DRBG of RFC 6979 section 3.2",201      "secret_involved": true,202      "verdict": "constant-time by construction",203      "rationale": "Checked against RFC 6979 3.2 steps a-h for qlen = hlen = 256: bits2octets = digest mod n, int2octets = 32-byte key. HMAC-SHA256 is constant time for fixed lengths. Since the hardening of QYV-CRY-002 the intermediate K, V and the two messages containing the private key are erased.",204      "finding_id": "QYV-CRY-002"205    },206    {207      "module": "QyvoraSecp256k1",208      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",209      "line": 324,210      "construct": "RFC 6979 candidate rejection: `!candidate.isZero, lessThan(candidate, n)`",211      "secret_involved": true,212      "verdict": "variable-time, rejection of values independent of the released secret",213      "rationale": "Branch on a secret candidate, taken with probability about 2^-128 (candidate >= n or zero). Required by the RFC; the rejected value is discarded."214    },215    {216      "module": "QyvoraSecp256k1",217      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",218      "line": 339,219      "construct": "ECDSA sign: deterministic nonce, r = (kG).x mod n, s = k^-1 (z + r d), retry loop",220      "secret_involved": true,221      "verdict": "constant-time by construction",222      "rationale": "Per-signature work is independent of d and k except for the retry conditions (r = 0, s = 0: probability about 2^-256). r, s, the parity of R.y and the low-s decision are functions of the published signature and recovery id. No verify-after-sign (fault attacks are outside the software threat model; recommended as defence in depth). Deterministic, not hedged: acceptable for RFC 6979, see entropy notes.",223      "finding_id": "QYV-CRY-003"224    },225    {226      "module": "QyvoraSecp256k1",227      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",228      "line": 355,229      "construct": "low-s normalisation: `if lessThan(halfN, s) { s = n - s }`",230      "secret_involved": false,231      "verdict": "variable-time, public data only",232      "rationale": "s is part of the published signature; halfN = (n-1)/2 checked by hand."233    },234    {235      "module": "QyvoraSecp256k1",236      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",237      "line": 364,238      "construct": "ECDSA verify: range checks 0 < r, s < n, optional low-s, u1 G + u2 Q, x mod n == r",239      "secret_involved": false,240      "verdict": "variable-time, public data only",241      "rationale": "Public inputs only. r = 0, s = 0, r >= n, s >= n rejected; the public key is parsed with the curve check; the identity result is rejected. High-s rejected by default (BIP-62 / EIP-2 policy)."242    },243    {244      "module": "QyvoraSecp256k1",245      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",246      "line": 381,247      "construct": "recoverPublicKey: recovery id < 4, x = r (+ n when bit 1), lift, Q = r^-1 (sR - zG)",248      "secret_involved": false,249      "verdict": "variable-time, public data only",250      "rationale": "r + n checked for overflow and for < p; identity result rejected."251    },252    {253      "module": "QyvoraSecp256k1",254      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",255      "line": 403,256      "construct": "parseDER: strict BIP-66 parser",257      "secret_involved": false,258      "verdict": "conforms",259      "rationale": "Total length 8...72 with a single-byte length field, INTEGER tags, lengths 1...33, no negative value, no superfluous leading zero, no trailing bytes. Every index is guarded before use: no trap on malformed input (read path by path). r = 0 or s = 0 parse and are rejected by verify."260    },261    {262      "module": "QyvoraSecp256k1",263      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",264      "line": 222,265      "construct": "parse(publicKey:): 33-byte compressed or 65-byte uncompressed SEC 1",266      "secret_involved": false,267      "verdict": "conforms",268      "rationale": "x >= p and y >= p rejected, curve equation checked (fromAffine) or square root verified (lift); hybrid encodings 06/07 and the identity encoding refused. Cofactor 1: no subgroup check needed."269    },270    {271      "module": "QyvoraSecp256k1",272      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",273      "line": 247,274      "construct": "privateKeyAdd (BIP-32): (d + t) mod n, error when t >= n or the sum is 0",275      "secret_involved": true,276      "verdict": "constant-time by construction",277      "rationale": "Modular addition by mask; the zero-result branch has probability about 2^-256 and is required by BIP-32."278    },279    {280      "module": "QyvoraSecp256k1",281      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",282      "line": 437,283      "construct": "schnorrSign (BIP-340): d and k negated by mask on the parity of the public point, aux-rand masking, verify-after-sign",284      "secret_involved": true,285      "verdict": "constant-time by construction",286      "rationale": "U256.select on the parity bit, no branch on d or k. The signature is verified before it is returned (BIP-340 recommendation). k = 0 is refused. The caller supplies auxRand: zeros give a deterministic signature, which BIP-340 allows."287    },288    {289      "module": "QyvoraSecp256k1",290      "file": "Sources/QyvoraSecp256k1/Secp256k1.swift",291      "line": 460,292      "construct": "schnorrVerify: lift_x of the key, r < p, s < n, R = sG - eP, R.y even, R.x == r",293      "secret_involved": false,294      "verdict": "variable-time, public data only",295      "rationale": "Matches BIP-340 verification; existing test replays the BIP-340 vectors."296    },297    {298      "module": "QyvoraSymmetric",299      "file": "Sources/QyvoraSymmetric/AES.swift",300      "line": 206,301      "construct": "AES S-box: algebraic inversion x^254 in GF(2^8) on eight bytes per 64-bit word, then the affine map",302      "secret_involved": true,303      "verdict": "constant-time by construction",304      "rationale": "No S-box table and no T-table: nothing is indexed by key or data, so the classical AES cache-timing attacks do not apply. Fixed sequence of shifts, masks and XORs. About two orders of magnitude slower than AES instructions; the product seals the vault with the system AES-256-GCM and uses this one as a cross-check."305    },306    {307      "module": "QyvoraSymmetric",308      "file": "Sources/QyvoraSymmetric/AES.swift",309      "line": 84,310      "construct": "AES key schedule: `i % nk` on the round index",311      "secret_involved": false,312      "verdict": "variable-time, public data only",313      "rationale": "Index and key length are public; SubWord goes through the table-free S-box. The expanded 32-bit schedule is erased with SecureMemory.zero."314    },315    {316      "module": "QyvoraSymmetric",317      "file": "Sources/QyvoraSymmetric/AESGCM.swift",318      "line": 67,319      "construct": "GHASH multiplication: 128 precomputed multiples of H, all read for every block and kept or dropped by a mask from one bit of the accumulator",320      "secret_involved": true,321      "verdict": "constant-time by construction",322      "rationale": "The table is read in full in a fixed order: no secret index. This is the bit-serial method (slow, no carry-less multiply instruction). The table is erased by GHASH.wipe."323    },324    {325      "module": "QyvoraSymmetric",326      "file": "Sources/QyvoraSymmetric/AESGCM.swift",327      "line": 242,328      "construct": "GCM tag comparison: ConstantTime.equal(expected, tag), expected tag erased",329      "secret_involved": true,330      "verdict": "constant-time by construction",331      "rationale": "Verification happens before any counter-mode decryption: no plaintext is produced on failure."332    },333    {334      "module": "QyvoraSymmetric",335      "file": "Sources/QyvoraSymmetric/AESGCM.swift",336      "line": 237,337      "construct": "GCM tag length fixed at 16 bytes",338      "secret_involved": false,339      "verdict": "conforms",340      "rationale": "A truncated tag throws invalidTagLength: the short-tag forgery weakness of SP 800-38D appendix C is not reachable."341    },342    {343      "module": "QyvoraSymmetric",344      "file": "Sources/QyvoraSymmetric/AESGCM.swift",345      "line": 121,346      "construct": "GCM limits: 96-bit nonce in the public interface, plaintext <= 2^36 - 32 bytes",347      "secret_involved": false,348      "verdict": "conforms",349      "rationale": "2^39 - 256 bits as in SP 800-38D 5.2.1.1. The associated-data limit (2^61 bytes) cannot be reached with an in-memory array. The 32-bit counter wraps modulo 2^32 as the specification requires (inc32)."350    },351    {352      "module": "QyvoraSymmetric",353      "file": "Sources/QyvoraSymmetric/AESGCM.swift",354      "line": 280,355      "construct": "AES256GCM.seal with a random 96-bit nonce from SystemRandom",356      "secret_involved": false,357      "verdict": "conforms",358      "rationale": "Birthday bound: after q seals under one key the probability of a repeated nonce is about q^2 / 2^97. SP 800-38D 8.3 limits a key to 2^32 seals (collision probability about 2^-33); 2^20 seals give about 2^-57, 2^24 about 2^-49. A repeated nonce reveals the XOR of two plaintexts and the GHASH key (forgeries). The engine does not count seals: the bound has to be respected by the callers (vault records are re-sealed at most a few times per user action)."359    },360    {361      "module": "QyvoraSymmetric",362      "file": "Sources/QyvoraSymmetric/ChaCha20Poly1305.swift",363      "line": 52,364      "construct": "ChaCha20 quarter round: add, rotate, XOR on 32-bit words",365      "secret_involved": true,366      "verdict": "constant-time by construction",367      "rationale": "No table, no branch. Block counter overflow is refused before encryption (messageTooLong)."368    },369    {370      "module": "QyvoraSymmetric",371      "file": "Sources/QyvoraSymmetric/ChaCha20Poly1305.swift",372      "line": 183,373      "construct": "Poly1305: five 26-bit limbs, 64-bit products, final reduction by mask",374      "secret_involved": true,375      "verdict": "constant-time by construction",376      "rationale": "Limb bounds checked: products stay below 2^59. The final 'h >= p' selection uses the sign of g4 as a mask. r, s and the accumulator are zeroed in finalize."377    },378    {379      "module": "QyvoraSymmetric",380      "file": "Sources/QyvoraSymmetric/ChaCha20Poly1305.swift",381      "line": 335,382      "construct": "ChaCha20-Poly1305 tag comparison: ConstantTime.equal, verify before decrypt",383      "secret_involved": true,384      "verdict": "constant-time by construction",385      "rationale": "Tag length fixed at 16; one-time key erased."386    },387    {388      "module": "QyvoraSymmetric",389      "file": "Sources/QyvoraSymmetric/ChaCha20Poly1305.swift",390      "line": 348,391      "construct": "ChaCha20Poly1305.seal with a random 96-bit nonce",392      "secret_involved": false,393      "verdict": "conforms",394      "rationale": "Same birthday bound as AES-GCM (q^2 / 2^97). Not used by the product at the reviewed revision ('available')."395    },396    {397      "module": "QyvoraSymmetric",398      "file": "Sources/QyvoraSymmetric/SHA2.swift",399      "line": 255,400      "construct": "HMAC: key block XOR ipad/opad, two hash passes",401      "secret_involved": true,402      "verdict": "constant-time by construction",403      "rationale": "Branches only on the key length (public). SHA-256/512 are add-rotate-xor. No verification routine is offered: callers compare tags themselves and must use ConstantTime.equal."404    },405    {406      "module": "QyvoraSymmetric",407      "file": "Sources/QyvoraSymmetric/KDF.swift",408      "line": 53,409      "construct": "HKDF.expand: length <= 255 * HashLen checked, PRK length checked",410      "secret_involved": true,411      "verdict": "conforms",412      "rationale": "RFC 5869 bounds enforced by returning nil; the counter cannot wrap."413    },414    {415      "module": "QyvoraSymmetric",416      "file": "Sources/QyvoraSymmetric/KDF.swift",417      "line": 89,418      "construct": "PBKDF2.deriveKey: preconditions on iterations >= 1 and on the output length",419      "secret_involved": true,420      "verdict": "conforms",421      "rationale": "The two preconditions trap. Verified callers: BIP-39 (constant 2048 iterations, 64 bytes) and the engine self-check (constants). The vault and backup paths use the system PBKDF2 and bound the file-supplied iteration count (KDFParameters.isWithinLimits) before any derivation: not reachable from untrusted input at the reviewed revision."422    },423    {424      "module": "QyvoraSymmetric",425      "file": "Sources/QyvoraSymmetric/Argon2.swift",426      "line": 312,427      "construct": "Argon2id second half / Argon2d: reference block index taken from the previous block (password-dependent memory access)",428      "secret_involved": true,429      "verdict": "variable-time on secret-derived data, inherent to the algorithm",430      "rationale": "Data-dependent addressing is the definition of Argon2d and of the second phase of Argon2id (RFC 9106 3.4.1.2); the first half of the first pass is data-independent. Cache-timing leakage about the password is the trade-off accepted by the RFC for resistance to time-memory trade-offs."431    },432    {433      "module": "QyvoraSymmetric",434      "file": "Sources/QyvoraSymmetric/Argon2.swift",435      "line": 315,436      "construct": "Argon2: `(pseudoRandom >> 32) % lanes` and `% laneLength`",437      "secret_involved": true,438      "verdict": "variable-time on secret-derived data, inherent to the algorithm",439      "rationale": "Division by a public divisor of a value derived from the password, in the same data-dependent phase as the memory access above. Not an additional channel of practical weight; the RFC reference implementation does the same."440    },441    {442      "module": "QyvoraSymmetric",443      "file": "Sources/QyvoraSymmetric/Argon2.swift",444      "line": 111,445      "construct": "Argon2 parameter checks: p, m >= 8p, t, tag length >= 4, salt >= 8, inputs < 2^32",446      "secret_involved": false,447      "verdict": "conforms",448      "rationale": "RFC 9106 3.1 bounds enforced with typed errors. There is deliberately no upper bound below the RFC maxima: a caller that feeds file-supplied parameters must cap them (the vault does: 2 GiB, t <= 64, p <= 16), otherwise a forged header could request terabytes (allocation failure = trap)."449    },450    {451      "module": "QyvoraSymmetric",452      "file": "Sources/QyvoraSymmetric/BLAKE2b.swift",453      "line": 197,454      "construct": "BLAKE2b: message word index from the sigma table",455      "secret_involved": false,456      "verdict": "variable-time, public data only",457      "rationale": "The permutation table is indexed by the round number; the words read are secret, the positions are not."458    },459    {460      "module": "QyvoraSymmetric",461      "file": "Sources/QyvoraSymmetric/BLAKE2b.swift",462      "line": 87,463      "construct": "BLAKE2b.init preconditions on digest, key, salt and personalization sizes",464      "secret_involved": false,465      "verdict": "conforms",466      "rationale": "Reached with constants only (Argon2 uses 4...64-byte digests after its own parameter check)."467    },468    {469      "module": "QyvoraSymmetric",470      "file": "Sources/QyvoraSymmetric/RIPEMD160.swift",471      "line": 75,472      "construct": "RIPEMD-160",473      "secret_involved": false,474      "verdict": "variable-time, public data only",475      "rationale": "Used on public keys and scripts only (HASH160)."476    },477    {478      "module": "QyvoraKeccak",479      "file": "Sources/QyvoraKeccak/Keccak.swift",480      "line": 59,481      "construct": "Keccak-f[1600]: 24 rounds on 25 local lanes",482      "secret_involved": true,483      "verdict": "constant-time by construction",484      "rationale": "XOR, AND, NOT, rotations by constants; round constants indexed by the round number."485    },486    {487      "module": "QyvoraKeccak",488      "file": "Sources/QyvoraKeccak/Keccak.swift",489      "line": 241,490      "construct": "KeccakSponge.squeezeAndWipe and the one-shot SHA-3 / SHAKE / cSHAKE functions",491      "secret_involved": true,492      "verdict": "conforms",493      "rationale": "Since QYV-CRY-002 the one-shot functions erase the sponge state: Keccak-f is invertible, so a state left in released memory gives back the last absorbed block (a seed d, xi, z or m).",494      "finding_id": "QYV-CRY-002"495    },496    {497      "module": "QyvoraKeccak",498      "file": "Sources/QyvoraKeccak/SP800185.swift",499      "line": 215,500      "construct": "KMAC.verify: tag length taken from the caller-supplied tag",501      "secret_involved": false,502      "verdict": "finding (fixed)",503      "rationale": "Before the fix an empty tag verified against any key and message, and a one-byte tag could be guessed in 256 tries: KMAC with output length L is a different function for every L, and L was chosen by the sender. Now refused below 8 bytes (SP 800-185 8.4.2). KMAC is not used by the product at the reviewed revision.",504      "finding_id": "QYV-CRY-001"505    },506    {507      "module": "QyvoraKeccak",508      "file": "Sources/QyvoraKeccak/Keccak.swift",509      "line": 198,510      "construct": "KeccakSponge.squeeze(count) / absorb-after-squeeze / KMAC state preconditions",511      "secret_involved": false,512      "verdict": "conforms",513      "rationale": "Programming-error traps (negative count, wrong call order); no caller derives them from untrusted input."514    },515    {516      "module": "QyvoraMLKEM",517      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",518      "line": 95,519      "construct": "Compress_d: multiplication by ceil(2^36 / q) and shift instead of a division by q",520      "secret_involved": true,521      "verdict": "constant-time by construction",522      "rationale": "No division instruction on secret data: the KyberSlash class (variable-time `/ q` in compress, including the d = 1 message decoding of decryption) does not apply. Exactness argued in the source and re-derived here: for a numerator n < 2^23, n (m q - 2^36) < 2^23 * 3329 < 2^36, hence floor(n m / 2^36) = floor(n / q). The existing test compressMatchesDefinition checks every x in [0, q) for the five widths in use (d = 1, 4, 5, 10, 11)."523    },524    {525      "module": "QyvoraMLKEM",526      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",527      "line": 63,528      "construct": "Montgomery and Barrett reductions, canonical(): shifts and masks",529      "secret_involved": true,530      "verdict": "constant-time by construction",531      "rationale": "Signed 16-bit arithmetic with wrapping operators; bounds of every caller re-derived (NTT growth 8q < 2^15, at most four accumulated products)."532    },533    {534      "module": "QyvoraMLKEM",535      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",536      "line": 127,537      "construct": "NTT / inverse NTT / base multiplication: fixed loops, zeta table indexed by the loop counter",538      "secret_involved": true,539      "verdict": "constant-time by construction",540      "rationale": "No coefficient-dependent branch or index."541    },542    {543      "module": "QyvoraMLKEM",544      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",545      "line": 280,546      "construct": "SampleNTT: rejection `d1 < 3329` on SHAKE128(rho, i, j)",547      "secret_involved": false,548      "verdict": "variable-time, public data only",549      "rationale": "The matrix A is public (expanded from rho, which is part of the encapsulation key)."550    },551    {552      "module": "QyvoraMLKEM",553      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",554      "line": 295,555      "construct": "SamplePolyCBD: bit-sliced popcount differences, branch on eta only",556      "secret_involved": true,557      "verdict": "constant-time by construction",558      "rationale": "eta is a parameter of the set. PRF output and sponge erased."559    },560    {561      "module": "QyvoraMLKEM",562      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",563      "line": 410,564      "construct": "messageToPoly: each message bit expanded to a mask, coefficient = mask & 1665",565      "secret_involved": true,566      "verdict": "constant-time by construction",567      "rationale": "No branch on a message bit (the 'Kyber message bit' leak of compilers turning a ternary into a branch is avoided at source level by arithmetic negation; the generated code is not guaranteed by the language - covered by the timing test)."568    },569    {570      "module": "QyvoraMLKEM",571      "file": "Sources/QyvoraMLKEM/MLKEMArithmetic.swift",572      "line": 376,573      "construct": "compressEncode / decodeDecompress / encode12: bit packing with loop counts depending on d only",574      "secret_involved": true,575      "verdict": "constant-time by construction",576      "rationale": "The `while filled >= 8` loops depend on the public bit width."577    },578    {579      "module": "QyvoraMLKEM",580      "file": "Sources/QyvoraMLKEM/MLKEM.swift",581      "line": 240,582      "construct": "ML-KEM.Decaps: re-encryption, difference accumulated over the whole ciphertext, mask select between K' and the implicit-rejection key",583      "secret_involved": true,584      "verdict": "constant-time by construction",585      "rationale": "FIPS 203 algorithm 18. No early exit in the comparison, no branch on the result, K-bar = J(z || c) always computed. A malformed-but-well-sized ciphertext yields the rejection key, never an error. Every temporary secret (m', K', r', z copy, G output) is erased."586    },587    {588      "module": "QyvoraMLKEM",589      "file": "Sources/QyvoraMLKEM/MLKEM.swift",590      "line": 145,591      "construct": "Encapsulation key check (FIPS 203 7.2): length and modulus check without early exit",592      "secret_involved": false,593      "verdict": "conforms",594      "rationale": "ByteDecode12/ByteEncode12 round trip implemented as 'every coefficient < q'. Applied by encapsulate(); encapsInternal() skips it by design and is not called by the product (only by the self-test with its own key)."595    },596    {597      "module": "QyvoraMLKEM",598      "file": "Sources/QyvoraMLKEM/MLKEM.swift",599      "line": 164,600      "construct": "Decapsulation key check (FIPS 203 7.3): length and H(ek) against the embedded hash, in constant time",601      "secret_involved": true,602      "verdict": "conforms",603      "rationale": "Ciphertext length checked first. A decapsulation key whose embedded s-hat or t-hat holds unreduced coefficients (< 4096) cannot overflow: bounds re-derived (4096 * 1664 < q * 2^15)."604    },605    {606      "module": "QyvoraMLKEM",607      "file": "Sources/QyvoraMLKEM/MLKEM.swift",608      "line": 117,609      "construct": "generateKeyPair / encapsulate: d, z and m from SystemRandom, erased after use",610      "secret_involved": true,611      "verdict": "conforms",612      "rationale": "No other randomness. Deterministic entry points (keyGenInternal, encapsInternal) take explicit seeds for the ACVP vectors."613    },614    {615      "module": "QyvoraMLDSA",616      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",617      "line": 109,618      "construct": "Decompose / HighBits / LowBits: multiply-and-shift, branch on gamma2 only",619      "secret_involved": true,620      "verdict": "constant-time by construction",621      "rationale": "No `/` or `%` on a secret coefficient (the constants are those of the reference implementation: 1025 >> 22 and 11275 >> 24). gamma2 is a public parameter."622    },623    {624      "module": "QyvoraMLDSA",625      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",626      "line": 327,627      "construct": "RejBoundedPoly (secret s1, s2): rejection `t < 15` / `t < 9` on nibbles of the seed expansion",628      "secret_involved": true,629      "verdict": "variable-time, rejection of values independent of the released secret",630      "rationale": "The rejected nibbles are discarded and independent of the accepted ones (they are consecutive XOF output); the timing reveals how many were rejected, not the coefficients. The modulo 5 is a multiply-shift. Same structure as the reference implementation; accepted by FIPS 204."631    },632    {633      "module": "QyvoraMLDSA",634      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",635      "line": 370,636      "construct": "ExpandMask (y): fixed-length unpack",637      "secret_involved": true,638      "verdict": "constant-time by construction",639      "rationale": "No rejection; sponge and buffer erased."640    },641    {642      "module": "QyvoraMLDSA",643      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",644      "line": 400,645      "construct": "SampleInBall: `while j > i` rejection and index by the sampled byte",646      "secret_involved": true,647      "verdict": "variable-time, rejection of values independent of the released secret",648      "rationale": "c is derived from the commitment hash. For the released signature c-tilde is public. For rejected attempts c is not published; its positions leak through timing and memory access as in every implementation of FIPS 204 (the standard considers the challenge of a rejected attempt non-sensitive because the attempt is independent of the signature released)."649    },650    {651      "module": "QyvoraMLDSA",652      "file": "Sources/QyvoraMLDSA/MLDSA.swift",653      "line": 369,654      "construct": "exceeds(): infinity-norm test over all coefficients, OR-accumulated, one Bool at the end",655      "secret_involved": true,656      "verdict": "constant-time by construction",657      "rationale": "No early exit inside the norm check."658    },659    {660      "module": "QyvoraMLDSA",661      "file": "Sources/QyvoraMLDSA/MLDSA.swift",662      "line": 523,663      "construct": "Signing rejection loop: `continue` on ||z||, ||r0||, ||c t0|| and the hint weight",664      "secret_involved": true,665      "verdict": "variable-time, rejection of values independent of the released secret",666      "rationale": "The number of iterations and which test failed are observable. The design of ML-DSA (Fiat-Shamir with aborts) allows this: a rejected candidate is independent of the secret given the released signature. Same order of tests and early continues as the pq-crystals reference."667    },668    {669      "module": "QyvoraMLDSA",670      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",671      "line": 139,672      "construct": "makeHint(low:high:): short-circuit comparisons on w0 - c s2 + c t0",673      "secret_involved": true,674      "verdict": "variable-time, rejection of values independent of the released secret",675      "rationale": "Evaluated after the z, r0 and c t0 tests passed but before the hint-weight test, so it can run on a candidate that is then rejected for weight > omega. Identical to the reference implementation. Recorded as a deviation from a strict reading of 'no secret-dependent branch'; no known attack uses it."676    },677    {678      "module": "QyvoraMLDSA",679      "file": "Sources/QyvoraMLDSA/MLDSA.swift",680      "line": 458,681      "construct": "Private-key decoding: s1 / s2 coefficients checked to lie in [-eta, eta] with one aggregated test",682      "secret_involved": true,683      "verdict": "conforms",684      "rationale": "A malformed private key throws invalidPrivateKey; no per-coefficient exit."685    },686    {687      "module": "QyvoraMLDSA",688      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",689      "line": 468,690      "construct": "HintBitUnpack with the three malformed-input checks of FIPS 204 algorithm 21",691      "secret_involved": false,692      "verdict": "conforms",693      "rationale": "Counters non-decreasing and <= omega, positions strictly increasing inside a polynomial, unused bytes zero: signatures are non-malleable in the hint part. Every read is bounded by omega + k (re-derived)."694    },695    {696      "module": "QyvoraMLDSA",697      "file": "Sources/QyvoraMLDSA/MLDSA.swift",698      "line": 560,699      "construct": "Verify: lengths, z range (BitUnpack is injective), hint, ||z|| < gamma1 - beta, c-tilde comparison with `==`",700      "secret_involved": false,701      "verdict": "variable-time, public data only",702      "rationale": "All inputs are public; the final comparison is not secret. Bounds of the unreduced NTT inputs re-derived (products below 2^31 q)."703    },704    {705      "module": "QyvoraMLDSA",706      "file": "Sources/QyvoraMLDSA/MLDSA.swift",707      "line": 236,708      "construct": "Context length <= 255, pre-hash OID check, external-mu entry points",709      "secret_involved": false,710      "verdict": "conforms",711      "rationale": "contextTooLong thrown on signing, false returned on verification."712    },713    {714      "module": "QyvoraMLDSA",715      "file": "Sources/QyvoraMLDSA/MLDSA.swift",716      "line": 351,717      "construct": "Signing randomness: hedged by default (rnd from SystemRandom), deterministic and explicit variants available",718      "secret_involved": true,719      "verdict": "conforms",720      "rationale": "Hedged signing is the FIPS 204 default and protects against fault and nonce-reuse scenarios. The product uses .deterministic once, for the identity self-probe (Identity.swift:369), outside this review's modules."721    },722    {723      "module": "QyvoraMLDSA",724      "file": "Sources/QyvoraMLDSA/MLDSAArithmetic.swift",725      "line": 487,726      "construct": "Workspace: one heap block for all secret polynomials, erased with memset_s in deinit",727      "secret_involved": true,728      "verdict": "conforms",729      "rationale": "~Copyable: cannot be duplicated; erased on every exit path including throws."730    },731    {732      "module": "QyvoraSLHDSA",733      "file": "Sources/QyvoraSLHDSA/Core.swift",734      "line": 88,735      "construct": "WOTS+ chain: number of F iterations taken from the message digits",736      "secret_involved": false,737      "verdict": "variable-time, public data only",738      "rationale": "The digits come from the value being signed at that layer (a FORS public key or an XMSS root), which anyone can recompute from the signature. The secret (SK.seed) only enters as a hash input."739    },740    {741      "module": "QyvoraSLHDSA",742      "file": "Sources/QyvoraSLHDSA/Core.swift",743      "line": 312,744      "construct": "FORS signing: leaf index from the message digest, all 2^a leaves computed for every tree",745      "secret_involved": false,746      "verdict": "variable-time, public data only",747      "rationale": "Indices derive from H_msg(R, PK, M), public. The per-leaf secret value is erased with memset_s."748    },749    {750      "module": "QyvoraSLHDSA",751      "file": "Sources/QyvoraSLHDSA/TweakableHash.swift",752      "line": 102,753      "construct": "PRF(PK.seed, SK.seed, ADRS): F on the secret seed, working memory erased",754      "secret_involved": true,755      "verdict": "constant-time by construction",756      "rationale": "Hash-based: no arithmetic on the secret. Since QYV-CRY-002 the SHA-2 block, its message schedule and the Keccak state used for a PRF call are erased (they hold SK.seed in clear or in an invertible form).",757      "finding_id": "QYV-CRY-002"758    },759    {760      "module": "QyvoraSLHDSA",761      "file": "Sources/QyvoraSLHDSA/TweakableHash.swift",762      "line": 307,763      "construct": "PRF_msg: HMAC-SHA-256/512 or SHAKE256 over SK.prf, opt_rand, M",764      "secret_involved": true,765      "verdict": "constant-time by construction",766      "rationale": "Randomizer R; hedged by default (opt_rand from SystemRandom), deterministic variant uses PK.seed as FIPS 205 specifies."767    },768    {769      "module": "QyvoraSLHDSA",770      "file": "Sources/QyvoraSLHDSA/SLHDSA.swift",771      "line": 316,772      "construct": "Verify: public key and signature lengths checked before any pointer arithmetic, root compared with ConstantTime.equal",773      "secret_involved": false,774      "verdict": "conforms",775      "rationale": "Signature size = (1 + k(1+a) + h + d len) n re-derived for the twelve sets (h = d h'); every read stays inside the signature. Digest split checked for the three (md, tree, leaf) layouts including the 64-bit tree index of the 256f sets."776    },777    {778      "module": "QyvoraSLHDSA",779      "file": "Sources/QyvoraSLHDSA/Core.swift",780      "line": 199,781      "construct": "Parallel leaf computation (DispatchQueue.concurrentPerform) writing disjoint cells",782      "secret_involved": true,783      "verdict": "conforms",784      "rationale": "Each task owns its output cell and its ADRS copies; TweakHash holds values, no shared mutable state. Thread-sanitizer run belongs to fork FUZZ."785    },786    {787      "module": "QyvoraSLHDSA",788      "file": "Sources/QyvoraSLHDSA/Core.swift",789      "line": 47,790      "construct": "base2b / T precondition on internal sizes",791      "secret_involved": false,792      "verdict": "conforms",793      "rationale": "Sizes come from the parameter set, never from the input."794    },795    {796      "module": "QyvoraCrypto",797      "file": "Sources/QyvoraCrypto/QyvoraCrypto.swift",798      "line": 119,799      "construct": "QyvoraEngine.selfTest: known answers compared with `==`",800      "secret_involved": false,801      "verdict": "variable-time, public data only",802      "rationale": "Public test values; passes unchanged after the hardening commits (QyvoraCryptoTests)."803    }804  ]805}
Files main
Menu

Theme