8个稳定版本
使用旧的Rust 2015
2.0.2 | 2021年12月31日 |
---|---|
2.0.1 | 2020年6月6日 |
2.0.0 | 2017年9月16日 |
1.1.1 | 2017年1月20日 |
0.1.0 | 2016年8月16日 |
1127 在 算法 中排名
1,078 每月下载量
在 11 个 包中使用(直接使用5个)
40KB
625 行
blake-rs

通过FFI实现BLAKE哈希函数的Rust版本。
文档
特别感谢
感谢在Patreon上支持进一步开发的所有人,特别是
- ThePhD
- Embark Studios
- Jasper Bekkers
lib.rs
:
通过FFI引用实现实现的BLAKE哈希函数。
有关BLAKE的更多信息,请访问其官方网站。
提供了两个API:一个用于单块哈希,一个用于多数据段哈希。
示例
使用256位BLAKE哈希函数对单个数据块进行哈希处理,然后验证结果。
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]);
使用512位BLAKE哈希函数对多个数据块进行哈希处理,然后验证结果。
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]);
使用384位BLAKE哈希函数对相同有效消息的单块和多块哈希方法进行比较。
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)));
特别感谢
感谢在Patreon上支持进一步开发的所有人,特别是
- ThePhD
- Embark Studios
- Jasper Bekkers
依赖项
~225KB