xmtp_cryptography/hash.rs
1pub use sha2::{Digest as Sha2Digest, Sha256 as Sha256Digest};
2
3/// Sha256 is used in places where cryptographic security is not required, as sha256 has a
4/// significant speed improvement over Keccak.
5pub fn sha256_bytes(bytes: &[u8]) -> Vec<u8> {
6 sha256_array(bytes).to_vec()
7}
8
9/// Compute the SHA-256 hash of `bytes` and return it as a fixed `[u8; 32]`,
10/// avoiding the heap allocation done by [`sha256_bytes`].
11#[inline]
12pub fn sha256_array(bytes: &[u8]) -> [u8; 32] {
13 Sha256Digest::digest(bytes).into()
14}