Skip to content

Add ByteSource abstraction for content protection - #22

Open
itsthisjustin wants to merge 9 commits into
mainfrom
crypto-support
Open

Add ByteSource abstraction for content protection#22
itsthisjustin wants to merge 9 commits into
mainfrom
crypto-support

Conversation

@itsthisjustin

Copy link
Copy Markdown
Contributor

Introduces a random-access byte source interface and miniz configuration for streaming inflate in the content protection module. ByteSource mirrors FreeInkBook's BookSource shape to enable easy adaptation of various file sources (SD, stdio) without direct filesystem access. Includes dual-mode miniz configuration to either bind to host application's existing miniz or compile a standalone prefixed copy to avoid symbol conflicts.

Introduces a random-access byte source interface and miniz configuration for streaming inflate in the content protection module. ByteSource mirrors FreeInkBook's BookSource shape to enable easy adaptation of various file sources (SD, stdio) without direct filesystem access. Includes dual-mode miniz configuration to either bind to host application's existing miniz or compile a standalone prefixed copy to avoid symbol conflicts.
Make ContentProtection library storage-agnostic by removing SD card file handling implementation. The integrating firmware now provides the ByteSource binding to device storage, keeping the portable library decoupled from specific storage backends.
Remove verbose implementation details from header comments, replacing them with concise descriptions. The comments now focus on what each component does rather than explaining the overall content protection architecture.
Refactors content decryption to use a callback-based sink pattern instead of loading entire files into memory. Adds decryptedSize() method and decryptToSink() interface. Implements chunked reading and decryption with fixed-size buffers (2KB cipher, 4KB output) to reduce memory footprint for large encrypted entries.
Allows embedding applications to classify a plain EPUB before initializing crypto, then transfer ownership of the already-scanned ZIP index instead of scanning the central directory twice. Refactors common opening logic into finishOpen method.
Request 2KB TLS record size limit (RFC 6066) to reduce memory pressure. wolfSSL allocates receive buffers per record, so default 16KB records can cause MEMORY_E failures when heap is constrained (~20KB free). The 2KB limit keeps allocations small while remaining compatible with servers that ignore the extension.
Replace in-memory decryption with streamed chunk processing and parse encryption.xml incrementally instead of loading it whole. Store entry paths as FNV-1a 64-bit hashes instead of strings to reduce per-entry overhead from heap strings to 8 bytes. This prevents OOM aborts on small-heap devices when opening containers with hundreds of encrypted files (~60KB manifests).
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.

1 participant