Skip to content

Commit 4792bcc

Browse files
committed
F-7261 - Use a constant-time compare for the bind entity Name test
1 parent e763ccd commit 4792bcc

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/tpm2_param_enc.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,27 @@ int TPM2_ParamEnc_AESCFB(
184184
static TPM2B_AUTH* TPM2_ParamEncBindKey(TPM2_AUTH_SESSION* session)
185185
{
186186
int digestSz = TPM2_GetHashDigestSize(session->authHash);
187-
if (session->bind != NULL && digestSz > 0 &&
188-
session->name.size > 0 &&
189-
session->name.size == session->bindName.size &&
190-
XMEMCMP(session->name.name, session->bindName.name,
191-
session->name.size) == 0 &&
192-
session->auth.size <= (UINT16)digestSz) {
193-
return session->bind;
187+
int sizeMismatch;
188+
int diff;
189+
UINT16 cmpLen;
190+
191+
if (session->bind == NULL || digestSz <= 0 ||
192+
session->name.size == 0 ||
193+
session->auth.size > (UINT16)digestSz) {
194+
return NULL;
194195
}
195-
return NULL;
196+
197+
cmpLen = session->name.size;
198+
if (cmpLen > (UINT16)sizeof(session->bindName.name)) {
199+
cmpLen = (UINT16)sizeof(session->bindName.name);
200+
}
201+
sizeMismatch = (session->name.size != session->bindName.size);
202+
diff = TPM2_ConstantCompare(session->name.name, session->bindName.name,
203+
cmpLen);
204+
if (sizeMismatch | diff) {
205+
return NULL;
206+
}
207+
return session->bind;
196208
}
197209

198210
/* Build combined param-enc key from session key + optional bind authValue. */

0 commit comments

Comments
 (0)