Download the PHP package accredifysg/php-keccak-64bit without Composer
On this page you can find all versions of the php package accredifysg/php-keccak-64bit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download accredifysg/php-keccak-64bit
More information about accredifysg/php-keccak-64bit
Files in accredifysg/php-keccak-64bit
Package php-keccak-64bit
Short Description Fast, dependency-free Keccak (224/256/384/512) and SHAKE (128/256) for 64-bit PHP — a drop-in, ~5x faster alternative to kornrunner/keccak.
License MIT
Informations about the package php-keccak-64bit
PHP-Keccak-64bit
Fast, dependency-free Keccak (224/256/384/512) and SHAKE (128/256) for 64-bit PHP.
It is a drop-in replacement for kornrunner/keccak
that is roughly 5× faster on large inputs. Output is byte-for-byte identical to
kornrunner for every fixed-length hash and for SHAKE up to the rate; for longer SHAKE output
this package follows the NIST standard, where kornrunner does not (see
Compatibility).
Note: this is the original (Ethereum-style,
0x01-suffixed) Keccak, the same variant implemented bykornrunner/keccak. It is not the NIST-finalised SHA-3 (which uses the0x06suffix). The SHAKE functions, however, are the NIST0x1F-suffixed XOFs.
Why
When the native Keccak256 C extension is not
installed, a pure-PHP Keccak dominates hashing time. Profiling a ~0.6 MB
document, a single Keccak-256 call accounted for ~99% of processing time. This package keeps the
1600-bit state as 25 native 64-bit integers, unpacks the message once, and unrolls the
permutation — for an end-to-end speed-up of ~5.6× over kornrunner/keccak:
| Workload (PHP 8.5, no C extension, Xdebug off) | kornrunner/keccak | this package | speed-up |
|---|---|---|---|
| Keccak-256 of 0.6 MB | ~525 ms | ~92 ms | ~5.7× |
| End-to-end wrap of a 0.59 MB document | ~540 ms | ~97 ms | ~5.6× |
The whole message is unpacked into memory up front (that's where most of the speed-up comes from), so peak memory is a few times the input size. This is ideal for documents and other bounded payloads; for streaming or very large (hundreds-of-MB) inputs, a constant-memory hasher is a better fit.
Requirements
- 64-bit PHP (
PHP_INT_SIZE === 8). The lane arithmetic relies on native 64-bit integers; on a 32-bit build the entry points throw aRuntimeExceptionrather than return a wrong digest. If you need 32-bit support, usekornrunner/keccakdirectly. - PHP 8.2+. No PHP extensions and no runtime dependencies.
Installation
Usage
The API mirrors kornrunner/keccak, so it is a drop-in replacement.
API
-
$bits— one of224,256,384,512. $security—128(SHAKE128) or256(SHAKE256).$length— output length in bits; must be a non-negative multiple of 8.
Both methods return a lowercase hex string, or raw bytes when $binaryOutput is true.
Compatibility with kornrunner/keccak
The API and output match kornrunner/keccak exactly for:
- all fixed-length hashes (
hashat 224/256/384/512), and - SHAKE output up to the rate — 168 bytes for SHAKE128, 136 bytes for SHAKE256.
For SHAKE output longer than the rate the two libraries diverge. kornrunner squeezes a
single 200-byte state once and never re-permutes, so it cannot return more than 200 bytes and
is non-conformant beyond the rate. This package implements the full NIST sponge squeeze, so its
long SHAKE output matches the SHA-3 standard (verified against OpenSSL / Python hashlib).
If you depend on kornrunner's exact byte stream past the rate, that output is not standard and
is not reproduced here.
Output length: shake() requires $length to be a multiple of 8 bits and throws
otherwise; kornrunner instead silently floors a non-multiple down to whole bytes. For
byte-aligned lengths (the usual case) the two behave identically.
Correctness
Digests are verified to be byte-for-byte identical to kornrunner/keccak by the test suite:
NIST/Ethereum known-answer vectors for every variant, cross-checks across rate-block
boundaries for all four hash sizes and both SHAKE variants, the multi-block squeeze path,
and a property test over random binary input.
License
MIT. See LICENSE.