libcrypto.hash¶
Cryptographic hash and key-derivation helpers. Standard hashes use hashlib;
Keccak-256 and the RIPEMD-160 fallback are pure-Python implementations shipped
inside the package. No external cryptography package is used.
Functions¶
| Function | Description |
|---|---|
sha256(data) -> bytes |
SHA-256 digest. |
sha512(data) -> bytes |
SHA-512 digest. |
double_sha256(data) -> bytes |
SHA256(SHA256(data)). |
ripemd160(data) -> bytes |
RIPEMD-160, using OpenSSL when available and the bundled pure-Python implementation otherwise. |
hash160(data) -> bytes |
RIPEMD160(SHA256(data)). |
keccak256(data) -> bytes |
True Keccak-256 (Ethereum/TRON/EVM). Never SHA3-256. |
hmac_sha512(key, message) -> bytes |
HMAC-SHA512. |
pbkdf2_hmac_sha512(password, salt, iterations, dk_length) -> bytes |
PBKDF2-HMAC-SHA512. |
bip39_pbkdf2(mnemonic, passphrase="") -> bytes |
BIP39 seed derivation (2048 iterations, 64-byte output). |
secure_random_bytes(n) -> bytes |
os.urandom(n) with validation. |
All functions validate that inputs are bytes and raise TypeError otherwise.
Keccak-256 vs SHA3-256¶
Ethereum, TRON, and EVM-compatible chains use the original Keccak padding byte
0x01, not the NIST SHA3 padding byte 0x06. keccak256 implements the former
and never falls back to hashlib.sha3_256, which would silently produce
wrong addresses.
from libcrypto.hash import keccak256
assert keccak256(b"").hex() == \
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"