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

Secret seeds and primes #139

Open
tansy opened this issue Oct 5, 2023 · 4 comments
Open

Secret seeds and primes #139

tansy opened this issue Oct 5, 2023 · 4 comments

Comments

@tansy
Copy link
Contributor

tansy commented Oct 5, 2023

First a question - as far as I understand these secret seeds are meant to be primes. Why is that, or where can I read about that?

Now to the point.
You said that secret seeds are more balanced. What you mean by that?

Also checking 2^32 division reminders is rather ineffective. checking 2^64 - 59 took me, literally 99 seconds.
There is this algorithm - Miller-Rabin primality test, that checks it in 1.3 s, and all four wyhash secret's seeds in 1.03 ms, yes millisecond. There is, not only one, example of it here (last C version).

@wangyi-fudan
Copy link
Owner

The secrets should be prime. because in wyrand, we add the secret to the seed. a prime secret ensure that the period is 2^64. For other part of wyhash library, it is a "feeling to be perfect". And non-prime secret seem to fail smhasher.
A balanced secret meant all its 8 bytes have popcount==4. The early version of secret are popcount==32 for the whole seed which is not fully balanced.
Thank you for your Miller-Rabin primality test. I am looking for the code. However, I need some time to port it to wyhash.
usually, we generate secret offline and hard code it to the .h file. A de novo make_secret is indeed time consuming. That's why someone propose a PR to remove the prime-test. And I didn't notice this change. Now, the prime-test is back as normal and intended.

@wangyi-fudan
Copy link
Owner

Miller-Rabin test is done by copying :-)

@wangyi-fudan
Copy link
Owner

The cleaned code for Miller Rabin test is available here https://github.com/wangyi-fudan/MillerRabin64

@tansy
Copy link
Contributor Author

tansy commented Oct 5, 2023

However, I need some time to port it to wyhash.
usually, we generate secret offline and hard code it to the .h file

It could be in separate tool/file. I already proposed it with hash map (#120). I don't get why would it have to be in hash itself. If you just mentioned in the hash that secret was generated with function moved to make-secret.c it would be fine and everyone wanting to dig it further would find the tool and used it.

May I propose PR #140 that does that.

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

No branches or pull requests

2 participants