multihash icon indicating copy to clipboard operation
multihash copied to clipboard

fncode with size of the hash output is not unique

Open benrayfield opened this issue 6 years ago • 1 comments

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?

benrayfield avatar Dec 09 '17 14:12 benrayfield

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.

ghost avatar Dec 10 '17 04:12 ghost