Download the PHP package regexp1987/blake3 without Composer
On this page you can find all versions of the php package regexp1987/blake3. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download regexp1987/blake3
More information about regexp1987/blake3
Files in regexp1987/blake3
Package blake3
Short Description Native PHP extension for the BLAKE3 cryptographic hash function — 4x faster than SHA-256 with SIMD support (AVX-512, AVX2, SSE4.1, SSE2, NEON)
License MIT
Informations about the package blake3
PHP BLAKE3 Extension
Native PHP extension for the BLAKE3 cryptographic hash function, based on the official C reference implementation from the BLAKE3 team.
Why BLAKE3?
| Feature | BLAKE3 | SHA-256 | MD5 |
|---|---|---|---|
| Speed (x86_64) | ~1.3 GB/s | ~0.3 GB/s | ~0.5 GB/s |
| Output length | Arbitrary (XOF) | Fixed 32 bytes | Fixed 16 bytes |
| Security | ✅ 256-bit | ✅ 256-bit | ❌ Broken |
| Keyed mode (MAC) | ✅ | ❌ (needs HMAC) | ❌ |
| Incremental | ✅ | ✅ | ✅ |
BLAKE3 is 4× faster than SHA-256 on modern CPUs thanks to SIMD parallelism (AVX-512, AVX2, SSE4.1, SSE2, NEON). It's ideal for:
- Content addressing — file deduplication, cache keys
- Prompt integrity — verify AI prompts haven't drifted
- Message authentication — keyed hash mode replaces HMAC
- Extendable output — generate arbitrary-length digests
Requirements
| Component | Minimum | Recommended |
|---|---|---|
| PHP | 8.1 | 8.4+ |
| GCC | 9+ | 12+ |
| Clang | 10+ | 15+ |
| OS | Linux / macOS / BSD | Linux x86_64 |
| Windows | Visual Studio 2019+ | Visual Studio 2022+ |
Installation
Via PIE (Recommended — PHP Installation & Extensions)
PIE is the modern PHP extension installer (replaces deprecated PECL). Requires PHP 8.1+.
PIE automatically:
- Downloads the source code
- Runs
phpize,./configure, andmake - Installs the compiled extension to the correct PHP extension directory
- Enables the extension in
php.ini
From source (Linux / macOS / BSD)
If you prefer manual installation or don't have PIE:
Windows (Visual Studio)
Copy Release\php_blake3.dll to your PHP ext directory and add
extension=php_blake3.dll to php.ini.
Docker
API Reference
Functions
blake3(string $data, int $output_length = 32, ?string $key = null, bool $raw_output = false): string
One-shot BLAKE3 hash. Returns lowercase hex by default.
| Parameters: | Parameter | Type | Default | Description |
|---|---|---|---|---|
$data |
string | required | Input data to hash | |
$output_length |
int | 32 | Output length in bytes (1–2^64−1, limited by available memory) | |
$key |
string|null | null | 32-byte key for keyed-hash (MAC) mode | |
$raw_output |
bool | false | If true, return raw bytes instead of hex |
Returns: string — lowercase hex digest, or raw bytes if $raw_output = true
Throws: ValueError if $key is not exactly 32 bytes, or $output_length < 1
blake3_file(string $filename, int $output_length = 32, ?string $key = null, bool $raw_output = false): string
Hash a file using streaming (8 KB chunks). Memory-efficient for large files.
| Parameters: | Parameter | Type | Default | Description |
|---|---|---|---|---|
$filename |
string | required | Path to the file | |
$output_length |
int | 32 | Output length in bytes | |
$key |
string|null | null | 32-byte key for keyed-hash (MAC) mode | |
$raw_output |
bool | false | If true, return raw bytes |
Returns: string — hex digest or raw bytes; false on read error
Throws: ValueError if $filename is empty, $output_length < 1, or $key is not exactly 32 bytes
blake3_hash(string $data, int $output_length = 32): string
Convenience alias for blake3($data, $output_length, null, false).
Returns hex string. Kept for backward compatibility.
blake3_hash_raw(string $data, int $output_length = 32): string
Convenience alias for blake3($data, $output_length, null, true).
Returns raw binary string.
blake3_keyed_hash(string $data, string $key, int $output_length = 32): string
Convenience alias for blake3($data, $output_length, $key, false).
Keyed-hash (MAC) mode. $key must be exactly 32 bytes.
blake3_init(?string $key = null): Blake3Context
Initialise an incremental hashing context.
With key:
| Parameters: | Parameter | Type | Default | Description |
|---|---|---|---|---|
$key |
string|null | null | 32-byte key for keyed-hash mode |
Returns: Blake3Context — opaque handle for incremental hashing
Throws: ValueError if $key is provided but not exactly 32 bytes
blake3_update(Blake3Context $ctx, string $data): void
Append data to an incremental hash context.
Throws: ValueError if $ctx is not a valid Blake3Context
blake3_final(Blake3Context $ctx, bool $raw_output = false): string
Finalise the incremental hash and return the digest.
| Parameters: | Parameter | Type | Default | Description |
|---|---|---|---|---|
$ctx |
Blake3Context | required | The hashing context (consumed — cannot reuse) | |
$raw_output |
bool | false | If true, return raw bytes |
Returns: string — hex digest or raw bytes
Note: After calling blake3_final(), the context is consumed. Use blake3_reset() to
reinitialise it, or create a new context with blake3_init() for subsequent hashes.
blake3_xof(string $data, int $output_length, ?string $key = null, bool $raw_output = false): string
Extendable Output Function (XOF). Equivalent to blake3() with an explicit, required output length.
| Parameters: | Parameter | Type | Default | Description |
|---|---|---|---|---|
$data |
string | required | Input data | |
$output_length |
int | required | Output length in bytes (must be ≥ 1) | |
$key |
string|null | null | 32-byte key for keyed-hash (MAC) mode | |
$raw_output |
bool | false | If true, return raw bytes |
blake3_derive_key(string $context, string $key_material, int $output_length = 32, bool $raw_output = false): string
Key Derivation Function (KDF) mode. Derives a key from a context string and key material. The context string must be unique to the application and protocol version — it is not secret.
| Parameters: | Parameter | Type | Default | Description |
|---|---|---|---|---|
$context |
string | required | Non-empty application context string (e.g. "my-app v1 purpose") |
|
$key_material |
string | required | Non-empty secret key material | |
$output_length |
int | 32 | Output length in bytes | |
$raw_output |
bool | false | If true, return raw bytes |
Returns: string — hex digest or raw bytes
Throws: ValueError if $context or $key_material is empty, or $output_length < 1
blake3_version(): string
Returns the BLAKE3 library version string.
Class: Blake3Context
Opaque resource handle returned by blake3_init(). Cannot be instantiated directly.
Constants
| Constant | Value | Description |
|---|---|---|
BLAKE3_OUT_LEN |
32 | Default output length (bytes) |
BLAKE3_KEY_LEN |
32 | Key length for MAC mode (bytes) |
BLAKE3_BLOCK_LEN |
64 | Block size (bytes) |
BLAKE3_MAX_DEPTH |
54 | Maximum tree depth |
BLAKE3_MAX_OUTPUT |
67108864 | Maximum output length enforced by this extension (64 MB) |
Benchmark
Compare BLAKE3 with PHP built-in hash functions:
Typical results (Intel Core i7, Linux x86_64):
Test Vectors
Known Limitations
- Maximum output length: limited by available memory (Zend string allocation). Practical limit is ~2GB on 32-bit systems, no practical limit on 64-bit.
- Thread safety: the extension is ZTS-compatible but incremental contexts
(
Blake3Context) are not thread-safe — don't share across threads. - Windows SIMD: assembly files are included but require MASM/NASM. Falls back to portable C if assembly tooling is unavailable.
License
MIT License — see LICENSE.
The bundled BLAKE3 C reference implementation is dual-licensed under CC0 and the Apache License 2.0.
Credits
- BLAKE3 designed by Jean-Philippe Aumasson and Samuel Neves
- C reference implementation by the BLAKE3 team
- PHP extension by Andrea Pievaioli