diff options
author | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2009-10-12 16:11:21 -0400 |
---|---|---|
committer | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2009-10-12 16:43:18 -0400 |
commit | 2150aca61f27dc80981a914d2b11c038e84b0c87 (patch) | |
tree | 506097d893e2804b1b919a4ad08d6a4c50b032df /src/block_template.c | |
parent | acf6183a53e2ce8849bc27afd51991babe69338d (diff) | |
download | pycrypto-2150aca61f27dc80981a914d2b11c038e84b0c87.tar.gz |
Release the global interpreter lock during encryption, decryption, and hashing.
These are the easy ones. We don't release the GIL on cipher initialization,
hash initialization, or hash finalization, because those functions might make
Python API calls, and we would need to add a mechism for re-acquiring the GIL
in those cases.
Diffstat (limited to 'src/block_template.c')
-rw-r--r-- | src/block_template.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/block_template.c b/src/block_template.c index 6b9a338..ec03f94 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -275,6 +275,7 @@ ALG_Encrypt(ALGobject *self, PyObject *args) _MODULE_STRING " encrypt"); return NULL; } + Py_BEGIN_ALLOW_THREADS; switch(self->mode) { case(MODE_ECB): @@ -409,11 +410,15 @@ ALG_Encrypt(ALGobject *self, PyObject *args) * and manipulate the counter directly. */ PCT_CounterObject *ctr = (PCT_CounterObject *)(self->counter); - if (!ctr->check_wraparound_func(ctr)) { + if (ctr->carry && !ctr->allow_wraparound) { + Py_BLOCK_THREADS; + PyErr_SetString(PyExc_OverflowError, + "counter wrapped without allow_wraparound"); free(buffer); return NULL; } if (ctr->buf_size != BLOCK_SIZE) { + Py_BLOCK_THREADS; PyErr_Format(PyExc_TypeError, "CTR counter function returned " "string not of length %i", @@ -426,6 +431,7 @@ ALG_Encrypt(ALGobject *self, PyObject *args) self->IV); ctr->inc_func(ctr); } else { + Py_BLOCK_THREADS; PyObject *ctr = PyObject_CallObject(self->counter, NULL); if (ctr == NULL) { free(buffer); @@ -448,9 +454,12 @@ ALG_Encrypt(ALGobject *self, PyObject *args) free(buffer); return NULL; } + Py_UNBLOCK_THREADS; block_encrypt(&(self->st), (unsigned char *)PyString_AsString(ctr), self->IV); + Py_BLOCK_THREADS; Py_DECREF(ctr); + Py_UNBLOCK_THREADS; } /* Move the pointer to the start of the keystream block */ @@ -466,6 +475,7 @@ ALG_Encrypt(ALGobject *self, PyObject *args) free(buffer); return NULL; } + Py_END_ALLOW_THREADS; result=PyString_FromStringAndSize((char *) buffer, len); free(buffer); return(result); @@ -518,6 +528,7 @@ ALG_Decrypt(ALGobject *self, PyObject *args) " decrypt"); return NULL; } + Py_BEGIN_ALLOW_THREADS; switch(self->mode) { case(MODE_ECB): @@ -628,6 +639,7 @@ ALG_Decrypt(ALGobject *self, PyObject *args) free(buffer); return NULL; } + Py_END_ALLOW_THREADS; result=PyString_FromStringAndSize((char *) buffer, len); free(buffer); return(result); |