rust-bitcoin-unsafe-fast/hashes/src
Andrew Poelstra 0f98e179c3
Merge rust-bitcoin/rust-bitcoin#1413: Add sha512_256 to bitcoin_hashes
411174c391 Add fuzz target for sha512_256 (Calvin Kim)
31fc1f8638 Add support for sha512/256 (Calvin Kim)
15b5af1117 Export sha512::HashEngine fields/function within the crate (Calvin Kim)

Pull request description:

  Adds a new file named `sha512_256.rs` that implements the `sha512/256` hash. This was needed as a part of https://github.com/rust-bitcoin/rust-bitcoin/discussions/1318 to drop the `sha2` dependency.

  All the actual hashing code is exactly the same as `sha512.rs`, minus the initial constants and the use of `hash_type!` macro. Some unit tests were added from wikipedia (for the "" input) and the rest were from the Go standard library's tests for sha512_256.

  Benchmarks on my Ryzen 3600 machine show that it is faster than sha256.

  ```
  test sha256::benches::sha256_10                   ... bench:          37 ns/iter (+/- 0) = 270 MB/s
  test sha256::benches::sha256_1k                   ... bench:       3,338 ns/iter (+/- 24) = 306 MB/s
  test sha256::benches::sha256_64k                  ... bench:     213,605 ns/iter (+/- 1,806) = 306 MB/s
  test sha512_256::benches::sha512_256_10           ... bench:          27 ns/iter (+/- 1) = 370 MB/s
  test sha512_256::benches::sha512_256_1k           ... bench:       2,196 ns/iter (+/- 12) = 466 MB/s
  test sha512_256::benches::sha512_256_64k          ... bench:     140,552 ns/iter (+/- 777) = 466 MB/s
  ```

  One caveat is that I could not get hongfuzz to build locally so I couldn't test the fuzz on my machine. I ended up only testing through the CI for the fuzz tests.

  I thought adding a completely separate file was the easiest and the most straightforward way of implementing it. I'm very much open to changing the implementation if you guys don't think this is the right direction.

ACKs for top commit:
  sanket1729:
    ACK 411174c391. Reviwed range diff from 43feb9ea7b282d9119708a27fa7a1c7412d1386a that I had ACked
  apoelstra:
    ACK 411174c391

Tree-SHA512: 98298a7c177cbb616bfbc02cec5c5860f10204df8275cc9f1e4ea07333b901095e574fbc3fe0a03375e0d321a1579e2c2023a5c14addd863e10cc927f155710c
2022-12-31 19:38:02 +00:00
..
cmp.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
error.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
hash160.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
hex.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
hmac.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
impls.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
internal_macros.rs Use hex from internals rather than hashes 2022-12-22 10:44:27 +01:00
lib.rs Merge rust-bitcoin/rust-bitcoin#1413: Add sha512_256 to bitcoin_hashes 2022-12-31 19:38:02 +00:00
ripemd160.rs Fix new clippy warnings 2022-12-01 15:59:08 -08:00
serde_macros.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
sha1.rs Fix new clippy warnings 2022-12-01 15:59:08 -08:00
sha256.rs Use hex from internals rather than hashes 2022-12-22 10:44:27 +01:00
sha256d.rs Fix new clippy warnings 2022-12-01 15:59:08 -08:00
sha256t.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
sha512.rs Merge rust-bitcoin/rust-bitcoin#1413: Add sha512_256 to bitcoin_hashes 2022-12-31 19:38:02 +00:00
sha512_256.rs Add support for sha512/256 2022-12-21 16:36:31 +09:00
siphash24.rs Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
util.rs Use hex from internals rather than hashes 2022-12-22 10:44:27 +01:00