Expand description
§RustCrypto: SHA-3
Pure Rust implementation of the SHA-3 cryptographic hash algorithms.
There are 6 standard algorithms specified in the SHA-3 standard:
SHA3-224SHA3-256SHA3-384SHA3-512SHAKE128, an extendable output function (XOF)SHAKE256, an extendable output function (XOF)Keccak224,Keccak256,Keccak384,Keccak512(NIST submission without padding changes)
This crates supports cSHAKE128 and cSHAKE256, the customizable XOFs as defined in the NIST SHA-3 Derived Functions.
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"));
// 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.
§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.
Re-exports§
pub use digest;
Structs§
- CShake128
Core - Core CSHAKE128 hasher state.
- CShake128
Reader Core - Core CSHAKE128 reader state.
- CShake256
Core - Core CSHAKE256 hasher state.
- CShake256
Reader Core - Core CSHAKE256 reader state.
- Keccak224
Core - Core Keccak-224 hasher state.
- Keccak256
Core - Core Keccak-256 hasher state.
- Keccak256
Full Core - Core SHA-3 CryptoNight variant hasher state.
- Keccak384
Core - Core Keccak-384 hasher state.
- Keccak512
Core - Core Keccak-512 hasher state.
- Sha3_
224Core - Core SHA-3-224 hasher state.
- Sha3_
256Core - Core SHA-3-256 hasher state.
- Sha3_
384Core - Core SHA-3-384 hasher state.
- Sha3_
512Core - Core SHA-3-512 hasher state.
- Shake128
Core - Core SHAKE128 hasher state.
- Shake128
Reader Core - Core SHAKE128 reader state.
- Shake256
Core - Core SHAKE256 hasher state.
- Shake256
Reader Core - Core SHAKE256 reader state.
- Turbo
Shake128 Core - Core TurboSHAKE128 hasher state.
- Turbo
Shake128 Reader Core - Core TurboSHAKE128 reader state.
- Turbo
Shake256 Core - Core TurboSHAKE256 hasher state.
- Turbo
Shake256 Reader Core - Core TurboSHAKE256 reader state.
Traits§
- Customized
Init - Trait for hash functions with customization string for domain separation.
- Digest
- Convenience wrapper trait covering functionality of cryptographic hash functions with fixed output size.
Type Aliases§
- CShake128
- CSHAKE128 hasher state.
- CShake256
- CSHAKE256 hasher state.
- CShake128
Reader - CSHAKE128 reader state.
- CShake256
Reader - CSHAKE256 reader state.
- Keccak224
- Keccak-224 hasher state.
- Keccak256
- Keccak-256 hasher state.
- Keccak384
- Keccak-384 hasher state.
- Keccak512
- Keccak-512 hasher state.
- Keccak256
Full - SHA-3 CryptoNight variant hasher state.
- Sha3_
224 - SHA-3-224 hasher state.
- Sha3_
256 - SHA-3-256 hasher state.
- Sha3_
384 - SHA-3-384 hasher state.
- Sha3_
512 - SHA-3-512 hasher state.
- Shake128
- SHAKE128 hasher state.
- Shake256
- SHAKE256 hasher state.
- Shake128
Reader - SHAKE128 reader state.
- Shake256
Reader - SHAKE256 reader state.
- Turbo
Shake128 - TurboSHAKE128 hasher state.
- Turbo
Shake256 - TurboSHAKE256 hasher state.
- Turbo
Shake128 Reader - TurboSHAKE128 reader state.
- Turbo
Shake256 Reader - TurboSHAKE256 reader state.