Message45752
This is a very simple module for accessing platform-
specific entropy sources.
On Win32, it uses CryptGenRandom. Otherwise, it tries
to use /dev/urandom. If it can't find that, it raises
NotImplementedError.
>>> import entropy
>>> entropy.entropy(10)
'\x99/\xbd\x8e\xb0\xfbz/\xf6\xe9'
To compile for Win32, you have to link with "advapi32".
The /dev/urandom code has not been tested.
Issues:
- I believe this works with all versions of Windows later
than Win95. But I'm not sure.
- there's overhead in opening/closing the source. On
Win32 at least, opening it is slower than reading from it -
it seems to take around 1/5th of a millisecond (i.e. I
can make 5000 calls per second). I think this is okay;
you can make fewer calls and buffer the results, or seed
your own PRNG. However, we could make it more
object-based, where you open an entropy-source, and
then repeatedly read from it.
- It would be nice if there was some attribute that told
you what source you were using, so you could display
it, and in case you trust /dev/urandom but not Win32's
CryptoAPI, for example. |
|
Date |
User |
Action |
Args |
2007-08-23 15:37:09 | admin | link | issue934711 messages |
2007-08-23 15:37:09 | admin | create | |
|