hanfei_fa/lib.rs
1//! # hanfei-fa 法
2//!
3//! ML model weight integrity verification via hierarchical Merkle trees.
4//!
5//! > 法不阿贵,绳不挠曲。
6//! > *The law does not favor the noble; the plumb line does not bend for the crooked.*
7//!
8//! ## Features
9//!
10//! - **O(1) root hash** — single comparison verifies the entire model
11//! - **O(k log C) diff** — layer-aware diff without scanning unchanged weights
12//! - **4-level hierarchy** — Model > Layer > Parameter > Chunk
13//! - **5 hash algorithms** — SHA-256, SHA-512, SHA3-256, BLAKE2b, BLAKE3
14//! - **Merkle proofs** — cryptographic proof that a chunk belongs to the tree
15//! - **Streaming** — O(chunk_size) memory for multi-GB files
16//!
17//! ## Quick Start
18//!
19//! ```rust
20//! use hanfei_fa::{MerkleTree, HashAlgorithm, compute_hash, chunk_bytes};
21//!
22//! let data = b"model weight bytes here...";
23//! let chunks = chunk_bytes(data, 16384);
24//! let hashes: Vec<String> = chunks.iter().map(|c| compute_hash(c, HashAlgorithm::Sha256)).collect();
25//! let tree = MerkleTree::new(hashes, 16384);
26//! println!("root: {}", tree.root_hash());
27//! ```
28//!
29//! Part of the [HanFei (韩非) verifiable AI series](https://github.com/GeoffreyWang1117/hanfei-shu).
30
31pub mod hasher;
32pub mod chunking;
33pub mod merkle_tree;
34pub mod comparison;
35pub mod strategies;
36
37pub use hasher::{HashAlgorithm, compute_hash, hash_pair, verify_hash};
38pub use chunking::{chunk_bytes, chunk_bytes_iter, estimate_chunk_count, DEFAULT_CHUNK_SIZE};
39pub use merkle_tree::{
40 MerkleNode, MerkleProof, MerkleTree,
41 LayerMerkleTree, ModelMerkleTree,
42 build_model_merkle_tree,
43};
44pub use comparison::{ComparisonResult, compare_model_trees, estimate_sync_savings};
45pub use strategies::{ChunkStrategy, FixedChunkStrategy, AdaptiveChunkStrategy};