sp_multihash/
lib.rs

1//! Multihash implementation.
2//!
3//! Feature Flags
4//! -------------
5//!
6//! Multihash has lots of [feature flags], by default a table with
7//! cryptographically secure hashers is created.
8//!
9//! Some of the features are about specific hash functions, these are ("default"
10//! marks the hashers that are enabled by default):
11//!
12//!  - `blake2b`: (default) Enable Blake2b hashers
13//!  - `blake2s`: (default) Enable Blake2s hashers
14//!  - `identity`: Enable the Identity hashers (using it is discouraged as it's
15//!    not a hash function in the sense that it produces a fixed sized output
16//!    independent of the input size)
17//!  - `sha1`: Enable SHA-1 hasher
18//!  - `sha2`: (default) Enable SHA-2 hashers
19//!  - `sha3`: (default) Enable SHA-3 hashers
20//!  - `strobe`: Enable Strobe hashers
21//!
22//! In order to enable all cryptographically secure hashers, you can set the
23//! `secure-hashes` feature flag (enabled by default).
24//!
25//! The library has support for `no_std`, if you disable the `std` feature flag.
26//!
27//! The `multihash-impl` feature flag (enabled by default) enables a default
28//! Multihash implementation that contains some of the bundled hashers. If you
29//! want a different set of hash algorithms you can change this with enabled the
30//! corresponding features.
31//!
32//! For example if you only need SHA2 hasher, you could set the features in the
33//! `multihash` dependency like this:
34//!
35//! ```toml
36//! multihash = { version = …, default-features = false, features = ["std", "multihash-impl", "sha2"] }
37//! ```
38//!
39//! If you want to customize your code table even more, for example you want
40//! only one specific hash digest size and not whole family, you would only
41//! enable the `derive` feature (enabled by default), which enables the
42//! [`Multihash` derive], together with the hashers you want.
43//!
44//! The `arb` feature flag enables the quickcheck arbitrary implementation for
45//! property based testing.
46//!
47//! For serializing the multihash there is support for [Serde] via the
48//! `serde-codec` feature and the [SCALE Codec] via the `scale-codec` feature.
49//!
50//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
51//! [`Multihash` derive]: crate::derive
52//! [Serde]: https://serde.rs
53//! [SCALE Codec]: https://github.com/paritytech/parity-scale-codec
54
55#![deny(missing_docs, unsafe_code)]
56#![cfg_attr(not(any(feature = "std", test)), no_std)]
57
58extern crate alloc;
59
60#[cfg(any(test, feature = "arb"))]
61mod arb;
62mod error;
63mod hasher;
64mod hasher_impl;
65mod multihash;
66#[cfg(feature = "multihash-impl")]
67mod multihash_impl;
68
69pub use crate::{
70  error::{
71    Error,
72    Result,
73  },
74  hasher::{
75    Digest,
76    Hasher,
77    StatefulHasher,
78  },
79  multihash::{
80    Multihash as MultihashGeneric,
81    MultihashDigest,
82  },
83};
84#[cfg(feature = "derive")]
85pub use sp_multihash_derive as derive;
86
87#[cfg(feature = "multihash-impl")]
88pub use crate::multihash_impl::{
89  Code,
90  Multihash,
91};
92
93#[cfg(feature = "blake2b")]
94pub use crate::hasher_impl::blake2b::{
95  Blake2b256,
96  Blake2b512,
97  Blake2bDigest,
98  Blake2bHasher,
99};
100#[cfg(feature = "blake2s")]
101pub use crate::hasher_impl::blake2s::{
102  Blake2s128,
103  Blake2s256,
104  Blake2sDigest,
105  Blake2sHasher,
106};
107#[cfg(feature = "blake3")]
108pub use crate::hasher_impl::blake3::{
109  Blake3Digest,
110  Blake3Hasher,
111  Blake3_256,
112};
113#[cfg(feature = "sha1")]
114pub use crate::hasher_impl::sha1::{
115  Sha1,
116  Sha1Digest,
117};
118#[cfg(feature = "sha2")]
119pub use crate::hasher_impl::sha2::{
120  Sha2Digest,
121  Sha2_256,
122  Sha2_512,
123};
124#[cfg(feature = "sha3")]
125pub use crate::hasher_impl::sha3::{
126  Keccak224,
127  Keccak256,
128  Keccak384,
129  Keccak512,
130  KeccakDigest,
131};
132#[cfg(feature = "sha3")]
133pub use crate::hasher_impl::sha3::{
134  Sha3Digest,
135  Sha3_224,
136  Sha3_256,
137  Sha3_384,
138  Sha3_512,
139};
140#[cfg(feature = "strobe")]
141pub use crate::hasher_impl::strobe::{
142  Strobe256,
143  Strobe512,
144  StrobeDigest,
145  StrobeHasher,
146};
147pub use crate::hasher_impl::{
148  identity::{
149    Identity256,
150    IdentityDigest,
151    IdentityHasher,
152  },
153  unknown::UnknownDigest,
154};