add value and type constructors for variable-length buffers and sha256 ctx8#372
Open
apoelstra wants to merge 5 commits into
Open
add value and type constructors for variable-length buffers and sha256 ctx8#372apoelstra wants to merge 5 commits into
apoelstra wants to merge 5 commits into
Conversation
The core::array::from_fn has been stable since Rust 1.63. We can use this to build an array, rather than constructing a vector, converting it to an arary, and unwrapping the conversion. This saves an allocation, eliminates a panic path, and (IMHO) makes the code easier to read. I need to duplicate this logic for the buffer type in the next commit, so I figured I should first clean it up.
This function panics if given an n which is out of range. This is arguably fine but we might as well return a Result, which gives the user the choice of whether or not to panic. Because the overwhelming number of calls in this codebase provide a fixed compile-time constant, also add a Final::two_two_n_fixed method which takes a complie-time constant and fails to compile if it's out of range.
Add precomputation tables for both `Tmr` and `Final`. Write a unit test which does a direct computation of the type and verifies all the precomp vectors. Also check against the Ctx8 output type of the sha256 init jet. Don't provide a Final::buffer8_two_n_plus_one_fixed function that avoids the Result by doing a compile-time check. It seems unlikely that this will be called with compile-time fixed values, except for the value 5 which is used in the Ctx8 type. But in the next commit we'll special-case Ctx8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 lays the groundwork for constructing and manipulating SHA256 contexts in an ergonomic way. This lets you construct variable-length buffers, and by producting those with a couple fixed-size words you can create a context. It also provides precomputed types for various sizes of buffers and
Ctx8itself.A later PR will implement conversions between these objects and Rust
sha256::Engineobjects, but this may require an update to bitcoin-hashes 1.0 so I am still working out how to do that.