summaryrefslogtreecommitdiff
path: root/src/block_template.c
diff options
context:
space:
mode:
authorDwayne C. Litzenberger <dlitz@dlitz.net>2008-09-14 16:08:44 -0400
committerDwayne C. Litzenberger <dlitz@dlitz.net>2008-09-14 16:08:44 -0400
commit4820664350a42ecca81cede53a6cb349fcffacde (patch)
tree2a3f1f53743af9b4f9b3a8cc98c168f28ed57326 /src/block_template.c
parentd2311689910240e425741a546576129f4c9735e2 (diff)
downloadpycrypto-4820664350a42ecca81cede53a6cb349fcffacde.tar.gz
ARC2: Add 'effective_keylen' keyword parameter so we can pass the RFC 2268 tests
Diffstat (limited to 'src/block_template.c')
-rw-r--r--src/block_template.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/block_template.c b/src/block_template.c
index 47a4db9..36e10f7 100644
--- a/src/block_template.c
+++ b/src/block_template.c
@@ -85,6 +85,9 @@ static char *kwlist[] = {"key", "mode", "IV", "counter", "segment_size",
#ifdef PCT_RC5_MODULE
"version", "word_size", "rounds",
#endif
+#ifdef PCT_ARC2_MODULE
+ "effective_keylen",
+#endif
NULL};
static ALGobject *
@@ -97,17 +100,26 @@ ALGnew(PyObject *self, PyObject *args, PyObject *kwdict)
#ifdef PCT_RC5_MODULE
int version = 0x10, word_size = 32, rounds = 16; /*XXX default rounds? */
#endif
+#ifdef PCT_ARC2_MODULE
+ int effective_keylen = 1024; /* this is a weird default, but it's compatible with old versions of PyCrypto */
+#endif
/* Set default values */
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "s#|is#Oi"
#ifdef PCT_RC5_MODULE
"iii"
#endif
+#ifdef PCT_ARC2_MODULE
+ "i"
+#endif
, kwlist,
&key, &keylen, &mode, &IV, &IVlen,
&counter, &segment_size
#ifdef PCT_RC5_MODULE
, &version, &word_size, &rounds
#endif
+#ifdef PCT_ARC2_MODULE
+ , &effective_keylen
+#endif
))
{
return NULL;
@@ -183,6 +195,14 @@ ALGnew(PyObject *self, PyObject *args, PyObject *kwdict)
return NULL;
}
#endif
+#ifdef PCT_ARC2_MODULE
+ if (effective_keylen<0 || effective_keylen>1024) {
+ PyErr_Format(PyExc_ValueError,
+ "RC2: effective_keylen must be between 0 and 1024, not %i",
+ effective_keylen);
+ return NULL;
+ }
+#endif
/* Copy parameters into object */
new = newALGobject();
@@ -194,6 +214,9 @@ ALGnew(PyObject *self, PyObject *args, PyObject *kwdict)
new->st.word_size = word_size;
new->st.rounds = rounds;
#endif
+#ifdef PCT_ARC2_MODULE
+ new->st.effective_keylen = effective_keylen;
+#endif
block_init(&(new->st), key, keylen);
if (PyErr_Occurred())