Skip to content

Commit e3003c0

Browse files
committed
chore: bump tpm nonce size to match the algorithm used
Bump the tpm nonce size to match the size of algorithm used. Fixes: #13379 Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent 8fd04da commit e3003c0

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

internal/pkg/secureboot/tpm2/seal.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ func Seal(key []byte, tpmPCRs []int) (*SealedResponse, error) {
6464
return nil, err
6565
}
6666

67+
h, err := tpm2.TPMAlgSHA256.Hash()
68+
if err != nil {
69+
return nil, err
70+
}
71+
6772
create := tpm2.Create{
6873
ParentHandle: tpm2.AuthHandle{
6974
Handle: createPrimaryResponse.ObjectHandle,
7075
Name: createPrimaryResponse.Name,
7176
Auth: tpm2.HMAC(
7277
tpm2.TPMAlgSHA256,
73-
20,
78+
h.Size(),
7479
tpm2.Salted(createPrimaryResponse.ObjectHandle, *outPub),
7580
tpm2.AESEncryption(128, tpm2.EncryptInOut),
7681
),

internal/pkg/secureboot/tpm2/unseal.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,15 @@ func Unseal(sealed SealedResponse) ([]byte, error) {
9898
return nil, err
9999
}
100100

101+
h, err := tpm2.TPMAlgSHA256.Hash()
102+
if err != nil {
103+
return nil, err
104+
}
105+
101106
policySess, policyCloseFunc, err := tpm2.PolicySession(
102107
t,
103108
tpm2.TPMAlgSHA256,
104-
20,
109+
h.Size(),
105110
tpm2.Salted(createPrimaryResponse.ObjectHandle, *outPub),
106111
)
107112
if err != nil {
@@ -254,7 +259,7 @@ func Unseal(sealed SealedResponse) ([]byte, error) {
254259

255260
unsealResponse, err := unsealOp.Execute(t, tpm2.HMAC(
256261
tpm2.TPMAlgSHA256,
257-
20,
262+
h.Size(),
258263
tpm2.Salted(createPrimaryResponse.ObjectHandle, *outPub),
259264
tpm2.AESEncryption(128, tpm2.EncryptOut),
260265
tpm2.Bound(loadResponse.ObjectHandle, loadResponse.Name, nil),

0 commit comments

Comments
 (0)