wire-core: QA log — gates green, port verified against Windows source

Verdict: PASS. Checked every PackageType value, byte offset, the
checksum range, the magic-hash shift/overflow expression, PBKDF2
parameters and the 48-byte stream preamble against the Windows source
directly, and re-derived the documented magic-number and PBKDF2
examples independently in Python. No findings beyond the hex-gloss typo
already fixed in the prior commit.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
lucioandClaude Sonnet 5 committed 2026-09-16 00:19:53 -07:00
1 parent 56448cca0d
commit e13748c225
1 file changed
+102
+102
View File
@@ -258,4 +258,106 @@ was touched.
## QA log
### 2026-09-16 — QA (Sonnet)
Ran `tools/guard.sh -t 600 -- tools/gates.sh`: all three gates green
(`swift-format lint --strict`, MWBCore layering, `swift build
-Xswiftc -warnings-as-errors`).
Checked every Status/TODO tick against the code and, line by line,
against the Windows source at
`/Users/guoliangchen/repo/PowerToys/src/modules/MouseWithoutBorders/App/`:
- `PackageType` raw values — every one of the 26 named types plus
`Matrix`/`Error`/`Invalid` compared 1:1 against `PackageType.cs:15-57`.
Exact match, including `MatrixSwapFlag`/`MatrixTwoRowFlag` as static
constants rather than enum cases (they are OR'd flags, not standalone
wire types).
- `isBig`'s explicit 12-type list (`Packet.swift:148-150`) matches
`DATA.cs:130` (`IsBigPackage`) name-for-name and order-for-order; the
bitwise fallback correctly makes `.error` (0xFE) and `.invalid` (0xFF)
big too, reproducing the Windows receive-loop quirk already recorded
in protocol.md §10.1 note 1 — verified by hand against
`SocketStuff.cs:578-600`.
- `Packet` byte offsets — `Type`(0), `Id`(4), `Src`(8), `Des`(12),
`DateTime`/`Md`(16), `Kd`(24), `Machine1..4`(16,20,24,28),
`PostAction`(16), `machineNameP1..4`(32,40,48,56) — checked against
`DATA.cs:27-73` field offsets computed from `sizeof(PackageType) +
n*sizeof(uint)`/`sizeof(long)`. `MOUSEDATA`/`KEYBDDATA` field order
checked against `MOUSEDATA.cs:18-26`, `KEYBDDATA.cs:18-25`. All
correct.
- Checksum range: `Framing.checksum` sums bytes 2..<32 only, matching
`SocketStuff.cs:509-513` (`TcpSendData`) and `:537-543`
(`ProcessReceivedDataEx`), both bounded by `Package.PACKAGE_SIZE`
(32) even though a big packet is 64 bytes on the wire.
- Magic hash: shift amounts and term order (`h[0]<<23, h[1]<<16,
h[last]<<8, h[2]`) match `Encryption.cs:199` exactly, including the
`<<23`/`<<24` overlap. Independently recomputed the documented
example (key `abcdefghijklmnop`) with a fresh Python SHA-512 chain of
50 001 rounds: got decimal `334517251`, matching the doc and the
Swift `&+` wrapping-arithmetic reproduction. **Found the hex gloss
next to that decimal wrong** — `docs/protocol.md:480` said
`0x13EC_4F03`; `334517251` is actually `0x13F0_5403`. Trivial doc typo,
fixed directly (commit `56448cc`, `qa:` prefix); the decimal value and
the Swift code were never wrong.
- PBKDF2: the `CCKeyDerivationPBKDF` call uses `kCCPRFHmacAlgSHA512`,
100 000 rounds, 32-byte output, UTF-8 password — matches
`Encryption.cs:107-115` and `Rfc2898DeriveBytes.Pbkdf2(string, ...)`'s
documented UTF-8 handling. Independently recomputed the documented
vector (key `abcdefghijklmnop`, salt 16×0x01) with Python's
`hashlib.pbkdf2_hmac('sha512', ...)`: got
`6c30ca8b15c27f6e…14ae2a4da14728e1`, matching the doc exactly.
- 48-byte preamble: `CipherWriter.header` is salt(16) + IV(16) +
encrypted sacrificial block(16) = 48 bytes, matching
`Encryption.cs:124-129` (`GetEncryptedStream`) plus
`Common.cs:1528-1558`/`SocketStuff.cs:105,119`
(`SendOrReceiveARandomDataBlockPerInitialIV`, called on the
*encrypted* stream so the sacrificial block is written through the
cipher, not appended in the clear). `CipherReader` consumes the same
32 clear bytes then discards the first 16 *plaintext* bytes the
cryptor emits, matching the Windows reader path
(`SendOrReceiveARandomDataBlockPerInitialIV(decryptedStream, false)`
reads through the already-wrapped `CryptoStream`).
- Big/small rule including `Error`/`Invalid`: covered above under
`isBig`.
Read every changed file top to bottom for readability against CLAUDE.md:
- File sizes: `Packet.swift` 404, `CipherStream.swift` 212,
`MagicHash.swift` 113, `Framing.swift` 72 lines — all well inside the
300–600 target. No function exceeds ~35 lines.
- No `!` force-unwrap, `try!`, `fatalError` or `precondition` anywhere
in the four files (`grep -n '!' ... | grep -v '//' | grep -v '!='`
turns up only `!input.isEmpty`, `!valid`, `!$0.isWhitespace` — boolean
negation, not force-unwrap).
- No `print`/`Logger`/`NSLog` call anywhere in the diff — nothing to
audit for key-material leakage because nothing logs at all.
- `CipherError`/`PacketError` cases carry only status ints or nothing;
none carry key, salt, IV or plaintext, as the doc comment on
`CipherError` promises.
- No dead code, no TODO/FIXME left in the shipped files.
- Every public symbol has a one-line doc comment; comments cite
Windows `file:line` throughout, none cite nothing.
- Confirmed nothing in these four files acts on a packet before
`Framing.open` returns it — they only encode/decode bytes; there is
no packet dispatch here for a "before decrypt" check to apply to
beyond that. The `CipherReader` doc comment correctly states the
invariant for its callers.
One note, not a finding: `SecurityKey.isValid`/`random` measure length
with Swift's `String.count` (grapheme clusters) where Windows measures
`string.Length` (UTF-16 code units) (`Encryption.cs:237`). For the
ASCII character sets the generator and the UI actually produce this
never differs; flagging only so a later lane doesn't assume the two
are interchangeable for arbitrary input.
No macOS permission was requested, no `CGEvent` posted, no pasteboard
was touched, matching CLAUDE.md invariant 5 — this lane has no such
surface to begin with.
Findings: none outstanding (one trivial doc typo found and fixed
directly, see above).
**Verdict: PASS**
## Review