2017 © Pedro PelĂĄez
 

library hash-equals

A compatibility library for hash_equals() to avoid timing attacks

image

znk3r/hash-equals

A compatibility library for hash_equals() to avoid timing attacks

  • Saturday, March 7, 2015
  • by znk3r
  • Repository
  • 1 Watchers
  • 1 Stars
  • 45 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

hash_equals

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)

Installation

Via composer.json, (*3)

"require": {
    "znk3r/hash_equals": "dev-master"
}

Basic Usage

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"; 
}

Timing attacks

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)

The Versions

07/03 2015

dev-master

9999999-dev https://github.com/znk3r/hash_equals

A compatibility library for hash_equals() to avoid timing attacks

  Sources   Download

MIT

The Development Requires

by Miguel Angel Liebana

hashing timing attacks