Python Glossary Русский

Python 3.6+hashlibfunction

hashlib.sha3_384()

hashing

The SHA3-384 hash (SHA-3 family, Keccak): 48 bytes, 96 hex digits. Same length as SHA-384, but a different algorithm.

Syntax

hashlib.sha3_384(data=b'', *, usedforsecurity=True)

SHA-3 is built differently from SHA-2 (a sponge instead of the Merkle-Damgard construction), so sha3_384() and sha384() give different values, and SHA-3 has no length-extension attack. A trap when matching other systems: Ethereum and some libraries call the original Keccak "keccak256", which is not the standardized SHA3-256 — the hashes will not match. Pick it when a format demands SHA3-384.

Examples

import hashlib
h = hashlib.sha3_384(b'abc')
print(h.hexdigest()[:16])  # → ec01498288516fc9
print(h.digest_size, h.block_size)  # → 48 104
import hashlib
a = hashlib.sha3_384(b'abc').hexdigest()
b = hashlib.sha384(b'abc').hexdigest()
print(len(a) == len(b), a == b)  # → True False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy