Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Created July 4, 2019 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgriffs/e04b4a6a9f94c7556fb059da03f2b116 to your computer and use it in GitHub Desktop.
Save kgriffs/e04b4a6a9f94c7556fb059da03f2b116 to your computer and use it in GitHub Desktop.
Compare Entire Strings in a Time-Stable Way to Mitigate Timing Attacks
def str_compare_timesafe(a, b):
all_chars_match = 0
for c1, c2 in zip(a, b):
all_chars_match |= ord(c1) ^ ord(c2)
return all_chars_match == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment