/php-sha3

PHP extension providing the sha3() hashing function

Primary LanguageCMIT LicenseMIT

PHP SHA-3 (Keccak) Extension

This PHP extension is a wrapper for the reference implementation of the SHA-3 (Keccak) hash function. SHA-3 is intended to replace older general use hash functions such as SHA-2 and MD5. The algorithm was designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.

This extension currently uses the FIPS 202 draft standard. Note that as of May 2015, standardization is still ongoing and the final output values may be different from the current implementation.

Installation

  1. git clone https://github.com/strawbrary/php-sha3
  2. cd php-sha3
  3. phpize
  4. ./configure --enable-sha3
  5. make && make install
  6. Add the following line to your php.ini file
extension=sha3.so

You may need to restart your httpd/FPM to load the extension. You can verify it is loaded by looking for sha3 in your phpinfo.

Usage

string sha3 ( string $str [, int $outputSize = 512, bool $rawOutput = false ] )
  • $str: The string to hash

  • $outputSize: The bit length of the output hash

  • $rawOutput: If set to true, then the hash is returned in raw binary format

  • Return value: A hex string containing the sha3 hash of the input string

Examples

echo sha3('');

a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26

echo sha3('', 256);

a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a

echo sha3('foobar', 384);

0fa8abfbdaf924ad307b74dd2ed183b9a4a398891a2f6bac8fd2db7041b77f068580f9c6c66f699b496c2da1cbcc7ed8