ec.c: Add missing optional argument to docstring.
[catacomb-python] / ec.c
diff --git a/ec.c b/ec.c
index 7fd369d..c006926 100644 (file)
--- 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;
@@ -298,11 +290,12 @@ static PyObject *epmeth_ec2osp(PyObject *me, PyObject *arg, PyObject *kw)
   char *p;
   ec_curve *c = ECPT_C(me);
   ec pp = EC_INIT;
-  int f = EC_EXPLY;
+  unsigned f = EC_EXPLY;
   int len;
   char *kwlist[] = { "flags", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|i:ec2osp", kwlist, &f))
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:ec2osp", kwlist,
+                                  convuint, &f))
     return (0);
   len = c->f->noctets * 2 + 1;
   rc = bytestring_pywrap(0, len);
@@ -866,12 +859,12 @@ static PyObject *meth__ECPtCurve_os2ecp(PyObject *me,
   buf b;
   PyObject *rc = 0;
   ec_curve *cc;
-  int f = EC_XONLY | EC_LSB | EC_SORT | EC_EXPLY;
+  unsigned f = EC_XONLY | EC_LSB | EC_SORT | EC_EXPLY;
   ec pp = EC_INIT;
   char *kwlist[] = { "class", "buf", "flags", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "Os#|f:os2ecp", kwlist,
-                                  &me, &p, &len, &f))
+  if (!PyArg_ParseTupleAndKeywords(arg, kw, "Os#|O&:os2ecp", kwlist,
+                                  &me, &p, &len, convuint, &f))
     return (0);
   buf_init(&b, p, len);
   cc = ECCURVE_C(me);
@@ -1491,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 }
 };