Documentation ¶
Index ¶
- Constants
- func AddPadding(b []byte, eraseVal byte, padLen int) []byte
- func CalcHash(bin []byte) []byte
- func MetaTlvTypeName(typ uint8) string
- func StripPadding(b []byte, eraseVal byte) []byte
- func VerifySigs(man manifest.MfgManifest, keys []sec.PubSignKey) (int, error)
- type Meta
- func (meta *Meta) Bytes() ([]byte, error)
- func (meta *Meta) ClearHash()
- func (meta *Meta) Clone() Meta
- func (meta *Meta) FindFirstTlv(typ uint8) *MetaTlv
- func (meta *Meta) FindTlvIndices(typ uint8) []int
- func (meta *Meta) FindTlvs(typ uint8) []*MetaTlv
- func (meta *Meta) Hash() []byte
- func (meta *Meta) HashOffset() int
- func (m *Meta) Json(offset int) (string, error)
- func (m *Meta) Map(endOffset int) map[string]interface{}
- func (meta *Meta) Offsets() MetaOffsets
- func (meta *Meta) Size() int
- func (meta *Meta) Write(w io.Writer) (int, error)
- func (meta *Meta) WritePlusOffsets(w io.Writer) (MetaOffsets, error)
- type MetaFooter
- type MetaOffsets
- type MetaTlv
- type MetaTlvBodyFlashArea
- type MetaTlvBodyHash
- type MetaTlvBodyMmrRef
- type MetaTlvHeader
- type Mfg
- func (m *Mfg) Bytes(eraseVal byte) ([]byte, error)
- func (m *Mfg) Clone() Mfg
- func (m *Mfg) ExtractFlashArea(area flash.FlashArea, eraseVal byte) ([]byte, error)
- func (m *Mfg) ExtractImages(man manifest.MfgManifest) ([]image.Image, error)
- func (m *Mfg) Hash(eraseVal byte) ([]byte, error)
- func (m *Mfg) RecalcHash(eraseVal byte) ([]byte, error)
- func (m *Mfg) RefillHash(eraseVal byte) error
- func (m *Mfg) Tlvs() []MetaTlv
- func (m *Mfg) VerifyManifest(man manifest.MfgManifest) error
- func (m *Mfg) VerifyStructure(eraseVal byte) error
Constants ¶
const MANIFEST_FILENAME = "manifest.json"
const META_FOOTER_SZ = 8
const META_HASH_SZ = 32
const META_MAGIC = 0x3bb2a269
const META_TLV_FLASH_AREA_SZ = 10
const META_TLV_HASH_SZ = META_HASH_SZ
const META_TLV_HEADER_SZ = 2
const META_TLV_MMR_REF_SZ = 1
const META_TLV_TYPE_FLASH_AREA = 0x02
const META_TLV_TYPE_HASH = 0x01
const META_TLV_TYPE_MMR_REF = 0x04
const META_VERSION = 2
const MFG_BIN_IMG_FILENAME = "mfgimg.bin"
const MFG_HEX_IMG_FILENAME = "mfgimg.hex"
Variables ¶
This section is empty.
Functions ¶
func AddPadding ¶
AddPadding produces a new byte slice by adding extra bytes to the end of an existing slice.
func CalcHash ¶
Calculates the SHA256 hash, using the full manufacturing image as input. Hash-calculation algorithm is as follows: 1. Zero out the 32 bytes that will contain the hash. 2. Apply SHA256 to the result.
This function assumes that the 32 bytes of hash data have already been zeroed.
func MetaTlvTypeName ¶
func StripPadding ¶
StripPadding produces a new byte slice by removing padding from an existing byte slice. Padding is defined as a sequence of trailing bytes, all with the specified value.
func VerifySigs ¶ added in v0.0.2
func VerifySigs(man manifest.MfgManifest, keys []sec.PubSignKey) (int, error)
VerifySigs checks an mfgimage's signatures against the provided set of keys. It succeeds if the mfgimage has no signatures or if any signature can be verified. An error is returned if there is at least one signature and they all fail the check.
Types ¶
type Meta ¶
type Meta struct { Tlvs []MetaTlv }
func (*Meta) FindFirstTlv ¶
FindTlvIndices searches an MMR for the first TLV of the specified type.
func (*Meta) FindTlvIndices ¶
FindTlvIndices searches an MMR for TLVs of the specified type and returns their indices.
func (*Meta) Hash ¶
Hash locates an MMR's SHA256 TLV and returns its value. It returns nil if the MMR doesn't have a SHA256 TLV.
func (*Meta) HashOffset ¶
HashOffset calculates the offset of the SHA256 TLV in an MMR if it were serialized.
func (*Meta) Offsets ¶
func (meta *Meta) Offsets() MetaOffsets
Offsets returns the offsets of each of an MMR's components if it were serialized.
func (*Meta) WritePlusOffsets ¶
func (meta *Meta) WritePlusOffsets(w io.Writer) (MetaOffsets, error)
WritePlusOffsets writes a binary MMR to the given writer. It returns the offsets of the mfgimage components that got written.
type MetaFooter ¶
type MetaFooter struct {}
func (*MetaFooter) Map ¶
func (f *MetaFooter) Map(offset int) map[string]interface{}
Map produces a JSON-friendly map representation of an MMR footer.
type MetaOffsets ¶
type MetaTlv ¶
type MetaTlv struct { Header MetaTlvHeader Data []byte }
func (*MetaTlv) StructuredBody ¶
StructuredBody constructs the appropriate "body" object from a raw TLV (e.g., MetaTlvBodyHash from a TLV with type=META_TLV_TYPE_HASH).
type MetaTlvBodyFlashArea ¶
type MetaTlvBodyFlashArea struct { Area uint8 // Unique value identifying this flash area. Device uint8 // Indicates host flash device (aka section number). Offset uint32 // The byte offset within the flash device. Size uint32 // Size, in bytes, of entire flash area. }
func (*MetaTlvBodyFlashArea) Map ¶
func (b *MetaTlvBodyFlashArea) Map() map[string]interface{}
type MetaTlvBodyHash ¶
type MetaTlvBodyHash struct {
Hash [META_HASH_SZ]byte
}
func (*MetaTlvBodyHash) Map ¶
func (b *MetaTlvBodyHash) Map() map[string]interface{}
type MetaTlvBodyMmrRef ¶
type MetaTlvBodyMmrRef struct {
Area uint8
}
func (*MetaTlvBodyMmrRef) Map ¶
func (b *MetaTlvBodyMmrRef) Map() map[string]interface{}
type MetaTlvHeader ¶
type Mfg ¶
func Parse ¶
Parse parses a serialized mfgimage (e.g., "mfgimg.bin") and produces an Mfg object. metaEndOff is the offset immediately following the MMR, or -1 if there is no MMR.
func (*Mfg) ExtractFlashArea ¶
ExtractFlashArea copies a portion out of a serialized mfgimage. The offset and size to copy indicated by the provided FlashArea.
func (*Mfg) ExtractImages ¶ added in v0.0.4
Constructs the set of images embedded in an mfgimage.
func (*Mfg) Hash ¶
Hash retrieves the SHA256 value associated with an mfgimage. If the mfgimage has an MMR with a SHA256 TLV, the TLV's value is returned. Otherwise, the hash is calculated and returned.
func (*Mfg) RefillHash ¶
RefillHash replace's the contents of an mfgimage's SHA256 TLV with a newly calculated hash.
func (*Mfg) Tlvs ¶
Tlvs retrieves the slice of TLVs present in an mfgimage's MMR. It returns nil if the mfgimage has no MMR.
func (*Mfg) VerifyManifest ¶
func (m *Mfg) VerifyManifest(man manifest.MfgManifest) error
VerifyManifest compares an mfgimage's structure to its manifest. It returns an error if the mfgimage doesn't match the manifest.
func (*Mfg) VerifyStructure ¶ added in v0.0.2
VerifyStructure checks an mfgimage's structure and internal consistency. It returns an error if the mfgimage is incorrect.