Skip to content

Commit

Permalink
Modify CreateKey (#85)
Browse files Browse the repository at this point in the history
Modify CreateKey to return all values from create instead of just the public and private blobs.
  • Loading branch information
Andrew Lytvynov authored Apr 10, 2019
2 parents 20331ed + 78c503b commit e84d59d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
11 changes: 4 additions & 7 deletions tpm2/tpm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,10 @@ func create(rw io.ReadWriter, parentHandle tpmutil.Handle, parentPassword, objec
}

// CreateKey creates a new key pair under the owner handle.
// Returns private key and public key blobs.
func CreateKey(rw io.ReadWriter, owner tpmutil.Handle, sel PCRSelection, parentPassword, ownerPassword string, pub Public) ([]byte, []byte, error) {
_, private, public, _, _, _, err := create(rw, owner, parentPassword, ownerPassword, nil /*inSensitive*/, pub, sel)
if err != nil {
return nil, nil, err
}
return private, public, nil
// Returns private key and public key blobs as well as the
// creation data, a hash of said data and the creation ticket.
func CreateKey(rw io.ReadWriter, owner tpmutil.Handle, sel PCRSelection, parentPassword, ownerPassword string, pub Public) (handle tpmutil.Handle, private, public, creationData, creationHash []byte, creationTicket Ticket, err error) {
return create(rw, owner, parentPassword, ownerPassword, nil /*inSensitive*/, pub, sel)
}

// Seal creates a data blob object that seals the sensitive data under a parent and with a
Expand Down
10 changes: 5 additions & 5 deletions tpm2/tpm2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestCombinedKeyTest(t *testing.T) {
}
defer FlushContext(rw, parentHandle)

privateBlob, publicBlob, err := CreateKey(rw, parentHandle, pcrSelection, defaultPassword, defaultPassword, defaultKeyParams)
_, privateBlob, publicBlob, _, _, _, err := CreateKey(rw, parentHandle, pcrSelection, defaultPassword, defaultPassword, defaultKeyParams)
if err != nil {
t.Fatalf("CreateKey failed: %s", err)
}
Expand All @@ -195,7 +195,7 @@ func TestCombinedEndorsementTest(t *testing.T) {
}
defer FlushContext(rw, parentHandle)

privateBlob, publicBlob, err := CreateKey(rw, parentHandle, pcrSelection, emptyPassword, defaultPassword, defaultKeyParams)
_, privateBlob, publicBlob, _, _, _, err := CreateKey(rw, parentHandle, pcrSelection, emptyPassword, defaultPassword, defaultKeyParams)
if err != nil {
t.Fatalf("CreateKey failed: %s", err)
}
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestCombinedContextTest(t *testing.T) {
defer FlushContext(rw, rootHandle)

// CreateKey (Quote Key)
quotePrivate, quotePublic, err := CreateKey(rw, rootHandle, pcrSelection, emptyPassword, emptyPassword, defaultKeyParams)
_, quotePrivate, quotePublic, _, _, _, err := CreateKey(rw, rootHandle, pcrSelection, emptyPassword, emptyPassword, defaultKeyParams)
if err != nil {
t.Fatalf("CreateKey failed: %v", err)
}
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestEvictControl(t *testing.T) {
defer FlushContext(rw, rootHandle)

// CreateKey (Quote Key)
quotePrivate, quotePublic, err := CreateKey(rw, rootHandle, pcrSelection, emptyPassword, emptyPassword, defaultKeyParams)
_, quotePrivate, quotePublic, _, _, _, err := CreateKey(rw, rootHandle, pcrSelection, emptyPassword, emptyPassword, defaultKeyParams)
if err != nil {
t.Fatalf("CreateKey failed: %v", err)
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ func TestEncryptDecrypt(t *testing.T) {
t.Fatalf("CreatePrimary failed: %s", err)
}
defer FlushContext(rw, parentHandle)
privateBlob, publicBlob, err := CreateKey(rw, parentHandle, pcrSelection, defaultPassword, defaultPassword, Public{
_, privateBlob, publicBlob, _, _, _, err := CreateKey(rw, parentHandle, pcrSelection, defaultPassword, defaultPassword, Public{
Type: AlgSymCipher,
NameAlg: AlgSHA256,
Attributes: FlagDecrypt | FlagSign | FlagUserWithAuth | FlagFixedParent | FlagFixedTPM | FlagSensitiveDataOrigin,
Expand Down

0 comments on commit e84d59d

Please sign in to comment.