Skip to content

Commit

Permalink
Generate a valid Keyset in DeriveKeyset
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 649183402
Change-Id: Ie150276669cd85e2a09122bfc6011aeb106e2ef4
  • Loading branch information
morambro authored and copybara-github committed Jul 3, 2024
1 parent 193b387 commit 505d5f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions keyderivation/prf_based_deriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,20 @@ func (p *prfBasedDeriver) DeriveKeyset(salt []byte) (*keyset.Handle, error) {
return nil, fmt.Errorf("derive key failed: %v", err)
}
// Fill in placeholder values for key ID, status, and output prefix type.
// The placeholder values are s.t. the keyset is valid and can be used to
// create a keyset handle.
// These will be populated with the correct values in the keyset deriver
// factory. This is acceptable because the keyset as-is will never leave Tink,
// and the user only interacts via the keyset deriver factory.
// factory. This is acceptable because the keyset as-is will never leave
// Tink, and the user only interacts via the keyset deriver factory.
var primaryKeyID uint32 = 0
return keysetHandle(&tinkpb.Keyset{
PrimaryKeyId: primaryKeyID,
Key: []*tinkpb.Keyset_Key{
&tinkpb.Keyset_Key{
KeyData: keyData,
Status: tinkpb.KeyStatusType_UNKNOWN_STATUS,
Status: tinkpb.KeyStatusType_ENABLED,
KeyId: primaryKeyID,
OutputPrefixType: tinkpb.OutputPrefixType_UNKNOWN_PREFIX,
OutputPrefixType: tinkpb.OutputPrefixType_RAW,
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions keyderivation/prf_based_deriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ func TestPRFBasedDeriverWithHKDFRFCVectorForAESGCM(t *testing.T) {
t.Fatal("keyset has no primary key")
}
// Verify key attributes set by prfBasedDeriver.
if got, want := key.GetStatus(), tinkpb.KeyStatusType_UNKNOWN_STATUS; got != want {
if got, want := key.GetStatus(), tinkpb.KeyStatusType_ENABLED; got != want {
t.Errorf("derived key status = %s, want %s", got, want)
}
if got, want := key.GetOutputPrefixType(), tinkpb.OutputPrefixType_UNKNOWN_PREFIX; got != want {
if got, want := key.GetOutputPrefixType(), tinkpb.OutputPrefixType_RAW; got != want {
t.Errorf("derived key output prefix type = %s, want %s", got, want)
}
// Verify key value.
Expand Down

0 comments on commit 505d5f0

Please sign in to comment.