Python 3.6+hashlibfunction
hashlib.blake2b()
hashing
The BLAKE2b hash: up to 64 bytes of output, faster than SHA-2 on 64-bit CPUs. It can hash with a key, a salt and a chosen length without a separate hmac.
Syntax
hashlib.blake2b(data=b'', *, digest_size=64, key=b'', salt=b'', person=b'')
digest_size is part of the algorithm parameters, so blake2b(digest_size=16) is not the beginning of the 64-byte hash but a different value; you cannot truncate a long digest instead of passing digest_size. With key=b'...' you get a ready message authentication code, equivalent to HMAC but faster. Every parameter except data is keyword-only.
Examples
import hashlib
print(hashlib.blake2b(b'abc').hexdigest()[:16]) # → ba80a53f981c4d0d
print(hashlib.blake2b(b'abc', digest_size=16).hexdigest()) # → cf4ab791c62b8d2b2109c90275287816
import hashlib
tag = hashlib.blake2b(b'abc', key=b'secret', digest_size=16)
print(tag.hexdigest()) # → b728f0c8cb10089e9c7b3549c0cdea97
See also
Open in the full glossarydocs.python.orgReport an inaccuracy