I am trying to trigger the hash randomization feature in Perl 5.8.2 and later. To do this, I need a set of keys that would be pathological but for the randomization feature. I tried using MJD's code
, but that didn't work. And, now that I look at it, I shouldn't be surprised. It comes from 1997, and we have switched hashing functions since then.
Does anyone know of a set of pathological keys, or how to generate them? I guess I should just go look at the hash function and reverse engineer a solution, but I am lazy.
Hashing involves applying a hashing algorithm to a data item, known as the hashing key, to create a hash value. Hashing algorithms take a large range of values (such as all possible strings or all possible files) and map them onto a smaller set of values (such as a 128 bit number).
Overview. A hash function takes a key as an input, which is associated with a datum or record and used to identify it to the data storage and retrieval application. The keys may be fixed length, like an integer, or variable length, like a name. In some cases, the key is the datum itself.
A cryptographic hash function must satisfy three criteria: Preimage resistance. Second preimage resistance (weak collision resistance) Strong collision resistance.
Some common hashing algorithms include MD5, SHA-1, SHA-2, NTLM, and LANMAN. MD5: This is the fifth version of the Message Digest algorithm. MD5 creates 128-bit outputs. MD5 was a very commonly used hashing algorithm.
Note: this information is valid for perl between 5.8.2 and 5.17.x. Beginning with perl 5.18, perl uses a new hash algorithm, hash randomization occurs on every startup (instead of only when a pathological hash is detected), and PERL_HASH_SEED
is interpreted differently. As perl now uses a 128-bit hash seed, the "pathological hash" condition should be almost impossible to trigger intentionally.
Original answer: If you force the hash seed to 0 by putting PERL_HASH_SEED=0
in the environment before perl starts, the collection of keys "\0"
, "\0\0"
, "\0\0\0"
, etc. will cause every key to land in hash bucket 0 with current perls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With