~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
catacomb/__init__.py: Implement equality and hashing for `KeyData' objects.
[catacomb-python]
/
ec.c
diff --git
a/ec.c
b/ec.c
index
82fc1a8
..
c9707b7
100644
(file)
--- 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));
}
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;
{
uint32 h;
ec p = EC_INIT;
@@
-251,10
+251,10
@@
static PyObject *epmeth_tobuf(PyObject *me)
else
n = mp_octets(p.x) + mp_octets(p.y) + 6;
rc = bytestring_pywrap(0, n);
else
n = mp_octets(p.x) + mp_octets(p.y) + 6;
rc = bytestring_pywrap(0, n);
- buf_init(&b,
PyString_AS_STRING
(rc), n);
+ buf_init(&b,
BIN_PTR
(rc), n);
buf_putec(&b, &p);
assert(BOK(&b));
buf_putec(&b, &p);
assert(BOK(&b));
-
_PyString_Resize(&
rc, BLEN(&b));
+
BIN_SETLEN(
rc, BLEN(&b));
EC_DESTROY(&p);
return (rc);
}
EC_DESTROY(&p);
return (rc);
}
@@
-270,12
+270,12
@@
static PyObject *epmeth_toraw(PyObject *me)
len = c->f->noctets * 2 + 1;
rc = bytestring_pywrap(0, len);
len = c->f->noctets * 2 + 1;
rc = bytestring_pywrap(0, len);
- p =
PyString_AS_STRING
(rc);
+ p =
BIN_PTR
(rc);
buf_init(&b, p, len);
EC_OUT(c, &pp, ECPT_P(me));
ec_putraw(c, &b, &pp);
EC_DESTROY(&pp);
buf_init(&b, p, len);
EC_OUT(c, &pp, ECPT_P(me));
ec_putraw(c, &b, &pp);
EC_DESTROY(&pp);
-
_PyString_Resize(&
rc, BLEN(&b));
+
BIN_SETLEN(
rc, BLEN(&b));
return (rc);
}
return (rc);
}
@@
-295,7
+295,7
@@
static PyObject *epmeth_ec2osp(PyObject *me, PyObject *arg, PyObject *kw)
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);
- p =
PyString_AS_STRING
(rc);
+ p =
BIN_PTR
(rc);
buf_init(&b, p, len);
EC_OUT(c, &pp, ECPT_P(me));
if (ec_ec2osp(c, f, &b, &pp)) {
buf_init(&b, p, len);
EC_OUT(c, &pp, ECPT_P(me));
if (ec_ec2osp(c, f, &b, &pp)) {
@@
-303,21
+303,20
@@
static PyObject *epmeth_ec2osp(PyObject *me, PyObject *arg, PyObject *kw)
VALERR("invalid flags");
}
EC_DESTROY(&pp);
VALERR("invalid flags");
}
EC_DESTROY(&pp);
-
_PyString_Resize(&
rc, BLEN(&b));
+
BIN_SETLEN(
rc, BLEN(&b));
end:
return (rc);
}
static PyObject *epmeth_frombuf(PyObject *me, PyObject *arg)
{
end:
return (rc);
}
static PyObject *epmeth_frombuf(PyObject *me, PyObject *arg)
{
+ struct bin in;
buf b;
buf b;
- char *p;
- Py_ssize_t sz;
PyObject *rc = 0;
ec pp = EC_INIT;
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));
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)
{
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;
buf b;
PyObject *rc = 0;
ec_curve *cc;
ec pp = EC_INIT;
- if (!PyArg_ParseTuple(arg, "
s#:fromraw", &me, &p, &le
n)) return (0);
- buf_init(&b,
p, len
);
+ if (!PyArg_ParseTuple(arg, "
O&:fromraw", convbin, &i
n)) return (0);
+ buf_init(&b,
(/*unconst*/ void *)in.p, in.sz
);
cc = ECCURVE_C(me);
if (ec_getraw(cc, &b, &pp))
VALERR("bad point");
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)
{
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;
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 };
ec pp = EC_INIT;
static const char *const kwlist[] = { "buf", "flags", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "
s#
|O&:os2ecp", KWLIST,
-
&p, &le
n, convuint, &f))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "
O&
|O&:os2ecp", KWLIST,
+
convbin, &i
n, convuint, &f))
return (0);
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);
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;
int rc = -1;
PyObject *y = 0, *z = 0, *t = 0;
mp *xx = 0;
- const void *q;
Py_ssize_t n;
qd_parse qd;
Py_ssize_t n;
qd_parse qd;
@@
-520,10
+516,8
@@
static int ecptxl_1(ec_curve *c, ec *p, PyObject *x)
else if (ECPT_PYCHECK(x)) {
getecptout(p, x);
goto fix;
else if (ECPT_PYCHECK(x)) {
getecptout(p, x);
goto fix;
- } else if (PyString_Check(x)) {
- if (PyObject_AsReadBuffer(x, &q, &n))
- goto end;
- qd.p = q;
+ } else if (TEXT_CHECK(x)) {
+ qd.p = TEXT_PTR(x);
qd.e = 0;
if (!ec_ptparse(&qd, p))
VALERR(qd.e);
qd.e = 0;
if (!ec_ptparse(&qd, p))
VALERR(qd.e);
@@
-1034,7
+1028,7
@@
end:
}
static PyObject *ecget_name(PyObject *me, void *hunoz)
}
static PyObject *ecget_name(PyObject *me, void *hunoz)
- { return (
PyString_FromString
(EC_NAME(ECCURVE_C(me)))); }
+ { return (
TEXT_FROMSTR
(EC_NAME(ECCURVE_C(me)))); }
static PyObject *ecget_a(PyObject *me, void *hunoz)
{ return (fe_pywrap(ECCURVE_FOBJ(me), MP_COPY(ECCURVE_C(me)->a))); }
static PyObject *ecget_a(PyObject *me, void *hunoz)
{ return (fe_pywrap(ECCURVE_FOBJ(me), MP_COPY(ECCURVE_C(me)->a))); }