extendhash

crates.io docs.rs

extendhash is a Rust library to compute hashes and hash extensions.

Supported hash algorithms:

It supports #![no_std]. All hash algorithms and hash extensions are implemented in constant functions (using const fn) and can therefore be used in constant values.

Usage

```rust use extendhash::sha256;

let secretdata = "This is a secret!".asbytes(); let hash = sha256::computehash(secretdata); let datalength = secretdata.len();

// Now we try computing a hash extension, // assuming that secret_data is not available. // We only need hash and data_length. let appendedmessage = "Appended message.".asbytes(); let combinedhash = sha256::extendhash( hash, datalength, appendedmessage);

// Now we verify that combined_hash matches the // concatenation (note the intermediate padding): let mut combineddata = Vec::::new(); combineddata.extendfromslice(secretdata); let padding = sha256::paddingforlength(datalength); combineddata.extendfromslice(padding.asslice()); combineddata.extendfromslice(appendedmessage); asserteq!( combinedhash, sha256::computehash(combineddata.as_slice())); ```

License

Licensed under either of

at your option.

Contribution

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.