#message-authentication #sha-1 #hmac #hashing #hash #rust-crypto #generation

hmac-sha1

A simple wrapper around the RustCrypto hmac and sha1 crates for simple HMAC-SHA1 generation

5 releases

0.2.2 Dec 8, 2023
0.2.1 Oct 22, 2023
0.1.3 Sep 24, 2016
0.1.2 Sep 24, 2016
0.1.1 Sep 21, 2016

#399 in Algorithms

Download history 13169/week @ 2024-10-29 12512/week @ 2024-11-05 13072/week @ 2024-11-12 15480/week @ 2024-11-19 17215/week @ 2024-11-26 13162/week @ 2024-12-03 14467/week @ 2024-12-10 13531/week @ 2024-12-17 4551/week @ 2024-12-24 7073/week @ 2024-12-31 10759/week @ 2025-01-07 13746/week @ 2025-01-14 11837/week @ 2025-01-21 13421/week @ 2025-01-28 13383/week @ 2025-02-04 12624/week @ 2025-02-11

53,912 downloads per month
Used in 80 crates (19 directly)

BSD-3-Clause

7KB
70 lines

Rust-HMAC-SHA1

crates.io version

A simple wrapper around the RustCrypto hmac and sha1 crates for simple HMAC-SHA1 generation.

Functionality Note

As the crate is now a thin wrapper around RustCrypto, please note that this crate can be replaced with the following code:

use sha1::Sha1;
use hmac::{Hmac, Mac};

pub fn main() {
    ...

    // Create the hasher with the key. We can use expect for Hmac algorithms as they allow arbitrary key sizes.
    let mut hasher: Hmac<Sha1> = Mac::new_from_slice(key) .expect("HMAC algoritms can take keys of any size");

    // hash the message
    hasher.update(message);

    // finalize the hash and convert to a static array
    let hmac: [u8;20] = hasher.finalize().into_bytes().into()

    ...
}

Usage

To import rust-hmac-sha1 add the following to your Cargo.toml:

[dependencies]
hmac-sha1 = "^0.2"

To use rust-hmac-sha1, simply use the single provided function:

let hmac_digest: [u8; hmac_sha1::SHA1_DIGEST_BYTES] = hmac_sha1::hmac_sha1(key, message);

Contributions

Any contributions are welcome.

This was implemented as a learning experience - an implementation for hmac-sha1 from just a SHA1 hasher is included in 0.1.x versions.

License

This crate is licensed under the BSD 3-Clause license.

This crate also depends on the RustCrypto Project to provide the underlying cryptographic implementations. These crates are dual licensed under MIT and Apache-2.0.

Dependencies

~735KB
~17K SLoC