Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. $ export PYTHONHASHSEED=12345
  2. $ python3 -c 'import sys, os;print(sys.flags.hash_randomization, os.environ.get("PYTHONHASHSEED"))'
  3. 12345 12345
  4.  
  5. $ export PYTHONHASHSEED=random
  6. $ python3 -c 'import sys, os;print(sys.flags.hash_randomization, os.environ.get("PYTHONHASHSEED"))'
  7. 1 random
  8.  
  9. from ctypes import (
  10. c_size_t,
  11. c_ubyte,
  12. c_uint64,
  13. pythonapi,
  14. Structure,
  15. Union,
  16. )
  17.  
  18.  
  19. class FNV(Structure):
  20. _fields_ = [
  21. ('prefix', c_size_t),
  22. ('suffix', c_size_t)
  23. ]
  24.  
  25.  
  26. class SIPHASH(Structure):
  27. _fields_ = [
  28. ('k0', c_uint64),
  29. ('k1', c_uint64),
  30. ]
  31.  
  32.  
  33. class DJBX33A(Structure):
  34. _fields_ = [
  35. ('padding', c_ubyte * 16),
  36. ('suffix', c_size_t),
  37. ]
  38.  
  39.  
  40. class EXPAT(Structure):
  41. _fields_ = [
  42. ('padding', c_ubyte * 16),
  43. ('hashsalt', c_size_t),
  44. ]
  45.  
  46.  
  47. class _Py_HashSecret_t(Union):
  48. _fields_ = [
  49. # ensure 24 bytes
  50. ('uc', c_ubyte * 24),
  51. # two Py_hash_t for FNV
  52. ('fnv', FNV),
  53. # two uint64 for SipHash24
  54. ('siphash', SIPHASH),
  55. # a different (!) Py_hash_t for small string optimization
  56. ('djbx33a', DJBX33A),
  57. ('expat', EXPAT),
  58. ]
  59.  
  60.  
  61. hashsecret = _Py_HashSecret_t.in_dll(pythonapi, '_Py_HashSecret')
  62. hashseed = bytes(hashsecret.uc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement