X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/d472b9a1b7acba2691f3a3c573dc05a5a9570098..3317491a2bc28732f805c8521777aafa52038793:/buffer.c diff --git a/buffer.c b/buffer.c index 0d3d165..d0df068 100644 --- a/buffer.c +++ b/buffer.c @@ -184,6 +184,22 @@ end: return (rc); } +static PyObject *rbmeth_os2ecp(PyObject *me, PyObject *arg, PyObject *kw) +{ + PyObject *cobj; + ec pt = EC_INIT; + unsigned f = EC_XONLY | EC_LSB | EC_SORT | EC_EXPLY; + PyObject *rc = 0; + static const char *const kwlist[] = { "curve", "flags", 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!|O&:os2ecp", KWLIST, + eccurve_pytype, &cobj, convuint, &f)) + goto end; + if (ec_os2ecp(ECCURVE_C(cobj), f, BUF_B(me), &pt)) VALERR("bad point"); + rc = ecpt_pywrapout(cobj, &pt); +end: + return (rc); +} + static PyObject *rbmeth_getge(PyObject *me, PyObject *arg) { PyObject *gobj; @@ -257,6 +273,7 @@ static const PyMethodDef rbuf_pymethods[] = { NAMETH(getgf, "RBUF.getgf() -> X") KWMETH(getecpt, "RBUF.getecpt([curve = None]) -> P") METH (getecptraw, "RBUF.getecptraw(CURVE) -> P") + KWMETH(os2ecp, "RBUF.os2ecp(CURVE, [flags = ...]) -> P") METH (getge, "RBUF.getge(GROUP) -> X") METH (getgeraw, "RBUF.getgeraw(GROUP) -> X") #undef METHNAME @@ -465,16 +482,37 @@ static PyObject *wbmeth_putecpt(PyObject *me, PyObject *arg) static PyObject *wbmeth_putecptraw(PyObject *me, PyObject *arg) { PyObject *ptobj; + ec_curve *cc; ec pt = EC_INIT; if (!PyArg_ParseTuple(arg, "O!:putecptraw", ecptcurve_pytype, &ptobj)) return (0); - EC_OUT(ECPT_C(ptobj), &pt, ECPT_P(ptobj)); - if (ensurebuf(me, ECPT_C(ptobj)->f->noctets * 2 + 1)) return (0); - ec_putraw(ECPT_C(ptobj), BUF_B(me), &pt); assert(BOK(BUF_B(me))); + cc = ECPT_C(ptobj); + EC_OUT(cc, &pt, ECPT_P(ptobj)); + if (ensurebuf(me, 2*cc->f->noctets + 1)) return (0); + ec_putraw(cc, BUF_B(me), &pt); assert(BOK(BUF_B(me))); EC_DESTROY(&pt); RETURN_ME; } +static PyObject *wbmeth_ec2osp(PyObject *me, PyObject *arg, PyObject *kw) +{ + PyTypeObject *ptobj; + ec_curve *cc; + ec pt = EC_INIT; + unsigned f = EC_EXPLY; + static const char *const kwlist[] = { "point", "flags", 0 }; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!|O&:os2ecp", KWLIST, + ecptcurve_pytype, &ptobj, convuint, &f)) + goto end; + cc = ECPT_C(ptobj); + EC_OUT(cc, &pt, ECPT_P(ptobj)); + if (ensurebuf(me, 2*cc->f->noctets + 1)) return (0); + if (ec_ec2osp(cc, f, BUF_B(me), &pt)) VALERR("invalid flags"); + RETURN_ME; +end: + return (0); +} + static PyObject *wbmeth_putge(PyObject *me, PyObject *arg) { PyObject *geobj; @@ -521,6 +559,7 @@ static const PyMethodDef wbuf_pymethods[] = { METH (putgf, "WBUF.putgf(X)") METH (putecpt, "WBUF.putecpt(P)") METH (putecptraw, "WBUF.putecptraw(P)") + KWMETH(ec2osp, "WBUF.ec2osp(P, [flags = EC_EXPLY])") METH (putge, "WBUF.putge(X)") METH (putgeraw, "WBUF.putgeraw(X)") #undef METHNAME