我现在对sha3算法还不是很清楚, 写的这些看法都不一定正确(我还在熟悉中),
1.simd优化
看到有些论文里面提到使用simd可以做到性能提升1.4-2.6倍,我们accmulator大量依赖于这个计算,
目前看到sha2有一些优化
https://github.com/RustCrypto/hashes/commit/93d895de72c2cb3ac7bc106f03e33715f8f304c2
sha3有些论文
https://sol.sbc.org.br/index.php/sbseg/article/download/4266/4197/
https://caslab.csl.yale.edu/workshops/hasp2016/HASP16-10_slides.pdf
2.使用库对比
目前我们的accumulator使用sha3计算hash使用的tiny-keccak库,
可能原因是tiny-keccak先实现的,从文档上来看
https://github.com/debris/tiny-keccak#readme
性能比rust_crypto好,
running 4 tests test rust_crypto_sha3_256_input_32_bytes ... bench: 677 ns/iter (+/- 113) = 47 MB/s test rust_crypto_sha3_256_input_4096_bytes ... bench: 17,619 ns/iter (+/- 4,174) = 232 MB/s test tiny_keccak_sha3_256_input_32_bytes ... bench: 569 ns/iter (+/- 204) = 56 MB/s test tiny_keccak_sha3_256_input_4096_bytes ... bench: 17,185 ns/iter (+/- 4,575) = 238 MB/
这是2年前情况(tiny-keccack一直没有迭代), 我在跳板机上测试结论
Intel(R) Xeon(R) CPU E5-2666 v3 @ 2.90GHz 7G Memory
rustup run nightly cargo bench running 4 tests test rust_crypto_sha3_256_input_32_bytes ... bench: 599 ns/iter (+/- 12) = 53 MB/s test rust_crypto_sha3_256_input_4096_bytes ... bench: 17,665 ns/iter (+/- 96) = 231 MB/s test tiny_keccak_sha3_256_input_32_bytes ... bench: 595 ns/iter (+/- 5) = 53 MB/s test tiny_keccak_sha3_256_input_4096_bytes ... bench: 17,737 ns/iter (+/- 158) = 230 MB/s
在macOs上
running 4 tests test rust_crypto_sha3_256_input_32_bytes ... bench: 441 ns/iter (+/- 47) = 72 MB/s test rust_crypto_sha3_256_input_4096_bytes ... bench: 12,875 ns/iter (+/- 775) = 318 MB/s test tiny_keccak_sha3_256_input_32_bytes ... bench: 452 ns/iter (+/- 23) = 70 MB/s test tiny_keccak_sha3_256_input_4096_bytes ... bench: 13,073 ns/iter (+/- 880) = 313 MB/s