dev-master
9999999-dev https://github.com/znk3r/hash_equalsA compatibility library for hash_equals() to avoid timing attacks
MIT
The Development Requires
by Miguel Angel Liebana
hashing timing attacks
Wallogit.com
2017 © Pedro PelĂĄez
A compatibility library for hash_equals() to avoid timing attacks
PHP implementation of hash_equals() for versions previous to 5.6, (*1)
This function has been created to compare hash strings, in a way that prevents timing attacks. Some libraries have similar implementations, but as part of bigger packages., (*2)
Via composer.json, (*3)
"require": {
"znk3r/hash_equals": "dev-master"
}
The function should be available automatically after being added to composer (remember to run "composer update"), (*4)
<?php
if (!hash_equals($storedHash, $userGeneratedHash)) {
echo "The strings are different";
}
As described by PĂĄdraic Brady in [an article from 2010] (http://blog.astrumfutura.com/2010/10/nanosecond-scale-remote-timing-attacks-on-php-applications-time-to-take-them-seriously/):, (*5)
A Timing Attack is a form of Side Channel Attack which allows an attacker to discover some secret input to an operation by measuring the operationâs execution time often based on a set of attacker derived inputs., (*6)
At first look, this seems like an impossible task but in reality it doesnât take much thinking to realise how many web applications likely treat existing and non-existing usernames differently during a login attempt. Differing treatment may lead to clues about the validity of any username in a few ways, (*7)
These attacks are complex to implement, but have already been used a couple of times., (*8)
On PHP-5.6, hash_equals() was added to help with this type of attack, but the function is not available for previous versions, leaving them vulnerable., (*9)
This function should be used to mitigate timing attacks, specially when comparing hashes, but not as general alternative for all string comparisons., (*10)
A compatibility library for hash_equals() to avoid timing attacks
MIT
hashing timing attacks