在种子中创造更高水平熵的方法
为了好玩,我一直在尝试加密方法。我使用的方法之一需要种子值。我想给它提供真正的随机数。我知道在 C++ 中获取种子的标准方法是调用 time(NULL),但是由于这只是伪随机,我想知道是否有任何可靠的方法来收集真正的随机数。唯一的限制是它必须可以用 C、C++ 和 Java 实现。
先感谢您。
澄清:当我运行 Ubuntu 时,此代码必须运行 Windows 系统。
For fun I have been experimenting with methods of encryption. One of the methods I am using requires a seed value. I would like to feed it with true random numbers. I know a standard method of acquiring a seed in for example C++ is to call time(NULL), however since this is only pseudo-random I was wondering if there are any reliable ways of gathering truly random numbers. The only constraint is that it must be possible to implement in C, C++, and Java.
Thank you in advance.
Clarification: While I run Ubuntu, this code must run a Windows system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们有很多,但您的术语很混乱,因为任何熵位源都将是随机数生成器。您实际上正在考虑“伪随机数”。
也就是说,现在有许多不同的熵源方案。许多类 UNIX 系统都有 /dev/random,它通过对物理进程(如缓存大小和内存内容)执行各种魔法来创建随机数。有一些更强的来源,例如使用放射性衰变的事件间时间。
Fourmilab.ch 此处提供真实的随机数。
CCD 在黑暗中工作良好。
熔岩灯很不错。
There are lots of them, but you've got your terminology confused, because any source of entropy bits will be a random number generator. You're actually thinking about "pseudorandom numbers".
Now, that said, there are a number of different schemes for entropy sources. A lot of UNIX-like systems have a /dev/random which creates random numbers by doing various magic on physical processes like cache sizes and memory contents. There are stronger sources that use, for example, inter-event times with radioactive decay.
Fourmilab.ch provides real random numbers here.
CCDs kept in the dark work well.
Lava lamps are nice.
根据您的系统,您可能可以访问真正随机的数据源。例如,Linux 中的
/dev/random
将为您提供加密的强随机位源。它通常很慢,因此当您并不真正需要真正的随机性时,使用它来播种 PRNG 是一个很好的使用方法。Depending on your system, you may have access to a source of truly random data. For example,
/dev/random
in Linux will give you a cryptographically strong source of random bits. It's usually slow, so using it to seed a PRNG is a good way to use it when you don't really need true randomness.高分辨率性能计数器的一些魔力可能会产生良好的种子。特别是,如果您考虑多核系统、不同的 CPU 负载等。
Some magic with high-resolution performance counters is, probably, going to give a good seed. Especially, if you consider, multi-core system, different CPU loads etc.
正如查理·马丁(Charlie Martin)提到的,真正随机数的一个很好的来源是来自相机(视频或静态)。如果您使用数码相机中像素的最低有效位并将它们连接成所需长度的字符串,您将拥有一个出色的随机数生成器。
As Charlie Martin mentions, a good source of truly random numbers is from cameras (video or still). If you use the least significant bit of pixels from a digital camera and concatenate them in a string of the required length, you will have an excellent random number generator.