Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I manufacture pathological keys for a hash?

Tags:

hash

perl

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.

like image 371
Chas. Owens Avatar asked Jul 17 '11 13:07

Chas. Owens


People also ask

How are hash keys generated?

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).

Does hash function generate keys?

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.

What are the key requirements of a hash function?

A cryptographic hash function must satisfy three criteria: Preimage resistance. Second preimage resistance (weak collision resistance) Strong collision resistance.

Which algorithms can be used to generate a hash?

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.


1 Answers

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.

like image 174
hobbs Avatar answered Nov 03 '22 04:11

hobbs