Skip to content

Commit 2306d5b

Browse files
authored
Merge pull request #7 from smallstep/herman/fix-ecdsa-hash-algorithm-zero
Ensure the `0` hash algorithm isn't passed as a `tpm2.Algorithm`
2 parents 25310fe + a43052b commit 2306d5b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

attest/wrapped_tpm20.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,26 @@ func signECDSA(rw io.ReadWriter, key tpmutil.Handle, digest []byte, curve ellipt
592592

593593
// if opts is provided, it can override the hash function to use.
594594
if opts != nil {
595-
h, err := tpm2.HashToAlgorithm(opts.HashFunc())
596-
if err != nil {
597-
return nil, fmt.Errorf("incorrect hash algorithm: %v", err)
595+
var (
596+
h tpm2.Algorithm
597+
err error
598+
)
599+
if v := opts.HashFunc(); v != 0 {
600+
h, err = tpm2.HashToAlgorithm(v)
601+
if err != nil {
602+
return nil, fmt.Errorf("incorrect hash algorithm: %v", err)
603+
}
604+
} else {
605+
switch curve {
606+
case elliptic.P384():
607+
h = tpm2.AlgSHA384
608+
case elliptic.P521():
609+
h = tpm2.AlgSHA512
610+
default:
611+
h = tpm2.AlgSHA256
612+
}
598613
}
614+
599615
scheme = &tpm2.SigScheme{
600616
Alg: tpm2.AlgECDSA,
601617
Hash: h,

0 commit comments

Comments
 (0)