amashukov / keccak-php
Keccak-256 and SHA-3 family permutations in pure PHP.
Requires
- php: >=8.3
- ext-mbstring: *
Requires (Dev)
- amashukov/rector-php-rules: ^0.1.0
- friendsofphp/php-cs-fixer: ^3.50
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- rector/rector: ^2.0
README
Pure-PHP Keccak-256, SHA-3 and SHAKE hashing — the keccak256 primitive behind Ethereum addresses, ABI selectors and EVM signatures.
amashukov/keccak-php is a pure-PHP implementation of the Keccak / SHA-3 family of cryptographic hash functions, including the SHAKE extendable-output functions (XOF). It provides the keccak256 hash primitive used across Ethereum and other modern blockchains for address derivation, ABI function selectors and EIP-191 / EIP-712 message signing. Zero composer dependencies — only ext-mbstring from PHP core.
Features
- Keccak-256 — the exact hash Ethereum uses for
keccak256, address derivation and ABI selectors. - Full SHA-3 family — output sizes
224,256,384,512. - SHAKE128 / SHAKE256 extendable-output functions with arbitrary output length.
- Hex or raw binary output via a single
raw_outputflag. - Pure PHP — no native extension to compile, no FFI; runs anywhere PHP 8.3 runs.
- Zero composer dependencies —
ext-mbstringonly. - PHPStan level 9 clean,
@PER-CSformatted, CI-tested.
Installation
composer require amashukov/keccak-php
Usage
use Amashukov\Keccak\Keccak; // Hex-encoded hash output (default). $digest = Keccak::hash('hello world', 256); // → 47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad // Raw 32-byte binary output. $raw = Keccak::hash('hello world', 256, raw_output: true);
Supported output sizes: 224, 256, 384, 512. SHAKE variants:
$xof = Keccak::shake('hello world', security_level: 128, outlen: 256);
Requirements
- PHP 8.3+
ext-mbstring
No composer dependencies.
Related packages
Part of a modular pure-PHP blockchain toolkit:
| Package | Purpose |
|---|---|
| amashukov/keccak-php | Keccak-256 / SHA-3 / SHAKE hashing |
| amashukov/secp256k1-php | secp256k1 ECDSA sign / verify / recover |
| amashukov/rlp-php | Ethereum RLP encode / decode |
| amashukov/ton-cell-php | TON TLB Cell / Builder / Slice / BOC |
| amashukov/abi-encoder-php | Ethereum ABI encoder |
| amashukov/eip1559-tx-signer-php | EIP-1559 transaction signer |
| amashukov/eth-rpc-client-php | Ethereum JSON-RPC client |
| amashukov/eth-php | EVM umbrella package |
Quality
- PHPStan level 9.
- php-cs-fixer with the
@PER-CSruleset. - GitHub Actions CI on every push.
- Test vectors validated against the published Keccak / SHA-3 reference outputs.
License
MIT License.