debris / tiny-keccak

An implementation of Keccak derived functions specified in FIPS-202, SP800-185 and KangarooTwelve
Creative Commons Zero v1.0 Universal
193 stars 49 forks source link

Add a test for overlapping buffers (WAS: Don't unroll outer loop for speed™) #29

Closed dvdplm closed 6 years ago

dvdplm commented 6 years ago

Not unrolling the outer loop seems to speed up hashing quite significally:

Original (unrolled):

running 3 tests
test bench_keccak_256_with_empty_input   ... bench:         557 ns/iter (+/- 46)
test bench_keccak_256_with_large_input   ... bench:      17,288 ns/iter (+/- 1,871) = 236 MB/s
test bench_keccak_256_with_typical_input ... bench:         577 ns/iter (+/- 28) = 88 MB/s

This branch (not unrolled):

running 3 tests
test bench_keccak_256_with_empty_input   ... bench:         487 ns/iter (+/- 25)
test bench_keccak_256_with_large_input   ... bench:      14,645 ns/iter (+/- 675) = 279 MB/s
test bench_keccak_256_with_typical_input ... bench:         495 ns/iter (+/- 32) = 103 MB/s

"Inspired" by https://github.com/RustCrypto/sponges/blob/master/keccak/src/lib.rs#L138

Running benchmarks from the keccak-hash crate so we can compare to the numbers here.

dvdplm commented 6 years ago

@debris ptal

debris commented 6 years ago

already merged #30 . Please rebase if still relevant :)

dvdplm commented 6 years ago

Now it's down to adding a test for overlapping buffers. Merge? :)