hash2curve: move oversized DST requirements to runtime errors #1901
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces two changes:
DST
s. Now these requirements are checked on runtime. While this is unfortunate, the currently limitations simply was that usage with regular sizedDST
s incurred limitations that were not necessary.len_in_bytes
fromNonZero<usize>
toNonZero<u16>
. This isn't a big improvement because the error is just moved fromexpand_msg()
to the variousGroupDigest
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:
In summary, we could cache this part:
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 aBlockSize
full of zeros that has been computed at compile-time. Which would also require no changes to the API except binding to this trait.