blake 1.1.0

Implementation of the BLAKE hash function for Rust via FFI

Crate blake [] [src]

An implementation of the BLAKE hash function, via FFI to reference implementation.

For more information about BLAKE visit its official homepage.

There are two APIs provided: one for single-chunk hashing and one for hashing of multiple data segments.

Examples

Hashing a single chunk of data with a 256-bit BLAKE hash function, then verifying the result.

let mut result = [0; 32];
blake::hash(256, b"The lazy fox jumps over the lazy dog", &mut result).unwrap();

assert_eq!(Vec::from_iter(result.iter().map(|&i| i)),
           vec![0x1B, 0x59, 0x7C, 0x7A, 0x88, 0x9F, 0xCE, 0xB1,
                0xCC, 0x75, 0x6D, 0x6C, 0x6C, 0x06, 0xA7, 0xF9,
                0x22, 0x5E, 0x02, 0xBB, 0x0C, 0x02, 0x6E, 0x8B,
                0xC5, 0xEB, 0x4E, 0xA7, 0x61, 0x0E, 0xBB, 0x9E]);

Hashing multiple chunks of data with a 512-bit BLAKE hash function, then verifying the result.

let mut result = [0; 64];
let state = Blake::new(512).unwrap();

state.update("Zażółć ".as_bytes());
state.update("gęślą ".as_bytes());
state.update("jaźń".as_bytes());

state.finalise(&mut result);
assert_eq!(Vec::from_iter(result.iter().map(|&i| i)),
           vec![0x34, 0x43, 0xD3, 0x15, 0x00, 0x60, 0xFE, 0x8D,
                0xBB, 0xB1, 0x21, 0x74, 0x87, 0x7B, 0x8A, 0xA2,
                0x67, 0x19, 0xED, 0xC9, 0x66, 0xD6, 0xEC, 0xB5,
                0x8F, 0x94, 0xBD, 0xE3, 0x5A, 0xD8, 0x96, 0x99,
                0xEA, 0x03, 0xEB, 0xC2, 0x0E, 0x2B, 0xCD, 0x80,
                0x5C, 0x0B, 0x09, 0x95, 0x6A, 0x1E, 0xEE, 0x3D,
                0x1F, 0x07, 0x2B, 0x33, 0x64, 0x47, 0x15, 0x68,
                0x10, 0x9E, 0x43, 0xC4, 0x0C, 0xE1, 0x27, 0xDA]);

Comparing result of single- and multi-chunk hash methods hashing the same effective message with a 384-bit BLAKE hash function.

let mut result_multi  = [0; 48];
let mut result_single = [0; 48];

let state = Blake::new(384).unwrap();
state.update("Zażółć ".as_bytes());
state.update("gęślą ".as_bytes());
state.update("jaźń".as_bytes());
state.finalise(&mut result_multi);

blake::hash(384, "Zażółć gęślą jaźń".as_bytes(), &mut result_single).unwrap();

assert_eq!(Vec::from_iter(result_multi .iter().map(|&i| i)),
           Vec::from_iter(result_single.iter().map(|&i| i)));

Structs

Blake

Hashing state for multiple data sets.

Enums

BlakeError

Some functions in the library can fail, this enum represents all the possible ways they can.

Functions

hash

Hash all data in one fell swoop.

Type Definitions

Result

Helper result type containing BlakeError.