mfg

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const MANIFEST_FILENAME = "manifest.json"
View Source
const META_FOOTER_SZ = 8
View Source
const META_HASH_SZ = 32
View Source
const META_MAGIC = 0x3bb2a269
View Source
const META_TLV_FLASH_AREA_SZ = 10
View Source
const META_TLV_HASH_SZ = META_HASH_SZ
View Source
const META_TLV_HEADER_SZ = 2
View Source
const META_TLV_MMR_REF_SZ = 1
View Source
const META_TLV_TYPE_FLASH_AREA = 0x02
View Source
const META_TLV_TYPE_HASH = 0x01
View Source
const META_TLV_TYPE_MMR_REF = 0x04
View Source
const META_VERSION = 2
View Source
const MFG_BIN_IMG_FILENAME = "mfgimg.bin"
View Source
const MFG_HEX_IMG_FILENAME = "mfgimg.hex"

Variables

This section is empty.

Functions

func AddPadding

func AddPadding(b []byte, eraseVal byte, padLen int) []byte

AddPadding produces a new byte slice by adding extra bytes to the end of an existing slice.

func CalcHash

func CalcHash(bin []byte) []byte

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 MetaTlvTypeName(typ uint8) string

func StripPadding

func StripPadding(b []byte, eraseVal byte) []byte

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
	Footer MetaFooter
}

func (*Meta) Bytes

func (meta *Meta) Bytes() ([]byte, error)

Bytes serializes an MMR to binary form.

func (*Meta) ClearHash

func (meta *Meta) ClearHash()

ClearHash zeroes out an MMRs SHA256 TLV.

func (*Meta) Clone

func (meta *Meta) Clone() Meta

Clone performs a deep copy of an MMR.

func (*Meta) FindFirstTlv

func (meta *Meta) FindFirstTlv(typ uint8) *MetaTlv

FindTlvIndices searches an MMR for the first TLV of the specified type.

func (*Meta) FindTlvIndices

func (meta *Meta) FindTlvIndices(typ uint8) []int

FindTlvIndices searches an MMR for TLVs of the specified type and returns their indices.

func (*Meta) FindTlvs

func (meta *Meta) FindTlvs(typ uint8) []*MetaTlv

FindTlvIndices searches an MMR for all TLVs of the specified type.

func (*Meta) Hash

func (meta *Meta) Hash() []byte

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

func (meta *Meta) HashOffset() int

HashOffset calculates the offset of the SHA256 TLV in an MMR if it were serialized.

func (*Meta) Json

func (m *Meta) Json(offset int) (string, error)

Json produces a JSON representation of an MMR.

func (*Meta) Map

func (m *Meta) Map(endOffset int) map[string]interface{}

Map produces a JSON-friendly map representation of an MMR.

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) Size

func (meta *Meta) Size() int

Size calculates the total size of an MMR if it were serialied.

func (*Meta) Write

func (meta *Meta) Write(w io.Writer) (int, error)

Write serializes and writes an MMR.

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 {
	Size    uint16 // Includes header, TLVs, and footer.
	Version uint8
	Pad8    uint8  // 0xff
	Magic   uint32 // META_MAGIC
}

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 MetaOffsets struct {
	Tlvs      []int
	Footer    int
	TotalSize int
}

type MetaTlv

type MetaTlv struct {
	Header MetaTlvHeader
	Data   []byte
}

func (*MetaTlv) Map

func (t *MetaTlv) Map(index int, offset int) map[string]interface{}

Map produces a JSON-friendly map representation of an MMR TLV.

func (*MetaTlv) StructuredBody

func (tlv *MetaTlv) StructuredBody() (interface{}, error)

StructuredBody constructs the appropriate "body" object from a raw TLV (e.g., MetaTlvBodyHash from a TLV with type=META_TLV_TYPE_HASH).

func (*MetaTlv) Write

func (tlv *MetaTlv) Write(w io.Writer) (int, error)

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 MetaTlvHeader struct {
	Type uint8 // Indicates the type of data to follow.
	Size uint8 // The number of bytes of data to follow.
}

type Mfg

type Mfg struct {
	Bin  []byte
	Meta *Meta

	// Unused if Meta==nil.
	MetaOff int
}

func Parse

func Parse(data []byte, metaEndOff int, eraseVal byte) (Mfg, error)

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) Bytes

func (m *Mfg) Bytes(eraseVal byte) ([]byte, error)

Bytes serializes an mfgimage into binary form.

func (*Mfg) Clone

func (m *Mfg) Clone() Mfg

Clone performs a deep copy of an mfgimage.

func (*Mfg) ExtractFlashArea

func (m *Mfg) ExtractFlashArea(area flash.FlashArea,
	eraseVal byte) ([]byte, error)

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

func (m *Mfg) ExtractImages(man manifest.MfgManifest) ([]image.Image, error)

Constructs the set of images embedded in an mfgimage.

func (*Mfg) Hash

func (m *Mfg) Hash(eraseVal byte) ([]byte, error)

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) RecalcHash

func (m *Mfg) RecalcHash(eraseVal byte) ([]byte, error)

func (*Mfg) RefillHash

func (m *Mfg) RefillHash(eraseVal byte) error

RefillHash replace's the contents of an mfgimage's SHA256 TLV with a newly calculated hash.

func (*Mfg) Tlvs

func (m *Mfg) Tlvs() []MetaTlv

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

func (m *Mfg) VerifyStructure(eraseVal byte) error

VerifyStructure checks an mfgimage's structure and internal consistency. It returns an error if the mfgimage is incorrect.

Jump to

Keyboard shortcuts

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