decomp(md5): improve ProcessBlock with sequential word consumption #1054

Merged
coah80 merged 1 commits from agent/bittle/md5-cursor-review into main 2026-10-03 05:26:53 +00:00
coah80 commented 2026-10-03 05:25:02 +00:00 (Migrated from github.com)

Partial reconstruction

The first 16 MD5 steps consume the context's block sequentially: two endian loads, then advance the cursor. Express that real pointer contract in rotateNextSum and use it only in the first round. The indexed remaining rounds retain rotateSum. This small helper distinction preserves the existing unsigned rotation expression; no extra state, arbitrary ordering hint or register forcing.

  • ProcessBlock: 94.30719% → 94.98366%, still 306/306 instructions
  • Unit: 96.179825% → 96.63377%
  • Exact functions 3/4, matched code 600/1824 and data 456/456 preserved

This archived natural form was previously discarded for helper duplication despite a safe partial gain; it is now reviewed under the decompiled-first priority. It remains nonexact and unlinked.

Independent verification

Rebased on 404a8675f1285007154a5aef7bbd755a691e8739; tested tree 63f3dd8f5a.

  • Full 43U build/progress/report/DOL passed; all 1,027 units compared, only MD5 fuzzy changes and zero regressions
  • Actual source and original PPC streams reduce to the same symbolic 64-step unsigned MD5 recurrence; 128 endian message loads, 64 constants, 48 indices and only four final state stores verified
  • 3,088 production-C digest/chunking cases against hashlib, including standard vectors, block boundaries and one-million-a input
  • 20,000 arbitrary-state production block checks against an independent recurrence under ASan/UBSan; count, block and canaries preserved. Leak detection disabled under ptrace
  • Host padding supplied externally; the PPC-endian GetDigest length stores are not exercised by that host digest test
  • All three exact APIs independently instruction-exact and byte-identical to baseline; allocated nontext data unchanged
  • Pool empty/identical; literal audit all four functions, no candidates/errors
  • DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d; worktree/diff checks pass

Detailed scope and evidence: tools/decomp-assist/allhands-md5-cursor.attempts.md. No linking flags, headers or compiler settings changed.

Note

Rewrite first round of MD5 ProcessBlock to use sequential word cursor

  • Adds a rotateNextSum helper and STEP_NEXT macro that consume one message word per step and advance a shared word cursor
  • Switches the sixteen first-round steps in ProcessBlock in md5.c to this form; the remaining three rounds keep the indexed STEP macro
  • Adds an engineering record in allhands-md5-cursor.attempts.md covering audits, validation, and build status
  • Risk: matches the original binary only if cursor advancement in rotateNextSum matches the removed pointer post-increments at each first-round step site

Macroscope summarized 5a9a0be.

## Partial reconstruction The first 16 MD5 steps consume the context's block sequentially: two endian loads, then advance the cursor. Express that real pointer contract in rotateNextSum and use it only in the first round. The indexed remaining rounds retain rotateSum. This small helper distinction preserves the existing unsigned rotation expression; no extra state, arbitrary ordering hint or register forcing. - ProcessBlock: 94.30719% → 94.98366%, still 306/306 instructions - Unit: 96.179825% → 96.63377% - Exact functions 3/4, matched code 600/1824 and data 456/456 preserved This archived natural form was previously discarded for helper duplication despite a safe partial gain; it is now reviewed under the decompiled-first priority. It remains nonexact and unlinked. ## Independent verification Rebased on 404a8675f1285007154a5aef7bbd755a691e8739; tested tree 63f3dd8f5ac4af93de6d9dade14c79e4db2e1e7b. - Full 43U build/progress/report/DOL passed; all 1,027 units compared, only MD5 fuzzy changes and zero regressions - Actual source and original PPC streams reduce to the same symbolic 64-step unsigned MD5 recurrence; 128 endian message loads, 64 constants, 48 indices and only four final state stores verified - 3,088 production-C digest/chunking cases against hashlib, including standard vectors, block boundaries and one-million-a input - 20,000 arbitrary-state production block checks against an independent recurrence under ASan/UBSan; count, block and canaries preserved. Leak detection disabled under ptrace - Host padding supplied externally; the PPC-endian GetDigest length stores are not exercised by that host digest test - All three exact APIs independently instruction-exact and byte-identical to baseline; allocated nontext data unchanged - Pool empty/identical; literal audit all four functions, no candidates/errors - DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d; worktree/diff checks pass Detailed scope and evidence: tools/decomp-assist/allhands-md5-cursor.attempts.md. No linking flags, headers or compiler settings changed. <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Rewrite first round of MD5 `ProcessBlock` to use sequential word cursor > - Adds a `rotateNextSum` helper and `STEP_NEXT` macro that consume one message word per step and advance a shared word cursor > - Switches the sixteen first-round steps in `ProcessBlock` in [md5.c](https://github.com/coah80/wii-ipl/pull/1054/files#diff-dbadc0abfbe32c537af7f9f3221ac1d057cd9705ae3611325af96ae5627bce7d) to this form; the remaining three rounds keep the indexed `STEP` macro > - Adds an engineering record in [allhands-md5-cursor.attempts.md](https://github.com/coah80/wii-ipl/pull/1054/files#diff-a1d37353a899cb9b400308c9ef46b3f05817cf221ff2ce49ef9c63f724520596) covering audits, validation, and build status > - Risk: matches the original binary only if cursor advancement in `rotateNextSum` matches the removed pointer post-increments at each first-round step site > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 5a9a0be.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-03 05:26:50 +00:00 (Migrated from github.com)

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.
Sign in to join this conversation.