Skip to content

Commit

Permalink
ESYS: StartAuthSession bind auth trailing zeroes
Browse files Browse the repository at this point in the history
When StartAuthSession is called with a bind entity with a auth value
containing trailing zeroes, the HMAC or policy session computation
of ESYS does not match the computation on the TPM2.

The fix is to remove trailing zeroes from the auth value according
to the specification (TPM2 Architecture, 19.6.5, Note 2) before
computation of the session key.

The fixed bug is especially tricky as a randomly generated auth value
of the bind object can cause HMAC or policy session to fail
occassionally.

Signed-off-by: Stefan Thöni <stefan.thoeni@gapfruit.com>
  • Loading branch information
throwException committed May 10, 2024
1 parent a19ac4c commit f7f97e8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/tss2-esys/api/Esys_StartAuthSession.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@ Esys_StartAuthSession_Finish(
LOG_ERROR("Out of memory.");
return TSS2_ESYS_RC_MEMORY;
}

/*
* TPM2.0 Architecture 19.6.5 Note 2
*
* Remove tailing zeroes from the auth value
*/
while ((bindNode->auth.size > 0) &&
(bindNode->auth.buffer[bindNode->auth.size - 1] == 0x00))
bindNode->auth.size--;

if (bind != ESYS_TR_NONE && bindNode != NULL
&& bindNode->auth.size > 0)
memcpy(&secret[0], &bindNode->auth.buffer[0], bindNode->auth.size);
Expand Down

0 comments on commit f7f97e8

Please sign in to comment.