X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/963a61481edc7a83698b18b518bf20cd93d268a6..85f15f07a01fc508f88fbbd2f1c3b61ec888cdd8:/group.c diff --git a/group.c b/group.c index dc72bc8..1f733a0 100644 --- a/group.c +++ b/group.c @@ -1,13 +1,11 @@ /* -*-c-*- * - * $Id$ - * * Abstract group inteface * * (c) 2004 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of the Python interface to Catacomb. * @@ -15,12 +13,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * Catacomb/Python is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Catacomb/Python; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -35,9 +33,7 @@ PyObject *fginfo_pywrap(gprime_param *dp, PyTypeObject *ty) { fginfo_pyobj *z = PyObject_New(fginfo_pyobj, ty); - z->dp.p = MP_COPY(dp->p); - z->dp.q = MP_COPY(dp->q); - z->dp.g = MP_COPY(dp->g); + z->dp = *dp; return ((PyObject *)z); } @@ -51,7 +47,7 @@ static PyObject *fginfo_pynew(PyTypeObject *ty, if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&O&:new", kwlist, convmp, &dp.p, convmp, &dp.q, - &convmp, dp.g)) + convmp, &dp.g)) goto end; z = PyObject_New(fginfo_pyobj, ty); z->dp = dp; @@ -64,22 +60,22 @@ end: } static PyObject *figet_r(PyObject *me, void *hunoz) - { return mp_pywrap(FGINFO_DP(me)->q); } + { return mp_pywrap(MP_COPY(FGINFO_DP(me)->q)); } static PyObject *diget_p(PyObject *me, void *hunoz) - { return mp_pywrap(FGINFO_DP(me)->p); } + { return mp_pywrap(MP_COPY(FGINFO_DP(me)->p)); } static PyObject *diget_g(PyObject *me, void *hunoz) - { return mp_pywrap(FGINFO_DP(me)->g); } + { return mp_pywrap(MP_COPY(FGINFO_DP(me)->g)); } static PyObject *biget_p(PyObject *me, void *hunoz) - { return gf_pywrap(FGINFO_DP(me)->p); } + { return gf_pywrap(MP_COPY(FGINFO_DP(me)->p)); } static PyObject *biget_m(PyObject *me, void *hunoz) { return PyInt_FromLong(mp_octets(FGINFO_DP(me)->p) - 1); } static PyObject *biget_g(PyObject *me, void *hunoz) - { return gf_pywrap(FGINFO_DP(me)->g); } + { return gf_pywrap(MP_COPY(FGINFO_DP(me)->g)); } static void fginfo_pydealloc(PyObject *me) { @@ -151,6 +147,35 @@ end: return (rc); } +static PyObject *meth__DHInfo_genkcdsa(PyObject *me, + PyObject *arg, PyObject *kw) +{ + dh_param dp; + unsigned ql, pl; + unsigned steps = 0; + grand *r = &rand_global; + pgev evt = { 0 }; + char *kwlist[] = { "class", "pbits", "qbits", + "event", "rng", "nsteps", 0 }; + mp *v = MP_NEW; + PyObject *rc = 0; + + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|O&O&O&:genkcdsa", kwlist, + &me, convuint, &pl, convuint, &ql, + convpgev, &evt, convgrand, &r, + convuint, &steps)) + goto end; + if (dh_kcdsagen(&dp, ql, pl, 0, steps, r, evt.proc, evt.ctx)) + PGENERR; + mp_div(&v, 0, dp.p, dp.q); + v = mp_lsr(v, v, 1); + rc = Py_BuildValue("(NN)", fginfo_pywrap(&dp, dhinfo_pytype), + mp_pywrap(v)); +end: + droppgev(&evt); + return (rc); +} + static PyObject *meth__DHInfo_gendsa(PyObject *me, PyObject *arg, PyObject *kw) { @@ -165,7 +190,7 @@ static PyObject *meth__DHInfo_gendsa(PyObject *me, { "class", "pbits", "qbits", "seed", "event", "nsteps", 0 }; PyObject *rc = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:generate", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:gendsa", kwlist, &me, convuint, &pl, convuint, &ql, &k, &ksz, convpgev, &evt, convuint, &steps)) @@ -200,11 +225,11 @@ static PyObject *namedgroups(const pentry *pp, int *ne) } c = PyInt_FromLong(i); found: - PyDict_SetItemString(d, (/*unconst*/ char *)pp[i].name, c); + PyDict_SetItemString(d, (/*unconst*/ char *)p, c); Py_DECREF(c); } *ne = i; - return (d); + return (d); } static PyObject *meth__groupn(PyObject *me, PyObject *arg, @@ -242,7 +267,7 @@ static PyObject *meth__parse(PyObject *me, PyObject *arg, PyTypeObject *ty, if (parse(&qd, &gp)) SYNERR(qd.e); rc = fginfo_pywrap(&gp, ty); end: - return (rc); + return (rc); } static PyObject *meth__DHInfo_parse(PyObject *me, PyObject *arg) @@ -441,7 +466,7 @@ group *group_copy(group *g) gb.p = gc->r.p; gb.q = gc->g.r; g = group_binary(&gb); - MP_DROP(gb.g); + MP_DROP(gb.g); } else if (strcmp(G_NAME(g), "ec") == 0) { gctx_ec *gc = (gctx_ec *)g; ec_info ei; @@ -507,17 +532,17 @@ static PyObject *group_dopywrap(PyTypeObject *ty, group *g) { group_pyobj *gobj = newtype(ty, 0, g->ops->name); gobj->g = g; - gobj->ty.type.tp_basicsize = sizeof(ge_pyobj); - gobj->ty.type.tp_base = ge_pytype; + gobj->ty.ht_type.tp_basicsize = sizeof(ge_pyobj); + gobj->ty.ht_type.tp_base = ge_pytype; Py_INCREF(group_pytype); - gobj->ty.type.tp_flags = (Py_TPFLAGS_DEFAULT | - Py_TPFLAGS_BASETYPE | - Py_TPFLAGS_CHECKTYPES | - Py_TPFLAGS_HEAPTYPE); - gobj->ty.type.tp_alloc = PyType_GenericAlloc; - gobj->ty.type.tp_free = 0; - gobj->ty.type.tp_new = ge_pynew; - PyType_Ready(&gobj->ty.type); + gobj->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT | + Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_CHECKTYPES | + Py_TPFLAGS_HEAPTYPE); + gobj->ty.ht_type.tp_alloc = PyType_GenericAlloc; + gobj->ty.ht_type.tp_free = 0; + gobj->ty.ht_type.tp_new = ge_pynew; + PyType_Ready(&gobj->ty.ht_type); return ((PyObject *)gobj); } @@ -656,7 +681,7 @@ static PyObject *ge_pylong(PyObject *me) if ((x = G_TOINT(GE_G(me), MP_NEW, GE_X(me))) == 0) TYERR("can't convert to integer"); - rc = (PyObject *)mp_topylong(x); + rc = mp_topylong(x); end: mp_drop(x); return (rc); @@ -757,13 +782,13 @@ static PyObject *gmeth_mexp(PyObject *me, PyObject *arg) gmexp_id, gmexp_fill, gmexp_exp, gmexp_drop)); } -static PyObject *gmeth_check(PyObject *me, PyObject *arg, PyObject *kw) +static PyObject *gmeth_checkgroup(PyObject *me, PyObject *arg, PyObject *kw) { char *kwlist[] = { "rng", 0 }; grand *r = &rand_global; const char *p; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:check", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:checkgroup", kwlist, convgrand, &r)) goto end; if ((p = G_CHECK(GROUP_G(me), r)) != 0) @@ -1024,7 +1049,7 @@ static PyMethodDef group_pymethods[] = { #define METHNAME(name) gmeth_##name METH (mexp, "\ G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...") - KWMETH(check, "G.check(rand = random): check group is good") + KWMETH(checkgroup, "G.checkgroup(rand = random): check group is good") #undef METHNAME { 0 } }; @@ -1323,13 +1348,16 @@ static PyMethodDef methods[] = { METH (_BinDHInfo__groupn, 0) KWMETH(_DHInfo_generate, "\ generate(PBITS, [qbits = 0, event = pgen_nullev,\n\ - rng = rand, nsteps = 0]) -> D") + rng = rand, nsteps = 0]) -> D") KWMETH(_DHInfo_genlimlee, "\ genlimlee(PBITS, QBITS, [event = pgen_nullev, ievent = pgen_nullev,\n\ - rng = rand, nsteps = 0, subgroupp = True]) -> (D, [Q, ...])") + rng = rand, nsteps = 0, subgroupp = True]) -> (D, [Q, ...])") KWMETH(_DHInfo_gendsa, "\ gendsa(PBITS, QBITS, SEED, [event = pgen_nullev, nsteps = 0])\n\ -> (D, SEED, COUNT)") + KWMETH(_DHInfo_genkcdsa, "\ +gendsa(PBITS, QBITS, [event = pgen_nullev, rng = rand, nsteps = 0])\n\ + -> (D, V)") #undef METHNAME { 0 } };