Expand description
Rust Bitcoin 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.
§Examples
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).expect("engine writes don't error");
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§
- cmp
- Useful comparison functions.
- hash160
- HASH160 (SHA256 then RIPEMD160) implementation.
- hkdf
- HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
- hmac
- Hash-based Message Authentication Code (HMAC).
- macros
- Public macros.
- ripemd160
- RIPEMD160 implementation.
- sha1
- SHA1 implementation.
- sha3_
256 - SHA3-256 from the family of hashes based on the Keccak permutation function.
- sha256
- SHA256 implementation.
- sha384
- SHA384 implementation.
- sha512
- SHA512 implementation.
- sha256d
- SHA256d implementation (double SHA256).
- sha256t
- SHA256t implementation (tagged SHA256).
- sha512_
256 - SHA512_256 implementation.
- siphash24
- SipHash 2-4 implementation.
Macros§
- hash_
newtype - Constructs a new newtype around a
Hashtype. - impl_
debug_ only_ for_ newtype - Implements
fmt::Debugusing hex for a new type created withcrate::hash_newtypemacro. - impl_
hex_ for_ newtype - Implements string functions using hex for a new type created with
crate::hash_newtypemacro. - impl_
serde_ for_ newtype - Implements
SerializeandDeserializefor a new type created withcrate::hash_newtypemacro. - sha256t_
tag - Macro used to define a tag.
Structs§
- Hash160
- HASH-160: Alias for the
hash160::Hashhash type. Output of the Bitcoin HASH160 hash function. (RIPEMD160(SHA256)) - Hkdf
- HMAC-based Extract-and-Expand Key Derivation Function (HKDF).
- Hmac
- A hash computed from a RFC 2104 HMAC. Parameterized by the underlying hash function.
- Hmac
Engine - Pair of underlying hash engines, used for the inner and outer hash of HMAC.
- Ripemd160
- RIPEMD-160: Alias for the
ripemd160::Hashhash type. Output of the RIPEMD160 hash function. - Sha1
- SHA-1: Alias for the
sha1::Hashhash type. Output of the SHA1 hash function. - Sha256
- SHA-256: Alias for the
sha256::Hashhash type. Output of the SHA256 hash function. - Sha384
- SHA-384: Alias for the
sha384::Hashhash type. Output of the SHA384 hash function. - Sha512
- SHA-512: Alias for the
sha512::Hashhash type. Output of the SHA512 hash function. - Sha256d
- Double SHA-256: Alias for the
sha256d::Hashhash type. Output of the SHA256d hash function. - Sha512_
256 - SHA-512-256: Alias for the
sha512_256::Hashhash type. Output of the SHA512/256 hash function. - Siphash24
- SipHash-2-4: Alias for the
siphash24::Hashhash type. Output of the SipHash24 hash function.
Traits§
- Hash
- Trait which applies to hashes of all types.
- Hash
Engine - A hashing engine which bytes can be serialized into.
- IsByte
Array - Ensures that a type is an array.
Functions§
- debug_
hex - Writes
bytesas ahexstring to the formatter.
Type Aliases§
- From
Slice Error Deprecation planned - Attempted to create a hash from an invalid length slice.
- Hkdf
Sha256 - HKDF-HMAC-SHA-256: Type alias for the
Hkdf<Sha256>type. - Hkdf
Sha512 - HKDF-HMAC-SHA-512: Type alias for the
Hkdf<Sha512>type. - Hmac
Sha256 - HMAC-SHA-256: Type alias for the
Hmac<Sha256>type. - Hmac
Sha512 - HMAC-SHA-512: Type alias for the
Hmac<Sha512>type. - Sha256t
- Tagged SHA-256: Type alias for the
sha256t::Hashhash type.