How do I change the default ONE_AT_A_TIME_HARD hash function in Perl 5.18?

131 views Asked by At

I'm not really familiar with Perl, but I've been searching in the documentation and other sources without success for the last 2 days. In the documentation, it is written:

Perl v5.18 includes support for multiple hash functions, and changed the default (to ONE_AT_A_TIME_HARD), you can choose a different algorithm by defining a symbol at compile time. For a current list, consult the INSTALL document. Note that as of Perl v5.18 we can only recommend use of the default or SIPHASH. All the others are known to have security issues and are for research purposes only.

The thing is that neither in INSTALL document nor in other sources/sites etc. I can find how to define this symbol.

What I want to do is to change the default ONE_AT_A_TIME_HARD hash function to ONE_AT_A_TIME_OLD so I can simulate the old Perl 5.16 behavior.

1

There are 1 answers

6
Sobrique On BEST ANSWER

This sounds like an XY problem. What are you trying to accomplish by forcibly downgrading the hash algorithm in perl to one that has known problems?

From comments:

I need to run a lot of test cases written in perl 5.16 whose functionality depends on the old hash implementation and it's quite impossible to change the code as the cases are hundreds.

Whew, that's bad news. Find those developers, and hit them around the head with a copy perldata:

Hashes are unordered collections of scalar values indexed by their associated string key.

Specifically - if this is a problem for you, it means your codebase treats hashes as ordered, when they aren't and never were. (It's just they were fairly consistent before 5.18 and more random after).

From perldelta:

When encountering these changes, the key to cleaning up from them is to accept that hashes are unordered collections and to act accordingly.

See: http://blog.booking.com/hardening-perls-hash-function.html

To answer your question - if you really must:

./Configure -DPERL_HASH_FUNC_ONE_AT_A_TIME_OLD -des && make && make test

But it's a very very bad idea, because as the INSTALL file in your perl source package points out:

Note that as of Perl 5.18 we can only recommend the use of default or SIPHASH. All the others are known to have security issues and are for research purposes only.

By building your perl this way you introduce a known security flaw for every perl program using it.

Note - ONE_AT_A_TIME_HARD is the new default, so this won't change how perl 5.18 works. You may mean PERL_HASH_FUNC_ONE_AT_A_TIME_OLD