Skip to content

Commit 0e0d7d3

Browse files
ansiwenorangecms
authored andcommitted
fix(intel/metadata/bg): Do not reuse Hash instance.
PR #394 reintroduced a bug for the BtG 1.0 code, that has been fixed by commit 743961f for the CBnT code already, and that results in the wrong calculation of the Key Manifest Pubkey Hash in PrintKMPubKey(). This change reapplies the same fix for the BtG 1.0 code. Signed-off-by: Sven Anderson <[email protected]>
1 parent 596cbff commit 0e0d7d3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pkg/intel/metadata/bg/crypto_routines.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ const (
3131
)
3232

3333
var hashInfo = []struct {
34-
alg Algorithm
35-
hash hash.Hash
34+
alg Algorithm
35+
hashFactory func() hash.Hash
3636
}{
37-
{AlgSHA1, crypto.SHA1.New()},
38-
{AlgSHA256, crypto.SHA256.New()},
37+
{AlgSHA1, crypto.SHA1.New},
38+
{AlgSHA256, crypto.SHA256.New},
3939
}
4040

4141
// IsNull returns true if a is AlgNull or zero (unset).
@@ -48,10 +48,10 @@ func (a Algorithm) IsNull() bool {
4848
func (a Algorithm) Hash() (hash.Hash, error) {
4949
for _, info := range hashInfo {
5050
if info.alg == a {
51-
if info.hash == nil {
51+
if info.hashFactory == nil {
5252
return nil, fmt.Errorf("go hash algorithm #%snot available", info.alg.String())
5353
}
54-
return info.hash, nil
54+
return info.hashFactory(), nil
5555
}
5656
}
5757
return nil, fmt.Errorf("hash algorithm not supported: %s", a.String())

0 commit comments

Comments
 (0)