6个版本
0.1.5 | 2022年10月20日 |
---|---|
0.1.4 | 2020年7月10日 |
0.1.3 | 2020年6月11日 |
0.1.2 | 2020年5月26日 |
0.1.1 | 2020年3月28日 |
#965 在 密码学
92 每月下载量
用于 k12sum
345KB
8K SLoC
kangarootwelve_xkcp.rs

这是一个围绕eXtended Keccak Code Package实现KangarooTwelve加密哈希函数的Rust包装器。该实现包括SSSE3、AVX2和AVX-512优化,并在运行时检测处理器支持。子crate k12sum
提供命令行界面。
此包通过FFI包装C代码,因此您必须安装C编译器才能构建它。
用法
k12sum
命令行工具
k12sum
使用KangarooTwelve对文件或标准输入的数据进行哈希处理。预构建的二进制文件可在Linux、Windows和macOS(需要未知的开发者解决方案)的发布页面上获得。
自己构建k12sum
- 确保您有一个可工作的C编译器。在Linux和macOS上,您可以通过运行
gcc --version
来检查GCC(或假装是GCC的Clang)是否已安装。在Windows上,如果您尚未安装Visual Studio,您可以安装Visual Studio 2019 C++构建工具。 - 安装Rust和Cargo。
- 运行
cargo install k12sum
。
如果 rustup
没有为您配置 PATH
,您可能需要查找已安装的二进制文件,例如在 ~/.cargo/bin
中。您可以通过创建一个大文件并对其进行散列来测试 KangarooTwelve 在您的机器上的速度,例如如下所示
# Create a 1 GB file.
head -c 1000000000 /dev/zero > /tmp/bigfile
# Hash it with SHA-256.
time openssl sha256 /tmp/bigfile
# Hash it with KangarooTwelve.
time k12sum /tmp/bigfile
kangarootwelve_xkcp
Rust 包
要从 Rust 代码中使用 KangarooTwelve,请将 kangarootwelve_xkcp
包添加到您的 Cargo.toml
中的依赖项。以下是一个散列一些字节的示例
// Hash an input all at once.
let hash1 = kangarootwelve_xkcp::hash(b"foobarbaz");
// Hash an input incrementally.
let mut hasher = kangarootwelve_xkcp::Hasher::new();
hasher.update(b"foo");
hasher.update(b"bar");
hasher.update(b"baz");
let hash2 = hasher.finalize();
assert_eq!(hash1, hash2);
// Extended output. OutputReader also implements Read.
let mut hasher = kangarootwelve_xkcp::Hasher::new();
hasher.update(b"foobarbaz");
let mut output_reader = hasher.finalize_xof();
let mut output = [0; 1000];
output_reader.squeeze(&mut output);
assert_eq!(&output[..32], hash1.as_bytes());
// Print a hash as hex.
println!("{}", hash1.to_hex());
许可证
依赖关系
80-260KB