3 ms·
In the case of Python, for certain built-in types, __hash__() combines information about the object with a salt value. The salt can be manually forced by an env
by ubernostrum 9y ago
In the case of Python, for certain built-in types, __hash__() combines information about the object with a salt value. The salt can be manually forced by an environment variable, but if not supplied that way will be randomly chosen on interpreter startup.
The result is consistent hashing within a given interpreter process, but unpredictability across multiple processes/invocations, which is what's needed to avoid a denial-of-service vector created by predictable hash values for built-in types.
- ninkendo 9y agoSalting isn’t what I mean by random, I mean literally having the hash value have nothing to do with the item you’re hashing. Either way, terminology is weird here, but it seems like in V8’s case the word “hashing” better describes what happens to the hash code when the hashtable algorithm decides what bucket to place the object in (likely a modulus operator or a bit shift), at which point the “hash code” isn’t a hash value at all but just a unique ID that’s a seed value for the real hash function... but again, terminology can be misleading.
- ubernostrum 9y agoI was pointing it out because the feature is called "hash randomization".