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日

#1612加密学

29 每月下载量

自定义许可证

365KB
9K SLoC

C 4.5K SLoC // 0.1% comments GNU Style Assembly 1.5K SLoC // 0.0% comments Rust 1.5K SLoC // 0.1% comments XSL 743 SLoC // 0.1% comments Python 74 SLoC // 0.1% comments Shell 4 SLoC

kangarootwelve_xkcp.rs Actions状态 docs.rs crates.io

这是一个Rust封装,围绕eXtended Keccak Code Package实现KangarooTwelve密码学散列函数。该实现包括SSSE3、AVX2和AVX-512优化,并在运行时检测处理器支持。k12sum子crate提供了一个命令行界面。

此包通过FFI包装C代码,因此您必须安装C编译器才能构建它。

用法

k12sum命令行实用程序

k12sum使用KangarooTwelve散列文件或从标准输入中的数据。Linux、Windows和macOS(需要未识别的开发者解决方案)上可用的预构建二进制文件在发布页面上。

自己构建k12sum

  1. 确保您有一个可工作的C编译器。在Linux和macOS上,您可以通过运行gcc --version来检查GCC(或伪装成GCC的Clang)是否已安装。在Windows上,如果您还没有安装Visual Studio,您可以安装Visual Studio 2019的C++构建工具
  2. 安装Rust和Cargo。
  3. 运行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());

许可协议

本项目中 Rust 包装的代码通过 CC0 发布到公有领域。分发的 XKCP 代码受多种许可协议的约束。

依赖关系

~0.9–1.4MB
~16K SLoC