Documentation
¶
Overview ¶
Package modelwrap defines the Modelwrap (MWP) and Encrypted Modelwrap (EMWP) artifact format: the cryptographic constants, the artifact reference grammar, the deterministic identity derivations, and the key derivation used by both the packer and the consumer. See SPEC.md for the full format specification.
Index ¶
Constants ¶
const ( EMWPCipher = "aes-xts-plain64" EMWPKeySizeBits = 512 EMWPKeyBytes = EMWPKeySizeBits / 8 EMWPMasterKeyBytes = 64 EMWPSectorSize = 4096 EMWPKeyDeriveInfo = "tinfoil/emwp/dm-crypt-key/v1" )
EMWP dm-crypt parameters.
const ( GPTSectorSize = 512 EMWPPartitionStartSector = 2048 EMWPGPTTrailingSectors = 40 )
EMWP GPT disk image geometry. The encrypted payload partition starts at a fixed sector so ciphertext placement is deterministic.
const ( VerityFormat = 1 VerityHashAlgorithm = "sha256" VerityDataBlockSize = 4096 VerityHashBlockSize = 4096 VeritySaltBytes = 32 // a SHA-256 digest )
dm-verity format parameters. These are passed explicitly to veritysetup so tool default changes never silently alter the artifact format, and consumers never read them from the artifact.
Variables ¶
This section is empty.
Functions ¶
func DeriveKey ¶
func DeriveKey(masterKey []byte, ref *ArtifactRef) ([]byte, error)
DeriveKey derives the per-artifact dm-crypt key from the EMWP master key using HKDF-SHA256 with the artifact ID as salt.
func HashDir ¶
HashDir computes a deterministic content hash over a model directory tree, used as the revision for local model directories.
func ParseMasterKey ¶
ParseMasterKey decodes and validates a base64-encoded EMWP master key.
func UUIDv5URL ¶
UUIDv5URL computes the deterministic RFC 4122 version 5 UUID of name in the URL namespace. All artifact UUIDs (dm-verity UUID, GPT disk GUID, GPT PARTUUID) are derived from the model identity this way.
func VeritySalt ¶ added in v0.2.1
VeritySalt returns the deterministic dm-verity salt for a model identity string (name@revision): the SHA-256 of the identity. The packer uses this when formatting; the consumer re-derives it from the attested model identity, so no on-disk metadata is ever consulted.
Types ¶
type ArtifactRef ¶
ArtifactRef is a parsed artifact reference of the form rootHash_hashOffset_uuid. For MWP artifacts the UUID is the dm-verity superblock UUID; for EMWP artifacts it is the GPT PARTUUID of the encrypted payload partition.
func ParseRef ¶
func ParseRef(ref string) (*ArtifactRef, error)
ParseRef parses and validates a rootHash_hashOffset_uuid reference.
func (*ArtifactRef) ArtifactID ¶
func (r *ArtifactRef) ArtifactID() string
ArtifactID returns the rootHash_uuid identity used as the HKDF salt for EMWP key derivation, binding the derived key to one specific artifact.
func (*ArtifactRef) HashOffsetBytes ¶ added in v0.2.1
func (r *ArtifactRef) HashOffsetBytes() (uint64, error)
HashOffsetBytes parses the reference's hash offset field.
func (*ArtifactRef) String ¶
func (r *ArtifactRef) String() string
String returns the canonical rootHash_hashOffset_uuid form.
type VerityParams ¶ added in v0.2.1
type VerityParams struct {
Salt []byte
DataBlocks uint64
HashTreeOffset uint64 // byte offset of the first hash tree block
}
VerityParams are the fully explicit parameters for opening an MWP hash tree with `veritysetup --no-superblock`, so that no unverified on-disk metadata is ever parsed by the dm-verity stack.
func VerityParamsForArtifact ¶ added in v0.2.1
func VerityParamsForArtifact(hashOffset uint64, salt []byte) (*VerityParams, error)
VerityParamsForArtifact derives explicit dm-verity parameters from the attested hash offset and the salt. In the MWP layout the data area is exactly the hashOffset bytes preceding the hash area, so the data size is attested rather than read from the artifact, and the hash tree begins one hash block past hashOffset (the slot occupied by the untrusted, ignored superblock the packer writes there).
func (*VerityParams) VeritysetupArgs ¶ added in v0.2.1
func (p *VerityParams) VeritysetupArgs() []string
VeritysetupArgs returns the explicit veritysetup arguments pinning every format parameter for a --no-superblock open or verify.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
modelwrap
command
Command modelwrap packs model weights into MWP/EMWP artifacts.
|
Command modelwrap packs model weights into MWP/EMWP artifacts. |
|
Package crypt implements the EMWP dm-crypt encryption (aes-xts-plain64, 512-bit key, 4096-byte sectors) in pure Go.
|
Package crypt implements the EMWP dm-crypt encryption (aes-xts-plain64, 512-bit key, 4096-byte sectors) in pure Go. |
|
Package unwrap implements the consumer side of the Modelwrap protocol: opening dm-crypt and dm-verity mappings over MWP/EMWP artifacts and mounting the verified filesystem read-only.
|
Package unwrap implements the consumer side of the Modelwrap protocol: opening dm-crypt and dm-verity mappings over MWP/EMWP artifacts and mounting the verified filesystem read-only. |
|
Package wrap implements the Modelwrap packer: it builds deterministic EROFS images of model directories, wraps them with dm-verity (MWP), and optionally encrypts them into a GPT disk image with dm-crypt (EMWP).
|
Package wrap implements the Modelwrap packer: it builds deterministic EROFS images of model directories, wraps them with dm-verity (MWP), and optionally encrypts them into a GPT disk image with dm-crypt (EMWP). |