0

I want to make use of Intel's RDRAND feature on Windows and generate true random numbers (since Python's random module isn't so random). Is there any API in Python which can access this feature?

I've tried installing the rdrand module mentioned in the comment below, but I keep getting an error. Log: http://pastebin.com/A2Vqsqec

The error seems to be thrown by these lines in rdrand.c:

#ifdef __GNUC__
#define USING_GCC 1
#elif __clang__
#define USING_CLANG 1
#else
#error Only support for gcc or clang currently
#error if you port to another compiler, please
#error send back the patch to https://github.com/stillson/rdrand
#endif

Why is this happening?

UPDATE: I've checked and made sure that __GNUC__ is defined

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
PK123
  • 43
  • 8
  • 1
    Have look at this: https://pypi.python.org/pypi/rdrand/0.9.0 Also interesting: http://stackoverflow.com/questions/22680441/using-the-hardware-rng-from-python – ppasler Dec 30 '16 at 09:43
  • Thank you. I tried pip installing the rdrand module, but I am getting an error: "rdrand.c: fatal error C1189 - Only support for gcc or clang currently" Why is this happening? – PK123 Dec 30 '16 at 09:47

2 Answers2

0

You will probably want to use Python to wrap a C/C++ routine, instead of using the Python implementation of RdRand(). A research paper here (http://iopscience.iop.org/article/10.3847/1538-4357/aa7ede/meta;jsessionid=A9DA9DDB925E6522D058F3CEEC7D0B21.ip-10-40-2-120), or non-paywalled version here (https://arxiv.org/abs/1707.02212) recently showed how poor the performance of RdRand() in Python is. Even so, as the paper mentions, the RdRand and RdSeed instructions are not quite "truly" random...

Hope that helps.

  • The links are poor, better links: [Intel® DRNG](https://software.intel.com/sites/default/files/m/d/4/1/d/8/441_Intel_R__DRNG_Software_Implementation_Guide_final_Aug7.pdf), [Intel® DRNG Software Implementation Guide](https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide) and Wikipedia [RdRand](https://en.wikipedia.org/wiki/RdRand). – zaph Nov 13 '17 at 22:34
0

You don't necessarily need RDRAND for quality randomness. The documentation for the random module states:

Use os.urandom() or SystemRandom if you require a cryptographically secure pseudo-random number generator.

The documentation for os.urandom(n) says:

Return a string of n random bytes suitable for cryptographic use.

This function returns random bytes from an OS-specific randomness source. The returned data should be unpredictable enough for cryptographic applications, though its exact quality depends on the OS implementation. On a UNIX-like system this will query /dev/urandom, and on Windows it will use CryptGenRandom().

SystemRandom is based on urandom.

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76