Full Domain Hash
A Full Domain Hash (FDH) is a useful cryptographic construction that extends the size of a hash digest to an arbitrary length. For example, SHA256 can be expanded to 1024 bits instead of the usual 256 bits.
We construct an FDH by computing a number of cycles where cycles=(target length)/(digest length) + 1. We then compute FDH(M) = HASH(M||0) || HASH(M||1) || ... || HASH(M||cycles−1), where HASH is any hash function, M is the message, || denotes concatenation, and numerical values are binary (\x01, \x02 etc).
FDHs are usually used with an RSA signature scheme where the target length is the size of the key. See https://en.wikipedia.org/wiki/Full_Domain_Hash
This crate makes extensive use of the digest crate's cryptograhic hash traits, so most useful methods are implemented as part of digest traits. These traits are re-exported for convenience. See https://github.com/RustCrypto/hashes for a list of compatible hashes.
Example
use Sha256;
use ;
// Expand SHA256 from 256 bits to 1024 bits.
let output_bits = 1024;
let output_bytes = 1024 / 8;
let mut hasher = new?;
hasher.input;
let result = hasher.vec_result;
no_std
This crate also supports no_std.
use Sha256;
use ;
// Expand SHA256 from 256 bits to 512 bits (and beyond!), reading it in 16 byte chunks.
let mut hasher = default;
hasher.input;
let mut reader = hasher.xof_result;
let mut read_buf = default;
// Read the first 16 bytes into read_buf
reader.read;
// Read the second 16 bytes into read_buf
reader.read;
// If we want, we can just keep going, reading as many bits as we want indefinitely.
reader.read;
reader.read;