Crate rs_sha3_384

Source
Expand description

§SHA3-384 rs_sha3_384 - Secure Hash Algorithm KECCAK-based variant

The SHA3-384 hash function is part of the SHA-3 family, which was developed by the National Institute of Standards and Technology (NIST). Unlike SHAKE256, SHA3-384 produces a fixed-size output of 384 bits.

SHA3-384 is suitable for a variety of cryptographic purposes, including generating unique identifiers and ensuring data integrity. It’s widely trusted and remains a popular choice for hash functions that require longer digests.

§Usage

The crate provides a straightforward and intuitive API. Users can create a new SHA3-384 hasher instance, update it with input data, and finalize to get the resultant hash.

§Example

Here is an example of how to use the SHA3-384 hash function in Rust:

let mut sha3_384hasher = Sha3_384State::default().build_hasher();
sha3_384hasher.write(b"hello world");
let result = sha3_384hasher.finish();
assert_eq!(result, 0x83BFF28DDE1B1BF5);

Or, as a HashSet:

let hello = "hello";
let sha3_384state = Sha3_384State::default();
let mut sha3_384hasher1 = sha3_384state.build_hasher();
let mut sha3_384hasher2 = sha3_384state.build_hasher();
let mut sha3_384hasher3 = sha3_384state.build_hasher();

sha3_384hasher1.write(hello.as_bytes());
hello.hash(&mut sha3_384hasher2);
sha3_384hasher3.write(hello.as_bytes());
sha3_384hasher3.write(&[0xFF]);

let u64result1 = sha3_384hasher1.finish();
let u64result2 = sha3_384hasher2.finish();
let u64result3 = sha3_384hasher3.finish();

assert_eq!(u64result1, 0x720AEA11019EF064);
assert_eq!(u64result2, 0xDE65635D14145147);
assert_eq!(u64result2, u64result3);
assert_ne!(u64result1, u64result2);

§Use Cases

SHA3-384 is recommended for a wide variety of tasks, including:

  • Cryptographic security, due to its resistance to collision attacks.
  • Creating unique identifiers for data.
  • Ensuring data integrity in situations where a larger hash value is beneficial.

NIST recommends SHA3-384 for cryptographic functions due to its security and versatility. Its fixed-length output makes it particularly suitable when a longer hash value is required.

Structs§

Sha3_384Hasher
Sha3_384Hasher is a type that provides the SHA3-384 hashing algorithm in Rust.
Sha3_384State
Sha3_384State represents the state of a SHA3-384 hashing process.

Traits§

HasherContext
Overloads the finish Hasher method for a version that mutates itself