slh-dsa: sha2: PK.Seed state caching
#1116
Merged
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 is meant to address issue #1035. It introduces an optimisation mentioned in section 8.1.6. of SPHINCS+ specification: caching the intermediate state during SHA-2 computations.
On my laptop, I observe an improvement in signing/verification time in the range of ~15-25% (using the
criterionbenchmark provided).In order to keep a unified interface between SLH-DSA instantiated with SHAKE or with SHA-2, the same cache mechanism is introduced for SHAKE256 computations. However, it is not expected to have any impact on the performance of SLH-DSA-SHAKE*.
The biggest change is that types implementing
HashSuiteare no longer zero-sized types and that some functions (the one benefitting from state caching) of the traitHashSuiteare now methods instead of just associated functions. This in turn means that all functions of subtraits (eg.HypertreeParamsorForsParams) using those methods are now also methods.Types implementing
HashSuitemust now implement a constructor,new_from_pk_seed, that is responsible for computing the cached state from the public seed. The public seed is no longer a parameter of cache-using methods (since they have access to the cached state through&self).As a side-effect of having a cached state, types implementing
HashSuitecan no longer use the derived macro forPartialEqandEq. Due to those macros not being "perfect derive", we still need them to implement those traits, even though they will never be actually used. I used theunreachable!macro in their implementations to avoid any potential use.Let me know if you have any remarks or suggestions.