Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/printfn/extendhash
Rust Hash Extender (for MD5, SHA-1, SHA-256, SHA-512 and more)
https://github.com/printfn/extendhash
hacktoberfest hash hash-algorithms hash-extensions length-extension rust sha1 sha256
Last synced: about 1 month ago
JSON representation
Rust Hash Extender (for MD5, SHA-1, SHA-256, SHA-512 and more)
- Host: GitHub
- URL: https://github.com/printfn/extendhash
- Owner: printfn
- License: apache-2.0
- Created: 2020-01-31T22:48:33.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-11-12T06:46:35.000Z (about 2 years ago)
- Last Synced: 2024-10-14T06:43:58.683Z (2 months ago)
- Topics: hacktoberfest, hash, hash-algorithms, hash-extensions, length-extension, rust, sha1, sha256
- Language: Rust
- Homepage:
- Size: 342 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# extendhash
[![crates.io](https://img.shields.io/crates/v/extendhash.svg)](https://crates.io/crates/extendhash)
[![docs.rs](https://docs.rs/extendhash/badge.svg)](https://docs.rs/extendhash)**extendhash** is a Rust library to compute hashes and hash extensions.
Supported hash algorithms:
* MD5
* SHA-0
* SHA-1
* SHA-256
* SHA-512It 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 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::::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
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or
http://opensource.org/licenses/MIT)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.