#crypto #sha2 #hash #digest

no-std sha2ni

SHA-2 hash functions

5 releases

Uses old Rust 2015

0.8.5 Apr 27, 2020
0.8.4 Apr 11, 2020
0.8.3 Mar 17, 2020
0.8.2 Mar 17, 2020
0.8.1 Feb 19, 2020

#1703 in Cryptography

Download history 14/week @ 2023-05-20 108/week @ 2023-05-27 38/week @ 2023-06-03 2/week @ 2023-06-10 34/week @ 2023-06-17 45/week @ 2023-06-24 57/week @ 2023-07-01 93/week @ 2023-07-08 41/week @ 2023-07-15 42/week @ 2023-07-22 25/week @ 2023-07-29 62/week @ 2023-08-05 31/week @ 2023-08-12 17/week @ 2023-08-19 19/week @ 2023-08-26 38/week @ 2023-09-02

112 downloads per month

MIT/Apache

56KB
1K SLoC

Sha2Ni

Build and test License Cargo Documentation

Sha2 implemention in Rust, aimed at performance. Forked from Sha2.

License

Dual-licensed under Apache 2.0 and MIT terms:


lib.rs:

An implementation of the SHA-2 cryptographic hash algorithms.

There are 6 standard algorithms specified in the SHA-2 standard:

  • Sha224, which is the 32-bit Sha256 algorithm with the result truncated to 224 bits.
  • Sha256, which is the 32-bit Sha256 algorithm.
  • Sha384, which is the 64-bit Sha512 algorithm with the result truncated to 384 bits.
  • Sha512, which is the 64-bit Sha512 algorithm.
  • Sha512Trunc224, which is the 64-bit Sha512 algorithm with the result truncated to 224 bits.
  • Sha512Trunc256, which is the 64-bit Sha512 algorithm with the result truncated to 256 bits.

Algorithmically, there are only 2 core algorithms: Sha256 and Sha512. All other algorithms are just applications of these with different initial hash values, and truncated to different digest bit lengths.

Usage

use sha2ni::{Sha256, Sha512, Digest};

// create a Sha256 object
let mut hasher = Sha256::new();

// write input message
hasher.input(b"hello world");

// read hash digest and consume hasher
let result = hasher.result();

assert_eq!(result[..], hex!("
    b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
")[..]);

// same for Sha512
let mut hasher = Sha512::new();
hasher.input(b"hello world");
let result = hasher.result();

assert_eq!(result[..], hex!("
    309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f
    989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
")[..]);

Also see RustCrypto/hashes readme.

Dependencies

~550–800KB
~16K SLoC