rust-bitcoin-unsafe-fast/hashes
Andrew Poelstra d06bb226bf
Merge rust-bitcoin/rust-bitcoin#1476: Use hex from internals rather than hashes
3e520f9094 Use hex from internals rather than hashes (Martin Habovstiak)

Pull request description:

  `bitcoin-internals` contains a more performant implementation of hex encoding than what `bitcoin_hashes` uses internally. This switches the implementations for formatting trait implementations as a step towards moving over completely.

  The public macros are also changed to delegate to inner type which is technically a breaking change but we will break the API anyway and the consuers should only call the macro on the actual hash newtypes where the inner types already have the appropriate implementations.

  Apart from removing reliance on internal hex from public API this reduces duplicated code generated and compiled. E.g. if you created 10 hash newtypes of SHA256 the formatting implementation would be instantiated 11 times despite being the same.

  To do all this some other changes were required to the hex infrastructure. Mainly modifying `put_bytes` to accept iterator (so that `iter().rev()` can be used) and adding a new `DisplayArray` type. The iterator idea was invented by Tobin C. Harding, this commit just adds a bound check and generalizes over `u8` and `&u8` returning iterators.

  While it may seem that `DisplayByteSlice` would suffice it'd create and initialize a large array even for small arrays wasting performance. Knowing the exact length `DisplayArray` fixes this.

  Another part of refactoring is changing from returning `impl Display` to return `impl LowerHex + UpperHex`. This makes selecting casing less annoying since the consumer no longer needs to import `Case` without cluttering the API with convenience methods.

ACKs for top commit:
  tcharding:
    ACK 3e520f9094
  apoelstra:
    ACK 3e520f9094

Tree-SHA512: 62988cec17550ed35990386e572c0d32dc7107e1c36b7c9099080747e15167e6d66497fb300178afbd22481c0360a6b7a1228fd09402d4ce5d295a8594c02aa6
2022-12-31 19:17:32 +00:00
..
contrib Merge rust-bitcoin/rust-bitcoin#1468: hashes: ci: Remove --all 2022-12-30 17:21:39 +00:00
embedded Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
extended_tests/schemars Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
fuzz Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
src Merge rust-bitcoin/rust-bitcoin#1476: Use hex from internals rather than hashes 2022-12-31 19:17:32 +00:00
CHANGELOG.md Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00
Cargo.toml Use hex from internals rather than hashes 2022-12-22 10:44:27 +01:00
README.md Import bitcoin_hashes crate into hashes 2022-11-08 08:58:09 +11:00

README.md

Status

Bitcoin Hashes Library

This is a simple, no-dependency library which implements the hash functions needed by Bitcoin. These are SHA1, SHA256, SHA256d, SHA512, and RIPEMD160. As an ancilliary thing, it exposes hexadecimal serialization and deserialization, since these are needed to display hashes anway.

Documentation

Minimum Supported Rust Version (MSRV)

This library should always compile with any combination of features on Rust 1.41.1.

Contributions

Contributions are welcome, including additional hash function implementations.

Githooks

To assist devs in catching errors before running CI we provide some githooks. If you do not already have locally configured githooks you can use the ones in this repository by running, in the root directory of the repository:

git config --local core.hooksPath githooks/

Alternatively add symlinks in your .git/hooks directory to any of the githooks we provide.

Running Benchmarks

We use a custom Rust compiler configuration conditional to guard the bench mark code. To run the bench marks use: RUSTFLAGS='--cfg=bench' cargo +nightly bench.