Created
March 13, 2024 19:37
-
-
Save rfl890/19dd4462210c2c0071a921d21855a55b to your computer and use it in GitHub Desktop.
Timing safe comparison in JavaScript
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
function timingSafeEqual(a, b) { | |
if (a.length !== b.length) return false; | |
let result = 0; | |
for (let i = 0; i < a.length; i++) { | |
result |= a[i] ^ b[i]; | |
} | |
return result === 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment