RustCrypto: Digest Algorithm Traits
Traits which describe functionality of cryptographic hash functions, a.k.a. digest algorithms.
See RustCrypto/hashes for implementations which use this trait.
Minimum Supported Rust Version
Rust 1.41 or higher.
Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.
- All on-by-default features of this library are covered by SemVer
- MSRV is considered exempt from SemVer as noted above
Let us demonstrate how to use crates in this repository using BLAKE2b as an example.
blake2 crate to your
 = "0.8"
blake2 and other crates re-export
digest crate and
Digest trait for
convenience, so you don't have to add
digest crate as an explicit dependency.
Now you can write the following code:
use ; let mut hasher = new; let data = b"Hello world!"; hasher.input; // `input` can be called repeatedly and is generic over `AsRef<[u8]>` hasher.input; // Note that calling `finalize()` consumes hasher let hash = hasher.finalize; println!;
In this example
hash has type
GenericArray<u8, U64>, which is a generic
Alternatively you can use chained approach, which is equivalent to the previous example:
let hash = new .chain .chain .finalize; println!;
If the whole message is available you also can use convinience
let hash = digest; println!;
If you want to hash data from
Read trait (e.g. from file) you can rely on
Write trait (requires enabled-by-default
use ; use ; let mut file = open?; let mut hasher = new; let n = copy?; let hash = hasher.finalize; println!; println!; println!;
You can write generic code over
Digest (or other traits from
trait which will work over different hash functions:
use Digest; // Toy example, do not use it in practice! // Instead use crates from: https://github.com/RustCrypto/password-hashing use Blake2b; use Sha256; ; ;
If you want to use hash functions with trait objects, use
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.