20 releases (11 stable)

1.0.10 Nov 12, 2022
1.0.9 Sep 7, 2020
1.0.8 Mar 9, 2020
1.0.1 Feb 10, 2020
0.1.0 Jan 31, 2020

#614 in Algorithms

Download history 1916/week @ 2025-10-11 2173/week @ 2025-10-18 1682/week @ 2025-10-25 1987/week @ 2025-11-01 2256/week @ 2025-11-08 3036/week @ 2025-11-15 1513/week @ 2025-11-22 2225/week @ 2025-11-29 3263/week @ 2025-12-06 2780/week @ 2025-12-13 980/week @ 2025-12-20 170/week @ 2025-12-27 1702/week @ 2026-01-03 1402/week @ 2026-01-10 1922/week @ 2026-01-17 5267/week @ 2026-01-24

10,380 downloads per month
Used in 17 crates (2 directly)

MIT/Apache

91KB
1.5K SLoC

extendhash

crates.io docs.rs

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

Supported hash algorithms:

  • MD5
  • SHA-0
  • SHA-1
  • SHA-256
  • SHA-512

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

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()));

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.

No runtime deps