image: reimplement and adapt measurement generation in Go

This commit is contained in:
Malte Poll 2023-09-21 14:50:18 +02:00 committed by Malte Poll
parent 8e706d6de3
commit f6d9f91877
31 changed files with 1343 additions and 286 deletions

View file

@ -0,0 +1,31 @@
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package measure
import (
"bytes"
"fmt"
"hash"
"io"
"github.com/foxboron/go-uefi/efi/pecoff"
)
// Authentihash returns the PE/COFF hash / Authentihash of a file.
func Authentihash(r io.Reader, h hash.Hash) ([]byte, error) {
buf := new(bytes.Buffer)
if _, err := buf.ReadFrom(r); err != nil {
return nil, fmt.Errorf("failed to read pe file: %v", err)
}
signingCtx := pecoff.PECOFFChecksum(buf.Bytes())
pecoff.PaddSigCtx(signingCtx)
h.Write(signingCtx.SigData.Bytes())
return h.Sum(nil), nil
}