summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-02-10 05:44:56 -0800
committerDwayne Litzenberger <dlitz@dlitz.net>2013-02-16 09:44:19 -0800
commit109aae13b378a87c344de05fd868653397ed2ad7 (patch)
tree0a18a309e3072ea2361862a8773cd9ddfd8e2dce
parentf3135db3fa324cf0b195ab7600a8f459860ea935 (diff)
downloadpycrypto-109aae13b378a87c344de05fd868653397ed2ad7.tar.gz
pct-speedtest.py: Python 2.1-2.3 compatibility
They don't have os.urandom, so use Crypto.Random.get_random_bytes
-rw-r--r--pct-speedtest.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/pct-speedtest.py b/pct-speedtest.py
index daed105..9763f09 100644
--- a/pct-speedtest.py
+++ b/pct-speedtest.py
@@ -30,11 +30,18 @@ import sys
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, ARC2, ARC4, Blowfish, CAST, DES3, DES, XOR
from Crypto.Hash import MD2, MD4, MD5, SHA256, SHA
+from Crypto.Random import get_random_bytes
try:
from Crypto.Hash import RIPEMD
except ImportError: # Some builds of PyCrypto don't have the RIPEMD module
RIPEMD = None
+# os.urandom() is less noisy when profiling, but it doesn't exist in Python < 2.4
+try:
+ urandom = os.urandom
+except AttributeError:
+ urandom = get_random_bytes
+
class Benchmark:
def __init__(self):
@@ -70,7 +77,7 @@ class Benchmark:
return self.__random_data
def _random_bytes(self, b):
- return os.urandom(b)
+ return urandom(b)
def announce_start(self, test_name):
sys.stdout.write("%s: " % (test_name,))