Merge lp:~songofacandy/pyopenssl/allow_thread_while_keygen into lp:~exarkun/pyopenssl/trunk

Proposed by methane
Status: Merged
Merged at revision: 167
Proposed branch: lp:~songofacandy/pyopenssl/allow_thread_while_keygen
Merge into: lp:~exarkun/pyopenssl/trunk
Diff against target: 36 lines (+15/-5)
1 file modified
OpenSSL/crypto/pkey.c (+15/-5)
To merge this branch: bzr merge lp:~songofacandy/pyopenssl/allow_thread_while_keygen
Reviewer Review Type Date Requested Status
Jean-Paul Calderone Pending
Review via email: mp+72331@code.launchpad.net

Description of the change

Generating key may use few seconds.
This proposal allows other threads runs while generating key.

To post a comment you must log in.
158. By methane

Fix didn't release while DSA key generation.

159. By methane

Fix compile error

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'OpenSSL/crypto/pkey.c'
2--- OpenSSL/crypto/pkey.c 2011-06-12 22:10:01 +0000
3+++ OpenSSL/crypto/pkey.c 2011-08-25 17:40:26 +0000
4@@ -52,17 +52,27 @@
5 PyErr_SetString(PyExc_ValueError, "Invalid number of bits");
6 return NULL;
7 }
8- if ((rsa = RSA_generate_key(bits, 0x10001, NULL, NULL)) == NULL)
9+ Py_BEGIN_ALLOW_THREADS;
10+ rsa = RSA_generate_key(bits, 0x10001, NULL, NULL);
11+ Py_END_ALLOW_THREADS;
12+ if (rsa == NULL)
13 FAIL();
14 if (!EVP_PKEY_assign_RSA(self->pkey, rsa))
15 FAIL();
16 break;
17
18 case crypto_TYPE_DSA:
19- if ((dsa = DSA_generate_parameters(bits, NULL, 0, NULL, NULL, NULL, NULL)) == NULL)
20- FAIL();
21- if (!DSA_generate_key(dsa))
22- FAIL();
23+ Py_BEGIN_ALLOW_THREADS;
24+ dsa = DSA_generate_parameters(bits, NULL, 0, NULL, NULL, NULL, NULL);
25+ if (dsa == NULL) {
26+ Py_BLOCK_THREADS;
27+ FAIL();
28+ }
29+ if (!DSA_generate_key(dsa)) {
30+ Py_BLOCK_THREADS;
31+ FAIL();
32+ }
33+ Py_END_ALLOW_THREADS;
34 if (!EVP_PKEY_assign_DSA(self->pkey, dsa))
35 FAIL();
36 break;

Subscribers

People subscribed via source and target branches

to status/vote changes: