简体   繁体   English

如何为 hash 制造病理钥匙?

[英]How can I manufacture pathological keys for a hash?

I am trying to trigger the hash randomization feature in Perl 5.8.2 and later.我正在尝试在 Perl 5.8.2 及更高版本中触发 hash 随机化功能。 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.我尝试使用MJD's code ,但没有奏效。 And, now that I look at it, I shouldn't be surprised.而且,现在我看着它,我不应该感到惊讶。 It comes from 1997, and we have switched hashing functions since then.它来自 1997 年,从那时起我们就切换了散列函数。

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.我想我应该只是 go 看看 hash function 并逆向工程解决方案,但我很懒。

Note: this information is valid for perl between 5.8.2 and 5.17.x.注意:此信息对 5.8.2 和 5.17.x 之间的 perl 有效。 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. 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.由于 perl 现在使用 128 位 hash 种子,因此几乎不可能故意触发“病态哈希”条件。

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.原始答案:如果在 perl 开始之前将PERL_HASH_SEED=0放入环境中,强制 hash 种子为 0,则键的集合"\0""\0\0""\0\0\0"等。将导致每个密钥都以当前的 perls 降落在 hash 存储桶 0 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM