Skip to content

Instantly share code, notes, and snippets.

@kirel
Created September 30, 2009 22:40
Show Gist options
  • Select an option

  • Save kirel/198529 to your computer and use it in GitHub Desktop.

Select an option

Save kirel/198529 to your computer and use it in GitHub Desktop.
# constant-time comparison algorithm to prevent timing attacks
def secure_compare(a, b)
if a.length == b.length
result = 0
for i in 0..(a.length - 1)
result |= a[i] ^ b[i]
end
result == 0
else
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment