gpt4 book ai didi

random - 随机和随机之间的区别

转载 作者:行者123 更新时间:2023-12-03 06:07:44 32 4
gpt4 key购买 nike

我正在尝试找出 /dev/random/dev/urandom 文件之间的差异

  1. /dev/random/dev/urandom 之间有什么区别?
  2. 我应该什么时候使用它们?
  3. 什么时候不应该使用它们?

最佳答案

使用/dev/random可能需要等待结果,因为它使用所谓的熵池,其中随机数据目前可能不可用。

/dev/urandom 返回用户请求的尽可能多的字节,因此它的随机性比 /dev/random 低。

可以从手册页中读取:

随机

When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. /dev/random should be suitable for uses that need very high quality randomness such as one-time pad or key generation. When the entropy pool is empty, reads from /dev/random will block until additional environmental noise is gathered.

随机

A read from the /dev/urandom device will not block waiting for more entropy. As a result, if there is not sufficient entropy in the entropy pool, the returned values are theoretically vulnerable to a cryptographic attack on the algorithms used by the driver. Knowledge of how to do this is not available in the current unclassified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead.

出于加密目的,您应该真正使用 /dev/random 因为它返回的数据的性质。出于安全考虑,可能的等待应被视为可接受的权衡,IMO。

当您需要快速随机数据时,您当然应该使用/dev/urandom

来源:Wikipedia页,man页面

关于random - 随机和随机之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23712581/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com