#crypto #sha #hmac #digest

hmac-sha

Minimal wrapper of HMAC-SHA-{1,2,3} in Rust

11 unstable releases (3 breaking)

Uses new Rust 2021

0.6.1 Nov 2, 2021
0.6.0 Nov 1, 2021
0.5.0 Aug 27, 2021
0.4.5 Aug 22, 2021
0.2.1 Jul 20, 2021

#193 in Cryptography

Download history 28/week @ 2021-08-15 48/week @ 2021-08-22 27/week @ 2021-08-29 20/week @ 2021-09-05 10/week @ 2021-09-12 15/week @ 2021-09-19 13/week @ 2021-09-26 7/week @ 2021-10-03 34/week @ 2021-10-10 13/week @ 2021-10-17 14/week @ 2021-10-24 39/week @ 2021-10-31 17/week @ 2021-11-07 18/week @ 2021-11-14 18/week @ 2021-11-21 23/week @ 2021-11-28

76 downloads per month
Used in ootp

MIT/Apache

7KB
126 lines

Rust-HMAC-SHA

CI status creates.io version

A pure Rust implementation of the Hash-based Message Authentication Code Algoritm for SHA-{1,2,3}. This project can be seen as an interface/wrapper for the RustCrypto crate, focusing on user/developer ease of use. Works in a #![no_std] environment.

Origins and motivations

This repo is a fork of Rust-HMAC-SHA1 by @pantsman0/Philip Woolford. Unlike the original version, it supports SHA-2 and SHA-3 in addition to SHA-1. In addition this fork uses the implementations of SHA provided by RustCrypto. Has been developed to assist in the development of OOTP.

Usage

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

[dependencies]
hmac-sha = "0.6"

and any other Hash crate that statisfy the Digest trait, like sha3

[dependencies]
...
sha3 = { version = "0.9", default-features = false }

You can use rust-hmac-sha in this way:

use hex;
use hmacsha::HmacSha;
use sha3::Sha3_256;

fn main() {
    let secret_key = "A very strong secret";
    let message = "My secret message";
    let mut hasher = HmacSha::from(secret_key, message, Sha3_256::default());
    let result = hasher.compute_digest();
    println!("{}", hex::encode(result));
}

Contributions

Any contributions are welcome. This was implemented as a learning experience and any advice is appreciated.

License

This crate is licensed under the MIT or Apache licenses, as is its dependancies of the RustCrypto family. The original crate was licensed under the BSD 3-Clause license, as the old dependency sha1

Dependencies

~780KB
~17K SLoC