Skip to content
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

Add procedures to initialize the hasher state #1311

Open
hackaugusto opened this issue Apr 25, 2024 · 2 comments
Open

Add procedures to initialize the hasher state #1311

hackaugusto opened this issue Apr 25, 2024 · 2 comments
Labels
stdlib Related to Miden standard library

Comments

@hackaugusto
Copy link
Contributor

We often write padw padw padw to initialize the hasher state on the stack. It would make the code easier to read and maintain if instead we had hasher::initialize.

Ideally we would have a initializer for each of the supported hashers in the stdlib. And a procedure to take care of initialize the state if the input requires padding.

@bobbinth
Copy link
Contributor

The no-padding case is pretty simple to handle (as you have done in #1313). The case when the number of elements is not a multiple of 8 (i.e., not a multiple of the rate), is more tricky and will actually differ between RPO and RPX. But the procedure could look something like:

#! Input: [num_elements]
#! Ouptut: [num_permutations, PERM, PERM, PERM, ...]
export.init_state

The idea is that it will take the number of elements to hash as input, set up the initial state correctly, and then return the state together with the number of permutations needed to hash the inputs. This num_permutations can then be used for a condition of a loop to absorb the input into the state (which we frequently do in practice).

@hackaugusto
Copy link
Contributor Author

For reference, here is an implementation along these lines, but instead of number of elements it uses number of words

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Related to Miden standard library
Projects
None yet
Development

No branches or pull requests

2 participants