litert_crypto 0.3.1
litert_crypto: ^0.3.1 copied to clipboard
Stop shipping your .tflite in plain sight. Encrypt LiteRT (TFLite) models at build time and decrypt them in memory only — with pluggable key providers.
Changelog #
0.3.1 #
Documentation release — no code changes.
Prefer the CLI flow over the asset transformer for now: encrypt with
dart run litert_crypto encrypt and register the .enc files as plain
assets — the README and the example app follow this flow again.
Multi-asset builds using the asset transformer (added in 0.3.0) have been
observed to crash on Windows — the parallel per-asset dart run processes
race while staging native assets (reported as
dart-lang/sdk#63933). The
transformer remains available.
0.3.0 #
Build-time encryption via a Flutter asset transformer
- Transformer mode (
--input/--output, invoked by the flutter tool) with optional--label,--key-id,--configargs; the label defaults to the asset's file name. - New
keypartscommand — (re)generates thekey_parts_outDart source without anencryptrun; rewrites when the key orkey_parts_symbolchanges. - The config can live in
pubspec.yamlas a top-levellitert_crypto:section; a dedicatedlitert_crypto.yamlwins when both exist. - With
key_parts_outset, a build with stale or missing key parts fails with akeypartshint — instead of failing at app runtime. - Builds need the key file — on CI, provision
.secrets/model_master.keyfrom a secret; a missing key fails the build with that hint. - Key rotation: bump
--key-idin the transformer args (orflutter clean) — the build cache cannot see a key change. See docs/key-management. - The loader names a plaintext TFLite model (
TFL3) instead of raising a generic format error — it means the asset was bundled unencrypted. - The first
flutter buildnow compiles the BoringSSL host library (cmake + C compiler, NASM on Windows x64) — previously onlyflutter testand the CLI did. Cached after the first run.
0.2.1 #
Documentation release — no code changes.
- README reworked for readability: the Windows NASM requirement now has its
own error → cause → fix walkthrough next to the CLI usage; key rotation and
key_idare explained instead of name-dropped; several sections trimmed of internals that belong in the design docs. - New in the repository (not part of the published package):
tool/setup.ps1, a one-shot NASM check/install/PATH-repair script for Windows hosts.
0.2.0 #
The crypto engine is now native BoringSSL (package:webcrypto, dart:ffi)
and the format is AES-256-GCM. Decryption is dramatically faster: about
1.2 ms/MB on an AES-NI desktop, so a 72 MB model decrypts in 87 ms. This is
a clean break from 0.1.0 — re-encrypting your models is the whole migration
(details under Breaking).
Breaking:
- LRTC format version 2 — AES-256-GCM (12-byte IV, 16-byte tag, header as
additional authenticated data) replaces AES-CTR + HMAC-SHA256. Files written
by 0.1.0 are refused with a re-encrypt hint; re-running
dart run litert_crypto encryptis the whole migration. LrtcCodec.decryptInPlace/decryptBufferInPlace/decryptWithProviderInPlaceare gone — GCM verifies and decrypts in one native call, which has no in-place variant.LrtcEnvelope'scipherText/tagfields becamesealed(ciphertext ‖ tag).- SDK floors rose to Dart 3.10 / Flutter 3.38 (webcrypto builds BoringSSL via Dart hooks).
- Host builds (
flutter test, CLI on a plain Dart VM) compile BoringSSL and needcmake+ a C compiler, plus NASM on Windows x64. App builds compile it through Gradle/NDK/Xcode with nothing to configure.
Also:
- Decryption now runs on a worker isolate by default, so the calling isolate
keeps rendering through it. Pass
inIsolate: false(available on every loader entry point) to keep it inline.
0.1.0 #
Initial release.
- LRTC encrypted model format: AES-256-CTR with encrypt-then-MAC
(HMAC-SHA256), HKDF-derived per-model subkeys,
keyIdfor key rotation — plus a Flutter-free codec entrypoint (package:litert_crypto/codec.dart) EncryptedModel.fromAsset/fromFile/fromBufferloader — decrypts in memory only, zeroes keys and plaintext after use, no inference-runtime dependency- Key providers:
EmbeddedKeyProvider(XOR parts),CallbackKeyProvider,RemoteKeyProvider(retries, single-flight, pluggableKeyCache),FallbackKeyProvider - CLI:
dart run litert_crypto init | keygen | encrypt, including generatedEmbeddedKeyProvidersource kept in sync with the key (key_parts_out)