0.0
No commit activity in last 3 years
No release in over 3 years
Constant time equality (also known as time insensitive equality) lets you compare user-provided strings with secrets in a way that does not leak data about those secrets.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Secure equals provides a constant time equality method for ruby strings.

By avoiding any branches that depend on the similarity of the two strings, we make it significantly harder for an attacker to discover properties of the secret by observing the time it takes to run the comparison.

You should use this for checking checksums or shared secrets in your code.

Installation

You can either gem install secure_equals or add gem 'secure_equals' to your Gemfile and then run bundle install

Usage

SecureEquals.equal? checksum, @params[:checksum]

TODO

I was unable to implement a successful timing attack against ruby's string == on my Mac Book Pro; so while the code here looks promising, I've not actually been able to verify that it actually solves the problem.

We should try running the attack on 16- and 32- byte sized chunks instead of the character-by-character mode, as I suspect the problem is memcmp(). Alternatively there might be a way to get higher resolution timings, or to use some stats that I don't know about, to make it work.

BUGS

I'm pretty sure this must already exist somewhere...