algorithms.c (AEADAAD.copy): Propagate the hashed length to the copy.
[catacomb-python] / group.c
diff --git a/group.c b/group.c
index 83608d3..3d29070 100644 (file)
--- a/group.c
+++ b/group.c
@@ -40,11 +40,11 @@ PyObject *fginfo_pywrap(gprime_param *dp, PyTypeObject *ty)
 static PyObject *fginfo_pynew(PyTypeObject *ty,
                              PyObject *arg, PyObject *kw)
 {
-  char *kwlist[] = { "p", "r", "g", 0 };
+  static const char *const kwlist[] = { "p", "r", "g", 0 };
   gprime_param dp = { 0 };
   fginfo_pyobj *z = 0;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&O&:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&O&:new", KWLIST,
                                   convmp, &dp.p,
                                   convmp, &dp.q,
                                   convmp, &dp.g))
@@ -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 };
-  char *kwlist[] =
+  struct excinfo exc = EXCINFO_INIT;
+  pypgev evt = { { 0 } };
+  static const char *const kwlist[] =
     { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 };
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", kwlist,
+  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,17 +119,21 @@ 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;
-  char *kwlist[] = { "class", "pbits", "qbits", "event", "ievent",
-                    "rng", "nsteps", "subgroupp", 0 };
+  static const char *const kwlist[] = {
+    "class", "pbits", "qbits", "event", "ievent",
+    "rng", "nsteps", "subgroupp", 0
+  };
   size_t i, nf;
   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,
+                                  "OO&O&|O&O&O&O&O&:genlimlee", KWLIST,
                                   &me, convuint, &pl, convuint, &ql,
                                   convpgev, &oe, convpgev, &ie,
                                   convgrand, &r, convuint, &steps,
@@ -135,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]));
@@ -154,19 +160,21 @@ static PyObject *meth__DHInfo_genkcdsa(PyObject *me,
   unsigned ql, pl;
   unsigned steps = 0;
   grand *r = &rand_global;
-  pgev evt = { 0 };
-  char *kwlist[] = { "class", "pbits", "qbits",
-                    "event", "rng", "nsteps", 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;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|O&O&O&:genkcdsa", kwlist,
+  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),
@@ -185,18 +193,20 @@ static PyObject *meth__DHInfo_gendsa(PyObject *me,
   dsa_seed ds;
   char *k;
   Py_ssize_t ksz;
-  pgev evt = { 0 };
-  char *kwlist[] =
+  struct excinfo exc = EXCINFO_INIT;
+  pypgev evt = { { 0 } };
+  static const char *const kwlist[] =
     { "class", "pbits", "qbits", "seed", "event", "nsteps", 0 };
   PyObject *rc = 0;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:gendsa", kwlist,
+  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);
@@ -325,7 +335,7 @@ static PyTypeObject fginfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "Abstract base class for field-group information objects.",
+"Abstract base class for field-group information objects.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -373,7 +383,7 @@ static PyTypeObject dhinfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "Standard (integer) Diffie-Hellman group information.",
+"DHInfo(P, R, G): standard (integer) Diffie-Hellman group information.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -421,7 +431,7 @@ static PyTypeObject bindhinfo_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-  "Binary-field Diffie-Hellman group information.",
+"BinDHInfo(P, R, G): binary-field Diffie-Hellman group information.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -493,7 +503,7 @@ PyObject *ge_pywrap(PyObject *gobj, ge *x)
 
 static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
 {
-  char *kwlist[] = { "x", 0 };
+  static const char *const kwlist[] = { "x", 0 };
   PyObject *x;
   group *g;
   ec p = EC_INIT;
@@ -502,7 +512,7 @@ static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
   mptext_stringctx sc;
 
   g = GROUP_G(ty);
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", kwlist, &x)) goto end;
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", KWLIST, &x)) goto end;
   xx = G_CREATE(g);
   if (ECPT_PYCHECK(x)) {
     getecptout(&p, x);
@@ -716,14 +726,14 @@ end:
 
 static PyObject *gemeth_toec(PyObject *me, PyObject *arg, PyObject *kw)
 {
-  char *kwlist[] = { "curve", 0 };
+  static const char *const kwlist[] = { "curve", 0 };
   PyTypeObject *cty = 0;
   PyObject *rc = 0;
   group *g;
   ec_curve *c;
   ec p = EC_INIT;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", KWLIST,
                                   &cty)) goto end;
   g = GROUP_G(GE_GOBJ(me));
   if (cty) {
@@ -800,11 +810,11 @@ static PyObject *gmeth_mexp(PyObject *me, PyObject *arg)
 
 static PyObject *gmeth_checkgroup(PyObject *me, PyObject *arg, PyObject *kw)
 {
-  char *kwlist[] = { "rng", 0 };
+  static const char *const kwlist[] = { "rng", 0 };
   grand *r = &rand_global;
   const char *p;
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:checkgroup", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:checkgroup", KWLIST,
                                   convgrand, &r))
     goto end;
   if ((p = G_CHECK(GROUP_G(me), r)) != 0)
@@ -964,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
@@ -1079,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(rng = rand): check group is good")
+  KWMETH(checkgroup,   "G.checkgroup([rng = rand]): check group is good")
 #undef METHNAME
   { 0 }
 };
@@ -1153,9 +1163,9 @@ static PyObject *primegroup_pynew(PyTypeObject *ty,
                                  PyObject *arg, PyObject *kw)
 {
   PyObject *i;
-  char *kwlist[] = { "info", 0 };
+  static const char *const kwlist[] = { "info", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", KWLIST,
                                   dhinfo_pytype, &i))
     return (0);
   return (group_dopywrap(ty, group_prime(FGINFO_DP(i))));
@@ -1186,7 +1196,7 @@ static PyTypeObject primegroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Subgroups of prime fields.",
+"PrimeGroup(INFO): subgroups of prime fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1230,9 +1240,9 @@ static PyObject *bingroup_pynew(PyTypeObject *ty,
                                PyObject *arg, PyObject *kw)
 {
   PyObject *i;
-  char *kwlist[] = { "info", 0 };
+  static const char *const kwlist[] = { "info", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", KWLIST,
                                   bindhinfo_pytype, &i))
     return (0);
   return (group_dopywrap(ty, group_binary(FGINFO_DP(i))));
@@ -1263,7 +1273,7 @@ static PyTypeObject bingroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Subgroups of binary fields.",
+"BinGroup(INFO): subgroups of binary fields.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1307,9 +1317,9 @@ static PyObject *ecgroup_pynew(PyTypeObject *ty,
 {
   PyObject *i;
   ec_info ei;
-  char *kwlist[] = { "info", 0 };
+  static const char *const kwlist[] = { "info", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", kwlist,
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", KWLIST,
                                   ecinfo_pytype, &i))
     return (0);
   ecinfo_copy(&ei, ECINFO_EI(i));
@@ -1341,7 +1351,7 @@ static PyTypeObject ecgroup_pytype_skel = {
     Py_TPFLAGS_BASETYPE,
 
   /* @tp_doc@ */
-"Elliptic curve groups.",
+"ECGroup(INFO): elliptic curve groups.",
 
   0,                                   /* @tp_traverse@ */
   0,                                   /* @tp_clear@ */
@@ -1377,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 }