X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/blobdiff_plain/c8b711c464a1feeef847453571d798bb60a94c51..cb46f06b084bb7574b6f7cde13bf413f58a1e91c:/ec.c?ds=sidebyside diff --git a/ec.c b/ec.c index 4ee4d05..e18cbb8 100644 --- a/ec.c +++ b/ec.c @@ -195,32 +195,24 @@ static PyObject *ecpt_pymul(PyObject *x, PyObject *y) static long ecpt_pyhash(PyObject *me) { uint32 h; - buf b; ec p = EC_INIT; - size_t sz = 2*ECPT_C(me)->f->noctets + 1; - octet *q = xmalloc(sz); - h = 0xe0fdd039 + ECPT_C(me)->f->ops->ty; - buf_init(&b, q, sz); - EC_OUT(ECPT_C(me), &p, ECPT_P(me)); - ec_putraw(ECPT_C(me), &b, &p); + getecptout(&p, me); + if (EC_ATINF(&p)) h = 0x81d81a94; + else h = 0xe0fdd039 ^ (2*mphash(p.x)) ^ (3*mphash(p.y)); EC_DESTROY(&p); - h = unihash_hash(&unihash_global, h, BBASE(&b), BLEN(&b)); - xfree(q); - return (h % LONG_MAX); + return (h%LONG_MAX); } static PyObject *ecpt_pyrichcompare(PyObject *x, PyObject *y, int op) { - ec_curve *c; - PyObject *cobj; ec p = EC_INIT, q = EC_INIT; int b; PyObject *rc = 0; - if (ecbinop(x, y, &c, &cobj, &p, &q)) RETURN_NOTIMPL; - EC_OUT(c, &p, &p); - EC_OUT(c, &q, &q); + if (!ECPT_PYCHECK(y)) RETURN_NOTIMPL; + getecptout(&p, x); + getecptout(&q, y); switch (op) { case Py_EQ: b = EC_EQ(&p, &q); break; case Py_NE: b = !EC_EQ(&p, &q); break; @@ -1071,7 +1063,7 @@ static PyMethodDef eccurve_pymethods[] = { METH (mmul, "\ E.mmul([(P0, N0), (P1, N1), ...]) = N0 P0 + N1 P1 + ...") METH (find, "E.find(X) -> P") - KWMETH(rand, "E.rand(rng = rand) ->P") + KWMETH(rand, "E.rand([rng = rand]) -> P") #undef METHNAME { 0 } }; @@ -1492,7 +1484,7 @@ static PyGetSetDef ecinfo_pygetset[] = { static PyMethodDef ecinfo_pymethods[] = { #define METHNAME(name) eimeth_##name - KWMETH(check, "I.check() -> None") + KWMETH(check, "I.check([rng = rand]) -> None") #undef METHNAME { 0 } };