X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/blobdiff_plain/bc243788edd0e564df8b67d0750a238d978c954b..e95512be8777eb7038fa26bffa0709013dc08f19:/group.c diff --git a/group.c b/group.c index 71d339e..b5a1815 100644 --- a/group.c +++ b/group.c @@ -40,11 +40,11 @@ PyObject *fginfo_pywrap(gprime_param *dp, PyTypeObject *ty) static PyObject *fginfo_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "p", "r", "g", 0 }; + static const char *const kwlist[] = { "p", "r", "g", 0 }; gprime_param dp = { 0 }; fginfo_pyobj *z = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&O&:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&O&:new", KWLIST, convmp, &dp.p, convmp, &dp.q, convmp, &dp.g)) @@ -93,11 +93,11 @@ static PyObject *meth__DHInfo_generate(PyObject *me, unsigned steps = 0; grand *r = &rand_global; pgev evt = { 0 }; - char *kwlist[] = + static const char *const kwlist[] = { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 }; PyObject *rc = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&|O&O&O&O&:generate", KWLIST, &me, convuint, &pl, convuint, &ql, convpgev, &evt, convgrand, &r, convuint, &steps)) @@ -120,14 +120,16 @@ static PyObject *meth__DHInfo_genlimlee(PyObject *me, pgev oe = { 0 }, ie = { 0 }; int subgroupp = 1; unsigned f = 0; - char *kwlist[] = { "class", "pbits", "qbits", "event", "ievent", - "rng", "nsteps", "subgroupp", 0 }; + static const char *const kwlist[] = { + "class", "pbits", "qbits", "event", "ievent", + "rng", "nsteps", "subgroupp", 0 + }; size_t i, nf; mp **v = 0; PyObject *rc = 0, *vec = 0; if (!PyArg_ParseTupleAndKeywords(arg, kw, - "OO&O&|O&O&O&O&O&:genlimlee", kwlist, + "OO&O&|O&O&O&O&O&:genlimlee", KWLIST, &me, convuint, &pl, convuint, &ql, convpgev, &oe, convpgev, &ie, convgrand, &r, convuint, &steps, @@ -155,12 +157,12 @@ static PyObject *meth__DHInfo_genkcdsa(PyObject *me, unsigned steps = 0; grand *r = &rand_global; pgev evt = { 0 }; - char *kwlist[] = { "class", "pbits", "qbits", - "event", "rng", "nsteps", 0 }; + static const char *const kwlist[] = + { "class", "pbits", "qbits", "event", "rng", "nsteps", 0 }; mp *v = MP_NEW; PyObject *rc = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|O&O&O&:genkcdsa", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&|O&O&O&:genkcdsa", KWLIST, &me, convuint, &pl, convuint, &ql, convpgev, &evt, convgrand, &r, convuint, &steps)) @@ -186,11 +188,11 @@ static PyObject *meth__DHInfo_gendsa(PyObject *me, char *k; Py_ssize_t ksz; pgev evt = { 0 }; - char *kwlist[] = + static const char *const kwlist[] = { "class", "pbits", "qbits", "seed", "event", "nsteps", 0 }; PyObject *rc = 0; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:gendsa", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "OO&O&s#|O&O&:gendsa", KWLIST, &me, convuint, &pl, convuint, &ql, &k, &ksz, convpgev, &evt, convuint, &steps)) @@ -325,7 +327,7 @@ static PyTypeObject fginfo_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Abstract base class for field-group information objects.", +"Abstract base class for field-group information objects.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -373,7 +375,7 @@ static PyTypeObject dhinfo_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Standard (integer) Diffie-Hellman group information.", +"DHInfo(P, R, G): standard (integer) Diffie-Hellman group information.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -421,7 +423,7 @@ static PyTypeObject bindhinfo_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ - "Binary-field Diffie-Hellman group information.", +"BinDHInfo(P, R, G): binary-field Diffie-Hellman group information.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -493,7 +495,7 @@ PyObject *ge_pywrap(PyObject *gobj, ge *x) static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "x", 0 }; + static const char *const kwlist[] = { "x", 0 }; PyObject *x; group *g; ec p = EC_INIT; @@ -502,7 +504,7 @@ static PyObject *ge_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) mptext_stringctx sc; g = GROUP_G(ty); - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", kwlist, &x)) goto end; + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:new", KWLIST, &x)) goto end; xx = G_CREATE(g); if (ECPT_PYCHECK(x)) { getecptout(&p, x); @@ -716,19 +718,35 @@ end: static PyObject *gemeth_toec(PyObject *me, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "curve", 0 }; - PyTypeObject *cty = ecpt_pytype; + static const char *const kwlist[] = { "curve", 0 }; + PyTypeObject *cty = 0; + PyObject *rc = 0; + group *g; + ec_curve *c; ec p = EC_INIT; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:toec", KWLIST, &cty)) goto end; - if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype)) - TYERR("want subtype of catacomb.ECPt"); - if (G_TOEC(GE_G(me), &p, GE_X(me))) + g = GROUP_G(GE_GOBJ(me)); + if (cty) { + if (!PyType_Check(cty) || !PyType_IsSubtype(cty, ecpt_pytype)) + TYERR("want subtype of catacomb.ECPt"); + Py_INCREF((PyObject *)cty); + } else if (strcmp(G_NAME(g), "ec") == 0) { + c = eccurve_copy(((gctx_ec *)g)->ei.c); + cty = (PyTypeObject *)eccurve_pywrap(0, c); + } else { + cty = ecpt_pytype; + Py_INCREF((PyObject *)cty); + } + if (G_TOEC(GE_G(me), &p, GE_X(me))) { + Py_DECREF((PyObject *)cty); TYERR("can't convert to ec point"); - return (ecpt_pywrapout(cty, &p)); + } + rc = ecpt_pywrapout(cty, &p); + Py_DECREF((PyObject *)cty); end: - return (0); + return (rc); } static PyObject *gemeth_tobuf(PyObject *me, PyObject *arg) @@ -784,11 +802,11 @@ static PyObject *gmeth_mexp(PyObject *me, PyObject *arg) static PyObject *gmeth_checkgroup(PyObject *me, PyObject *arg, PyObject *kw) { - char *kwlist[] = { "rng", 0 }; + static const char *const kwlist[] = { "rng", 0 }; grand *r = &rand_global; const char *p; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:checkgroup", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:checkgroup", KWLIST, convgrand, &r)) goto end; if ((p = G_CHECK(GROUP_G(me), r)) != 0) @@ -1137,9 +1155,9 @@ static PyObject *primegroup_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { PyObject *i; - char *kwlist[] = { "info", 0 }; + static const char *const kwlist[] = { "info", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", KWLIST, dhinfo_pytype, &i)) return (0); return (group_dopywrap(ty, group_prime(FGINFO_DP(i)))); @@ -1170,7 +1188,7 @@ static PyTypeObject primegroup_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Subgroups of prime fields.", +"PrimeGroup(INFO): subgroups of prime fields.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -1214,9 +1232,9 @@ static PyObject *bingroup_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) { PyObject *i; - char *kwlist[] = { "info", 0 }; + static const char *const kwlist[] = { "info", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", KWLIST, bindhinfo_pytype, &i)) return (0); return (group_dopywrap(ty, group_binary(FGINFO_DP(i)))); @@ -1247,7 +1265,7 @@ static PyTypeObject bingroup_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Subgroups of binary fields.", +"BinGroup(INFO): subgroups of binary fields.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */ @@ -1291,9 +1309,9 @@ static PyObject *ecgroup_pynew(PyTypeObject *ty, { PyObject *i; ec_info ei; - char *kwlist[] = { "info", 0 }; + static const char *const kwlist[] = { "info", 0 }; - if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", kwlist, + if (!PyArg_ParseTupleAndKeywords(arg, kw, "O!:new", KWLIST, ecinfo_pytype, &i)) return (0); ecinfo_copy(&ei, ECINFO_EI(i)); @@ -1325,7 +1343,7 @@ static PyTypeObject ecgroup_pytype_skel = { Py_TPFLAGS_BASETYPE, /* @tp_doc@ */ -"Elliptic curve groups.", +"ECGroup(INFO): elliptic curve groups.", 0, /* @tp_traverse@ */ 0, /* @tp_clear@ */