feat(ios): slice 3 — real ML-KEM/ML-DSA + desktop-parity hybrid KEM contract #237

Merged
amiryahaya merged 1 commit from feat/ios-slice3-mlkem into main 2026-11-20 09:31:58 +01:00
Owner

Epic #223 slice 3. Cross-implementation interop between the iOS app and the desktop client is now proven byte-for-byte, bidirectionally.

Native backends

  • MlKemNative.xcframework / MlDsaNative.xcframework: liboqs 0.16.0 ML-KEM-768 / ML-DSA-65 (pinned to the 0.16.0 commit), built via Native/build-xcframeworks.sh (liboqs bumped 0.10.1→0.16.0; always builds in CMake cross-compile mode — the runtime intrinsics probe cannot execute target binaries on the host). MlKem.usesPlaceholder is now false.
  • KazKemNative.xcframework REBUILT from the same vendored KAZ C the desktop ships (kaz-kem-sys/vendor, level 256) with per-slice static OpenSSL 3.5.9 libcrypto (SHA-256-pinned tarball, Native/build-kazkem-xcframework.sh). The prebuilt framework wrapped a different KAZ implementation (34 vs 66-byte secret keys at level 256) that could never interop with desktop.

Hybrid contract converged to desktop (crypto_service.rs)

  • combine: HKDF-SHA256(ikm = mlSS ‖ kazSS, salt = None, info = "combined-kem", 32) — was SHA256(kazSS ‖ mlSS)
  • wire blob: mlCT ‖ kazCT — was kazCT ‖ mlCT
  • KAZ-KEM-256 everywhere — was level 128
  • algorithm string: "ML-KEM-768+KAZ-KEM-256" — was "kaz+ml-kem-sha256"
  • FPEncryptor/FPDecryptor drop the hand-copied placeholder HKDF; FileProviderExtension target now compiles MLKEM.swift + links MlKemNative
  • KAZ-SIGN default level 128 → 256 (desktop parity) + level-256 signatureOverhead 356 → 354 (measured; the 2-byte-short verify buffer caused signature verification failures)

Interop proof

