You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project is a pure Python implementations of the BLAKE3 cryptographic hash
function. It's intended for educational and testing use only. It's too slow for
production use, and it hasn't been audited. If you're writing production Python
code, see the blake3 module, which
provides bindings for the high-performance Rust implementation.
This a direct port of the Rust reference
implementation.
It supports all the features of BLAKE3, including keyed hashing, key
derivation, and extendable output. Python 3.8 or later is required.
Examples
importpure_blake3# regular hashinghasher1=pure_blake3.Hasher()
hasher1.update(b"foobarbaz")
output1=hasher1.finalize()
# regular hashing in multiple stepshasher2=pure_blake3.Hasher()
hasher2.update(b"foo")
hasher2.update(b"bar")
hasher2.update(b"baz")
output2=hasher2.finalize()
assertoutput2==output1# extendable outputhasher3=pure_blake3.Hasher()
hasher3.update(b"foobarbaz")
output3=hasher3.finalize(100)
assertoutput3[:32] ==output2# keyed hashingimportsecretsrandom_key=secrets.token_bytes(32)
message=b"a message to authenticate"keyed_hasher=pure_blake3.Hasher.new_keyed(random_key)
keyed_hasher.update(message)
mac=keyed_hasher.finalize()
# key derivationcontext_string="pure_blake3 2021-10-29 18:37:44 example context"key_material=b"usually at least 32 random bytes, not a password"kdf=pure_blake3.Hasher.new_derive_key(context_string)
kdf.update(key_material)
derived_key=kdf.finalize()