+static PyObject *epmeth_ec2osp(PyObject *me, PyObject *arg, PyObject *kw)
+{
+ buf b;
+ PyObject *rc;
+ char *p;
+ ec_curve *c = ECPT_C(me);
+ ec pp = EC_INIT;
+ unsigned f = EC_EXPLY;
+ int len;
+ static const char *const kwlist[] = { "flags", 0 };
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:ec2osp", KWLIST,
+ convuint, &f))
+ return (0);
+ len = c->f->noctets * 2 + 1;
+ rc = bytestring_pywrap(0, len);
+ p = PyString_AS_STRING(rc);
+ buf_init(&b, p, len);
+ EC_OUT(c, &pp, ECPT_P(me));
+ if (ec_ec2osp(c, f, &b, &pp)) {
+ Py_DECREF(rc); rc = 0;
+ VALERR("invalid flags");
+ }
+ EC_DESTROY(&pp);
+ _PyString_Resize(&rc, BLEN(&b));
+end:
+ return (rc);
+}
+
+static PyObject *epmeth_frombuf(PyObject *me, PyObject *arg)
+{
+ struct bin in;
+ buf b;
+ PyObject *rc = 0;
+ ec pp = EC_INIT;
+
+ if (!PyArg_ParseTuple(arg, "O&:frombuf", convbin, &in)) goto end;
+ buf_init(&b, (/*unconst*/ void *)in.p, in.sz);
+ if (buf_getec(&b, &pp)) VALERR("malformed data");
+ rc = Py_BuildValue("(NN)", ecpt_pywrapout(me, &pp),
+ bytestring_pywrapbuf(&b));
+end:
+ return (rc);
+}
+
+static PyObject *epmeth_parse(PyObject *me, PyObject *arg)
+{
+ char *p;
+ qd_parse qd;
+ PyObject *rc = 0;
+ ec pp = EC_INIT;
+
+ if (!PyArg_ParseTuple(arg, "s:parse", &p)) goto end;
+ qd.p = p; qd.e = 0;
+ if (!ec_ptparse(&qd, &pp)) VALERR(qd.e);
+ rc = Py_BuildValue("(Ns)", ecpt_pywrapout(me, &pp), qd.p);
+end:
+ return (rc);
+}
+
+static PyObject *epmeth_fromraw(PyObject *me, PyObject *arg)
+{
+ struct bin in;
+ buf b;
+ PyObject *rc = 0;
+ ec_curve *cc;
+ ec pp = EC_INIT;
+
+ if (!PyArg_ParseTuple(arg, "O&:fromraw", convbin, &in)) return (0);
+ buf_init(&b, (/*unconst*/ void *)in.p, in.sz);
+ cc = ECCURVE_C(me);
+ if (ec_getraw(cc, &b, &pp))
+ VALERR("bad point");
+ EC_IN(cc, &pp, &pp);
+ rc = Py_BuildValue("(NN)", ecpt_pywrap(me, &pp), bytestring_pywrapbuf(&b));
+end:
+ return (rc);
+}
+
+static PyObject *epmeth_os2ecp(PyObject *me, PyObject *arg, PyObject *kw)
+{
+ struct bin in;
+ buf b;
+ PyObject *rc = 0;
+ ec_curve *cc;
+ unsigned f = EC_XONLY | EC_LSB | EC_SORT | EC_EXPLY;
+ ec pp = EC_INIT;
+ static const char *const kwlist[] = { "buf", "flags", 0 };
+
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:os2ecp", KWLIST,
+ convbin, &in, convuint, &f))
+ return (0);
+ buf_init(&b, (/*unconst*/ void *)in.p, in.sz);
+ cc = ECCURVE_C(me);
+ if (ec_os2ecp(cc, f, &b, &pp)) VALERR("bad point");
+ EC_IN(cc, &pp, &pp);
+ rc = Py_BuildValue("(NN)", ecpt_pywrap(me, &pp), bytestring_pywrapbuf(&b));
+end:
+ return (rc);
+}