Prüfsumme und wiederholbarer Zufall
FNV-1a für Zustandsprüfsummen und SplitMix64 als einzige Zufallsquelle des Kerns. Beide sind gegen veröffentlichte Referenzwerte geprüft. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
//! FNV-1a hashing for state checksums.
|
||||
//!
|
||||
//! The hash only has to reveal accidental divergence between peers. It is
|
||||
//! not meant to resist tampering.
|
||||
|
||||
const FNV_OFFSET_BASIS: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
|
||||
|
||||
/// Returns the 64-bit FNV-1a hash of `bytes`.
|
||||
pub fn fnv1a64(bytes: &[u8]) -> u64 {
|
||||
let mut hash = FNV_OFFSET_BASIS;
|
||||
for &byte in bytes {
|
||||
hash ^= u64::from(byte);
|
||||
hash = hash.wrapping_mul(FNV_PRIME);
|
||||
}
|
||||
hash
|
||||
}
|
||||
Reference in New Issue
Block a user