chiark
/
gitweb
/
~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mp.c: Factor out and export `mphash'.
[catacomb-python]
/
ec.c
diff --git
a/ec.c
b/ec.c
index 6dcf1cb17fa5c85bd99512b9d0fbe0db0721973d..4ee4d05ea4259e1d06c961ac91b9bcd8d22ce3c0 100644
(file)
--- a/
ec.c
+++ b/
ec.c
@@
-188,6
+188,7
@@
static PyObject *ecpt_pymul(PyObject *x, PyObject *y)
if (ECPT_PYCHECK(x)) { PyObject *t; t = x; x = y; y = t; }
if (!ECPT_PYCHECK(y) || (xx = tomp(x)) == 0) RETURN_NOTIMPL;
ec_imul(ECPT_C(y), &zz, ECPT_P(y), xx);
if (ECPT_PYCHECK(x)) { PyObject *t; t = x; x = y; y = t; }
if (!ECPT_PYCHECK(y) || (xx = tomp(x)) == 0) RETURN_NOTIMPL;
ec_imul(ECPT_C(y), &zz, ECPT_P(y), xx);
+ MP_DROP(xx);
return (ecpt_pywrap(ECPT_COBJ(y), &zz));
}
return (ecpt_pywrap(ECPT_COBJ(y), &zz));
}
@@
-204,8
+205,8
@@
static long ecpt_pyhash(PyObject *me)
EC_OUT(ECPT_C(me), &p, ECPT_P(me));
ec_putraw(ECPT_C(me), &b, &p);
EC_DESTROY(&p);
EC_OUT(ECPT_C(me), &p, ECPT_P(me));
ec_putraw(ECPT_C(me), &b, &p);
EC_DESTROY(&p);
- xfree(q);
h = unihash_hash(&unihash_global, h, BBASE(&b), BLEN(&b));
h = unihash_hash(&unihash_global, h, BBASE(&b), BLEN(&b));
+ xfree(q);
return (h % LONG_MAX);
}
return (h % LONG_MAX);
}
@@
-297,11
+298,12
@@
static PyObject *epmeth_ec2osp(PyObject *me, PyObject *arg, PyObject *kw)
char *p;
ec_curve *c = ECPT_C(me);
ec pp = EC_INIT;
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 };
int len;
char *kwlist[] = { "flags", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "|i:ectosp", 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);
return (0);
len = c->f->noctets * 2 + 1;
rc = bytestring_pywrap(0, len);
@@
-419,9
+421,9
@@
static int ecptxl_3(ec_curve *c, ec *p,
if (!x || !y || !z) TYERR("missing argument");
if (!c) VALERR("internal form with no curve!");
if (!x || !y || !z) TYERR("missing argument");
if (!c) VALERR("internal form with no curve!");
- if ((p->x =
=
coord_in(c->f, x)) == 0 ||
- (p->y =
=
coord_in(c->f, y)) == 0 ||
- (z != Py_None && (p->z = coord_in(c->f, z))
) == 0
)
+ if ((p->x = coord_in(c->f, x)) == 0 ||
+ (p->y = coord_in(c->f, y)) == 0 ||
+ (z != Py_None && (p->z = coord_in(c->f, z))
== 0)
)
goto end;
if (!p->z) p->z = MP_COPY(c->f->one); /* just in case */
rc = 0;
goto end;
if (!p->z) p->z = MP_COPY(c->f->one); /* just in case */
rc = 0;
@@
-525,8
+527,8
@@
static PyObject *ecpt_pyint(PyObject *me)
PyObject *rc = 0;
if (EC_ATINF(ECPT_P(me))) VALERR("point at infinity");
getecptout(&p, me);
PyObject *rc = 0;
if (EC_ATINF(ECPT_P(me))) VALERR("point at infinity");
getecptout(&p, me);
- if (
mp_tolong_checked(p.x, &l)) goto end
;
-
rc = PyInt_FromLong(l
);
+ if (
!mp_tolong_checked(p.x, &l, 0)) rc = PyInt_FromLong(l)
;
+
else rc = mp_topylong(p.x
);
end:
EC_DESTROY(&p);
return (rc);
end:
EC_DESTROY(&p);
return (rc);
@@
-787,10
+789,14
@@
static PyTypeObject ecptcurve_pytype_skel = {
static PyObject *eccurve_pyrichcompare(PyObject *x, PyObject *y, int op)
{
static PyObject *eccurve_pyrichcompare(PyObject *x, PyObject *y, int op)
{
- int b = ec_samep(ECCURVE_C(x), ECCURVE_C(y));
+ int b;
+
+ assert(ECCURVE_PYCHECK(x));
+ if (!ECCURVE_PYCHECK(y)) RETURN_NOTIMPL;
+ b = ec_samep(ECCURVE_C(x), ECCURVE_C(y));
switch (op) {
case Py_EQ: break;
switch (op) {
case Py_EQ: break;
- case Py_NE: b = !b;
+ case Py_NE: b = !b;
break;
default: TYERR("can't order elliptic curves");
}
return (getbool(b));
default: TYERR("can't order elliptic curves");
}
return (getbool(b));
@@
-861,12
+867,12
@@
static PyObject *meth__ECPtCurve_os2ecp(PyObject *me,
buf b;
PyObject *rc = 0;
ec_curve *cc;
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;
ec pp = EC_INIT;
- char *kwlist[] = { "buf", "flags", 0 };
+ 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);
return (0);
buf_init(&b, p, len);
cc = ECCURVE_C(me);