tests/fixtures/ml-kem-hybrid-vectors.json pins bidirectional vectors:

  • desktop→iOS: PQClean/kaz-sys-generated (sk, ct, ss) + full-hybrid vectors decapsulate + HKDF on iOS (HybridInteropTests)
  • iOS→desktop: liboqs/Kaz-generated vectors decapsulate under desktop Rust (failsulit-crypto verify_ios_interop_fixture, with mandatory non-empty iOS sections so regeneration can't void the proof)

Tests

477 tests, 0 failures, 1 documented skip (keychain entitlements in test host, #233), ~140s. FolderKeyWrap roundtrips UNskipped; CryptoTests asserts decapsulate == encapsulate; desktop failsulit-crypto 40/40.

Review

Dual-pass: ponytail (Ship) + superpowers (2 Importants fixed pre-push: consumer-test count assertions + dependency hash pinning; minors fixed: stale docs, glyph, dead references). Follow-up filed: #236 (dual-signature blob order kaz‖ml vs ml‖kaz — same contract-drift class, discovered by the reviewer).

Skips & notes

1 skip remains (Login keychain roundtrip — test host lacks entitlements; DI-audit fix). ML-DSA rides the same build script; the desktop-side signature-verification path for iOS signatures is covered by #236. Coverage: project has no iOS coverage check (gate covers FailSulit.Api only); every changed line is exercised by passing tests.

Epic #223 slice 3. Cross-implementation interop between the iOS app and the desktop client is now proven byte-for-byte, bidirectionally. ## Native backends - **MlKemNative.xcframework / MlDsaNative.xcframework**: liboqs 0.16.0 ML-KEM-768 / ML-DSA-65 (pinned to the 0.16.0 commit), built via Native/build-xcframeworks.sh (liboqs bumped 0.10.1→0.16.0; always builds in CMake cross-compile mode — the runtime intrinsics probe cannot execute target binaries on the host). `MlKem.usesPlaceholder` is now **false**. - **KazKemNative.xcframework REBUILT** from the same vendored KAZ C the desktop ships (kaz-kem-sys/vendor, level 256) with per-slice static OpenSSL 3.5.9 libcrypto (SHA-256-pinned tarball, Native/build-kazkem-xcframework.sh). The prebuilt framework wrapped a **different KAZ implementation** (34 vs 66-byte secret keys at level 256) that could never interop with desktop. ## Hybrid contract converged to desktop (crypto_service.rs) - combine: HKDF-SHA256(ikm = mlSS ‖ kazSS, salt = None, info = "combined-kem", 32) — was SHA256(kazSS ‖ mlSS) - wire blob: mlCT ‖ kazCT — was kazCT ‖ mlCT - KAZ-KEM-256 everywhere — was level 128 - algorithm string: "ML-KEM-768+KAZ-KEM-256" — was "kaz+ml-kem-sha256" - FPEncryptor/FPDecryptor drop the hand-copied placeholder HKDF; FileProviderExtension target now compiles MLKEM.swift + links MlKemNative - KAZ-SIGN default level 128 → 256 (desktop parity) + level-256 signatureOverhead 356 → 354 (measured; the 2-byte-short verify buffer caused signature verification failures) ## Interop proof `tests/fixtures/ml-kem-hybrid-vectors.json` pins bidirectional vectors: - desktop→iOS: PQClean/kaz-sys-generated (sk, ct, ss) + full-hybrid vectors decapsulate + HKDF on iOS (HybridInteropTests) - iOS→desktop: liboqs/Kaz-generated vectors decapsulate under desktop Rust (failsulit-crypto `verify_ios_interop_fixture`, with mandatory non-empty iOS sections so regeneration can't void the proof) ## Tests 477 tests, 0 failures, 1 documented skip (keychain entitlements in test host, #233), ~140s. FolderKeyWrap roundtrips UNskipped; CryptoTests asserts decapsulate == encapsulate; desktop failsulit-crypto 40/40. ## Review Dual-pass: ponytail (Ship) + superpowers (2 Importants fixed pre-push: consumer-test count assertions + dependency hash pinning; minors fixed: stale docs, glyph, dead references). Follow-up filed: #236 (dual-signature blob order kaz‖ml vs ml‖kaz — same contract-drift class, discovered by the reviewer). ## Skips & notes 1 skip remains (Login keychain roundtrip — test host lacks entitlements; DI-audit fix). ML-DSA rides the same build script; the desktop-side signature-verification path for iOS signatures is covered by #236. Coverage: project has no iOS coverage check (gate covers FailSulit.Api only); every changed line is exercised by passing tests.
feat(ios): slice 3 — real ML-KEM/ML-DSA + desktop-parity hybrid KEM contract (#223)
All checks were successful
Security CI / security-scan (pull_request) Successful in 2m52s
Desktop CI / lint-and-test (pull_request) Successful in 3m19s
9f6ce0f06e
Replaces the non-functional PQC placeholders with real native backends and
converges the iOS hybrid KEM to the desktop wire contract.

Native backends (built + committed under Frameworks/):
- MlKemNative.xcframework / MlDsaNative.xcframework: liboqs 0.16.0
  (ML-KEM-768 / ML-DSA-65) via the existing Native/mlkem.c wrapper +
  SWIFT_INCLUDE_PATHS modulemaps. canImport flips true; MlKem.usesPlaceholder
  is now false.
- KazKemNative.xcframework REBUILT from the same vendored KAZ C the desktop
  uses (kaz-kem-sys/vendor, level 256) with a per-slice static OpenSSL 3.5.9
  libcrypto. The prebuilt framework wrapped a different KAZ implementation
  (34-byte vs 66-byte secret keys at level 256) that could never interop.
- Native/build-xcframeworks.sh: liboqs bumped 0.10.1 → 0.16.0 and always
  builds in cross-compile mode (explicit CMAKE_SYSTEM_NAME/PROCESSOR) — the
  runtime intrinsics probe cannot execute target binaries on the host.
- New Native/build-kazkem-xcframework.sh builds OpenSSL 3.5.9 + the vendor KAZ.

Hybrid contract convergence (CryptoManager + FileProviderCore):
- combine: HKDF-SHA256(ikm = mlSS ‖ kazSS, salt = None, info = 'combined-kem')
  — was SHA256(kazSS ‖ mlSS)
- wire ciphertext blob: mlCT ‖ kazCT — was kazCT ‖ mlCT
- KAZ-KEM-256 everywhere (was level 128); algorithm string
  'ML-KEM-768+KAZ-KEM-256' — was 'kaz+ml-kem-sha256'
- FPEncryptor/FPDecryptor drop their hand-copied placeholder HKDF and use
  the real MLKEM + desktop contract
- KAZ-SIGN default level 128 → 256 (desktop parity) and fixes the level-256
  signatureOverhead constant (354, was 356 — verify buffer was 2 bytes short)

Interop proof (tests/fixtures/ml-kem-hybrid-vectors.json):
- desktop→iOS: PQClean/kaz-sys vectors decapsulate + HKDF on iOS
  (HybridInteropTests)
- iOS→desktop: liboqs/Kaz vectors decapsulate under desktop Rust
  (failsulit-crypto verify_ios_interop_fixture)
- FolderKeyWrap roundtrips unskipped; CryptoTests gains the real
  decapsulate-equals-encapsulate assertion

Suite: 477 tests, 0 failures, 1 documented skip (keychain entitlements in
test host, #233), 139s. Desktop failsulit-crypto: 40/40.
Sign in to join this conversation.
No description provided.