Skip to content

Instantly share code, notes, and snippets.

@rfl890
Created March 13, 2024 19:37
Show Gist options
  • Save rfl890/19dd4462210c2c0071a921d21855a55b to your computer and use it in GitHub Desktop.
Save rfl890/19dd4462210c2c0071a921d21855a55b to your computer and use it in GitHub Desktop.
Timing safe comparison in JavaScript
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