4 ms·
Does anyone have a link to the commit that fixed this? I'd be interesting in seeing the before and after.
by bmm6o 15y ago
Does anyone have a link to the commit that fixed this? I'd be interesting in seeing the before and after.
- ken 15y agoIt looks like most of it is in http://hg.python.org/cpython/rev/f4b7ecf8a5f8 http://hg.python.org/cpython/rev/f4b7ecf8a5f8
- obtu 15y agoThat's a lot of work to make os.urandom portable across all their platforms.
- bmm6o 15y agoFor anyone else that's curious, it's a pretty simple change: 23.1 --- a/Modules/datetimemodule.c 23.2 +++ b/Modules/datetimemodule.c 23.3 @@ -2566,10 +2566,12 @@ generic_hash(unsigned char *data, int len) 23.4 register long x; 23.5 23.6 p = (unsigned char *) data; 23.7 - x = *p << 7; 23.8 + x = _Py_HashSecret.prefix; 23.9 + x ^= *p << 7; 23.10 while (--len >= 0) 23.11 x = (1000003*x) ^ *p++; 23.12 x ^= len; 23.13 + x ^= _Py_HashSecret.suffix; 23.14 if (x == -1) 23.15 x = -2; The hash computation is initialized with a global random value, and a second one is xored in at the end. (-1 isn't allowed as a hash, since it's the sentinel value that indicates the hash hasn't been computed yet.)