Skip to content

Commit 9880886

Browse files
committed
Add support for determining hash function in signECDSA
1 parent a7219d9 commit 9880886

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

attest/wrapped_tpm20.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,12 @@ func signECDSA(rw io.ReadWriter, key tpmutil.Handle, digest []byte, curve ellipt
841841
}
842842

843843
var scheme *tpm2.SigScheme
844-
if runtime.GOOS == "windows" {
844+
switch {
845+
case opts == nil && runtime.GOOS == "windows":
845846
// On Windows, if no scheme (nil) is specified, error code 0x12
846847
// "unsupported or incompatible scheme" will be returned.
847-
// This is prevented by selecting an appropriate signature scheme.
848+
// This is prevented by selecting an appropriate signature
849+
// scheme based on the curve.
848850
var h tpm2.Algorithm
849851
switch curve {
850852
case elliptic.P384():
@@ -854,7 +856,15 @@ func signECDSA(rw io.ReadWriter, key tpmutil.Handle, digest []byte, curve ellipt
854856
default:
855857
h = tpm2.AlgSHA256
856858
}
857-
859+
scheme = &tpm2.SigScheme{
860+
Alg: tpm2.AlgECDSA,
861+
Hash: h,
862+
}
863+
case opts != nil:
864+
h, err := tpm2.HashToAlgorithm(opts.HashFunc())
865+
if err != nil {
866+
return nil, fmt.Errorf("incorrect hash algorithm: %v", err)
867+
}
858868
scheme = &tpm2.SigScheme{
859869
Alg: tpm2.AlgECDSA,
860870
Hash: h,

0 commit comments

Comments
 (0)