SPB Git

Repository Public

QYV-CRY-003.json 6.6 KB 27 lines json

1{2  "id": "QYV-CRY-003",3  "title": "Key material that the engine cannot erase: secp256k1 scalars on the stack, hash scratch, keys returned as arrays",4  "severity": "medium",5  "cvss_vector": "CVSS:3.1/AV:L/AC:H/PR:H/UI:N/S:U/C:H/I:N/A:N",6  "cvss_score": 4.1,7  "cwe": "CWE-226",8  "masvs": "MASVS-STORAGE-2",9  "area": "crypto",10  "location": "Sources/QyvoraSecp256k1/Secp256k1.swift:339",11  "tool": "manual-review",12  "rule": "secret-not-erasable",13  "status": "open",14  "fix_commit": "",15  "regression_test": "QyvoraCoreTests.KeyMaterialHygieneTests (theSeedFromBytesIsTheSeedFromWords, wipeErasesThePrivateKeyAndTheChainCodeWhereTheyAre, wipeLeavesALiveCopyIntact, derivationAlongAPathIsUnchangedByTheErasureOfItsIntermediates); QyvoraWalletTests.SigningPathHygieneTests (theStoredPhraseFormIsRecognised, signingFromBytesGivesTheSameKeysAsTheImport)",16  "description": "Root cause: Swift offers no way to erase registers or stack frames, and [UInt8] is a copy-on-write value the callee cannot follow. Remaining after QYV-CRY-002: (1) the secp256k1 private scalar d, the ECDSA/Schnorr nonce k, k^-1 and the projective coordinates of k*G are U256 structs in registers and stack slots during and after sign() and schnorrSign(); a leaked nonce together with its signature gives the private key; (2) the message schedule and working variables of the generic SHA-256/SHA-512/RIPEMD-160 compression (stack scratch) and the chaining states copied by HMAC and PBKDF2; (3) every private key, seed, shared secret or derived key returned by the engine as Bytes, whose lifetime and number of copies are decided by the caller. Impact: same as QYV-CRY-002 (post-hoc memory read), with a shorter window for the stack items, which later calls overwrite without guarantee.",17  "recommendation": "Before production: (a) run the secp256k1 signing path on a heap workspace erased with memset_s, as ML-DSA does with its Workspace; (b) give HashFunction an erase requirement and call it from HMAC, HKDF and PBKDF2; (c) carry keys across module boundaries in a non-copyable secret container (QyvoraVault.SecretBytes already exists in the service layer) instead of plain arrays; (d) have the independent reviewer inspect the generated code for spilled secrets. Not fixed in this pass: (a) and (c) change the public signatures used by the service modules and the application.",18  "evidence": "see security/audit/review/memory-hygiene-crypto.json, section not_erased",19  "fingerprint": "2502f62d19b1",20  "open_note": "Reduced on 2026-12-04 (6ac0546), not closed. Done on the signing path of the service: the recovery phrase and the passphrase are read from the vault as bytes and the seed is computed from those bytes (`BIP39.seed(normalizedMnemonic:normalizedPassphrase:)`): no `String` of the phrase is built for a signature; phrase, passphrase, seed, master key, account key, the intermediate extended keys of every derivation (`ExtendedKey.derive(path)`, `BIP84Account.privateKey`), the BIP-32 tweak IL and the child private key are erased with memset_s where they are, each being the only owner of its buffer when it is erased (`ExtendedKey.wipe`, `BIP84Account.wipe`; the test pins that the buffer does not move). STILL NOT ERASABLE: (1) inside QyvoraSecp256k1, the private scalar d, the nonce k, k^-1 and the coordinates of k*G, which are U256 structs in registers and stack slots during and after `sign` and `schnorrSign` (now also during the verify-after-sign); (2) the message schedule and working variables of SHA-256 / SHA-512 / RIPEMD-160 and the chaining states copied by HMAC and PBKDF2 (the seed derivation runs 2 048 HMAC-SHA512 iterations keyed by the phrase); (3) the `String` / `[String]` forms of the phrase wherever it is displayed or typed: creation (`createWallet` returns the words), import, `revealRecoveryPhrase`, the recovery sheet, `verifyPhraseBackup`, the restoration of a backup, and SwiftUI's own copies of text fields; passwords and PINs as `String`; (4) keys the engine returns as arrays to other callers (identity keys, ML-KEM shared secrets, HKDF / Argon2 outputs), whose copies the caller decides; (5) whatever CryptoKit and the system keep internally.",21  "proposed_disposition": "Keep open until the independent review. Proposed for the reviewer: run the secp256k1 signing path on a heap workspace erased with memset_s (as ML-DSA does), give `HashFunction` an erase requirement, and inspect the generated code for spilled secrets. Owner decision for any acceptance of the residual risk.",22  "updated": "2026-12-04",23  "mitigation_commit": "6ac0546",24  "verification": "package tests on M4M64c (Swift 6.3.3, release) and on the laptop (Swift 6.4, release).",25  "resolution_note": "Still open. Reduced on 2026-12-04 (6ac0546), not closed. Done on the signing path of the service: the recovery phrase and the passphrase are read from the vault as bytes and the seed is computed from those bytes (`BIP39.seed(normalizedMnemonic:normalizedPassphrase:)`): no `String` of the phrase is built for a signature; phrase, passphrase, seed, master key, account key, the intermediate extended keys of every derivation (`ExtendedKey.derive(path)`, `BIP84Account.privateKey`), the BIP-32 tweak IL and the child private key are erased with memset_s where they are, each being the only owner of its buffer when it is erased (`ExtendedKey.wipe`, `BIP84Account.wipe`; the test pins that the buffer does not move). STILL NOT ERASABLE: (1) inside QyvoraSecp256k1, the private scalar d, the nonce k, k^-1 and the coordinates of k*G, which are U256 structs in registers and stack slots during and after `sign` and `schnorrSign` (now also during the verify-after-sign); (2) the message schedule and working variables of SHA-256 / SHA-512 / RIPEMD-160 and the chaining states copied by HMAC and PBKDF2 (the seed derivation runs 2 048 HMAC-SHA512 iterations keyed by the phrase); (3) the `String` / `[String]` forms of the phrase wherever it is displayed or typed: creation (`createWallet` returns the words), import, `revealRecoveryPhrase`, the recovery sheet, `verifyPhraseBackup`, the restoration of a backup, and SwiftUI's own copies of text fields; passwords and PINs as `String`; (4) keys the engine returns as arrays to other callers (identity keys, ML-KEM shared secrets, HKDF / Argon2 outputs), whose copies the caller decides; (5) whatever CryptoKit and the system keep internally. Proposed disposition: Keep open until the independent review. Proposed for the reviewer: run the secp256k1 signing path on a heap workspace erased with memset_s (as ML-DSA does), give `HashFunction` an erase requirement, and inspect the generated code for spilled secrets. Owner decision for any acceptance of the residual risk."26}27
Files main
Menu

Theme