[]Module cjdns_crypto::hash

Hashing

Security model

The hash() function is designed to be usable as a strong component of DSA, RSA-PSS, key derivation, hash-based message-authentication codes, hash-based ciphers, and various other common applications. "Strong" means that the security of these applications, when instantiated with hash(), is the same as the security of the applications against generic attacks. In particular, the hash() function is designed to make finding collisions difficult.

Selected primitive

hash() is currently an implementation of SHA-512.

There has been considerable degradation of public confidence in the security conjectures for many hash functions, including SHA-512. However, for the moment, there do not appear to be alternatives that inspire satisfactory levels of confidence. One can hope that NIST's SHA-3 competition will improve the situation.

Alternate primitives

NaCl supports the following hash functions:


crypto_hashprimitiveBYTES
crypto_hash_sha256SHA-25632
crypto_hash_sha512SHA-51264

Example

use sodiumoxide::crypto::hash;

let data_to_hash = b"some data";
let digest = hash::hash(data_to_hash);

let mut hash_state = hash::State::new();
hash_state.update(b"some ");
hash_state.update(b"data!");
let digest = hash_state.finalize();

Modules

sha256

SHA-256.

sha512

SHA-512.

Structs

Digest

Digest-structure

State

State contains the state for multi-part (streaming) hash computations. This allows the caller to process a message as a sequence of multiple chunks.

Constants

BLOCKBYTES

Block size of the hash function.

DIGESTBYTES

Number of bytes in a Digest.

Functions

hash

hash hashes a message m. It returns a hash h.