ec.c (ecpt_pyhash): Fix hashing.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 15 Oct 2019 11:02:59 +0000 (12:02 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 17 Nov 2019 02:50:40 +0000 (02:50 +0000)
Previously, hashing a curveless point would just crash, which is
surprisingly bad form.  Replace this mess with a simpler thing which
just converts the point to external form and hashes the coordinates.

ec.c

diff --git a/ec.c b/ec.c
index 4ee4d05..1bf24cf 100644 (file)
--- a/ec.c
+++ b/ec.c
@@ -195,19 +195,13 @@ 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)