From f7f97e8323bb8d6e6b7abc63900d19af4b2c8ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Th=C3=B6ni?= Date: Fri, 10 May 2024 23:16:37 +0200 Subject: [PATCH] ESYS: StartAuthSession bind auth trailing zeroes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/tss2-esys/api/Esys_StartAuthSession.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tss2-esys/api/Esys_StartAuthSession.c b/src/tss2-esys/api/Esys_StartAuthSession.c index 076760d0b..aa8c03f8f 100644 --- a/src/tss2-esys/api/Esys_StartAuthSession.c +++ b/src/tss2-esys/api/Esys_StartAuthSession.c @@ -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);