#hash #hashing #data #verifying #multiple #blake-rs

blake

Implementation of the BLAKE hash function for Rust via FFI

8 stable releases

Uses old Rust 2015

2.0.2 Dec 31, 2021
2.0.1 Jun 6, 2020
2.0.0 Sep 16, 2017
1.1.1 Jan 20, 2017
0.1.0 Aug 16, 2016

#1117 in Algorithms

Download history 144/week @ 2024-07-19 116/week @ 2024-07-26 179/week @ 2024-08-02 259/week @ 2024-08-09 294/week @ 2024-08-16 282/week @ 2024-08-23 608/week @ 2024-08-30 347/week @ 2024-09-06 168/week @ 2024-09-13 200/week @ 2024-09-20 246/week @ 2024-09-27 292/week @ 2024-10-04 290/week @ 2024-10-11 489/week @ 2024-10-18 591/week @ 2024-10-25 600/week @ 2024-11-01

2,061 downloads per month
Used in 11 crates (5 directly)

MIT license

40KB
625 lines

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

Implementation of the BLAKE hash function for Rust via FFI.

Docs

Special thanks

To all who support further development on Patreon, in particular:

  • ThePhD
  • Embark Studios
  • Jasper Bekkers

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.

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 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.

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

Special thanks

To all who support further development on Patreon, in particular:

  • ThePhD
  • Embark Studios
  • Jasper Bekkers

Dependencies

~0.4–325KB