enclave-model-seal

command
v0.6.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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

  1. 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).
  2. 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).
  3. Signs and verifies a node-identity attestation digest (SHA-256 over host, model, tenant, and X9.63 public key) via SecKeyCreateSignature / SecKeyVerifySignature.
  4. 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.
  5. Verifies fail-closed tamper rejection on both mutated ciphertext and mutated AAD (enclave.ErrAuthFailed).
  6. 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).

Documentation

Rendered for darwin/amd64

Overview

Command enclave-model-seal demonstrates hardware-backed P-256 node identity attestation and hybrid ECIES + AES-256-GCM sealing of 16 MiB model weight or KV-cache chunks using github.com/tmc/apple/x/enclave.

Usage:

go run ./examples/security/enclave-model-seal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL