bg

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: BSD-3-Clause Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RandReader exports the rand.Reader
	RandReader = rand.Reader
)
View Source
var SM2UID = []byte{0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38}
View Source
var (
	// StrictOrderCheck defines if elements order checks should be performed.
	// For example in the Boot Policy Manifest elements could be in a wrong
	// order. And we still can parse it, but in this way `*Offset` methods
	// could be confusing, since they will show the offset as they will
	// be written (not as they were parsed).
	//
	// We require a strict order because it is explicitly required
	// in the documentation #575623:
	//
	// > The order of the elements and the order of the fields within each
	// > element are architectural and must be followed.
	StrictOrderCheck = true
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm uint16

Algorithm represents a crypto algorithm value.

const (
	AlgUnknown Algorithm = 0x0000
	AlgRSA     Algorithm = 0x0001
	AlgSHA1    Algorithm = 0x0004
	AlgSHA256  Algorithm = 0x000B
	AlgNull    Algorithm = 0x0010
	AlgRSASSA  Algorithm = 0x0014
)

func GetAlgFromString

func GetAlgFromString(name string) (Algorithm, error)

func (Algorithm) Hash

func (a Algorithm) Hash() (hash.Hash, error)

Hash returns a crypto.Hash based on the given id. An error is returned if the given algorithm is not a hash algorithm or is not available.

func (Algorithm) IsNull

func (a Algorithm) IsNull() bool

IsNull returns true if a is AlgNull or zero (unset).

func (Algorithm) PrettyString

func (v Algorithm) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the bits of the flags in an easy-to-read format.

func (Algorithm) ReadFrom

func (v Algorithm) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the Algorithm from 'r' in binary format.

func (Algorithm) String

func (a Algorithm) String() string

func (Algorithm) TotalSize

func (v Algorithm) TotalSize() uint64

TotalSize returns the total size measured through binary.Size.

func (Algorithm) WriteTo

func (v Algorithm) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Algorithm into 'w' in binary format.

type BitSize

type BitSize uint16

BitSize is a size in bits.

func (BitSize) InBits

func (ks BitSize) InBits() uint16

InBits returns the size in bits.

func (BitSize) InBytes

func (ks BitSize) InBytes() uint16

InBytes returns the size in bytes.

func (BitSize) PrettyString

func (v BitSize) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the bits of the flags in an easy-to-read format.

func (BitSize) ReadFrom

func (v BitSize) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the BitSize from 'r' in binary format.

func (*BitSize) SetInBits

func (ks *BitSize) SetInBits(amountOfBits uint16)

SetInBits sets the size in bits.

func (*BitSize) SetInBytes

func (ks *BitSize) SetInBytes(amountOfBytes uint16)

SetInBytes sets the size in bytes.

func (BitSize) TotalSize

func (v BitSize) TotalSize() uint64

TotalSize returns the total size measured through binary.Size.

func (BitSize) WriteTo

func (v BitSize) WriteTo(w io.Writer) (int64, error)

WriteTo writes the BitSize into 'w' in binary format.

type Element

type Element interface {
	Structure
	ReadDataFrom(r io.Reader) (int64, error)
	GetStructInfo() StructInfo
	SetStructInfo(StructInfo)
}

type ElementsContainer

type ElementsContainer interface {
	Structure
	GetFieldByStructID(structID string) interface{}
}

type HashStructure

type HashStructure struct {
	HashAlg    Algorithm `default:"0x10" json:"hsAlg"`
	HashBuffer []byte    `json:"hsBuffer"`
}

HashStructure describes a digest.

func NewHashStructure

func NewHashStructure() *HashStructure

NewHashStructure returns a new instance of HashStructure with all default values set.

func (*HashStructure) HashAlgOffset

func (s *HashStructure) HashAlgOffset() uint64

HashAlgOffset returns the offset in bytes of field HashAlg

func (*HashStructure) HashAlgTotalSize

func (s *HashStructure) HashAlgTotalSize() uint64

HashAlgSize returns the size in bytes of the value of field HashAlg

func (*HashStructure) HashBufferOffset

func (s *HashStructure) HashBufferOffset() uint64

HashBufferOffset returns the offset in bytes of field HashBuffer

func (*HashStructure) HashBufferTotalSize

func (s *HashStructure) HashBufferTotalSize() uint64

HashBufferSize returns the size in bytes of the value of field HashBuffer

func (*HashStructure) PrettyString

func (s *HashStructure) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the content of the structure in an easy-to-read format.

func (*HashStructure) ReadFrom

func (s *HashStructure) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the HashStructure from 'r' in format defined in the document #575623.

func (*HashStructure) Rehash

func (s *HashStructure) Rehash()

Rehash sets values which are calculated automatically depending on the rest data. It is usually about the total size field of an element.

func (*HashStructure) RehashRecursive

func (s *HashStructure) RehashRecursive()

RehashRecursive calls Rehash (see below) recursively.

func (*HashStructure) TotalSize

func (s *HashStructure) TotalSize() uint64

Size returns the total size of the HashStructure.

func (*HashStructure) Validate

func (s *HashStructure) Validate() error

Validate (recursively) checks the structure if there are any unexpected values. It returns an error if so.

func (*HashStructure) WriteTo

func (s *HashStructure) WriteTo(w io.Writer) (int64, error)

WriteTo writes the HashStructure into 'w' in format defined in the document #575623.

type HashStructureFill

type HashStructureFill struct {
	HashAlg    Algorithm `default:"0x0b" json:"hsAlg"`
	HashBuffer []byte    `countValue:"hashSize()" prettyValue:"hashSizePrint()" json:"hsBuffer"`
}

func NewHashStructureFill

func NewHashStructureFill() *HashStructureFill

NewHashStructureFill returns a new instance of HashStructureFill with all default values set.

func (*HashStructureFill) HashAlgOffset

func (s *HashStructureFill) HashAlgOffset() uint64

HashAlgOffset returns the offset in bytes of field HashAlg

func (*HashStructureFill) HashAlgTotalSize

func (s *HashStructureFill) HashAlgTotalSize() uint64

HashAlgSize returns the size in bytes of the value of field HashAlg

func (*HashStructureFill) HashBufferOffset

func (s *HashStructureFill) HashBufferOffset() uint64

HashBufferOffset returns the offset in bytes of field HashBuffer

func (*HashStructureFill) HashBufferTotalSize

func (s *HashStructureFill) HashBufferTotalSize() uint64

HashBufferSize returns the size in bytes of the value of field HashBuffer

func (*HashStructureFill) PrettyString

func (s *HashStructureFill) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the content of the structure in an easy-to-read format.

func (*HashStructureFill) ReadFrom

func (s *HashStructureFill) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the HashStructureFill from 'r' in format defined in the document #575623.

func (*HashStructureFill) Rehash

func (s *HashStructureFill) Rehash()

Rehash sets values which are calculated automatically depending on the rest data. It is usually about the total size field of an element.

func (*HashStructureFill) RehashRecursive

func (s *HashStructureFill) RehashRecursive()

RehashRecursive calls Rehash (see below) recursively.

func (*HashStructureFill) TotalSize

func (s *HashStructureFill) TotalSize() uint64

Size returns the total size of the HashStructureFill.

func (*HashStructureFill) Validate

func (s *HashStructureFill) Validate() error

Validate (recursively) checks the structure if there are any unexpected values. It returns an error if so.

func (*HashStructureFill) WriteTo

func (s *HashStructureFill) WriteTo(w io.Writer) (int64, error)

WriteTo writes the HashStructureFill into 'w' in format defined in the document #575623.

type Key

type Key struct {
	KeyAlg  Algorithm `json:"keyAlg"`
	Version uint8     `require:"0x10"  json:"keyVersion"`
	KeySize BitSize   `json:"keyBitsize"`
	Data    []byte    `countValue:"keyDataSize()" json:"keyData"`
}

Key is a public key of an asymmetric crypto keypair.

func NewKey

func NewKey() *Key

NewKey returns a new instance of Key with all default values set.

func (*Key) DataOffset

func (s *Key) DataOffset() uint64

DataOffset returns the offset in bytes of field Data

func (*Key) DataTotalSize

func (s *Key) DataTotalSize() uint64

DataSize returns the size in bytes of the value of field Data

func (*Key) KeyAlgOffset

func (s *Key) KeyAlgOffset() uint64

KeyAlgOffset returns the offset in bytes of field KeyAlg

func (*Key) KeyAlgTotalSize

func (s *Key) KeyAlgTotalSize() uint64

KeyAlgSize returns the size in bytes of the value of field KeyAlg

func (*Key) KeySizeOffset

func (s *Key) KeySizeOffset() uint64

KeySizeOffset returns the offset in bytes of field KeySize

func (*Key) KeySizeTotalSize

func (s *Key) KeySizeTotalSize() uint64

KeySizeSize returns the size in bytes of the value of field KeySize

func (*Key) PrettyString

func (s *Key) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the content of the structure in an easy-to-read format.

func (*Key) PrintBPMPubKey

func (k *Key) PrintBPMPubKey(bpmAlg Algorithm) error

PrintBPMPubKey prints the BPM public signing key hash to fuse into the Intel ME

func (*Key) PrintKMPubKey

func (k *Key) PrintKMPubKey(kmAlg Algorithm) error

PrintKMPubKey prints the KM public signing key hash to fuse into the Intel ME

func (Key) PubKey

func (k Key) PubKey() (crypto.PublicKey, error)

PubKey parses Data into crypto.PublicKey.

func (*Key) ReadFrom

func (s *Key) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the Key from 'r' in format defined in the document #575623.

func (*Key) Rehash

func (s *Key) Rehash()

Rehash sets values which are calculated automatically depending on the rest data. It is usually about the total size field of an element.

func (*Key) RehashRecursive

func (s *Key) RehashRecursive()

RehashRecursive calls Rehash (see below) recursively.

func (*Key) SetPubKey

func (k *Key) SetPubKey(key crypto.PublicKey) error

SetPubKey sets Data the value corresponding to passed `key`.

func (*Key) TotalSize

func (s *Key) TotalSize() uint64

Size returns the total size of the Key.

func (*Key) Validate

func (s *Key) Validate() error

Validate (recursively) checks the structure if there are any unexpected values. It returns an error if so.

func (*Key) VersionOffset

func (s *Key) VersionOffset() uint64

VersionOffset returns the offset in bytes of field Version

func (*Key) VersionTotalSize

func (s *Key) VersionTotalSize() uint64

VersionSize returns the size in bytes of the value of field Version

func (*Key) WriteTo

func (s *Key) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Key into 'w' in format defined in the document #575623.

type KeySignature

type KeySignature struct {
	Version   uint8     `require:"0x10" json:"ksVersion,omitempty"`
	Key       Key       `json:"ksKey"`
	Signature Signature `json:"ksSignature"`
}

KeySignature

func NewKeySignature

func NewKeySignature() *KeySignature

NewKeySignature returns a new instance of KeySignature with all default values set.

func (*KeySignature) FillSignature

func (ks *KeySignature) FillSignature(signAlgo Algorithm, pubKey crypto.PublicKey, signedData []byte, hashAlgo Algorithm) error

FillSignature sets a signature and all the values of KeyManifest, accordingly to arguments signAlgo, pubKey and signedData.

if signAlgo is zero then it is detected automatically, based on the type of the provided private key.

func (*KeySignature) KeyOffset

func (s *KeySignature) KeyOffset() uint64

KeyOffset returns the offset in bytes of field Key

func (*KeySignature) KeyTotalSize

func (s *KeySignature) KeyTotalSize() uint64

KeySize returns the size in bytes of the value of field Key

func (*KeySignature) PrettyString

func (s *KeySignature) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the content of the structure in an easy-to-read format.

func (*KeySignature) ReadFrom

func (s *KeySignature) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the KeySignature from 'r' in format defined in the document #575623.

func (*KeySignature) Rehash

func (s *KeySignature) Rehash()

Rehash sets values which are calculated automatically depending on the rest data. It is usually about the total size field of an element.

func (*KeySignature) RehashRecursive

func (s *KeySignature) RehashRecursive()

RehashRecursive calls Rehash (see below) recursively.

func (*KeySignature) SetSignature

func (ks *KeySignature) SetSignature(signAlgo Algorithm, privKey crypto.Signer, signedData []byte) error

SetSignature generates a signature and sets all the values of KeyManifest, accordingly to arguments signAlgo, privKey and signedData.

if signAlgo is zero then it is detected automatically, based on the type of the provided private key.

func (*KeySignature) SetSignatureAuto

func (ks *KeySignature) SetSignatureAuto(privKey crypto.Signer, signedData []byte) error

SetSignatureAuto generates a signature and sets all the values of KeyManifest, accordingly to arguments privKey and signedData.

Signing algorithm will be detected automatically based on the type of the provided private key.

func (*KeySignature) SignatureOffset

func (s *KeySignature) SignatureOffset() uint64

SignatureOffset returns the offset in bytes of field Signature

func (*KeySignature) SignatureTotalSize

func (s *KeySignature) SignatureTotalSize() uint64

SignatureSize returns the size in bytes of the value of field Signature

func (*KeySignature) TotalSize

func (s *KeySignature) TotalSize() uint64

Size returns the total size of the KeySignature.

func (*KeySignature) Validate

func (s *KeySignature) Validate() error

Validate (recursively) checks the structure if there are any unexpected values. It returns an error if so.

func (*KeySignature) Verify

func (m *KeySignature) Verify(signedData []byte) error

Verify verifies the builtin signature with the builtin public key.

func (*KeySignature) VersionOffset

func (s *KeySignature) VersionOffset() uint64

VersionOffset returns the offset in bytes of field Version

func (*KeySignature) VersionTotalSize

func (s *KeySignature) VersionTotalSize() uint64

VersionSize returns the size in bytes of the value of field Version

func (*KeySignature) WriteTo

func (s *KeySignature) WriteTo(w io.Writer) (int64, error)

WriteTo writes the KeySignature into 'w' in format defined in the document #575623.

type Manifest

type Manifest interface {
	Structure
}

type SVN

type SVN uint8

SVN represents Security Version Number.

func (SVN) PrettyString

func (v SVN) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the bits of the flags in an easy-to-read format.

func (SVN) ReadFrom

func (v SVN) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the SVN from 'r' in binary format.

func (SVN) SVN

func (svn SVN) SVN() uint8

SVN returns the Security Version Number of an SVN field

func (SVN) TotalSize

func (v SVN) TotalSize() uint64

TotalSize returns the total size measured through binary.Size.

func (SVN) WriteTo

func (v SVN) WriteTo(w io.Writer) (int64, error)

WriteTo writes the SVN into 'w' in binary format.

type Signature

type Signature struct {
	SigScheme Algorithm `json:"sigScheme"`
	Version   uint8     `require:"0x10" json:"sigVersion,omitempty"`
	KeySize   BitSize   `json:"sigKeysize,omitempty"`
	HashAlg   Algorithm `json:"sigHashAlg"`
	Data      []byte    `countValue:"KeySize.InBytes()" prettyValue:"dataPrettyValue()" json:"sigData"`
}

Signature exports the Signature structure

func NewSignature

func NewSignature() *Signature

NewSignature returns a new instance of Signature with all default values set.

func (*Signature) DataOffset

func (s *Signature) DataOffset() uint64

DataOffset returns the offset in bytes of field Data

func (*Signature) DataTotalSize

func (s *Signature) DataTotalSize() uint64

DataSize returns the size in bytes of the value of field Data

func (*Signature) FillSignature

func (m *Signature) FillSignature(signAlgo Algorithm, pubKey crypto.PublicKey, signedData []byte, hashAlgo Algorithm) error

FillSignature sets the signature accordingly to arguments signAlgo, pubKey and signedData; and sets all the fields of the structure Signature.

if signAlgo is zero then it is detected automatically, based on the type of the provided private key.

func (*Signature) HashAlgOffset

func (s *Signature) HashAlgOffset() uint64

HashAlgOffset returns the offset in bytes of field HashAlg

func (*Signature) HashAlgTotalSize

func (s *Signature) HashAlgTotalSize() uint64

HashAlgSize returns the size in bytes of the value of field HashAlg

func (*Signature) KeySizeOffset

func (s *Signature) KeySizeOffset() uint64

KeySizeOffset returns the offset in bytes of field KeySize

func (*Signature) KeySizeTotalSize

func (s *Signature) KeySizeTotalSize() uint64

KeySizeSize returns the size in bytes of the value of field KeySize

func (*Signature) PrettyString

func (s *Signature) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the content of the structure in an easy-to-read format.

func (*Signature) ReadFrom

func (s *Signature) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the Signature from 'r' in format defined in the document #575623.

func (*Signature) Rehash

func (s *Signature) Rehash()

Rehash sets values which are calculated automatically depending on the rest data. It is usually about the total size field of an element.

func (*Signature) RehashRecursive

func (s *Signature) RehashRecursive()

RehashRecursive calls Rehash (see below) recursively.

func (*Signature) SetSignature

func (m *Signature) SetSignature(signAlgo Algorithm, privKey crypto.Signer, signedData []byte) error

SetSignature calculates the signature accordingly to arguments signAlgo, privKey and signedData; and sets all the fields of the structure Signature.

if signAlgo is zero then it is detected automatically, based on the type of the provided private key.

func (*Signature) SetSignatureByData

func (m *Signature) SetSignatureByData(sig SignatureDataInterface, hashAlgo Algorithm) error

SetSignatureByData sets all the fields of the structure Signature by accepting one of these types as the input argument `sig`: * SignatureRSAPSS * SignatureRSAASA * SignatureECDSA * SignatureSM2

func (*Signature) SetSignatureData

func (m *Signature) SetSignatureData(sig SignatureDataInterface) error

SetSignatureData sets the value of the field Data by accepting one of these types as the input argument `sig`: * SignatureRSAPSS * SignatureRSAASA * SignatureECDSA * SignatureSM2

func (*Signature) SigSchemeOffset

func (s *Signature) SigSchemeOffset() uint64

SigSchemeOffset returns the offset in bytes of field SigScheme

func (*Signature) SigSchemeTotalSize

func (s *Signature) SigSchemeTotalSize() uint64

SigSchemeSize returns the size in bytes of the value of field SigScheme

func (Signature) SignatureData

func (m Signature) SignatureData() (SignatureDataInterface, error)

SignatureData parses field Data and returns the signature as one of these types: * SignatureRSAPSS * SignatureRSAASA * SignatureECDSA * SignatureSM2

func (*Signature) TotalSize

func (s *Signature) TotalSize() uint64

Size returns the total size of the Signature.

func (*Signature) Validate

func (s *Signature) Validate() error

Validate (recursively) checks the structure if there are any unexpected values. It returns an error if so.

func (*Signature) VersionOffset

func (s *Signature) VersionOffset() uint64

VersionOffset returns the offset in bytes of field Version

func (*Signature) VersionTotalSize

func (s *Signature) VersionTotalSize() uint64

VersionSize returns the size in bytes of the value of field Version

func (*Signature) WriteTo

func (s *Signature) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Signature into 'w' in format defined in the document #575623.

type SignatureDataInterface

type SignatureDataInterface interface {
	fmt.Stringer

	// Verify returns nil if signedData was indeed signed by key pk, and
	// returns an appropriate error otherwise.
	Verify(pk crypto.PublicKey, signedData []byte) error
}

SignatureDataInterface is the interface which abstracts all the signature data types.

func NewSignatureByData

func NewSignatureByData(
	signAlgo Algorithm,
	pubKey crypto.PublicKey,
	signedData []byte,
) (SignatureDataInterface, error)

NewSignatureByData returns an implementation of SignatureDataInterface, accordingly to signAlgo, publicKey and signedData.

if signAlgo is zero then it is detected automatically, based on the type of the provided private key.

func NewSignatureData

func NewSignatureData(
	signAlgo Algorithm,
	privKey crypto.Signer,
	signedData []byte,
) (SignatureDataInterface, error)

NewSignatureData returns an implementation of SignatureDataInterface, accordingly to signAlgo, privKey and signedData.

if signAlgo is zero then it is detected automatically, based on the type of the provided private key.

type SignatureRSAASA

type SignatureRSAASA []byte

SignatureRSAASA is RSAASA signature bytes.

func (SignatureRSAASA) String

func (s SignatureRSAASA) String() string

String implements fmt.Stringer

func (SignatureRSAASA) Verify

func (s SignatureRSAASA) Verify(pkIface crypto.PublicKey, signedData []byte) error

Verify implements SignatureDataInterface.

type StructInfo

type StructInfo struct {
	ID      StructureID `json:"StructInfoID"`
	Version uint8       `json:"StructInfoVersion"`
}

func NewStructInfo

func NewStructInfo() *StructInfo

NewStructInfo returns a new instance of StructInfo with all default values set.

func (*StructInfo) IDOffset

func (s *StructInfo) IDOffset() uint64

IDOffset returns the offset in bytes of field ID

func (*StructInfo) IDTotalSize

func (s *StructInfo) IDTotalSize() uint64

IDSize returns the size in bytes of the value of field ID

func (*StructInfo) PrettyString

func (s *StructInfo) PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string

PrettyString returns the content of the structure in an easy-to-read format.

func (*StructInfo) ReadFrom

func (s *StructInfo) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the StructInfo from 'r' in format defined in the document #575623.

func (*StructInfo) Rehash

func (s *StructInfo) Rehash()

Rehash sets values which are calculated automatically depending on the rest data. It is usually about the total size field of an element.

func (*StructInfo) RehashRecursive

func (s *StructInfo) RehashRecursive()

RehashRecursive calls Rehash (see below) recursively.

func (StructInfo) StructInfo

func (s StructInfo) StructInfo() StructInfo

func (*StructInfo) TotalSize

func (s *StructInfo) TotalSize() uint64

Size returns the total size of the StructInfo.

func (*StructInfo) Validate

func (s *StructInfo) Validate() error

Validate (recursively) checks the structure if there are any unexpected values. It returns an error if so.

func (*StructInfo) VersionOffset

func (s *StructInfo) VersionOffset() uint64

VersionOffset returns the offset in bytes of field Version

func (*StructInfo) VersionTotalSize

func (s *StructInfo) VersionTotalSize() uint64

VersionSize returns the size in bytes of the value of field Version

func (*StructInfo) WriteTo

func (s *StructInfo) WriteTo(w io.Writer) (int64, error)

WriteTo writes the StructInfo into 'w' in format defined in the document #575623.

type Structure

type Structure interface {
	io.ReaderFrom
	io.WriterTo
	TotalSize() uint64
	PrettyString(depth uint, withHeader bool, opts ...pretty.Option) string
}

type StructureID

type StructureID [8]byte

func (StructureID) String

func (s StructureID) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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