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
Open
@markkawika

Description

@markkawika

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0