X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/blobdiff_plain/eee202c309ed165de8a46a44486cea5ac0b4828e..be6df1c38491ef517f2f55f2abc9c9e64ea034b0:/pubkey.c diff --git a/pubkey.c b/pubkey.c index f94108f..5167a97 100644 --- a/pubkey.c +++ b/pubkey.c @@ -65,8 +65,12 @@ static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u, if (!u) { g->d.u = 0; u = Py_None; - } else if ((g->d.u = getmp(u)) == 0) - goto end; + } else { + if ((g->d.u = getmp(u)) == 0) + goto end; + if (MP_PYCHECK(u)) Py_INCREF(u); + else u = mp_pywrap(g->d.u); + } if (!p) { assert(g->d.u); assert(calcpub); pp = G_CREATE(GROUP_G(G)); @@ -78,7 +82,7 @@ static PyObject *dsa_setup(PyTypeObject *ty, PyObject *G, PyObject *u, g->d.p = GE_X(p); g->d.r = GRAND_R(rng); g->d.h = GCHASH_CH(hash); - g->G = G; Py_INCREF(G); g->u = u; Py_INCREF(u); g->p = p; + g->G = G; Py_INCREF(G); g->u = u; g->p = p; g->rng = rng; Py_INCREF(rng); g->hash = hash; Py_INCREF(hash); return ((PyObject *)g); end: @@ -344,7 +348,7 @@ static PyObject *kcdsapriv_pynew(PyTypeObject *ty, { PyObject *G, *u, *p = 0, *rng = rand_pyobj, *hash = has160_pyobj; PyObject *rc = 0; - char *kwlist[] = { "G", "p", "u", "hash", "rng", 0 }; + char *kwlist[] = { "G", "u", "p", "hash", "rng", 0 }; if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!O|O!O!O!:new", kwlist, group_pytype, &G, @@ -728,19 +732,24 @@ static PyObject *meth__RSAPriv_generate(PyObject *me, unsigned nbits; unsigned n = 0; rsa_priv rp; + mp *e = 0; pgev evt = { 0 }; - char *kwlist[] = { "class", "nbits", "event", "rng", "nsteps", 0 }; + char *kwlist[] = { "class", "nbits", "event", "rng", "nsteps", "e", 0 }; PyObject *rc = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&:generate", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", kwlist, &me, convuint, &nbits, convpgev, &evt, - convgrand, &r, convuint, &n)) + convgrand, &r, convuint, &n, + convmp, &e)) goto end; - if (rsa_gen(&rp, nbits, r, n, evt.proc, evt.ctx)) + if (e) MP_COPY(e); + else e = mp_fromulong(MP_NEW, 65537); + if (rsa_gen_e(&rp, nbits, e, r, n, evt.proc, evt.ctx)) PGENERR; rc = rsapriv_pywrap(&rp); end: droppgev(&evt); + mp_drop(e); return (rc); }