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)
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
#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 }
};