-
Notifications
You must be signed in to change notification settings - Fork 215
Add FNV-1a hash function #505
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
Conversation
12730b2 to
ad46b9e
Compare
|
Ah, that's how you meant it (was unsure what and how much of the One main point: it needs a version for The implementation is a bit slow. You can do it in one loop and because using And as much as I hate to insist on it but we really need a complete unit test. Just a couple of |
0212975 to
911b6df
Compare
|
I updated the patch. Please, take a look at it. However, I am still not sure about some details e.g. signs handling and test cases. |
|
Looks good to me at first glance! |
58ef57e to
75fc980
Compare
|
Looks good to me, thanks for the work! Travis is still/again not working? Great! *sigh* |
sjaeckel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like where this is heading towards 👍
The only things I think we should take into account are that hashes should be stable for each MPI, i.e. the implementation should return the same results no matter what MP_DIGIT_BIT says. Or am I wrong there?
Also I can see the need for a smaller hash, so that's fine for me as well but that one should (maybe) also be stable independent of MP_DIGIT_BIT.
Maybe it'd make sense to have mp_hash32(mp_int *a, uint32_t *hash) and mp_hash64(mp_int *a, uint64_t *hash)?
Yeah, we should really put some effort into migrating away from travis, but I don't know where we should migrate to ... :( ... maybe GH actions? |
|
I thought that If we would have So I think the result of hashing and the size of hash (respectively type of algorithm) depends on platform. Please correct me if I understand something wrong. Also, the only reference for bignum hashing I found is CPython's longobject hashing and they use some small custom algorithm. |
Took a look. But there is documentation. Sort of. And it seems as if we could implement a Travis clone with it if I understood it correctly. There is a time limit of 3,000 minutes/month (of what? CPU time?) for free accounts (or is it?). Travis runs for about 10 CPU-minutes (hard to tell exactly, of course) with our long list of tests. That are about 300 tests per month and with the current method of one automatic test per commit, there is a chance of a DoS but I think that can be restricted. @urazoff You could take the Or you ask yourself if |
|
If you agree that it is impossible to do stable hashing (and I am not sure if it even could be needed in any case) using FNV then I think the patch is ready because I don't see why platform-dependent |
8c800e1 to
68d818b
Compare
This allows to compute non-cryptographic hash of mp_int which can be used as a key in a hash table.
|
Sorry for the long silence ... I hope you still have time&passion to follow up and finish this :)
Yeah, the same for me. Then I saw some examples of other projects and suddenly it wasn't that bad anymore :)
I agree that my previous point regarding stable hashing was more wish than reality. So yes, stable hashing doesn't make sense in this case/isn't possible/necessary and I think as well that the patch itself is ready, but CI says it isn't 😄 It's still missing documentation in
Would it be sufficient to describe what the function does and is useful for? or could this maybe also include some minimal abstract "real application" example? I started with this, feel free to improve&extend \section{Hashing}
To get a non-cryptographic hash of an \texttt{mp\_int} use the following function.
\index{mp\_hash}
\begin{alltt}
mp_err mp_hash (mp_int *a, mp_hval *hash);
\end{alltt}
This will create the hash of $a$ following the FNV-1a algorithm as described on
\url{http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-1a}.
NB: The hashing is not stable over different widths of an \texttt{mp\_digit}. |
|
Yes, I still have passion to finish this! I guess, it could be placed somewhere under chapter "Basic operations" as a section. May be it's sufficient to describe what the function does and is useful for so the description won't be too heavy. |
|
@czurnieden something to add to that documentation? If not I'll commit it and merge this PR soon'ish. |
|
@sjaeckel I think No, it's good, can go into |
Signed-off-by: Steffen Jaeckel <[email protected]>
This allows to compute non-cryptographic hash
of mp_int which can be used as a key in a hash table.