Merge branch '1.3.x'
[catacomb-python] / group.c
diff --git a/group.c b/group.c
index c3d2386..239456f 100644 (file)
--- a/group.c
+++ b/group.c
@@ -92,18 +92,20 @@ static PyObject *meth__DHInfo_generate(PyObject *me,
   unsigned ql = 0, pl;
   unsigned steps = 0;
   grand *r = &rand_global;
-  pgev evt = { 0 };
+  struct excinfo exc = EXCINFO_INIT;
+  pypgev evt = { { 0 } };
   static const char *const kwlist[] =
     { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 };
   PyObject *rc = 0;
 
+  evt.exc = &exc;
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", KWLIST,
                                   &me, convuint, &pl, convuint, &ql,
                                   convpgev, &evt, convgrand, &r,
                                   convuint, &steps))
     goto end;
-  if (dh_gen(&dp, ql, pl, steps, r, evt.proc, evt.ctx))
-    PGENERR;
+  if (dh_gen(&dp, ql, pl, steps, r, evt.ev.proc, evt.ev.ctx))
+    PGENERR(&exc);
   rc = fginfo_pywrap(&dp, dhinfo_pytype);
 end:
   droppgev(&evt);
@@ -117,7 +119,8 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me,
   unsigned ql, pl;
   unsigned steps = 0;
   grand *r = &rand_global;
-  pgev oe = { 0 }, ie = { 0 };
+  struct excinfo exc = EXCINFO_INIT;
+  pypgev oe = { { 0 } }, ie = { { 0 } };
   int subgroupp = 1;
   unsigned f = 0;
   static const char *const kwlist[] = {
@@ -128,6 +131,7 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me,
   mp **v = 0;
   PyObject *rc = 0, *vec = 0;
 
+  oe.exc = ie.exc = &exc;
   if (!PyArg_ParseTupleAndKeywords(arg, kw,
                                   "OO&O&|O&O&O&O&O&:genlimlee", KWLIST,
                                   &me, convuint, &pl, convuint, &ql,
@@ -137,8 +141,8 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me,
     goto end;
   if (subgroupp) f |= DH_SUBGROUP;
   if (dh_limlee(&dp, ql, pl, f, steps, r,
-               oe.proc, oe.ctx, ie.proc, ie.ctx, &nf, &v))
-    PGENERR;
+               oe.ev.proc, oe.ev.ctx, ie.ev.proc, ie.ev.ctx, &nf, &v))
+    PGENERR(&exc);
   vec = PyList_New(nf);
   for (i = 0; i < nf; i++)
     PyList_SetItem(vec, i, mp_pywrap(v[i]));
@@ -156,19 +160,21 @@ static PyObject *meth__DHInfo_genkcdsa(PyObject *me,
   unsigned ql, pl;
   unsigned steps = 0;
   grand *r = &rand_global;
-  pgev evt = { 0 };
+  struct excinfo exc = EXCINFO_INIT;
+  pypgev evt = { { 0 } };
   static const char *const kwlist[] =
     { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 };
   mp *v = MP_NEW;
   PyObject *rc = 0;
 
+  evt.exc = &exc;
   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;
+  if (dh_kcdsagen(&dp, ql, pl, 0, steps, r, evt.ev.proc, evt.ev.ctx))
+    PGENERR(&exc);
   mp_div(&v, 0, dp.p, dp.q);
   v = mp_lsr(v, v, 1);
   rc = Py_BuildValue("(NN)", fginfo_pywrap(&dp, dhinfo_pytype),
@@ -187,18 +193,20 @@ static PyObject *meth__DHInfo_gendsa(PyObject *me,
   dsa_seed ds;
   char *k;
   Py_ssize_t ksz;
-  pgev evt = { 0 };
+  struct excinfo exc = EXCINFO_INIT;
+  pypgev evt = { { 0 } };
   static const char *const kwlist[] =
     { "class", "pbits", "qbits", "seed", "event", "nsteps", 0 };
   PyObject *rc = 0;
 
+  evt.exc = &exc;
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:gendsa", KWLIST,
                                   &me, convuint, &pl, convuint, &ql,
                                   &k, &ksz, convpgev, &evt,
                                   convuint, &steps))
     goto end;
-  if (dsa_gen(&dp, ql, pl, steps, k, ksz, &ds, evt.proc, evt.ctx))
-    PGENERR;
+  if (dsa_gen(&dp, ql, pl, steps, k, ksz, &ds, evt.ev.proc, evt.ev.ctx))
+    PGENERR(&exc);
   rc = Py_BuildValue("(NNl)", fginfo_pywrap(&dp, dhinfo_pytype),
                     bytestring_pywrap(ds.p, ds.sz), (long)ds.count);
   xfree(ds.p);
@@ -966,7 +974,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
@@ -1081,7 +1089,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 }
 };
@@ -1379,16 +1387,16 @@ static PyMethodDef methods[] = {
   METH (_DHInfo__groupn,       0)
   METH (_BinDHInfo__groupn,    0)
   KWMETH(_DHInfo_generate,     "\
-generate(PBITS, [qbits = 0, event = pgen_nullev,\n\
-        rng = rand, nsteps = 0]) -> D")
+generate(PBITS, [qbits = 0], [event = pgen_nullev],\n\
+        [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, ...])")
+genlimlee(PBITS, QBITS, [event = pgen_nullev], [ievent = pgen_nullev],\n\
+         [rng = rand], [nsteps = 0], [subgroupp = True]) -> (D, [Q, ...])")
   KWMETH(_DHInfo_gendsa,       "\
-gendsa(PBITS, QBITS, SEED, [event = pgen_nullevnsteps = 0])\n\
+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\
+gendsa(PBITS, QBITS, [event = pgen_nullev], [rng = rand], [nsteps = 0])\n\
   -> (D, V)")
 #undef METHNAME
   { 0 }