Skip to content

Commit 5620ca1

Browse files
authored
feat: add SACM version 4 (#446)
Signed-off-by: Christian Walter <christian.walter@9elements.com>
1 parent d844cd9 commit 5620ca1

1 file changed

Lines changed: 81 additions & 2 deletions

File tree

pkg/intel/metadata/fit/ent_startup_ac_module_entry.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ const (
110110

111111
// ACHeaderVersion3 is version "3.0 – for SINIT ACM of converge of BtG and TXT"
112112
ACHeaderVersion3 = ACModuleHeaderVersion(0x00030000)
113+
114+
// ACHeaderVersion4 is version "4.0 for SINIT ACM of BtG"
115+
ACHeaderVersion4 = ACModuleHeaderVersion(0x00040000)
113116
)
114117

115118
func (ver ACModuleHeaderVersion) GoString() string {
@@ -483,6 +486,77 @@ type EntrySACMData struct {
483486
UserArea []byte
484487
}
485488

489+
type EntrySACMData4 struct {
490+
EntrySACMDataCommon
491+
492+
RSAPubKey [384]byte
493+
RSASig [384]byte
494+
XMSSPubKey [64]byte
495+
XMSSSig [2692]byte
496+
Reserved [60]byte
497+
Scratch [3584]byte
498+
}
499+
500+
var entrySACMData4Size = uint(binary.Size(EntrySACMData4{}))
501+
502+
// Read parses the ACM v3 headers
503+
func (entryData *EntrySACMData4) Read(b []byte) (int, error) {
504+
n, err := entryData.ReadFrom(bytesextra.NewReadWriteSeeker(b))
505+
return int(n), err
506+
}
507+
508+
// ReadFrom parses the ACM v3 headers
509+
func (entryData *EntrySACMData4) ReadFrom(r io.Reader) (int64, error) {
510+
err := binary.Read(r, binary.LittleEndian, entryData)
511+
if err != nil {
512+
return -1, err
513+
}
514+
return int64(entrySACMData3Size), nil
515+
}
516+
517+
// Write compiles the SACM v3 headers into a binary representation
518+
func (entryData *EntrySACMData4) Write(b []byte) (int, error) {
519+
n, err := entryData.WriteTo(bytesextra.NewReadWriteSeeker(b))
520+
return int(n), err
521+
}
522+
523+
// WriteTo compiles the SACM v3 headers into a binary representation
524+
func (entryData *EntrySACMData4) WriteTo(w io.Writer) (int64, error) {
525+
err := binary.Write(w, binary.LittleEndian, entryData)
526+
if err != nil {
527+
return -1, err
528+
}
529+
return int64(entrySACMData4Size), nil
530+
}
531+
532+
// GetRSAPubKey returns the RSA public key
533+
func (entryData *EntrySACMData4) GetRSAPubKey() rsa.PublicKey {
534+
pubKey := rsa.PublicKey{
535+
N: big.NewInt(0),
536+
E: 0x10001, // see Table 9. "RSAPubExp" of https://www.intel.com/content/www/us/en/software-developers/txt-software-development-guide.html
537+
}
538+
pubKey.N.SetBytes(entryData.RSAPubKey[:])
539+
return pubKey
540+
}
541+
542+
// GetRSASig returns the RSA signature.
543+
func (entryData *EntrySACMData4) GetRSASig() []byte { return entryData.RSASig[:] }
544+
545+
// RSASigBinaryOffset returns the RSA signature offset
546+
func (entryData *EntrySACMData4) RSASigBinaryOffset() uint64 {
547+
return uint64(binary.Size(entryData.EntrySACMDataCommon)) +
548+
uint64(binary.Size(entryData.RSAPubKey))
549+
}
550+
551+
// GetXMSSPubKey returns the XMSS public key
552+
func (entryData *EntrySACMData4) GetXMSSPubKey() []byte { return entryData.XMSSPubKey[:] }
553+
554+
// GetXMSSSig returns the XMSS signature.
555+
func (entryData *EntrySACMData4) GetXMSSSig() []byte { return entryData.XMSSSig[:] }
556+
557+
// GetScratch returns the Scratch field value
558+
func (entryData *EntrySACMData4) GetScratch() []byte { return entryData.Scratch[:] }
559+
486560
// Read parses the ACM
487561
func (entryData *EntrySACMData) Read(b []byte) (int, error) {
488562
n, err := entryData.ReadFrom(bytesextra.NewReadWriteSeeker(b))
@@ -536,6 +610,8 @@ func (entryData *EntrySACMData) GetCommon() *EntrySACMDataCommon {
536610
return &data.EntrySACMDataCommon
537611
case *EntrySACMData3:
538612
return &data.EntrySACMDataCommon
613+
case *EntrySACMData4:
614+
return &data.EntrySACMDataCommon
539615
}
540616
return nil
541617
}
@@ -594,6 +670,9 @@ func ParseSACMData(r io.Reader) (*EntrySACMData, error) {
594670
case ACHeaderVersion3:
595671
result.EntrySACMDataInterface = &EntrySACMData3{EntrySACMDataCommon: common}
596672
requiredKeySize = uint64(len(EntrySACMData3{}.RSAPubKey))
673+
case ACHeaderVersion4:
674+
result.EntrySACMDataInterface = &EntrySACMData4{EntrySACMDataCommon: common}
675+
requiredKeySize = uint64(len(EntrySACMData4{}.RSAPubKey))
597676
default:
598677
return result, &ErrUnknownACMHeaderVersion{ACHeaderVersion: common.HeaderVersion}
599678
}
@@ -629,9 +708,9 @@ func ParseSACMData(r io.Reader) (*EntrySACMData, error) {
629708
// Read UserArea
630709

631710
// `UserArea` has variable length and therefore was not included into
632-
// `EntrySACMData0` and `EntrySACMData3`, but it is in the tail,
711+
// `EntrySACMData0` and `EntrySACMData3/4`, but it is in the tail,
633712
// so we just calculate the startIndex as the end of
634-
// EntrySACMData0/EntrySACMData3.
713+
// EntrySACMData0/EntrySACMData3/4.
635714
userAreaStartIdx := uint64(binary.Size(result.EntrySACMDataInterface))
636715
userAreaEndIdx := result.EntrySACMDataInterface.GetSize().Size()
637716
if userAreaEndIdx > userAreaStartIdx {

0 commit comments

Comments
 (0)