Module orion::hash

source ·
Available on crate feature safe_api only.
Expand description

Hashing.

Use case:

orion::hash can be used to hash some given data.

An example of this could be using hashes of files to ensure integrity. Meaning, checking if a file has been modified since the time the hash was recorded.

If you are looking for a keyed hash, please see the orion::auth module.

About:

  • Uses BLAKE2b with an output size of 32 bytes (i.e BLAKE2b-256).

Parameters:

  • data: The data to be hashed.

Panics:

A panic will occur if:

  • More than 2*(2^64-1) bytes of data are hashed.

Security:

  • This interface does not support supplying BLAKE2b with a secret key, and the hashes retrieved from using orion::hash are therefore not suitable as MACs.
  • BLAKE2b is not suitable for password hashing. See orion::pwhash instead.

Examples

Hashing in-memory data

use orion::hash::{digest, Digest};

let hash: Digest = digest(b"Some data")?;

Hashing data from an arbitrary reader

use orion::hash::{digest_from_reader, Digest};

// `reader` could instead be `File::open("file.txt")?`
let reader = std::io::Cursor::new(b"some data");
let hash: Digest = digest_from_reader(reader)?;

Re-exports

  • pub use crate::hazardous::hash::blake2::blake2b::Digest;

Functions