Module openssl::hash

source ·
Expand description

Message digest (hash) computation support.

Examples

Calculate a hash in one go:

use openssl::hash::{hash, MessageDigest};

let data = b"\x42\xF4\x97\xE0";
let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
let res = hash(MessageDigest::md5(), data)?;
assert_eq!(&*res, spec);

Supply the input in chunks:

use openssl::hash::{Hasher, MessageDigest};

let mut hasher = Hasher::new(MessageDigest::sha256())?;
hasher.update(b"test")?;
hasher.update(b"this")?;
let digest: &[u8] = &hasher.finish()?;

let expected = hex::decode("9740e652ab5b4acd997a7cca13d6696702ccb2d441cca59fc6e285127f28cfe6")?;
assert_eq!(digest, expected);

Structs

Functions

  • Computes the hash of the data with the non-XOF hasher t.
  • Computes the hash of the data with the XOF hasher t and stores it in buf.