X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/5779eaf1c6c738aac2227dcadb9e8c27ca22631e..c306066969fa47d1f0a82c92b1c56a3fd6eb3b87:/group.c diff --git a/group.c b/group.c index 7d5b257..83608d3 100644 --- a/group.c +++ b/group.c @@ -184,7 +184,7 @@ static PyObject *meth__DHInfo_gendsa(PyObject *me, unsigned steps = 0; dsa_seed ds; char *k; - int ksz; + Py_ssize_t ksz; pgev evt = { 0 }; char *kwlist[] = { "class", "pbits", "qbits", "seed", "event", "nsteps", 0 }; @@ -717,18 +717,34 @@ end: static PyObject *gemeth_toec(PyObject *me, PyObject *arg, PyObject *kw) { char *kwlist[] = { "curve", 0 }; - PyTypeObject *cty = ecpt_pytype; + PyTypeObject *cty = 0; + PyObject *rc = 0; + group *g; + ec_curve *c; ec p = EC_INIT; if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", kwlist, &cty)) goto end; - if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype)) - TYERR("want subtype of catacomb.ECPt"); - if (G_TOEC(GE_G(me), &p, GE_X(me))) + g = GROUP_G(GE_GOBJ(me)); + if (cty) { + if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype)) + TYERR("want subtype of catacomb.ECPt"); + Py_INCREF((PyObject *)cty); + } else if (strcmp(G_NAME(g), "ec") == 0) { + c = eccurve_copy(((gctx_ec *)g)->ei.c); + cty = (PyTypeObject *)eccurve_pywrap(0, c); + } else { + cty = ecpt_pytype; + Py_INCREF((PyObject *)cty); + } + if (G_TOEC(GE_G(me), &p, GE_X(me))) { + Py_DECREF((PyObject *)cty); TYERR("can't convert to ec point"); - return (ecpt_pywrapout(cty, &p)); + } + rc = ecpt_pywrapout(cty, &p); + Py_DECREF((PyObject *)cty); end: - return (0); + return (rc); } static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg) @@ -815,7 +831,7 @@ static PyObject *meth__GE_frombuf(PyObject *me, PyObject *arg) { buf b; char *p; - int n; + Py_ssize_t n; group *g; ge *x = 0; @@ -836,7 +852,7 @@ static PyObject *meth__GE_fromraw(PyObject *me, PyObject *arg) { buf b; char *p; - int n; + Py_ssize_t n; group *g; ge *x = 0; @@ -857,7 +873,7 @@ static PyObject *meth__GE_fromstring(PyObject *me, PyObject *arg) { mptext_stringctx sc; char *p; - int n; + Py_ssize_t n; group *g; ge *x = 0; @@ -870,7 +886,7 @@ static PyObject *meth__GE_fromstring(PyObject *me, PyObject *arg) if (G_READ(g, x, &mptext_stringops, &sc)) VALERR("bad group element string"); return (Py_BuildValue("(Ns#)", ge_pywrap(me, x), - sc.buf, (int)(sc.lim - sc.buf))); + sc.buf, (Py_ssize_t)(sc.lim - sc.buf))); end: if (x) G_DESTROY(g, x); return (0); @@ -948,7 +964,7 @@ static PyMethodDef ge_pymethods[] = { METH (check, "X.check() -> check X really belongs to its group") METH (toint, "X.toint() -> X converted to an integer") KWMETH(toec, "\ -X.toec(curve = ecpt) -> X converted to elliptic curve point") +X.toec(curve = ECPt) -> X converted to elliptic curve point") METH (tobuf, "X.tobuf() -> X in buffer representation") METH (toraw, "X.toraw() -> X in raw representation") #undef METHNAME @@ -1063,7 +1079,7 @@ static PyMethodDef group_pymethods[] = { #define METHNAME(name) gmeth_##name METH (mexp, "\ G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...") - KWMETH(checkgroup, "G.checkgroup(rand = random): check group is good") + KWMETH(checkgroup, "G.checkgroup(rng = rand): check group is good") #undef METHNAME { 0 } }; @@ -1122,7 +1138,7 @@ static PyObject *pgget_info(PyObject *me, void *hunoz) gctx_prime *gg = (gctx_prime *)GROUP_G(me); dp.p = MP_COPY(gg->mm.m); dp.q = MP_COPY(gg->g.r); - dp.g = mpmont_reduce(&gg->mm, MP_NEW, gg->gen); + dp.g = mpmont_reduce(&gg->mm, MP_NEW, gg->gen.x); return (fginfo_pywrap(&dp, dhinfo_pytype)); } @@ -1199,7 +1215,7 @@ static PyObject *bgget_info(PyObject *me, void *hunoz) gctx_bin *gg = (gctx_bin *)GROUP_G(me); dp.p = MP_COPY(gg->r.p); dp.q = MP_COPY(gg->g.r); - dp.g = MP_COPY(gg->gen); + dp.g = MP_COPY(gg->gen.x); return (fginfo_pywrap(&dp, bindhinfo_pytype)); }