enclave-model-seal
Demonstrates zero-cgo macOS Secure Enclave P-256 node-identity attestation and
hybrid ECIES + AES-256-GCM envelope sealing for multi-megabyte model weights or
KV-cache chunks using github.com/tmc/apple/x/enclave.
What It Does
- Probes Secure Enclave availability (
enclave.Probe()) by testing
ephemeral hardware P-256 key creation and reporting the exact OSStatus
reason if unavailable (for example, errSecMissingEntitlement -34018 on
environments that require keychain-access-groups /
application-identifier).
- Generates a P-256 key (
enclave.Generate) backed by the Secure Enclave
hardware token when available, or an ephemeral software SecKey fallback
otherwise (clearly labeled in output; pass -require-hardware to fail
closed).
- Signs and verifies a node-identity attestation digest (SHA-256 over host,
model, tenant, and X9.63 public key) via
SecKeyCreateSignature /
SecKeyVerifySignature.
- Seals and unseals a 16 MiB synthetic weight/KV chunk with
enclave.SealPayload / enclave.OpenPayload, wrapping an ephemeral 32-byte
AES-256 DEK under P-256 ECIES
(eciesEncryptionCofactorVariableIVX963SHA256AESGCM) and binding the
envelope header plus model=<id>;tenant=<id>;chunk=0 AAD into AES-256-GCM.
- Verifies fail-closed tamper rejection on both mutated ciphertext and
mutated AAD (
enclave.ErrAuthFailed).
- Benchmarks 16 MiB seal/open throughput (GiB/s) and ECDSA sign/verify
latency (µs/op).
Usage
CGO_ENABLED=0 go run ./examples/security/enclave-model-seal
Flags:
-size — synthetic chunk size in bytes (default 16777216, 16 MiB)
-iters — seal/open benchmark iterations (default 5)
-sign-iters — sign/verify benchmark iterations (default 200)
-require-hardware — fail closed if Secure Enclave is unavailable
-model — model ID bound into AAD (default llama-3.3-70b-q4)
-tenant — tenant ID bound into AAD (default acme-prod)
Measured Results (Apple M4 Max, macOS 26.6.2)
Observed with CGO_ENABLED=0 go run ./examples/security/enclave-model-seal:
=== Secure Enclave Probe ===
Secure Enclave: available
=== Key Generation ===
Backing: Secure Enclave hardware token (P-256)
Public key: 04e3fbbb226c9b044cb76896e0470973... (65 bytes X9.63)
=== Node-Identity Attestation ===
Digest (SHA256): 96449e2c400e6273503c6270785ff7695136b8ab773899abb740b565a9c844f9
ECDSA sig len: 71 bytes (verified OK)
=== Hybrid Model/KV Chunk Sealing (ECIES + AES-256-GCM) ===
AAD: model=llama-3.3-70b-q4;tenant=acme-prod;chunk=0
Plaintext: 16.00 MiB (16777216 bytes)
Sealed envelope: 16777365 bytes (+149 bytes overhead)
Round-trip: OK (byte-identical)
Tamper check: mutated ciphertext rejected=true, mutated AAD rejected=true
=== Benchmarks ===
Seal throughput (5 x 16.0 MiB): 0.44 GiB/s
Open throughput (5 x 16.0 MiB): 1.22 GiB/s
Sign latency (200 iters): 32830.2 us/op
Verify latency (200 iters): 205.5 us/op
Note: Secure Enclave private-key operations (Sign and UnsealDEK) execute on
the hardware coprocessor, so per-call sign latency (~33 ms under load) is
dominated by Secure Enclave IPC while bulk 16 MiB payload sealing/opening runs
at AES-256-GCM speed (0.44–1.22 GiB/s) because ECIES only wraps the 32-byte
ephemeral DEK (+149 bytes total envelope overhead).