#digest #hash #keccak #hashing #crypto

no-std sha3

Pure Rust implementation of SHA-3, a family of Keccak-based hash functions including the SHAKE family of eXtendable-Output Functions (XOFs), as well as the accelerated variant TurboSHAKE

31 releases

0.11.0-pre.3 Feb 1, 2024
0.10.8 May 5, 2023
0.10.6 Oct 18, 2022
0.10.2 Jul 30, 2022
0.3.0 Nov 17, 2016

#44 in Cryptography

Download history 323630/week @ 2023-11-26 302499/week @ 2023-12-03 313417/week @ 2023-12-10 291107/week @ 2023-12-17 144620/week @ 2023-12-24 236851/week @ 2023-12-31 321800/week @ 2024-01-07 330455/week @ 2024-01-14 359824/week @ 2024-01-21 362526/week @ 2024-01-28 370330/week @ 2024-02-04 345789/week @ 2024-02-11 333562/week @ 2024-02-18 341796/week @ 2024-02-25 337854/week @ 2024-03-03 130135/week @ 2024-03-10

1,164,208 downloads per month
Used in 4,217 crates (708 directly)

MIT/Apache

1MB
702 lines

RustCrypto: SHA-3

crate Docs Apache2/MIT licensed Rust Version Project Chat Build Status

Pure Rust implementation of the SHA-3 cryptographic hash algorithms.

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

  • SHA3-224
  • SHA3-256
  • SHA3-384
  • SHA3-512
  • SHAKE128, an extendable output function (XOF)
  • SHAKE256, an extendable output function (XOF)
  • Keccak224, Keccak256, Keccak384, Keccak512 (NIST submission without padding changes)

This crates additionally supports the TurboSHAKE XOF variant.

Examples

Output size of SHA3-256 is fixed, so its functionality is usually accessed via the Digest trait:

use hex_literal::hex;
use sha3::{Digest, Sha3_256};

let mut hasher = Sha3_256::new();
hasher.update(b"abc");
let hash = hasher.finalize();

assert_eq!(hash, hex!("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"));

SHAKE functions have an extendable output, so finalization method returns XOF reader from which results of arbitrary length can be read. Note that these functions do not implement Digest, so lower-level traits have to be imported:

use sha3::{Shake128, digest::{Update, ExtendableOutput, XofReader}};
use hex_literal::hex;

let mut hasher = Shake128::default();
hasher.update(b"abc");
let mut reader = hasher.finalize_xof();
let mut buf = [0u8; 10];
reader.read(&mut buf);
assert_eq!(buf, hex!("5881092dd818bf5cf8a3"));

Also, see the examples section in the RustCrypto/hashes readme.

Minimum Supported Rust Version

Rust 1.71 or higher.

Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.

SemVer Policy

  • All on-by-default features of this library are covered by SemVer
  • MSRV is considered exempt from SemVer as noted above

License

The crate is 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.

Dependencies