Deterministic hash of a `SocketAddr` into a `u64`. Uses SHA-256 truncated to the first 8 bytes. Deterministic across processes and hosts so that sender and receiver agree on the value. Not a MAC — the envelope MAC is the actual integrity primitive; this hash exists only as a binding between the envelope's claimed origin and the packet's observed source address.
(addr: SocketAddr)
| 55 | /// hash exists only as a binding between the envelope's claimed origin |
| 56 | /// and the packet's observed source address. |
| 57 | pub fn addr_hash(addr: SocketAddr) -> u64 { |
| 58 | let mut h = Sha256::new(); |
| 59 | h.update(addr.to_string().as_bytes()); |
| 60 | let digest = h.finalize(); |
| 61 | u64::from_le_bytes(digest[..8].try_into().expect("sha256 is 32 bytes")) |
| 62 | } |
| 63 | |
| 64 | /// Per-transport auth state: MAC key, per-peer outbound counters, and a |
| 65 | /// per-peer inbound replay-detection window. Owned by the |