New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sha256t_hash_newtype!
evocative of the output.
#1773
Conversation
Computing hashes in const fn is useful for esily creating tags for `sha256t`. This adds `const fn` implementation for `sha256::Hash` and the algorithm for computing midstate of tagged hash in `const` context. Part of rust-bitcoin#1427
The Rust API guidelines state that macros should be evocative of the output, which is a sensible recommendation. We already had this for `hash_newtype!` macro but didn't for sha256t version. This changes the macro to have this syntax: ```rust sha256t_hash_newtype! { // Order of these structs is fixed. /// Optional documentation details here. Summary is auto-generated. /*pub*/ struct Tag = raw(MIDSTATE_BYTES, LEN); /// Documentation here #[hash_newtype(forward)] // optional, default is backward /*pub*/ struct HashType(/* attributes allowed here */ _); } ``` Closes rust-bitcoin#1427
Previous changes enabled passing the string used as a tag into `sha256t_hash_newtype!` macro rather than hard-coding midstate. This commit takes advantage of it and replaces the hard-coded values with compile-time executed (`const`) hashing.
f0c0991
to
91f45a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 91f45a2
Cool. |
I think #1758 will fix the CI fail. |
Looks good to me. I kinda think they should be renamed as
But I'm not gonna hold up the PR over these. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 91f45a2
LOL, you merged it already. OK I guess. :) Regarding naming, all of them are IVs, so telling what's specific about them seems better. Mentioning BIP-340 sounds good. Byte version was added just in case something comes up in the future. Maybe just |
@Kixunil Yes, yes, sorry for going ahead and merging -- the PR seemed reasonably large and conflict-prone, and the naming unimportant enough that it could get slipped, that I figured it'd be nicer to do the renaming (if we decided to) in a different PR. |
The Rust API guidelines state that macros should be evocative of the
output, which is a sensible recommendation. We already had this for
hash_newtype!
macro but didn't for sha256t version.This changes the macro to have this syntax:
Closes #1427
Depends on #1769
How do you like the syntax? Is weird
struct Foo = bar(..);
acceptable?