uhash_core/lib.rs
1//! # UniversalHash Core Algorithm
2//!
3//! A democratic proof-of-work algorithm designed for fair mining where
4//! smartphones can meaningfully compete with servers.
5//!
6//! ## Features
7//!
8//! - **Democratic Mining**: Phone-to-desktop ratio of 1:3-5
9//! - **ASIC Resistance**: Multi-primitive design (AES + SHA-256 + BLAKE3)
10//! - **Memory-Hard**: 2MB scratchpad prevents GPU parallelism
11//!
12//! ## Algorithm Parameters (v4)
13//!
14//! - 4 parallel computation chains
15//! - 512KB scratchpad per chain (2MB total)
16//! - 12,288 rounds per chain
17//! - Triple primitive rotation: AES, SHA-256, BLAKE3
18//!
19//! ## Example
20//!
21//! ```rust
22//! use uhash_core::{UniversalHash, hash, meets_difficulty};
23//!
24//! // Single-shot hashing
25//! let result = hash(b"input data");
26//!
27//! // Check difficulty (leading zero bits)
28//! if meets_difficulty(&result, 16) {
29//! println!("Found hash with 16+ leading zero bits!");
30//! }
31//!
32//! // Reusable hasher (avoids re-allocation)
33//! let mut hasher = UniversalHash::new();
34//! let hash1 = hasher.hash(b"first");
35//! let hash2 = hasher.hash(b"second");
36//! ```
37//!
38//! ## no_std Support
39//!
40//! This crate supports `no_std` environments with the `alloc` crate:
41//!
42//! ```toml
43//! [dependencies]
44//! uhash-core = { version = "0.1", default-features = false }
45//! ```
46
47#![cfg_attr(not(feature = "std"), no_std)]
48
49#[cfg(not(feature = "std"))]
50extern crate alloc;
51
52#[cfg(not(feature = "std"))]
53use alloc::vec;
54#[cfg(not(feature = "std"))]
55use alloc::vec::Vec;
56
57mod params;
58mod primitives;
59mod uhash;
60
61#[cfg(feature = "std")]
62mod ffi;
63
64pub use params::*;
65pub use uhash::{hash, meets_difficulty, UniversalHash};
66
67#[cfg(test)]
68mod tests;