Skip to content

Commit

Permalink
Ensure the 0 hash algorithm isn't passed as a tpm2.Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
hslatman committed Nov 19, 2024
1 parent 25310fe commit a43052b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions attest/wrapped_tpm20.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,26 @@ func signECDSA(rw io.ReadWriter, key tpmutil.Handle, digest []byte, curve ellipt

// if opts is provided, it can override the hash function to use.
if opts != nil {
h, err := tpm2.HashToAlgorithm(opts.HashFunc())
if err != nil {
return nil, fmt.Errorf("incorrect hash algorithm: %v", err)
var (
h tpm2.Algorithm
err error
)
if v := opts.HashFunc(); v != 0 {
h, err = tpm2.HashToAlgorithm(v)
if err != nil {
return nil, fmt.Errorf("incorrect hash algorithm: %v", err)
}
} else {
switch curve {
case elliptic.P384():
h = tpm2.AlgSHA384
case elliptic.P521():
h = tpm2.AlgSHA512
default:
h = tpm2.AlgSHA256
}
}

scheme = &tpm2.SigScheme{
Alg: tpm2.AlgECDSA,
Hash: h,
Expand Down

0 comments on commit a43052b

Please sign in to comment.