X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/4648f560097060c1eaeb07ba0752e6a036c07ab9..be17c8c27ee7ae2e14fe34bb517484a11b1cf300:/ec.c diff --git a/ec.c b/ec.c index baab989..d621a71 100644 --- a/ec.c +++ b/ec.c @@ -192,7 +192,7 @@ static PyObject *ecpt_pymul(PyObject *x, PyObject *y) return (ecpt_pywrap(ECPT_COBJ(y), &zz)); } -static long ecpt_pyhash(PyObject *me) +static Py_hash_t ecpt_pyhash(PyObject *me) { uint32 h; ec p = EC_INIT; @@ -310,14 +310,13 @@ end: static PyObject *epmeth_frombuf(PyObject *me, PyObject *arg) { + struct bin in; buf b; - char *p; - Py_ssize_t sz; PyObject *rc = 0; ec pp = EC_INIT; - if (!PyArg_ParseTuple(arg, "s#:frombuf", &p, &sz)) goto end; - buf_init(&b, p, sz); + 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)); @@ -342,15 +341,14 @@ end: static PyObject *epmeth_fromraw(PyObject *me, PyObject *arg) { - char *p; - Py_ssize_t len; + struct bin in; buf b; PyObject *rc = 0; ec_curve *cc; ec pp = EC_INIT; - if (!PyArg_ParseTuple(arg, "s#:fromraw", &me, &p, &len)) return (0); - buf_init(&b, p, len); + 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"); @@ -362,8 +360,7 @@ end: static PyObject *epmeth_os2ecp(PyObject *me, PyObject *arg, PyObject *kw) { - char *p; - Py_ssize_t len; + struct bin in; buf b; PyObject *rc = 0; ec_curve *cc; @@ -371,10 +368,10 @@ static PyObject *epmeth_os2ecp(PyObject *me, PyObject *arg, PyObject *kw) ec pp = EC_INIT; static const char *const kwlist[] = { "buf", "flags", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#|O&:os2ecp", KWLIST, - &p, &len, convuint, &f)) + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&|O&:os2ecp", KWLIST, + convbin, &in, convuint, &f)) return (0); - buf_init(&b, p, len); + 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); @@ -510,7 +507,6 @@ static int ecptxl_1(ec_curve *c, ec *p, PyObject *x) int rc = -1; PyObject *y = 0, *z = 0, *t = 0; mp *xx = 0; - const void *q; int n; qd_parse qd; @@ -521,9 +517,7 @@ static int ecptxl_1(ec_curve *c, ec *p, PyObject *x) getecptout(p, x); goto fix; } else if (PyString_Check(x)) { - if (PyObject_AsReadBuffer(x, &q, &n)) - goto end; - qd.p = q; + qd.p = PyString_AS_STRING(x); qd.e = 0; if (!ec_ptparse(&qd, p)) VALERR(qd.e);