summaryrefslogtreecommitdiff
path: root/src/block_template.c
diff options
context:
space:
mode:
authorakuchling <akuchling@rivest.dlitz.net>2002-05-24 18:51:09 -0700
committerakuchling <akuchling@rivest.dlitz.net>2002-05-24 18:51:09 -0700
commitabd26b185e91fff78e708b20a0b76438131198b0 (patch)
tree304fe1816719e198a7c2045e08d8e6b48fb373bc /src/block_template.c
parentdd8d35181c7412af444290d0bad3d27ea57510e1 (diff)
downloadpycrypto-abd26b185e91fff78e708b20a0b76438131198b0.tar.gz
[project @ akuchling-20020525015109-687c9cfd7ee58cf9]
[project @ 2002-05-24 18:51:09 by akuchling] Overwriting the object is safe in Python 2.2, but not in Python 2.1 because _PyObject_Del() looks at the type pointer to see if the type is GCed or not. Instead, just zap the block cipher states and all the other fields in ALGobject. In the allocator, set the counter field to NULL.
Diffstat (limited to 'src/block_template.c')
-rw-r--r--src/block_template.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/block_template.c b/src/block_template.c
index 0a38f47..dc44f2c 100644
--- a/src/block_template.c
+++ b/src/block_template.c
@@ -58,14 +58,22 @@ newALGobject(void)
ALGobject * new;
new = PyObject_New(ALGobject, &ALGtype);
new->mode = MODE_ECB;
+ new->counter = NULL;
return new;
}
static void
ALGdealloc(PyObject *ptr)
{
+ ALGobject *self = (ALGobject *)ptr;
+
/* Overwrite the contents of the object */
- memset((char *)ptr, 0, sizeof(ALGobject));
+ Py_XDECREF(self->counter);
+ self->counter = NULL;
+ memset(self->IV, 0, BLOCK_SIZE);
+ memset(self->oldCipher, 0, BLOCK_SIZE);
+ memset((char*)&(self->st), 0, sizeof(block_state));
+ self->mode = self->count = self->segment_size = 0;
PyObject_Del(ptr);
}