Skip to content

Commit 40e11cb

Browse files
committed
Made HMAC verification constant time array checks
1 parent 5a32f50 commit 40e11cb

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

MLAPI/NetworkingManagerComponents/Core/MessageManager.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ internal static BitStream UnwrapMessage(BitStream inputStream, uint clientId, ou
8989
{
9090
byte[] computedHmac = hmac.ComputeHash(inputStream.GetBuffer(), 0, (int)inputStream.Length);
9191

92-
for (int i = 0; i < computedHmac.Length; i++)
92+
93+
if (!CryptographyHelper.ConstTimeArrayEqual(computedHmac, HMAC_BUFFER))
9394
{
94-
if (computedHmac[i] != HMAC_BUFFER[i])
95-
{
96-
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Received HMAC at position [" + i + "] did not match the computed HMAC");
97-
messageType = MLAPIConstants.INVALID;
98-
return null;
99-
}
95+
if (LogHelper.CurrentLogLevel <= LogLevel.Error) LogHelper.LogError("Received HMAC did not match the computed HMAC");
96+
messageType = MLAPIConstants.INVALID;
97+
return null;
10098
}
10199
}
102100
}

0 commit comments

Comments
 (0)