ClockHash-256
A high-performance, cryptographic hash function designed specifically for blockchain consensus operations in ClockinChain. ClockHash-256 provides 256-bit security with exceptional performance and memory safety guarantees.
Table of Contents
- Features
- Installation
- Usage
- API Documentation
- Performance
- Security
- Algorithm Overview
- Testing
- Contributing
- License
Features
- 🚀 High Performance: ≥1.5 GB/s single-threaded on modern x86_64 CPUs
- 🔒 Cryptographic Security: 256-bit preimage resistance, 128-bit collision resistance
- 🛡️ Memory Safe: Zero unsafe code, guaranteed by Rust's ownership system
- 🔄 Domain Separation: Prevents cross-domain collision attacks
- 📦 no_std Compatible: Works in embedded and constrained environments
- ⚡ SIMD Optimized: Hardware acceleration on x86_64, ARM, and other architectures
- 🔄 Incremental Hashing: Stream large datasets efficiently
- ⏱️ Constant-Time: Timing attack resistant operations
- 🏗️ Zero Dependencies: Pure Rust implementation
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
Feature Flags
default: Includesstdandbenchfeaturesstd: Enables standard library support (default)no_std: Disables standard library for embedded usesimd: Enables SIMD optimizations (default on supported platforms)bench: Includes benchmarking utilities
For no_std environments:
[]
= { = "1.0.0", = false, = ["alloc"] }
Usage
Basic Hashing
use clockhash256;
Domain-Separated Hashing
Prevent cross-domain collisions by using domain tags:
use ;
Incremental Hashing
For large datasets or streaming data:
use ClockHasher;
Domain Tags
ClockHash-256 supports the following domain tags for cryptographic separation:
| Tag | Purpose | Description |
|---|---|---|
CLK_BLOCK |
Block hashing | Consensus block headers |
CLK_TX |
Transaction IDs | Transaction identifiers |
CLK_MERKLE |
Merkle trees | Merkle tree nodes |
CLK_NONCE |
Nonce derivation | Signature nonce generation |
CLK_RNG |
RNG seeding | Deterministic random seeding |
API Documentation
The API is designed to be simple and ergonomic:
clockhash256(data: &[u8]) -> [u8; 32]: One-shot hashingclockhash256_domain(tag: u8, data: &[u8]) -> [u8; 32]: Domain-separated hashingClockHasher: Incremental hasher structtags: Predefined domain tag constants
Performance
ClockHash-256 is optimized for high throughput:
- Target: ≥1.5 GB/s single-threaded on modern x86_64
- SIMD: Hardware acceleration on AVX2/AVX-512, NEON, and other SIMD instruction sets
- Memory: Minimal memory footprint, suitable for constrained environments
- Scalability: Performance scales with CPU core count
Run benchmarks locally:
Security
ClockHash-256 is designed with security as the highest priority:
- 256-bit preimage resistance: Resistant to finding preimages
- 128-bit collision resistance: Resistant to finding collisions
- Domain separation: Prevents cross-domain collision attacks
- Constant-time operations: Immune to timing attacks
- Memory safety: Zero unsafe code, guaranteed by Rust
- Comprehensive testing: Property-based testing, fuzzing, and formal verification
For security-related issues, see our Security Policy.
Algorithm Overview
ClockHash-256 processes messages in 128-byte blocks using a novel construction:
- ClockPermute: 16-round permutation with strong diffusion
- S-box: 256-byte substitution table for nonlinearity
- ClockMix: Message scrambling with avalanche effect
- Output folding: Final compression to 256 bits
See RFC-0002 for the complete cryptographic specification.
Testing
ClockHash-256 has comprehensive test coverage:
# Run all tests
# Run tests without default features
# Run fuzzing (requires nightly Rust)
&&
# Run benchmarks
Test Coverage
- ✅ Unit tests for all public APIs
- ✅ Property-based testing with proptest
- ✅ Fuzzing with cargo-fuzz
- ✅ Cross-platform testing (Linux, macOS, Windows)
- ✅ no_std compatibility testing
- ✅ Security property verification
- ✅ Performance regression testing
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone the repository
# Run tests
# Run benchmarks
# Check code formatting
# Run linting
Security Reviews
All changes undergo security review. See our Security Policy for vulnerability reporting.
Changelog
See CHANGELOG.md for version history and migration guides.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
ClockHash-256 - High-performance cryptography for blockchain consensus ⚡🔒