Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ export PYTHONHASHSEED=12345
- $ python3 -c 'import sys, os;print(sys.flags.hash_randomization, os.environ.get("PYTHONHASHSEED"))'
- 12345 12345
- $ export PYTHONHASHSEED=random
- $ python3 -c 'import sys, os;print(sys.flags.hash_randomization, os.environ.get("PYTHONHASHSEED"))'
- 1 random
- from ctypes import (
- c_size_t,
- c_ubyte,
- c_uint64,
- pythonapi,
- Structure,
- Union,
- )
- class FNV(Structure):
- _fields_ = [
- ('prefix', c_size_t),
- ('suffix', c_size_t)
- ]
- class SIPHASH(Structure):
- _fields_ = [
- ('k0', c_uint64),
- ('k1', c_uint64),
- ]
- class DJBX33A(Structure):
- _fields_ = [
- ('padding', c_ubyte * 16),
- ('suffix', c_size_t),
- ]
- class EXPAT(Structure):
- _fields_ = [
- ('padding', c_ubyte * 16),
- ('hashsalt', c_size_t),
- ]
- class _Py_HashSecret_t(Union):
- _fields_ = [
- # ensure 24 bytes
- ('uc', c_ubyte * 24),
- # two Py_hash_t for FNV
- ('fnv', FNV),
- # two uint64 for SipHash24
- ('siphash', SIPHASH),
- # a different (!) Py_hash_t for small string optimization
- ('djbx33a', DJBX33A),
- ('expat', EXPAT),
- ]
- hashsecret = _Py_HashSecret_t.in_dll(pythonapi, '_Py_HashSecret')
- hashseed = bytes(hashsecret.uc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement