Skip to content

oconnor663/pure_python_blake3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pure Python BLAKE3 Actions Status

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

import pure_blake3

# regular hashing
hasher1 = pure_blake3.Hasher()
hasher1.update(b"foobarbaz")
output1 = hasher1.finalize()

# regular hashing in multiple steps
hasher2 = pure_blake3.Hasher()
hasher2.update(b"foo")
hasher2.update(b"bar")
hasher2.update(b"baz")
output2 = hasher2.finalize()
assert output2 == output1

# extendable output
hasher3 = pure_blake3.Hasher()
hasher3.update(b"foobarbaz")
output3 = hasher3.finalize(100)
assert output3[:32] == output2

# keyed hashing
import secrets
random_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 derivation
context_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()

About

a pure Python implementation of BLAKE3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages