Skip to content

Update to hash2curve changes #1256

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

Closed
wants to merge 1 commit into from

Conversation

daxpedda
Copy link
Contributor

Companion PR to RustCrypto/traits#1901.

tarcieri pushed a commit to RustCrypto/traits that referenced this pull request Jun 13, 2025
This PR introduces two changes:
- Remove requirements that were only relevant for oversized `DST`s. Now
these requirements are checked on runtime. While this is unfortunate,
the currently limitations simply was that usage with regular sized
`DST`s incurred limitations that were not necessary.
- Change `len_in_bytes` from `NonZero<usize>` to `NonZero<u16>`. This
isn't a big improvement because the error is just moved from
`expand_msg()` to the various `GroupDigest` methods.

Companion PR: RustCrypto/elliptic-curves#1256.

---
I know I have been refactoring this API over and over again, but I
actually think this is the last of it (apart from
#872 with
`generic_const_exprs`).

But for completions sake I want to mention the following [from the
spec](https://www.rfc-editor.org/rfc/rfc9380.html#section-5.3.1-8):
> It is possible, however, to entirely avoid this overhead by taking
advantage of the fact that Z_pad depends only on H, and not on the
arguments to expand_message_xmd. To do so, first precompute and save the
internal state of H after ingesting Z_pad. Then, when computing b_0,
initialize H using the saved state. Further details are implementation
dependent and are beyond the scope of this document.

In summary, we could cache this part:
```rust
let mut b_0 = HashT::default();
b_0.update(&Array::<u8, HashT::BlockSize>::default());
```
Doing this requires passing `ExpandMsg` state, which would change the
entire API having to add a parameter to every function.

However, as the spec mentions, the cost of not caching it is most likely
negligible. We will see in the future if this shows up in benchmarks and
if it does we can re-evaluate. I don't believe this will be the case
though.

Alternatively, we could add a trait to `digest` which allows users to
construct a hash prefixed with a `BlockSize` full of zeros that has been
computed at compile-time. Which would also require no changes to the API
except binding to this trait.
@daxpedda daxpedda force-pushed the hash2curve-update-4 branch from 66d4140 to 6ef0abd Compare June 13, 2025 21:06
@daxpedda daxpedda marked this pull request as ready for review June 13, 2025 21:06
@daxpedda daxpedda mentioned this pull request Jun 13, 2025
@daxpedda
Copy link
Contributor Author

Closing in favor of #1257.

@daxpedda daxpedda closed this Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant