Crates.io | extendhash |
lib.rs | extendhash |
version | 1.0.10 |
source | src |
created_at | 2020-01-31 22:59:12.908121 |
updated_at | 2022-11-12 06:46:22.214179 |
description | Rust Hash Extender |
homepage | |
repository | https://github.com/printfn/extendhash |
max_upload_size | |
id | 203788 |
size | 102,662 |
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.
use extendhash::sha256;
let secret_data = "This is a secret!".as_bytes();
let hash = sha256::compute_hash(secret_data);
let data_length = secret_data.len();
// Now we try computing a hash extension,
// assuming that `secret_data` is not available.
// We only need `hash` and `data_length`.
let appended_message = "Appended message.".as_bytes();
let combined_hash = sha256::extend_hash(
hash, data_length, appended_message);
// Now we verify that `combined_hash` matches the
// concatenation (note the intermediate padding):
let mut combined_data = Vec::<u8>::new();
combined_data.extend_from_slice(secret_data);
let padding = sha256::padding_for_length(data_length);
combined_data.extend_from_slice(padding.as_slice());
combined_data.extend_from_slice(appended_message);
assert_eq!(
combined_hash,
sha256::compute_hash(combined_data.as_slice()));
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.