Created
July 4, 2019 04:31
-
-
Save kgriffs/e04b4a6a9f94c7556fb059da03f2b116 to your computer and use it in GitHub Desktop.
Compare Entire Strings in a Time-Stable Way to Mitigate Timing Attacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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