diff --git a/tpm.go b/tpm.go index ca31a8f..87418c1 100644 --- a/tpm.go +++ b/tpm.go @@ -260,7 +260,8 @@ func (t *TPM) createLocked(opts ...KeyOption) ([]byte, error) { } case TypeECC: - unique := make([]byte, 64) + uniqueSize := opt.curve.Params().BitSize / 8 + unique := make([]byte, 2*uniqueSize) if _, err := io.ReadFull(rand.Reader, unique); err != nil { return nil, fmt.Errorf("rand: %w", err) } @@ -307,8 +308,8 @@ func (t *TPM) createLocked(opts ...KeyOption) ([]byte, error) { Unique: tpm2.NewTPMUPublicID( tpm2.TPMAlgECC, &tpm2.TPMSECCPoint{ - X: tpm2.TPM2BECCParameter{Buffer: unique[:32]}, - Y: tpm2.TPM2BECCParameter{Buffer: unique[32:]}, + X: tpm2.TPM2BECCParameter{Buffer: unique[:uniqueSize]}, + Y: tpm2.TPM2BECCParameter{Buffer: unique[uniqueSize:]}, }, ), } @@ -433,9 +434,6 @@ func (t *TPM) unmarshalLocked(in []byte) (*Key, error) { pub: *pub, keyb: in, } - if t.loadedKey == out.id { - t.flushLocked() - } if err := out.loadLocked(); err != nil { return nil, err } diff --git a/tpm_test.go b/tpm_test.go index 59836ab..db9b1e5 100644 --- a/tpm_test.go +++ b/tpm_test.go @@ -139,6 +139,9 @@ func TestECC(t *testing.T) { } pub := key.Public() + if got, want := pub.(*ecdsa.PublicKey).Curve.Params().BitSize, curve.Params().BitSize; got != want { + t.Fatalf("pub.Curve.Params().BitSize = %d, want %d", got, want) + } hashed := sha256.Sum256([]byte(payload)) sig, err := key.Sign(nil, hashed[:], crypto.SHA256) if err != nil {