Skip to main content

Module crypto_hash

Module crypto_hash 

Source
Expand description

Hash functions

§SHA-2 and SHA-3 hashing

Implements libsodium’s crypto_hash_sha256_*, crypto_hash_sha512_*, crypto_hash_sha3256_*, and crypto_hash_sha3512_* functions.

SHA-2 and SHA-3 are unkeyed hash functions. They produce fixed-size digests that identify input bytes, but they do not prove who created the input. Use crate::classic::crypto_auth or the direct HMAC modules when a shared secret key is required.

use dryoc::classic::crypto_hash::*;

let message = b"The empty vessel makes the loudest sound.";

let mut default_digest: Digest = [0u8; 64];
crypto_hash(&mut default_digest, message);
assert_eq!(default_digest.len(), 64);

let mut sha256 = Sha256Digest::default();
crypto_hash_sha256(&mut sha256, message);
assert_eq!(sha256.len(), 32);

let mut sha512: Sha512Digest = [0u8; 64];
crypto_hash_sha512(&mut sha512, message);
assert_eq!(sha512.len(), 64);

let mut sha3256 = Sha3256Digest::default();
crypto_hash_sha3256(&mut sha3256, message);
assert_eq!(sha3256.len(), 32);

let mut sha3512: Sha3512Digest = [0u8; 64];
crypto_hash_sha3512(&mut sha3512, message);
assert_eq!(sha3512.len(), 64);

Structs§

Sha256State
Internal state for SHA-256 functions.
Sha512State
Internal state for SHA-512 functions.
Sha3256State
Internal state for SHA3-256 functions.
Sha3512State
Internal state for SHA3-512 functions.

Functions§

crypto_hash
Computes a SHA-512 hash from input using libsodium’s default crypto_hash primitive.
crypto_hash_sha256
Computes a SHA-256 hash from input.
crypto_hash_sha512
Computes a SHA-512 hash from input.
crypto_hash_sha256_final
Finalizes state of SHA-256, and writes the digest to output consuming state.
crypto_hash_sha256_init
Initializes a SHA-256 hasher.
crypto_hash_sha256_update
Updates state of SHA-256 hasher with input.
crypto_hash_sha512_final
Finalizes state of SHA-512, and writes the digest to output consuming state.
crypto_hash_sha512_init
Initializes a SHA-512 hasher.
crypto_hash_sha512_update
Updates state of SHA-512 hasher with input.
crypto_hash_sha3256
Computes a SHA3-256 hash from input.
crypto_hash_sha3512
Computes a SHA3-512 hash from input.
crypto_hash_sha3256_final
Finalizes state of SHA3-256, and writes the digest to output consuming state.
crypto_hash_sha3256_init
Initializes a SHA3-256 hasher.
crypto_hash_sha3256_update
Updates state of SHA3-256 hasher with input.
crypto_hash_sha3512_final
Finalizes state of SHA3-512, and writes the digest to output consuming state.
crypto_hash_sha3512_init
Initializes a SHA3-512 hasher.
crypto_hash_sha3512_update
Updates state of SHA3-512 hasher with input.

Type Aliases§

Digest
Type alias for SHA512 digest output.
Sha256Digest
Type alias for SHA256 digest output.
Sha512Digest
Type alias for SHA512 digest output.
Sha3256Digest
Type alias for SHA3-256 digest output.
Sha3512Digest
Type alias for SHA3-512 digest output.