Skip to content

Restart a stored ZipCrypto member mid-member from known plaintext (RustyGet) - #373

Closed
xbmc4lyfe wants to merge 1 commit into
mainfrom
zipcrypto-restart
Closed

xbmc4lyfe wants to merge 1 commit into
mainfrom
zipcrypto-restart

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

Closes #362 (RustyGet#813, prybar#225).

A stored ZipCrypto member can now restart at any offset from the known plaintext before it. Before, it could only restart at its start.

How it works

  • Why it's exact: ZipCrypto's three keys at byte n depend only on the password, the 12-byte header and plaintext bytes 0..n-1. Rolling the keys over the known plaintext puts the decryptor exactly at the target, so no packed byte between the header and the target is read.
  • Grain: member_restart now reports StoredSequential with the new RestartGrain::KnownPlaintext (the enum is #[non_exhaustive]).
  • Plan: open_at returns Start::ZipCrypto { donor }. The spans are the header followed by 12 + target..end, and target == size is allowed.
  • Finish:
    • resume_zipcrypto checks the check byte first: the CRC high byte, or the time high byte when bit 3 is set. It then rolls the keys over the header and the known plaintext and returns a positioned ZipCryptoResume.
    • complete_zipcrypto decrypts the rest and proves the member by CRC32 over the known prefix plus the rest.
    • A wrong prefix comes out as Crc, never as accepted output. A supplied prefix_crc is checked, not trusted.
  • Without a map: ZipCryptoResume::new(&ZipCryptoEntry, ...).
  • Errors: OpenAtError::ZipCrypto(ZipCryptoError::…).
  • Supporting changes: ZipCrypto::absorb rolls the keys over plaintext. zipcrypto_check is now shared with the ZIP mapper.

Tests

tests/zip_crypto_restart.rs:

  • Offsets: 0, 1, 11, 12, 13, mid, size-1 and size are byte-exact against a full decrypt, with and without a data descriptor.
  • Counting reader: only the header and the bytes from the target on are read, each once.
  • Check byte: it follows bit 3.
  • Failures: a wrong password fails at the check byte, reading nothing past the header, and a corrupted prefix fails the CRC.
  • Hostile input: short or long headers, mismatched prefixes, a target past the size or u64::MAX, and truncated or over-long data are refused without panics.
  • Empty member.

Fixtures (tests/fixtures/zip-crypto-restart/): one made with Info-ZIP zip -0 -P (bit 3 set, so its check byte is the time byte), one with 7-Zip -mem=ZipCrypto (no descriptor). The binaries were run in docker; the README gives the commands.

Clean-room: written from PKWARE APPNOTE only.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi

…styGet) (#362)

ZipCrypto's keys before member output byte n depend only on the password, the
12-byte encryption header and the plaintext 0..n, so a handover that holds that
plaintext rolls the keys over it and decrypts from packed byte 12 + n on.

- member_restart reports StoredSequential with the new
  RestartGrain::KnownPlaintext; open_at plans Start::ZipCrypto { donor: 0..n }
  with spans = header (0..12), then 12 + n to the end (n may equal the size).
- resume_zipcrypto / complete_zipcrypto (and ZipCryptoResume::new without a
  map) verify the check byte (time high byte with a data descriptor, CRC high
  byte otherwise), roll the keys, decrypt the rest and prove the whole output by
  the member's CRC32. The prefix CRC is always computed from the bytes the keys
  were rolled over; a given one must match.
- skipped_spans keeps the header of a ZipCrypto plan.
- tests/zip_crypto_restart.rs over Info-ZIP (descriptor) and 7-Zip (no
  descriptor) fixtures: offsets 0, 1, 11, 12, 13, mid, size-1, size, a counting
  reader, wrong password, corrupted prefix, hostile inputs.

Clean-room from PKWARE APPNOTE.TXT and observed behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LG44gYJFfVCupfunL2idYi
@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

@codex review

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator Author

Merged onto main via signed fast-forward stack at ae82635..8045570 after clean-room review and macOS + Linux workspace/doctest gates (including persistent-partials).

@xbmc4lyfe xbmc4lyfe closed this Dec 1, 2026
@xbmc4lyfe
xbmc4lyfe deleted the zipcrypto-restart branch December 1, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restart a stored ZipCrypto member mid-member from known plaintext

1 participant