def test_fix_seed(): old_val = os.environ.get('PYTHONHASHSEED', None) try: os.environ['PYTHONHASHSEED'] = '0' initialize_from_env() assert siphash24("foo") == 15988776847138518036 # value checked with CPython 3.5 (turned positive by adding 2**64) os.environ['PYTHONHASHSEED'] = '4000000000' initialize_from_env() assert siphash24("foo") == 13829150778707464258 # value checked with CPython 3.5 (turned positive by adding 2**64) for env in ['', 'random']: os.environ['PYTHONHASHSEED'] = env initialize_from_env() hash1 = siphash24("foo") initialize_from_env() hash2 = siphash24("foo") assert hash1 != hash2 # extremely unlikely finally: if old_val is None: del os.environ['PYTHONHASHSEED'] else: os.environ['PYTHONHASHSEED'] = old_val
def check(s): q = rffi.str2charp('?' + s) with choosen_seed(0x8a9f065a358479f4, 0x11cb1e9ee7f40e1f, test_misaligned_path=True): x = siphash24(s) y = _siphash24(llmemory.cast_ptr_to_adr(rffi.ptradd(q, 1)), len(s)) rffi.free_charp(q) assert x == y return x