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

fncode with size of the hash output is not unique #87

Open
benrayfield opened this issue Dec 9, 2017 · 1 comment
Open

fncode with size of the hash output is not unique #87

benrayfield opened this issue Dec 9, 2017 · 1 comment

Comments

@benrayfield
Copy link

https://github.com/multiformats/multihash/blob/master/hashtable.csv says:
blake2s-256 0xb260
blake2b-256 0xb220

blake2s-256 and blake2b-256 for the same input generate different hashcodes of the same size but have the same fncode 0xb2 and different digsize than their lengths which are both 0x20.

This may be ok for people who store a table of 2 byte codes that each map to a function name and output size, but it does not work for my usecase of only fncode and store size in my own data format which is more general than hashes. I therefore cant use fncode with the actual output size because its not unique and will have to make my own table of fncodes.

Do the hash functions have more parameters than I'm considering? Why is it done this way? Or is the csv file wrong?

@ghost
Copy link

ghost commented Dec 10, 2017

The hash function code is represented in binary as a varint -- compliant multihash implementations will correctly parse 0xb260 (and 0xb220) as the hash function code, not 0xb2. The length of the hash is a separate varint.

In your system, you'd need to use 2 bytes (or 4, or ideally a varint) for storing the hash function code.

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

1 participant