chiark
/
gitweb
/
~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
pubkey.c: Catch invalid arguments to `RSAPub' and `RSAPriv'.
[catacomb-python]
/
pubkey.c
diff --git
a/pubkey.c
b/pubkey.c
index c47f1b514cda3403b5b885b86cd927d76b2c21e4..8790e4083a518c64d20ca07c7f4e251ed1f16183 100644
(file)
--- a/
pubkey.c
+++ b/
pubkey.c
@@
-553,6
+553,7
@@
static PyObject *rsapub_pynew(PyTypeObject *ty,
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", kwlist,
convmp, &rp.n, convmp, &rp.e))
goto end;
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:new", kwlist,
convmp, &rp.n, convmp, &rp.e))
goto end;
+ if (!MP_ODDP(rp.n)) VALERR("RSA modulus must be even");
o = (rsapub_pyobj *)ty->tp_alloc(ty, 0);
o->pub = rp;
rsa_pubcreate(&o->pubctx, &o->pub);
o = (rsapub_pyobj *)ty->tp_alloc(ty, 0);
o->pub = rp;
rsa_pubcreate(&o->pubctx, &o->pub);
@@
-625,6
+626,10
@@
static PyObject *rsapriv_pynew(PyTypeObject *ty,
convmp, &rp.q_inv,
&rng))
goto end;
convmp, &rp.q_inv,
&rng))
goto end;
+ if ((rp.n && !MP_ODDP(rp.n)) ||
+ (rp.p && !MP_ODDP(rp.p)) ||
+ (rp.p && !MP_ODDP(rp.q)))
+ VALERR("RSA modulus and factors must be odd");
if (rsa_recover(&rp)) VALERR("couldn't construct private key");
if (rng != Py_None && !GRAND_PYCHECK(rng))
TYERR("not a random number source");
if (rsa_recover(&rp)) VALERR("couldn't construct private key");
if (rng != Py_None && !GRAND_PYCHECK(rng))
TYERR("not a random number source");