Skip to content

Instantly share code, notes, and snippets.

@xoebus
Created January 20, 2011 21:58
Show Gist options
  • Save xoebus/788771 to your computer and use it in GitHub Desktop.
Save xoebus/788771 to your computer and use it in GitHub Desktop.
Cryptographic Array Comparisons
// VERY BAD
for (i = 0; i < MAC_LEN; i++)
{
if (MAC_computed[i] != MAC_received[i])
{
return MAC_IS_BAD;
}
}
return MAC_IS_GOOD;
// GOOD
for (x = i = 0; i < MAC_LEN; i++)
{
x |= MAC_computed[i] − MAC_received[i];
}
return (x ? MAC_IS_BAD : MAC_IS_GOOD);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment