znk3r/hash-equals 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

znk3r/hash-equals

Composer 安装命令:

composer require znk3r/hash-equals

包简介

A compatibility library for hash_equals() to avoid timing attacks

README 文档

README

PHP implementation of hash_equals() for versions previous to 5.6

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.

Installation

Via composer.json

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

Basic Usage

The function should be available automatically after being added to composer (remember to run "composer update")

<?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/):

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.

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

These attacks are complex to implement, but have already been used a couple of times.

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.

This function should be used to mitigate timing attacks, specially when comparing hashes, but not as general alternative for all string comparisons.

统计信息

  • 总下载量: 69
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-08