Crate clock_hash

Crate clock_hash 

Source
Expand description

§ClockHash-256: Consensus Hash Function for ClockinChain

ClockHash-256 is a deterministic, fixed-output cryptographic hash function designed for ClockinChain consensus operations. It provides 256-bit security with domain separation for multi-purpose blockchain use cases.

§Features

  • 256-bit security: Preimage and collision resistance
  • Domain separation: Different hash outputs for different use cases
  • no_std compatibility: Works in embedded environments
  • Incremental hashing: Stream data processing
  • Constant-time operations: Side-channel resistant
  • Performance optimized: ~1.5 GB/s target on modern hardware

§Quick Start

use clock_hash::clockhash256;

let data = b"Hello, ClockinChain!";
let hash = clockhash256(data);
assert_eq!(hash.len(), 32);

§Domain Separation

ClockHash-256 uses domain separation to ensure different use cases produce different hash outputs, preventing cross-domain collision attacks.

use clock_hash::{clockhash256_domain, clockhash256_with_domain, DomainTag, tags};

let data = b"block header data";

// Using domain bytes
let block_hash = clockhash256_domain(tags::CLK_BLOCK, data);

// Using typed domain enum
let tx_hash = clockhash256_with_domain(DomainTag::Transaction, data);

assert_ne!(block_hash, tx_hash); // Different domains = different hashes

§Incremental Hashing

For large or streaming data, use incremental hashing:

use clock_hash::ClockHasher;

let mut hasher = ClockHasher::new();
hasher.update(b"part 1");
hasher.update(b"part 2");
hasher.update(b"part 3");
let hash = hasher.finalize();

§Domain Use Cases

§Block Headers

let block_header = b"previous_hash || merkle_root || timestamp || ...";
let block_hash = clockhash256_with_domain(DomainTag::Block, block_header);

§Transaction IDs

let tx_data = b"inputs || outputs || metadata";
let tx_id = clockhash256_with_domain(DomainTag::Transaction, tx_data);

§Merkle Trees

let left_node = b"left child data";
let right_node = b"right child data";
let left_hash = clockhash256_with_domain(DomainTag::Merkle, left_node);
let right_hash = clockhash256_with_domain(DomainTag::Merkle, right_node);
let parent_data = [left_hash, right_hash].concat();
let parent_hash = clockhash256_with_domain(DomainTag::Merkle, &parent_data);

§Signature Nonces

let secret_data = b"private_key || message || counter";
let nonce = clockhash256_with_domain(DomainTag::Nonce, secret_data);

§Deterministic RNG

let seed_data = b"user_seed || domain_info";
let rng_seed = clockhash256_with_domain(DomainTag::Rng, seed_data);

§Security Properties

  • Preimage resistance: Hard to find input for a given hash
  • Second preimage resistance: Hard to find different input with same hash
  • Collision resistance: Hard to find any two inputs with same hash
  • Avalanche effect: Small input changes affect ~50% of output bits
  • Domain separation: Different domains cannot collide

§Performance

ClockHash-256 is optimized for modern hardware:

  • Throughput: ~1.5 GB/s on x86_64 (target)
  • Memory: Minimal footprint, cache-friendly
  • SIMD: AVX2/AVX-512 acceleration available
  • no_std: Zero heap allocations in core path

Re-exports§

pub use constants::IV;
pub use constants::P0;
pub use constants::P1;
pub use constants::ROTATION_SCHEDULE;
pub use constants::SBOX;
pub use utils::rotl8;
pub use utils::rotl64;
pub use utils::rotr64;

Modules§

constants
Constants for ClockHash-256
cpuid
CPUID interface for safe CPU feature detection
tags
Predefined domain tag constants for ClockinChain use cases
utils
Utility functions for ClockHash-256

Structs§

ClockHasher
Incremental hasher for ClockHash-256

Enums§

DomainTag
Type-safe domain tag enumeration for ClockinChain use cases

Functions§

benchmark_sizes
Benchmark different input sizes and return performance characteristics
clock_mix
Apply ClockMix to a 16-word (128-byte) message block.
clock_permute
Apply ClockPermute to the 8-word state (16 rounds).
clockhash256
Compute the ClockHash-256 hash of the input data.
clockhash256_domain
Compute ClockHash-256 with custom domain separation.
clockhash256_with_domain
Compute ClockHash-256 with a typed domain tag.
estimate_memory_usage
Memory usage estimation for ClockHash-256 operations
measure_throughput
Measure the throughput of ClockHash-256 for a given data size
performance_stats
Get performance statistics
verify_avalanche
Verify avalanche effect for security
verify_collision_resistance
Verify collision resistance properties
verify_domain_separation
Verify domain separation properties
verify_performance
Verify that performance meets minimum requirements