summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2012-04-03 15:04:55 -0400
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2012-04-03 15:04:55 -0400
commit5f2cd26054adff5a1fbf9ba5d56766b972f46670 (patch)
tree8a8cd53ea439c6bf6652dc8282085689938342d6
parentcf141b18925da8889bd19c88fb39a3e705d3ae56 (diff)
downloadpyopenssl-5f2cd26054adff5a1fbf9ba5d56766b972f46670.tar.gz
Add a multithreaded stress tester for key generation. Hopefully provides additional confidence that that code is correct with respect to threading.
-rw-r--r--leakcheck/thread-key-gen.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/leakcheck/thread-key-gen.py b/leakcheck/thread-key-gen.py
new file mode 100644
index 0000000..62e1a58
--- /dev/null
+++ b/leakcheck/thread-key-gen.py
@@ -0,0 +1,38 @@
+# Copyright (C) Jean-Paul Calderone
+# See LICENSE for details.
+#
+# Stress tester for thread-related bugs in RSA and DSA key generation. 0.12 and
+# older held the GIL during these operations. Subsequent versions release it
+# during them.
+
+from threading import Thread
+
+from OpenSSL.crypto import TYPE_RSA, TYPE_DSA, PKey
+
+def generate_rsa():
+ keys = []
+ for i in range(100):
+ key = PKey()
+ key.generate_key(TYPE_RSA, 1024)
+ keys.append(key)
+
+def generate_dsa():
+ keys = []
+ for i in range(100):
+ key = PKey()
+ key.generate_key(TYPE_DSA, 512)
+ keys.append(key)
+
+
+def main():
+ threads = []
+ for i in range(3):
+ t = Thread(target=generate_rsa, args=())
+ threads.append(t)
+ t = Thread(target=generate_dsa, args=())
+ threads.append(t)
+
+ for t in threads:
+ t.start()
+
+main()