8000 FNV value calculation is incorrect · Issue #4 · flier/pyfasthash · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FNV value calculation is incorrect #4

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

Open
markkawika opened this issue Nov 15, 2014 · 1 comment
Open

FNV value calculation is incorrect #4

markkawika opened this issue Nov 15, 2014 · 1 comment

Comments

@markkawika
Copy link

I ran a comparison of your implementation of fnv1a_32 against my own implementation, and yours has a bug. The specification calls for all multiplication to be performed modulo the size of the result. You don't do the modulus operation until after the full calculation is finished. If you run this on a 64-bit machine, the result is wrong.

You need to do something like "hash %= (2 ** 32);" after every multiplication operation to correct this problem.

I considered submitting a push request but the 64-bit code looks pretty hairy, especially the stuff that is meant to calculate the 64-bit checksum on a 32-bit machine. So I didn't want to attempt to patch it.

See here:

http://www.isthe.com/chongo/tech/comp/fnv/#FNV-param

Specifically, this bullet point:

o The multiplication is performed modulo 2^n where n is the bit length of hash.

Your implementation is incorrect.

@egtork
Copy link
egtork commented Dec 15, 2014

The pyfasthash library appears to use the reference implementation created by FNV's co-author at

http://www.isthe.com/chongo/tech/comp/fnv/#FNV-reference-source

The reference implementation on that site does not perform an explicit modulo operation either. I believe the modulo operation is implicit in fnv1a_32 due to the types being unsigned 32 bit integers.

If you believe this implementation is incorrect, can you provide the test data and results from your implementation to be tested directly against the reference implementation?

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

No branches or pull requests

3 participants
0