F-13452 - Free the wrap HMAC only after it is initialized

pull/604/head
Aidan Garske 2026-09-10 11:24:40 -07:00
parent ef6e19e25b
commit 55135d1cd2
1 changed files with 7 additions and 1 deletions

View File

@ -2259,6 +2259,7 @@ int FwWrapPrivate(FWTPM_Object* parent, WC_RNG* rng,
FWTPM_DECLARE_VAR(hmac, Hmac); FWTPM_DECLARE_VAR(hmac, Hmac);
int sensSz = 0; int sensSz = 0;
int aesInit = 0; int aesInit = 0;
int hmacInit = 0;
int pos = 0; int pos = 0;
FWTPM_ALLOC_BUF(sensBuf, FWTPM_MAX_PRIVKEY_DER + 128); FWTPM_ALLOC_BUF(sensBuf, FWTPM_MAX_PRIVKEY_DER + 128);
@ -2304,6 +2305,9 @@ int FwWrapPrivate(FWTPM_Object* parent, WC_RNG* rng,
/* HMAC integrity over IV and encrypted data */ /* HMAC integrity over IV and encrypted data */
if (rc == 0) { if (rc == 0) {
rc = wc_HmacInit(hmac, NULL, INVALID_DEVID); rc = wc_HmacInit(hmac, NULL, INVALID_DEVID);
if (rc == 0) {
hmacInit = 1;
}
} }
if (rc == 0) { if (rc == 0) {
rc = wc_HmacSetKey(hmac, WC_SHA256, macKey, sizeof(macKey)); rc = wc_HmacSetKey(hmac, WC_SHA256, macKey, sizeof(macKey));
@ -2317,7 +2321,9 @@ int FwWrapPrivate(FWTPM_Object* parent, WC_RNG* rng,
if (rc == 0) { if (rc == 0) {
rc = wc_HmacFinal(hmac, hmacDigest); rc = wc_HmacFinal(hmac, hmacDigest);
} }
wc_HmacFree(hmac); if (hmacInit) {
wc_HmacFree(hmac);
}
/* Pack into TPM2B_PRIVATE */ /* Pack into TPM2B_PRIVATE */
if (rc == 0) { if (rc == 0) {