Python Glossary Русский

Python 3.6+hashlibfunction

hashlib.blake2s()

hashing

The BLAKE2s hash: up to 32 bytes of output, tuned for 8- to 32-bit processors. The parameters match blake2b(), but key and salt limits are half as large.

Syntax

hashlib.blake2s(data=b'', *, digest_size=32, key=b'', salt=b'', person=b'')

On an ordinary 64-bit computer blake2b() is faster, so blake2s() is chosen for a short output or weak hardware. Limits: key up to 32 bytes, salt and person up to 8; anything longer raises ValueError. A short salt is padded with zeros, so salt=b'salt' and salt=b'salt\x00' give the same hash — this does not hold for the key.

Examples

import hashlib
print(hashlib.blake2s(b'abc').hexdigest()[:16])  # → 508c5e8c327c14e2
print(hashlib.blake2s.MAX_KEY_SIZE, hashlib.blake2s.SALT_SIZE)  # → 32 8
import hashlib
try:
    hashlib.blake2s(b'abc', key=b'x' * 33)
except ValueError as e:
    print(e)  # → maximum key length is 32 bytes

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy