oconnor663 / blake3-py

Python bindings for the BLAKE3 cryptographic hash function
Other
139 stars 12 forks source link

64 byte hash with blake3 #6

Closed SmithSamuelM closed 4 years ago

SmithSamuelM commented 4 years ago

How do I use this library to create a 64 byte (or any other size) hash with blake3 or am I always limited to 32 bytes. I thought Blake3 supported configurable hash sizes like blake2b.

oconnor663 commented 4 years ago

Yes you can! See the "extendable output" part of the README example:

# Extendable output. The default OUT_LEN is 32 bytes.
extended = blake3(b"foo").digest(length=100)
assert extended[:OUT_LEN] == blake3(b"foo").digest()
assert extended[75:100] == blake3(b"foo").digest(length=25, seek=75)
SmithSamuelM commented 4 years ago

Thanks. So when using “seek” it computes a seek plus length digest and then just returns the chunk at seek of length? Any other undocumented functionality?

oconnor663 commented 4 years ago

Depends on what you mean by undocumented :) Every feature in the library is demonstrated in that README example, but there is no other documentation.

The idea of seek and length is this: length says how many hash bytes you want in the hash. Normally these bytes come from the start of the output stream, which we call offset 0. If you use the seek parameter, though, you can specify a different offset. So in this case, .digest(length=25, seek=75) means "give me 25 bytes of output, starting at index 75 in the output stream".