hashlib icon indicating copy to clipboard operation
hashlib copied to clipboard

How do you hash a file using hashlib's xxhash?

Open firasuke opened this issue 2 years ago • 2 comments

I am trying to use xxHash3 128 bits for hashing a file, I am using readFile but I am getting an incorrect checksum.

I also tried using streams with openFileStream and I am getting the same wrong checksum.

Any ideas?

firasuke avatar Mar 27 '23 00:03 firasuke

Here is what I am using:

...
import hashlib/misc/xxhash

proc verify*(file: string, checksum: string): bool =
    checksum == $count[XXHASH3_128](readFile(file))
...

Where file is a .tar.gz tarball (I'll be using make-4.4.tar.gz as an example.

I am using xxh128sum to get the expected checksum 15bf27bd70e74eb8c4f71a1028513adf, but the function above is returning a wrong checksum of faae50855f65ad63b1c4c71c19166a3c.

How can I fix this?

firasuke avatar Mar 29 '23 18:03 firasuke

Any updates to this?

firasuke avatar Feb 19 '24 14:02 firasuke

I was able to solve this by using xxhash.nim.

Closing..

firasuke avatar Sep 27 '24 11:09 firasuke