Skip to content

Encryption: portable core, KeyGen and existing asset compatibility - #91

Merged
defisym merged 13 commits into
masterfrom
codex/portable-encryption-sample
Nov 4, 2026
Merged

defisym merged 13 commits into
masterfrom
codex/portable-encryption-sample

Conversation

@defisym

@defisym defisym commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Existing Encryption users relied on Windows BCrypt and the historical Fusion class. This PR replaces the implementation with one portable C++17/OpenSSL core while retaining the compatibility methods, Fusion event interfaces and existing asset format.

Based on master b1a0551f after the GeneralDefinition split in #103. FFMpeg playback/AVIO changes remain in dependent PR #102. Existing commits are replayed onto master; review follow-ups remain separate commits.

Module layout

The outer Encryption.h / Encryption.cpp remain the compatibility entry point; EncryptionStream.h keeps the historical push API. The implementation, C adapters, VS projects, CMake and tests now live under _DeLib/Encryption/: Core.h, KeyGen.h, CAPI.h/.cpp, Encryption.sln and Encryption.vcxproj. The library/CMake target is encryption; EncryptionPortable naming and the old directory are removed. Installed headers retain this hierarchy, so repository and installed consumers use the same include paths. C adapters are consolidated into one CAPI.h and one CAPI.cpp, including shared callback declarations and private error translation; the eight split adapter/helper files are removed. All 29 exported C function names and definitions are unchanged.

Changes

  • Shared incremental AES-128-CBC/PKCS#7, hashes and seekable DecryptReader. The reusable core has no FFmpeg dependency.
  • Encryption.h/.cpp compatibility facade and C ABI. Windows SDK EFS undef guards prevent aliases from renaming EncryptFile/DecryptFile; BCrypt and Windows type aliases are no longer required.
  • Arbitrary-length KeyGen preserves the original Win32/Win64 seed rules and existing ciphertext bytes. Empty input retains bytes 00..0f.
  • Generic UTF conversions now live in UnicodeConversion.h, exposed globally through GeneralDefinition: to_utf16_string (UTF-8/native-wide overloads) and to_utf16_bytes (UTF-16LE without BOM). This standalone C++17 header has no OpenSSL, Windows API or iconv dependency. Encryption translates conversion errors to its existing argument errors. EncryptionText.h is removed.
  • File call sites use std::filesystem::path directly. No custom path-conversion helper remains. C file APIs accept caller-owned FILE handles or callbacks; mobile bridges select their own encodings/file opening.
  • Compatibility cleanup removes unused constants/state, uses Mode in Encrypter and adds ClearEncryptData. Valid empty data remains distinct from cleared input, including standard empty-file hashes. Directly methods retain incremental reads and complete in-memory output.
  • VS EncryptDependencies automatically downloads and verifies the repository's fixed OpenSSL SDK for all nine consumers. Normal builds do not run vcpkg; source builds remain an explicit option.

Review follow-up

  • MSVC-only SAL postconditions describe require's normal-return contract. Zero-length file reads return before the non-null output requirement, making the fread path explicit to the analyzer.
  • Use if constexpr for native wchar_t width and explicit smart-pointer boolean conversion. Guard the MSVC warning pragma on other compilers.
  • Move the bounded 64 KiB transform/file-hash scratch buffers to the heap. The C file-hash API returns its existing out-of-memory result if allocation fails.
  • Propagate SaveFile failure from Encrypter's helper instead of returning true after a failed write. A local harness compiled the actual helper and checked invalid destinations plus exact existing-asset round trips.
  • Added actual MSVC /analyze builds, treating analysis warnings as errors, and C file-hash checks for both abc and EOF/empty input.

