#hash #blake

blake

Implementation of the BLAKE hash function for Rust via FFI

7 releases (stable)

2.0.0 Sep 16, 2017
1.1.1 Jan 20, 2017
1.0.2 Aug 19, 2016
0.1.0 Aug 16, 2016

#455 in Algorithms

Download history 126/week @ 2019-12-02 108/week @ 2019-12-09 80/week @ 2019-12-16 52/week @ 2019-12-23 60/week @ 2019-12-30 98/week @ 2020-01-06 115/week @ 2020-01-13 88/week @ 2020-01-20 30/week @ 2020-01-27 111/week @ 2020-02-03 63/week @ 2020-02-10 114/week @ 2020-02-17 96/week @ 2020-02-24 24/week @ 2020-03-02 91/week @ 2020-03-09 62/week @ 2020-03-16

475 downloads per month
Used in 4 crates (2 directly)

MIT license

39KB
614 lines

blake-rs TravisCI build status AppVeyorCI build status Licence Crates.io version

Implementation of the BLAKE hash function for Rust via FFI.

Docs


lib.rs:

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.

# use blake::Blake;
# use std::iter::FromIterator;
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.

# use blake::Blake;
# use std::iter::FromIterator;
let mut result = [0; 64];
let mut 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.

# use blake::Blake;
# use std::iter::FromIterator;
let mut result_multi  = [0; 48];
let mut result_single = [0; 48];

let mut 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)));

Dependencies

~37KB