/*----- DH and binary group infos -----------------------------------------*/
-PyObject *fginfo_pywrap(gprime_param *dp, PyTypeObject *ty)
+static PyTypeObject *fginfo_pytype, *dhinfo_pytype, *bindhinfo_pytype;
+
+typedef struct fginfo_pyobj {
+ PyObject_HEAD
+ gprime_param dp;
+} fginfo_pyobj;
+
+#define FGINFO_DP(fg) (&((fginfo_pyobj *)(fg))->dp)
+
+static PyObject *fginfo_pywrap(gprime_param *dp, PyTypeObject *ty)
{
fginfo_pyobj *z = PyObject_New(fginfo_pyobj, ty);
z->dp = *dp;
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))
grand *r = &rand_global;
struct excinfo exc = EXCINFO_INIT;
pypgev evt = { { 0 } };
- char *kwlist[] =
+ static const char *const kwlist[] =
{ "class", "pbits", "qbits", "event", "rng", "nsteps", 0 };
PyObject *rc = 0;
evt.exc = &exc;
- 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))
pypgev 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;
oe.exc = ie.exc = &exc;
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,
PGENERR(&exc);
vec = PyList_New(nf);
for (i = 0; i < nf; i++)
- PyList_SetItem(vec, i, mp_pywrap(v[i]));
+ PyList_SET_ITEM(vec, i, mp_pywrap(v[i]));
xfree(v);
rc = Py_BuildValue("(NN)", fginfo_pywrap(&dp, dhinfo_pytype), vec);
end:
grand *r = &rand_global;
struct excinfo exc = EXCINFO_INIT;
pypgev 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;
evt.exc = &exc;
- 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))
Py_ssize_t ksz;
struct excinfo exc = EXCINFO_INIT;
pypgev evt = { { 0 } };
- char *kwlist[] =
+ static const char *const kwlist[] =
{ "class", "pbits", "qbits", "seed", "event", "nsteps", 0 };
PyObject *rc = 0;
evt.exc = &exc;
- 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))
static PyGetSetDef fginfo_pygetset[] = {
#define GETSETNAME(op, name) fi##op##_##name
- GET (r, "I.r -> group order")
+ GET (r, "I.r -> group order")
#undef GETSETNAME
{ 0 }
};
static PyGetSetDef dhinfo_pygetset[] = {
#define GETSETNAME(op, name) di##op##_##name
- GET (p, "I.p -> prime")
- GET (g, "I.g -> generator")
+ GET (p, "I.p -> prime")
+ GET (g, "I.g -> generator")
#undef GETSETNAME
{ 0 }
};
static PyGetSetDef bindhinfo_pygetset[] = {
#define GETSETNAME(op, name) bi##op##_##name
- GET (p, "I.p -> irreducible polynomial")
- GET (m, "I.m -> degree of polynomial")
- GET (g, "I.g -> generator")
+ GET (p, "I.p -> irreducible polynomial")
+ GET (m, "I.m -> degree of polynomial")
+ GET (g, "I.g -> generator")
#undef GETSETNAME
{ 0 }
};
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@ */
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@ */
/*----- General utilities -------------------------------------------------*/
PyTypeObject *ge_pytype, *group_pytype;
-PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
+static PyTypeObject *primegroup_pytype, *bingroup_pytype, *ecgroup_pytype;
group *group_copy(group *g)
{
- if (strcmp(G_NAME(g), "prime") == 0) {
+ if (STRCMP(G_NAME(g), ==, "prime")) {
gctx_prime *gc = (gctx_prime *)g;
gprime_param gp;
gp.g = G_TOINT(g, MP_NEW, g->g);
gp.q = gc->g.r;
g = group_prime(&gp);
MP_DROP(gp.g);
- } else if (strcmp(G_NAME(g), "bin") == 0) {
+ } else if (STRCMP(G_NAME(g), ==, "bin")) {
gctx_bin *gc = (gctx_bin *)g;
gbin_param gb;
gb.g = G_TOINT(g, MP_NEW, g->g);
gb.q = gc->g.r;
g = group_binary(&gb);
MP_DROP(gb.g);
- } else if (strcmp(G_NAME(g), "ec") == 0) {
+ } else if (STRCMP(G_NAME(g), ==, "ec")) {
gctx_ec *gc = (gctx_ec *)g;
ec_info ei;
if ((ei.c = eccurve_copy(gc->ei.c)) == 0)
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;
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);
{
PyTypeObject *ty;
- if (strcmp(G_NAME(g), "prime") == 0) ty = primegroup_pytype;
- else if (strcmp(G_NAME(g), "bin") == 0) ty = bingroup_pytype;
- else if (strcmp(G_NAME(g), "ec") == 0) ty = ecgroup_pytype;
+ if (STRCMP(G_NAME(g), ==, "prime")) ty = primegroup_pytype;
+ else if (STRCMP(G_NAME(g), ==, "bin")) ty = bingroup_pytype;
+ else if (STRCMP(G_NAME(g), ==, "ec")) ty = ecgroup_pytype;
else abort();
return (group_dopywrap(ty, g));
}
static PyObject *gemeth_toec(PyObject *me, PyObject *arg, PyObject *kw)
{
- char *kwlist[] = { "curve", 0 };
+ 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;
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) {
+ } else if (STRCMP(G_NAME(g), ==, "ec")) {
c = eccurve_copy(((gctx_ec *)g)->ei.c);
cty = (PyTypeObject *)eccurve_pywrap(0, c);
} else {
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)
METH (sqr, "X.sqr() -> X^2 = X * X")
METH (check, "X.check() -> check X really belongs to its group")
METH (toint, "X.toint() -> X converted to an integer")
- KWMETH(toec, "\
-X.toec([curve = ECPt]) -> X converted to elliptic curve point")
+ KWMETH(toec, "X.toec([curve = ECPt]) -> "
+ "X converted to elliptic curve point")
METH (tobuf, "X.tobuf() -> X in buffer representation")
METH (toraw, "X.toraw() -> X in raw representation")
#undef METHNAME
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Group elements, abstract base class.",
+ "Group elements, abstract base class.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
static PyMethodDef group_pymethods[] = {
#define METHNAME(name) gmeth_##name
- METH (mexp, "\
-G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...")
+ METH (mexp, "G.mexp([(X0, N0), (X1, N1), ...]) -> X0^N0 X1^N1 ...")
KWMETH(checkgroup, "G.checkgroup([rng = rand]): check group is good")
#undef METHNAME
{ 0 }
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Abstract base class for groups.",
+ "Abstract base class for groups.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
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))));
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Subgroups of prime fields.",
+ "PrimeGroup(INFO): subgroups of prime fields.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
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))));
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Subgroups of binary fields.",
+ "BinGroup(INFO): subgroups of binary fields.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
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));
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
-"Elliptic curve groups.",
+ "ECGroup(INFO): elliptic curve groups.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
static PyMethodDef methods[] = {
#define METHNAME(name) meth_##name
- METH (_GE_frombuf, "frombuf(BUF) -> X, REST")
- METH (_GE_fromraw, "fromraw(BUF) -> X, REST")
- METH (_GE_fromstring, "fromstring(STR) -> X, REST")
- METH (_Group_parse, "parse(STR) -> G, REST")
- METH (_DHInfo_parse, "parse(STR) -> D, REST")
- METH (_BinDHInfo_parse, "parse(STR) -> D, REST")
- METH (_DHInfo__groupn, 0)
- METH (_BinDHInfo__groupn, 0)
- KWMETH(_DHInfo_generate, "\
-generate(PBITS, [qbits = 0], [event = pgen_nullev],\n\
- [rng = rand], [nsteps = 0]) -> D")
- KWMETH(_DHInfo_genlimlee, "\
-genlimlee(PBITS, QBITS, [event = pgen_nullev], [ievent = pgen_nullev],\n\
- [rng = rand], [nsteps = 0], [subgroupp = True]) -> (D, [Q, ...])")
- KWMETH(_DHInfo_gendsa, "\
-gendsa(PBITS, QBITS, SEED, [event = pgen_nullev], [nsteps = 0])\n\
- -> (D, SEED, COUNT)")
- KWMETH(_DHInfo_genkcdsa, "\
-gendsa(PBITS, QBITS, [event = pgen_nullev], [rng = rand], [nsteps = 0])\n\
- -> (D, V)")
+ METH (_GE_frombuf, "frombuf(BUF) -> X, REST")
+ METH (_GE_fromraw, "fromraw(BUF) -> X, REST")
+ METH (_GE_fromstring, "fromstring(STR) -> X, REST")
+ METH (_Group_parse, "parse(STR) -> G, REST")
+ METH (_DHInfo_parse, "parse(STR) -> D, REST")
+ METH (_BinDHInfo_parse, "parse(STR) -> D, REST")
+ METH (_DHInfo__groupn, 0)
+ METH (_BinDHInfo__groupn, 0)
+ KWMETH(_DHInfo_generate,
+ "generate(PBITS, [qbits = 0, event = pgen_nullev,\n"
+ " rng = rand, nsteps = 0]) -> D")
+ KWMETH(_DHInfo_genlimlee,
+ "genlimlee(PBITS, QBITS, [event = pgen_nullev], "
+ "[ievent = pgen_nullev],\n"
+ " [rng = rand], [nsteps = 0], [subgroupp = True]) "
+ "-> (D, [Q, ...])")
+ KWMETH(_DHInfo_gendsa,
+ "gendsa(PBITS, QBITS, SEED, [event = pgen_nullev], [nsteps = 0])\n"
+ " -> (D, SEED, COUNT)")
+ KWMETH(_DHInfo_genkcdsa,
+ "gendsa(PBITS, QBITS, [event = pgen_nullev], "
+ "[rng = rand], [nsteps = 0])\n"
+ " -> (D, V)")
#undef METHNAME
{ 0 }
};