Improve key generation stack usage #87
Open
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 was an attempt to address #82, but after many tries, it turned out that manually re-using allocations usually made stack usage worse.
There are two things that can be salvaged from all these trials:
shake128we were always initializing fourKeccakStatestructs, even if we only need one, as is the case for on-the-fly sampling (and we don't have any parallelism to exploit on the IoT target anyway).PRFxNfor sampling ring elements, meaning we would sample a lot of randomness first and then generating ring elements from that. Splitting that up and sampling randomness for individual ring elements reduces stack usage in key generation by about 20%.In the course of these changes I removed the
Hashabstraction and we should usePortableHasheverywhere now.These are the measurements for stack usage:
and cycles: