使用沙桥的硬件真随机数生成器?

2022-01-17 00:00:00 generator numbers intel c++ hardware

我想知道是否有一种方法可以利用 intel 的 Sandy Bridge CPU 中新的基于硬件的真数生成器?我读到英特尔的 MKL(数学内核库)公开了这个功能,但这需要 MKL 套件和英特尔编译器,最终相当昂贵.

I was wondering if there is a way to make use of the new hardware based true number generator found in intel's sandy bridge CPU? I read that intel's MKL (Math Kernel Library) exposes this functionality, but this requires the MKL suite and an intel complier, ending up pretty expensive.

还有其他方法可以在我的 C++ 代码中使用硬件随机数生成器吗?例如一个不错的,只有标题的库?

Is there another way to employ the hardware random number generator in my C++ code? For example a nice, header only library?

推荐答案

英特尔在 rdrand 指令的手册、库和代码示例.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide" rel="noreferrer">http://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide.

Intel has posted a manual, library, and code examples for the rdrand instruction at http://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide.

来自自述文件:

由于许多编译器工具链不支持这个新指令,这个库是创建以方便访问它.这个想法很简单:链接到已构建的静态库并享受新功能!"

"Because the many of compiler toolchains do not support this new instruction, this library was created to facilitate easy access to it. The idea is simple: link to a built static library and enjoy the new feature!"

main.c中有所有库调用的例子.

There are examples of all the library calls in main.c.

我能够在 Mac OS X 上用 gcc 编译静态库和测试程序.文档指出它还兼容 Linux 和 Windows.

I was able to compile the static library and test program in gcc on Mac OS X. The documentation states that it is also compatible with Linux and Windows.

请注意,rdrand 实际上是一个 128 位伪随机数生成器,具有硬件生成的熵.(即将推出的 Broadwell 架构将提供 rdseed 指令来访问真正的随机数生成器.)差异的详细信息及其含义可以在 http://software.intel.com/en-us/blogs/2012/11/17/the-difference-between-rdrand-and-rdseed.

Be aware that rdrand is actually a 128-bit pseudo-random number generator with hardware-generated entropy. (The upcoming Broadwell architecture will provide an rdseed instruction to access the true random number generator.) The details of the difference and its implications can be found under the "Long Answer" heading at http://software.intel.com/en-us/blogs/2012/11/17/the-difference-between-rdrand-and-rdseed.

相关文章