SHA-3 (Keccak) for Python

1.0.5 · active · verified Thu Apr 16

safe-pysha3 is an actively maintained fork of `pysha3`, providing SHA-3 (Keccak) hashing functionalities for Python versions 3.9 to 3.13. It wraps the optimized Keccak Code Package, offering FIPS202-compliant SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE128, SHAKE256, and pre-NIST Keccak hashes. This library ensures compatibility with modern Python versions and incorporates critical security fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to calculate SHA3-256 and SHAKE-128 hashes using the standard `hashlib` interface, which `safe-pysha3` extends. It also shows how to access the `keccak_512` function directly for pre-NIST Keccak hashes.

import hashlib

data = b"Hello, safe-pysha3!"

# Calculate SHA3-256 hash
sha3_256_hasher = hashlib.sha3_256()
sha3_256_hasher.update(data)
print(f"SHA3-256: {sha3_256_hasher.hexdigest()}")

# Calculate SHAKE-128 hash with 32-byte output
shake_128_hasher = hashlib.shake_128()
shake_128_hasher.update(data)
print(f"SHAKE-128 (32 bytes): {shake_128_hasher.hexdigest(32)}")

# Accessing a pre-NIST Keccak hash directly from sha3 module (if needed)
from sha3 import keccak_512
keccak_512_hasher = keccak_512()
keccak_512_hasher.update(data)
print(f"Keccak-512: {keccak_512_hasher.hexdigest()}")

view raw JSON →