Download the PHP package tourze/blake3-php without Composer
On this page you can find all versions of the php package tourze/blake3-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tourze/blake3-php
More information about tourze/blake3-php
Files in tourze/blake3-php
Package blake3-php
Short Description A PHP implementation of the BLAKE3 cryptographic hash function
License MIT
Informations about the package blake3-php
BLAKE3 PHP Implementation
中文
A pure PHP implementation of the BLAKE3 cryptographic hash function, providing high-security hashing capabilities with support for standard hashing, keyed hashing, and key derivation.
Table of Contents
- Features
- Installation
- Quick Start
- Configuration
- Advanced Usage
- Performance Considerations
- API Reference
- Security
- Testing
- Directory Structure
- Contributing
- References
- License
Features
- Pure PHP Implementation - Following the official BLAKE3 specification
- Multiple Modes - Standard hashing, keyed hashing, and key derivation
- Streaming API - Process large files with low memory usage
- Variable Output Length - Support for custom output sizes
- Low Memory Mode - Optimized memory usage for constrained environments
- PSR-4 & PSR-12 Compliant - Following PHP community standards
- Comprehensive Test Suite - Thoroughly tested against official test vectors
Installation
Install via Composer:
Requirements
- PHP 8.1 or higher
- Composer for dependency management
Quick Start
Basic Hashing
Keyed Hashing (MAC)
Key Derivation
Hashing Files with Streaming
Variable Output Length
Configuration
The library works out of the box without additional configuration. However, you can optimize performance for specific use cases:
Memory Usage
For large file processing, enable low memory mode:
Buffer Size Management
The library automatically optimizes buffer sizes based on data characteristics. For manual control:
Performance Considerations
This is a pure PHP implementation prioritizing compatibility and ease of deployment over raw performance. Based on our benchmarks:
- Speed: Significantly slower than PHP's built-in hash functions (SHA256, MD5)
- Memory: Efficient memory usage, especially in low memory mode
- Use Cases: Best suited for applications requiring BLAKE3's specific features rather than maximum throughput
For performance-critical applications, consider:
- Using PHP's built-in hash functions if BLAKE3 is not specifically required
- Looking for a PHP extension with native BLAKE3 implementation
- Caching hash results when processing the same data multiple times
See benchmark results for detailed performance data.
API Reference
Blake3::newInstance(bool $lowMemoryMode = false)
Creates a standard BLAKE3 hasher instance.
Blake3::newKeyedInstance(string $key)
Creates a keyed BLAKE3 hasher for MAC operations. The key must be exactly 32 bytes.
Blake3::newKeyDerivationInstance(string $context)
Creates a BLAKE3 hasher for key derivation with the given context string.
$hasher->update(string $data): self
Updates the hash state with new data. Can be called multiple times.
$hasher->finalize(int $length = 32): string
Finalizes the hash and returns the output of the specified length in bytes.
$hasher->reset(): self
Resets the hasher to its initial state, allowing reuse of the same instance.
Advanced Usage
Incremental Hashing
Process data in multiple stages:
Key Stretching
Use for password-based key derivation:
Batch Processing
Process multiple inputs efficiently:
Security
Key Management
- Use secure random keys: Always use
random_bytes()for key generation - Key size: MAC keys must be exactly 32 bytes
- Key storage: Store keys securely, never hardcode in source code
- Key rotation: Implement regular key rotation for production systems
Best Practices
- Constant-time operations: The implementation uses constant-time comparisons where possible
- Memory clearing: Sensitive data is cleared from memory when possible
- Side-channel resistance: Implementation minimizes timing-based side channels
Security Considerations
- This is a pure PHP implementation - consider timing attacks in highly sensitive environments
- For maximum security, use in conjunction with secure key management systems
- Validate input sizes to prevent resource exhaustion attacks
Testing
Run the test suite:
Directory Structure
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to:
- Update tests as appropriate
- Follow PSR-12 coding standards
- Add documentation for new features
References
License
The MIT License (MIT). Please see License File for more information.