GOST R 34.11-2012 (Stribog) Hash Function implementation for PHP.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis
tests
.gitignore
.travis.yml
LICENSE
LICENSE.gost
README.md
benchmark.php
config.m4
gost3411-2012-mmx.c
gost3411-2012-mmx.h
gost3411-2012-ref.c
gost3411-2012-ref.h
gost3411-2012-sse2.c
gost3411-2012-sse2.h
gost3411-2012-sse41.c
gost3411-2012-sse41.h
gost3411-2012.c
gost3411-2012.h
php_stribog.h
stribog.c
tables.c
tables.h

README.md

php-stribog Build Status

GOST R 34.11-2012 (Stribog) Hash Function implementation for PHP.

Tested with PHP 5.2, 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, nightly (7.3 as of writing)

Introduction

This extension provides implementation of GOST R 34.11-2012 256 and 512 bit hash functions to be used with PHP hash extension.

The extension does not introduce any new functions; instead, it registers three hashes:

  • stribog-256 (GOST R 34.11-2012 256 bit hash function);
  • stribog-512 (GOST R 34.11-2012 512 bit hash function);
  • stribog (alias of stribog-512).

These hashes can be used with any function from PHP hash extension.

The implementation of the hash function (gost3411-2012-*.c) is based on the implementation by Alexey Degtyarev, see LICENSE.gost. The changes made to Alexey's code:

  • the MMX implementation was almost completely rewritten in order not to use SSE instructions;
  • optimization of 64-bit version of extract() — gained extra 0.7 MB/s;
  • the generic implementation was optimized by removing unnecessary memcpy calls;
  • inline functions instead of macros;
  • the implementation (generic/MMX/SSE) is chosen at runtime depending on CPU capabilities (GCC 4.6 or newer is required for that);
  • fixed add512() implementation.

Installing/Configuring

phpize
./configure
make
sudo make install

There are no configuration directives defined in php.ini.

Usage Example

Hash calculation:

$data = '012345678901234567890123456789012345678901234567890123456789012';
echo hash('stribog256', $data), PHP_EOL;
echo hash('stribog512', $data), PHP_EOL;
echo hash('stribog', $data), PHP_EOL;

HMAC calculation:

$data = 'Very secret data';
$key  = 'password';
echo hash_hmac('stribog', $data, $key);