| Crates.io | sha3 |
| lib.rs | sha3 |
| version | 0.11.0-rc.3 |
| created_at | 2016-10-06 19:27:19.095615+00 |
| updated_at | 2025-09-03 21:26:29.767213+00 |
| description | 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 |
| homepage | |
| repository | https://github.com/RustCrypto/hashes |
| max_upload_size | |
| id | 6750 |
| size | 904,905 |
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-512SHAKE128 and SHAKE256 (an extendable output function (XOF))Additionally, this crate supports:
cSHAKE128 and cSHAKE256 the customizable XOFs as defined in the NIST SHA-3 Derived FunctionsTurboSHAKE XOF variantKeccak224, Keccak256, Keccak384, Keccak512 (NIST submission without padding changes)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"));
// Hex-encode hash using https://docs.rs/base16ct
let hex_hash = base16ct::lower::encode_string(&hash);
assert_eq!(hex_hash, "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.
The crate is licensed under either of:
at your option.
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.