Validation

  • Native Release and ASan/UBSan core suites pass, including frozen Win32/Win64 KeyGen vectors, Unicode, C ABI, >4 GiB offsets, streaming and seeks.
  • Key 12345678ABCDEFGH decrypts all 1,641,882 original JPEG bytes and reproduces all 1,641,888 old ciphertext bytes.
  • Chinese-path save/open/hash/encrypt/decrypt checks pass using filesystem paths directly.
  • Shared helper regressions and 22 standalone C++17 Unicode checks pass on Linux. Installed public headers compile independently with C++17.
  • Dependent MemBuf/AVIO tests also pass under ASan/UBSan. Local leak detection is disabled in the ptrace-limited environment.
  • CI covers VS/MSBuild Win32/x64 Release/Debug, Linux sanitizers and macOS; shared-header CI also covers Visual Studio. Current-head Linux/macOS tests, shared-header Windows/Linux checks, and VS Win32/x64 Release/Debug builds and tests have passed. Win32 and x64 native MSVC analysis also passed with warnings treated as errors (run). Source-SDK rebuild/package stages are still running. The module-layout follow-up has also passed clean static/shared builds, Release and ASan/UBSan regressions, and installed C/C++ consumer smoke tests; the renamed VS projects have also passed Win32/x64 Release/Debug builds, runtime tests and /analyze, alongside Linux/macOS CI (module-layout run).

Core build instructions · Dependency setup · Pinned SDK release

Manual acceptance

  • Build consuming extensions with VS and load the rebuilt .mfx files in Fusion.
  • Exercise existing encrypted image/configuration/video assets through their existing actions.

C++ class binary layout is not retained. Full Fusion runtime and device packaging remain separate from native tests. Merge this PR before #102.

@defisym defisym changed the title Add portable streaming encryption sample Add deterministic portable encryption and streaming decryption sample Oct 12, 2026
@defisym defisym changed the title Add deterministic portable encryption and streaming decryption sample Add portable C API for encryption and streaming decryption Oct 12, 2026
@defisym defisym changed the title Add portable C API for encryption and streaming decryption Add portable C buffer API and one-shot encryption helpers Oct 12, 2026
@defisym defisym changed the title Add portable C buffer API and one-shot encryption helpers Add portable encryption API and shared streaming decryptor Oct 13, 2026
@defisym defisym changed the title Add portable encryption API and shared streaming decryptor Add portable streaming encryption and decryption API Oct 13, 2026
@defisym
defisym force-pushed the codex/portable-encryption-sample branch from aece6a3 to caee0d2 Compare October 13, 2026 06:05
@defisym defisym changed the title Add portable streaming encryption and decryption API Unify encryption behind a shared C++ core and legacy-compatible interface Oct 31, 2026
@defisym
defisym force-pushed the codex/portable-encryption-sample branch from 66b0986 to 3037507 Compare October 31, 2026 17:08
@defisym defisym changed the title Unify encryption behind a shared C++ core and legacy-compatible interface Encryption: shared C++ core, legacy facade and streaming playback Oct 31, 2026
@defisym
defisym force-pushed the codex/portable-encryption-sample branch from 3037507 to c3f3457 Compare November 1, 2026 15:04
@defisym defisym changed the title Encryption: shared C++ core, legacy facade and streaming playback Encryption: shared C++ core, KeyGen and automatic OpenSSL dependencies Nov 1, 2026
@defisym
defisym force-pushed the codex/portable-encryption-sample branch from c3f3457 to 40ffd48 Compare November 1, 2026 15:16
@defisym defisym closed this Nov 2, 2026
@defisym
defisym deleted the codex/portable-encryption-sample branch November 2, 2026 01:34
@defisym
defisym restored the codex/portable-encryption-sample branch November 2, 2026 07:37
@defisym defisym reopened this Nov 2, 2026
@defisym
defisym force-pushed the codex/portable-encryption-sample branch from 40ffd48 to d80a1bf Compare November 2, 2026 07:40
@defisym defisym changed the title Encryption: shared C++ core, KeyGen and automatic OpenSSL dependencies Encryption: portable core, KeyGen and existing asset compatibility Nov 2, 2026
@defisym
defisym force-pushed the codex/portable-encryption-sample branch 3 times, most recently from b8ec293 to 2f214ee Compare November 3, 2026 06:37
@defisym
defisym force-pushed the codex/portable-encryption-sample branch from 45e68cc to 2fdd46c Compare November 4, 2026 02:05
@defisym
defisym marked this pull request as ready for review November 4, 2026 02:56
@defisym
defisym merged commit 3681217 into master Nov 4, 2026
6 checks passed
@defisym
defisym deleted the codex/portable-encryption-sample branch November 4, 2026 02:57
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