Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Add tagged SHA-256 hash module #4

Merged
merged 5 commits into from
May 14, 2024
Merged

Add tagged SHA-256 hash module #4

merged 5 commits into from
May 14, 2024

Conversation

tcharding
Copy link
Owner

The bitcoin_hashes module supports domain separation by way of the sha256t module, this crate currently does not - that is a regression.

Introduce tagged SHA-256 hashes. First import the code from rust-bitcoin then add the tag to the engine as well as the Hash.

@tcharding tcharding force-pushed the 05-13-tagged branch 3 times, most recently from e90c964 to a2f5b0f Compare May 14, 2024 02:36
We do not need a variable for `$hash` in the `hash_trait_imlps`. This
patch reverts back to how this was in `rust-bitcoin` sans the generics.

Refactor only, no logic changes.
Turns out we do need generics on the `hash_trait_impls` macro. This
patch reverts back to how this was in `rust-bitcoin` sans the generics.
The `AsRef<[u8]` trait better describes the functionality we are trying
to provide - a reference to the underlying byte array.
Import the `sha256t` type from `rust-bitcoin` excluding the macro
`sha256t_hash_newtype.` Patch the imported code to fit in with the
current design of this crate, requires:

- Add inherent methods instead of using the `Hash` trait.
- Mimic API of other hash types.
Currently the `sha256t` module uses an alias to the
`sha256::HashEngine`, this is a footgun because if a user accidentally
uses the `sha256t` module the same way as the other hash modules they
will get the wrong engine. For example this code looks fine but is
buggy (it does not pre-tag the engine):

```
 let mut engine = sha256t::HashEngine::new();  // Or `default()`.
 engine.input(some_data);
 let hash = engine.finalize();
```

We can fix the situation by adding a `HashEngine<T>` type to the
`sha256t` module and implementing `Default` for it by calling the
`Tag::engine` function.
@tcharding tcharding merged commit 5054272 into master May 14, 2024
11 checks passed
@tcharding tcharding deleted the 05-13-tagged branch May 14, 2024 08:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant