diff options
author | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2012-05-24 07:47:26 -0400 |
---|---|---|
committer | Dwayne C. Litzenberger <dlitz@dlitz.net> | 2012-05-24 07:47:26 -0400 |
commit | b382f9f9229121054ae6a87678ee3601381de099 (patch) | |
tree | 13288d107d39deae83b45cb2f31e72229505eac7 | |
parent | daeea7879651877c771b2bb3e44b9e5d3379e395 (diff) | |
download | pycrypto-b382f9f9229121054ae6a87678ee3601381de099.tar.gz |
In ALGnew, check the mode before checking other parameters
-rw-r--r-- | src/block_template.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/block_template.c b/src/block_template.c index 3526cd1..bc7aa74 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -145,37 +145,37 @@ ALGnew(PyObject *self, PyObject *args, PyObject *kwdict) return NULL; } - if (KEY_SIZE!=0 && keylen!=KEY_SIZE) + if (mode<MODE_ECB || mode>MODE_CTR) { PyErr_Format(PyExc_ValueError, + "Unknown cipher feedback mode %i", + mode); + return NULL; + } + if (mode == MODE_PGP) { + PyErr_Format(PyExc_ValueError, + "MODE_PGP is not supported anymore"); + return NULL; + } + if (KEY_SIZE!=0 && keylen!=KEY_SIZE) + { + PyErr_Format(PyExc_ValueError, "Key must be %i bytes long, not %i", KEY_SIZE, keylen); return NULL; } if (KEY_SIZE==0 && keylen==0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "Key cannot be the null string"); return NULL; } if (IVlen != BLOCK_SIZE && IVlen != 0) { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "IV must be %i bytes long", BLOCK_SIZE); return NULL; } - if (mode<MODE_ECB || mode>MODE_CTR) - { - PyErr_Format(PyExc_ValueError, - "Unknown cipher feedback mode %i", - mode); - return NULL; - } - if (mode == MODE_PGP) { - PyErr_Format(PyExc_ValueError, - "MODE_PGP is not supported anymore"); - return NULL; - } /* Mode-specific checks */ if (mode == MODE_CFB) { |