Expand description
Rust hashes library.
This library implements the hash functions needed by Bitcoin. As an ancillary thing, it exposes hexadecimal serialization and deserialization, since these are needed to display hashes.
§Commonly used operations
Hashing a single byte slice or a string:
use bitcoin_hashes::Sha256;
let bytes = [0u8; 5];
let _hash_of_bytes = Sha256::hash(&bytes);
let _hash_of_string = Sha256::hash("some string".as_bytes());
Hashing content from a reader:
use bitcoin_hashes::Sha256;
let mut reader: &[u8] = b"hello"; // In real code, this could be a `File` or `TcpStream`.
let mut engine = Sha256::engine();
std::io::copy(&mut reader, &mut engine).unwrap();
let _hash = Sha256::from_engine(engine);
Hashing content using std::io::Write
on a HashEngine
:
use std::io::Write as _;
use bitcoin_hashes::Sha256;
let part1: &[u8] = b"hello";
let part2: &[u8] = b" ";
let part3: &[u8] = b"world";
let mut engine = Sha256::engine();
engine.write_all(part1).expect("engine writes don't error");
engine.write_all(part2).unwrap();
engine.write_all(part3).unwrap();
let _hash = Sha256::from_engine(engine);
Re-exports§
Modules§
- Useful comparison functions.
- HASH160 (SHA256 then RIPEMD160) implementation.
- HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
- Hash-based Message Authentication Code (HMAC).
- Public macros.
- RIPEMD160 implementation.
- serde_
macros Deprecated Macros for serde trait implementations, and supporting code. - SHA1 implementation.
- SHA256 implementation.
- SHA384 implementation.
- SHA512 implementation.
- SHA256d implementation (double SHA256).
- SHA256t implementation (tagged SHA256).
- SHA512_256 implementation.
- SipHash 2-4 implementation.
Macros§
- Creates a new newtype around a
Hash
type. - sha256t_
hash_ newtype Deprecated Macro used to define a newtype tagged hash. - Macro used to define a tag.
Structs§
- Attempted to create a hash from an invalid length slice.
- HASH-160: Alias for the
hash160::Hash
hash type. Output of the Bitcoin HASH160 hash function. (RIPEMD160(SHA256)) - HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
- A hash computed from a RFC 2104 HMAC. Parameterized by the underlying hash function.
- Pair of underlying hash engines, used for the inner and outer hash of HMAC.
- RIPEMD-160: Alias for the
ripemd160::Hash
hash type. Output of the RIPEMD160 hash function. - SHA-1: Alias for the
sha1::Hash
hash type. Output of the SHA1 hash function. - SHA-256: Alias for the
sha256::Hash
hash type. Output of the SHA256 hash function. - SHA-384: Alias for the
sha384::Hash
hash type. Output of the SHA384 hash function. - SHA-512: Alias for the
sha512::Hash
hash type. Output of the SHA512 hash function. - Double SHA-256: Alias for the
sha256d::Hash
hash type. Output of the SHA256d hash function. - SHA-512-256: Alias for the
sha512_256::Hash
hash type. Output of the SHA512/256 hash function. - SipHash-2-4: Alias for the
siphash24::Hash
hash type. Output of the SipHash24 hash function.
Traits§
- Trait describing hash digests which can be constructed by hashing arbitrary data.
- Trait which applies to hashes of all types.
- A hashing engine which bytes can be serialized into.
- Ensures that a type is an array.
Type Aliases§
- HKDF-HMAC-SHA-256: Type alias for the
Hkdf<Sha256>
type. - HKDF-HMAC-SHA-512: Type alias for the
Hkdf<Sha512>
type. - HMAC-SHA-256: Type alias for the
Hmac<Sha256>
type. - HMAC-SHA-512: Type alias for the
Hmac<Sha512>
type. - Tagged SHA-256: Type alias for the
sha256t::Hash
hash type.