oconnor663 / blake3-py

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

[Enhancement] - More bytes for random_key. #36

Closed therealOri closed 1 year ago

therealOri commented 2 years ago

It'd be nice if I/we could use more than just 32 bytes for the creation of a random key.

I'm not sure if it is possible but I'd like to chose as many bytes as I want.

oconnor663 commented 2 years ago

Could you say a little more? Are you asking about the size of the key parameter or the size of the output? The former is defined to always be 32 bytes in the BLAKE3 spec, but the latter can be as large as you want, using the length parameter.

therealOri commented 2 years ago

Could you say a little more? Are you asking about the size of the key parameter or the size of the output? The former is defined to always be 32 bytes in the BLAKE3 spec, but the latter can be as large as you want, using the length parameter.

I mean the size of the key parameter. (keyed hashing mode) The output length of the hash is fine and all that. I just would like to give idk say 64 random bytes (or more) for it to use...instead of just 32. Like I said, idk if that can be done or where that would be handled.

And now that you are saying it is defined to always be 32 bytes makes me think increasing the amount/size isn't going to be a thing. Unless we change how blake3 does what it does.

Anyways, it'd be neat.

oconnor663 commented 2 years ago

Right, the key parameter is the same size as a "chaining value" in BLAKE3, so changing it would pretty much mean designing an entirely new hash function. That said, it's totally reasonable to use the 32-byte hash of a larger value as your key. You could do this with the regular BLAKE3 hash() function, or if you wanted to mix in a context string you could use derive_key(). 32 bytes is large enough that you should never have to worry about two different longer inputs resulting in the same hash. This is called "collision resistance", and it's one of the most important properties of any secure hash function.