Crate sha3

source · []
Expand description

An 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)


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};

// create a SHA3-256 object
let mut hasher = Sha3_256::new();

// write input message

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

assert_eq!(result[..], hex!("

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();
let mut reader = hasher.finalize_xof();
let mut res1 = [0u8; 10];
reader.read(&mut res1);
assert_eq!(res1, hex!("5881092dd818bf5cf8a3"));

Also see RustCrypto/hashes readme.


pub use digest;


Core Keccak-224 hasher state.

Core Keccak-256 hasher state.

Core SHA-3 CryptoNight variant hasher state.

Core Keccak-384 hasher state.

Core Keccak-512 hasher state.

Core SHA-3-224 hasher state.

Core SHA-3-256 hasher state.

Core SHA-3-384 hasher state.

Core SHA-3-512 hasher state.

Core SHAKE128 hasher state.

Core SHAKE128 reader state.

Core SHAKE256 hasher state.

Core SHAKE256 reader state.


Convinience wrapper trait covering functionality of cryptographic hash functions with fixed output size.

Type Definitions

Keccak-224 hasher state.

Keccak-256 hasher state.

SHA-3 CryptoNight variant hasher state.

Keccak-384 hasher state.

Keccak-512 hasher state.

SHA-3-224 hasher state.

SHA-3-256 hasher state.

SHA-3-384 hasher state.

SHA-3-512 hasher state.

SHAKE128 hasher state.

SHAKE128 reader state.

SHAKE256 hasher state.

SHAKE256 reader state.