如何更改 Perl 5.18 中的默认 ONE_AT_A_TIME_HARD 哈希函数?

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

我不太熟悉 Perl,但过去两天我一直在文档和其他资源中搜索但没有成功。在文档中,它是这样写的:

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.

问题是,无论是在 INSTALL 文件还是在其他 sources/sites 等文件中。我都可以找到如何定义这个符号。

我想做的是将默认的 ONE_AT_A_TIME_HARD 哈希函数更改为 ONE_AT_A_TIME_OLD,这样我就可以模拟旧的 Perl 5.16 行为。

这听起来像是一个 XY 问题。你想通过强行将 perl 中的哈希算法降级为已知问题的哈希算法来完成什么?

来自评论:

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.

哎呀,这是个坏消息。找到那些开发人员,然后用副本打他们的脑袋 perldata:

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

具体来说 - 如果这对您来说是个问题,这意味着您的代码库按顺序处理哈希,而实际上它们不是,也从来没有。 (只是它们在 5.18 之前 相当 一致,之后更随机)。

来自 perldelta:

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

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

要回答您的问题 - 如果您真的必须:

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

但这是一个非常非常糟糕的主意,因为正如您的 perl 源代码包中的 INSTALL 文件指出的那样:

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.

通过以这种方式构建 perl,您为每个使用它的 perl 程序引入了一个已知的安全漏洞。

注意 - ONE_AT_A_TIME_HARDnew 默认值,因此这不会改变 perl 5.18 的工作方式。你的意思可能是 PERL_HASH_FUNC_ONE_AT_A_TIME_OLD