| Crates.io | clock-hash |
| lib.rs | clock-hash |
| version | 1.0.0 |
| created_at | 2026-01-14 05:18:56.521086+00 |
| updated_at | 2026-01-14 05:18:56.521086+00 |
| description | ClockHash-256: Consensus hash function for ClockinChain |
| homepage | |
| repository | https://github.com/Olyntar-Labs/clock-hash.git |
| max_upload_size | |
| id | 2042227 |
| size | 465,393 |
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.
Add this to your Cargo.toml:
[dependencies]
clock-hash = "1.0.0"
default: Includes std and bench featuresstd: Enables standard library support (default)no_std: Disables standard library for embedded usesimd: Enables SIMD optimizations (default on supported platforms)bench: Includes benchmarking utilitiesFor no_std environments:
[dependencies]
clock-hash = { version = "1.0.0", default-features = false, features = ["alloc"] }
use clock_hash::clockhash256;
fn main() {
let data = b"Hello, ClockHash!";
let hash = clockhash256(data);
println!("Hash: {:x}", hash.iter().fold(String::new(), |mut acc, &b| {
acc.push_str(&format!("{:02x}", b));
acc
}));
// Output: 32-byte hash array
}
Prevent cross-domain collisions by using domain tags:
use clock_hash::{clockhash256_domain, tags};
fn hash_blockchain_data() {
let block_data = b"block_header_data";
let tx_data = b"transaction_data";
// Hash block data with domain separation
let block_hash = clockhash256_domain(tags::CLK_BLOCK, block_data);
// Hash transaction data with domain separation
let tx_hash = clockhash256_domain(tags::CLK_TX, tx_data);
// These hashes will be different even if block_data == tx_data
assert_ne!(block_hash, tx_hash);
}
For large datasets or streaming data:
use clock_hash::ClockHasher;
fn hash_large_file() -> Result<(), Box<dyn std::error::Error>> {
let mut hasher = ClockHasher::new();
// Process data in chunks
let chunks = vec![b"chunk1", b"chunk2", b"chunk3"];
for chunk in chunks {
hasher.update(chunk);
}
let final_hash = hasher.finalize();
println!("Final hash: {:x}", final_hash.iter().fold(String::new(), |mut acc, &b| {
acc.push_str(&format!("{:02x}", b));
acc
}));
Ok(())
}
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 |
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 constantsClockHash-256 is optimized for high throughput:
Run benchmarks locally:
cargo bench
ClockHash-256 is designed with security as the highest priority:
For security-related issues, see our Security Policy.
ClockHash-256 processes messages in 128-byte blocks using a novel construction:
See RFC-0002 for the complete cryptographic specification.
ClockHash-256 has comprehensive test coverage:
# Run all tests
cargo test
# Run tests without default features
cargo test --no-default-features --features no_std
# Run fuzzing (requires nightly Rust)
cd fuzz && cargo fuzz run clockhash256_fuzz
# Run benchmarks
cargo bench
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repository
git clone https://github.com/Olyntar-Labs/clock-hash.git
cd clock-hash
# Run tests
cargo test
# Run benchmarks
cargo bench
# Check code formatting
cargo fmt --check
# Run linting
cargo clippy
All changes undergo security review. See our Security Policy for vulnerability reporting.
See CHANGELOG.md for version history and migration guides.
Licensed under either of:
at your option.
ClockHash-256 - High-performance cryptography for blockchain consensus ⚡🔒