chiark / gitweb /
group: Implement KCDSA group generation.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 12 Feb 2006 00:39:05 +0000 (00:39 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 12 Feb 2006 00:39:05 +0000 (00:39 +0000)
Requires the corresponding feature in Catacomb.  Also fix a memory
management snafu in field-group-info handling.

group.c

diff --git a/group.c b/group.c
index d9c232b7bc7fe16ea9d4a45ddf234a59847cb108..1c869a42c57691ea88c1530f4700d2d6fbd8f800 100644 (file)
--- a/group.c
+++ b/group.c
@@ -35,9 +35,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);
 }
 
@@ -64,22 +62,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 +149,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)
 {
@@ -1330,6 +1357,9 @@ genlimlee(PBITS, QBITS, [event = pgen_nullev, ievent = pgen_nullev,\n\
   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 }
 };