/* -*-c-*-
- *
- * $Id$
*
* Abstract group inteface
*
* (c) 2004 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of the Python interface to Catacomb.
*
* 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.
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);
}
}
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)
{
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)
{
}
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,
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)
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;
{
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);
}
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)
#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 }
};
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 }
};