chiark / gitweb /
group.c: Make element `toec()' method return point on correct curve.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 1 May 2017 00:38:30 +0000 (01:38 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 4 May 2017 11:04:59 +0000 (12:04 +0100)
Rather than a generic point.  Now it will print correctly.

group.c

diff --git a/group.c b/group.c
index 71d339e1f49069390a009fd842704daa5382657f..cc8bbc1986608450df3132db8bb72b6a33c7aee0 100644 (file)
--- a/group.c
+++ b/group.c
@@ -717,18 +717,34 @@ end:
 static PyObject *gemeth_toec(PyObject *me, PyObject *arg, PyObject *kw)
 {
   char *kwlist[] = { "curve", 0 };
-  PyTypeObject *cty = ecpt_pytype;
+  PyTypeObject *cty = 0;
+  PyObject *rc = 0;
+  group *g;
+  ec_curve *c;
   ec p = EC_INIT;
 
   if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", kwlist,
                                   &cty)) goto end;
-  if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype))
-    TYERR("want subtype of catacomb.ECPt");
-  if (G_TOEC(GE_G(me), &p, GE_X(me)))
+  g = GROUP_G(GE_GOBJ(me));
+  if (cty) {
+    if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype))
+      TYERR("want subtype of catacomb.ECPt");
+    Py_INCREF((PyObject *)cty);
+  } else if (strcmp(G_NAME(g), "ec") == 0) {
+    c = eccurve_copy(((gctx_ec *)g)->ei.c);
+    cty = (PyTypeObject *)eccurve_pywrap(0, c);
+  } else  {
+    cty = ecpt_pytype;
+    Py_INCREF((PyObject *)cty);
+  }
+  if (G_TOEC(GE_G(me), &p, GE_X(me))) {
+    Py_DECREF((PyObject *)cty);
     TYERR("can't convert to ec point");
-  return (ecpt_pywrapout(cty, &p));
+  }
+  rc = ecpt_pywrapout(cty, &p);
+  Py_DECREF((PyObject *)cty);
 end:
-  return (0);
+  return (rc);
 }
 
 static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg)