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

perf: Amortise cost of make_secret for RandomWyHashState #12

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

Bluefinger
Copy link
Owner

This PR introduces a performance optimisation for fully_randomised_wyhash, where new random secrets are instead generated once per runtime and then reused for all RandomWyHashStates. Each RandomWyHashState will still have unique/random seeds, just that the secret is now shared. While this reduces the security/entropy between each instance, it shouldn't matter as it is unlikely if ever that different hashers are being compared directly against each other. As long as the secret is new per runtime, this should be sufficient to avoid DOS/prediction attacks. However, if one really desires that extra assurance, I've made make_secret public as well as methods to accept a secrets array.

Providing this optimisation requires the MSRV to be raised to 1.70.0, and also requires the feature fully_randomised_wyhash to be for std only. make_secret being pub now plus additional methods should allow for no_std use-cases to still be considered, though it is up to the user to ensure it is used correctly.

Closes #11

@Bluefinger Bluefinger added the enhancement New feature or request label Apr 16, 2024
@@ -85,7 +86,7 @@ impl WyHash {
#[inline]
fn consume_bytes(&self, bytes: &[u8]) -> (u64, u64, u64) {
let length = bytes.len();
if length <= 0 {
if length == 0 {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this because Clippy got mad at me

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that's a reason to never do that again. I'll keep that in mind for the future, lol.

@Bluefinger Bluefinger merged commit 34512d3 into main Apr 17, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amortise the cost of make_secret for fully_randomised_wyhash feature
2 participants