openssl_random_pseudo_bytes() 很慢(PHP)

2024-04-26

我在 PHP 中使用 opennssl_random_pseudo_bytes() ,它的执行速度非常慢。我的应用程序经常超时(引发执行时间限制错误)。 OpenSSL random 这么慢有什么特殊原因吗?我目前在我的开发机器上使用 Windows 7 x86。


在 Windows 上, openssl_random_pseudo_bytes() 调用 OpenSSL 的 RAND_screen() 来生成熵。它非常慢,而且 PHP 并不是第一个遇到这种情况的 unix->windows 移植。看起来常见的建议是使用 RAND_seed() 代替。

值得注意的是,OpenSSL 文档指出:

The RAND_screen() function is available for the convenience of Windows programmers. It adds the current contents of the screen to the PRNG. For applications that can catch Windows events, seeding the PRNG by calling RAND_event() is a significantly better source of randomness. **It should be noted that both methods cannot be used on servers that run without user interaction**.

所以这实际上可能是一个经过认证的错误 - 我已经向核心开发人员提出了这个问题。在 Win32 上为 OpenSSL 生成熵的更好方法出现之前,简短的答案似乎是“是的,它在 Windows 上很慢。对此感到抱歉。”

讨论该问题的一些附加链接:


curl 开发人员讨论在 Win32 上收集熵的替代方法 http://curl.haxx.se/mail/lib-2004-06/0133.html

关于 mail-archive.com 的 OpenSSL 用户档案中 RAND_screen() 缓慢的另一次讨论 http://www.mail-archive.com/openssl-users@openssl.org/msg61551.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

openssl_random_pseudo_bytes() 很慢(PHP) 的相关文章

随机推荐