{
PyObject *x;
mp *z;
- char *kwlist[] = { "x", 0 };
+ static const char *const kwlist[] = { "x", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe", kwlist, &x))
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe", KWLIST, &x))
return (0);
if (FE_PYCHECK(x) && FE_F(x) == FIELD_F(ty)) RETURN_OBJ(x);
if ((z = getmp(x)) == 0) return (0);
{
PyTypeObject *ty;
- if (strcmp(F_NAME(f), "prime") == 0) ty = primefield_pytype;
- else if (strcmp(F_NAME(f), "niceprime") == 0) ty = niceprimefield_pytype;
- else if (strcmp(F_NAME(f), "binpoly") == 0) ty = binpolyfield_pytype;
- else if (strcmp(F_NAME(f), "binnorm") == 0) ty = binnormfield_pytype;
+ if (STRCMP(F_NAME(f), ==, "prime")) ty = primefield_pytype;
+ else if (STRCMP(F_NAME(f), ==, "niceprime")) ty = niceprimefield_pytype;
+ else if (STRCMP(F_NAME(f), ==, "binpoly")) ty = binpolyfield_pytype;
+ else if (STRCMP(F_NAME(f), ==, "binnorm")) ty = binnormfield_pytype;
else abort();
return (field_dopywrap(ty, f));
}
field *field_copy(field *f)
{
- if (strcmp(F_NAME(f), "prime") == 0)
+ if (STRCMP(F_NAME(f), ==, "prime"))
f = field_prime(f->m);
- else if (strcmp(F_NAME(f), "niceprime") == 0)
+ else if (STRCMP(F_NAME(f), ==, "niceprime"))
f = field_niceprime(f->m);
- else if (strcmp(F_NAME(f), "binpoly") == 0)
+ else if (STRCMP(F_NAME(f), ==, "binpoly"))
f = field_binpoly(f->m);
- else if (strcmp(F_NAME(f), "binnorm") == 0) {
+ else if (STRCMP(F_NAME(f), ==, "binnorm")) {
fctx_binnorm *fc = (fctx_binnorm *)f;
f = field_binnorm(f->m, fc->ntop.r[fc->ntop.n - 1]);
} else
return (y);
}
-mp *getfe(field *f, PyObject *o)
-{
- mp *x = 0;
- if ((x = tofe(f, o)) == 0) {
- PyErr_Format(PyExc_TypeError, "can't convert %.100s to fe",
- o->ob_type->tp_name);
- }
- return (x);
-}
-
/*----- Field elements ----------------------------------------------------*/
static int febinop(PyObject *x, PyObject *y,
#define BASEOP(name, radix, pre) \
static PyObject *fe_py##name(PyObject *x) { \
mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); \
- PyObject *rc = mp_topystring(FE_X(x), radix, 0, pre, 0); \
+ PyObject *rc = mp_topystring(xx, radix, 0, pre, 0); \
MP_DROP(xx); \
return (rc); \
}
static PyGetSetDef fe_pygetset[] = {
#define GETSETNAME(op, name) fe##op##_##name
GET (field, "X.field -> field containing X")
- GET (value, "X.value -> `natural' integer representation of X")
- GET (_value, "X._value -> internal integer representation of X")
+ GET (value, "X.value -> `natural' MP/GF representation of X")
+ GET (_value, "X._value -> internal MP/GF representation of X")
#undef GETSETNAME
{ 0 }
};
static PyObject *fmeth_rand(PyObject *me, PyObject *arg, PyObject *kw)
{
- char *kwlist[] = { "rng", 0 };
+ static const char *const kwlist[] = { "rng", 0 };
grand *r = &rand_global;
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand", KWLIST,
convgrand, &r))
return (0);
return (fe_pywrap(me, F_RAND(FIELD_F(me), MP_NEW, r)));
static PyMethodDef field_pymethods[] = {
#define METHNAME(name) fmeth_##name
METH (_adopt, "F._adopt(X) -> FE")
- KWMETH(rand, "F.rand(rng = rand) -> FE, uniformly distributed")
+ KWMETH(rand, "F.rand([rng = rand]) -> FE, uniformly distributed")
#undef METHNAME
{ 0 }
};
{
mp *xx = 0;
field *f;
- char *kwlist[] = { "p", 0 };
+ static const char *const kwlist[] = { "p", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:primefield", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:primefield", KWLIST,
convmp, &xx))
goto end;
if ((f = field_prime(xx)) == 0)
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
- "Prime fields.",
+"PrimeField(P): prime fields.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
mp *xx = 0;
field *f;
- char *kwlist[] = { "p", 0 };
+ static const char *const kwlist[] = { "p", 0 };
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:niceprimefield",
- kwlist, convmp, &xx))
+ KWLIST, convmp, &xx))
goto end;
if ((f = field_niceprime(xx)) == 0)
VALERR("bad prime for niceprimefield");
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
- "Nice prime fields.",
+"NicePrimeField(P): prime field using Solinas reduction.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
- "Binary fields. Abstract class.",
+"Binary fields. Abstract class.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
mp *xx = 0;
field *f;
- char *kwlist[] = { "p", 0 };
+ static const char *const kwlist[] = { "p", 0 };
- if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield", KWLIST,
convgf, &xx))
goto end;
if ((f = field_binpoly(xx)) == 0) VALERR("bad poly for binpolyfield");
return (0);
}
+static PyObject *bfget_p(PyObject *me, void *hunoz)
+ { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); }
+
static PyGetSetDef binpolyfield_pygetset[] = {
-#define GETSETNAME(op, name) pf##op##_##name
+#define GETSETNAME(op, name) bf##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
{ 0 }
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
- "Binary fields with polynomial basis representation.",
+"BinPolyField(P): binary fields with polynomial basis representation.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */
{
mp *xx = 0, *yy = 0;
field *f;
- char *kwlist[] = { "p", "beta", 0 };
+ static const char *const kwlist[] = { "p", "beta", 0 };
if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:binnormfield",
- kwlist, convgf, &xx, convgf, &yy))
+ KWLIST, convgf, &xx, convgf, &yy))
goto end;
if ((f = field_binnorm(xx, yy)) == 0) VALERR("bad args for binnormfield");
MP_DROP(xx); MP_DROP(yy);
}
static PyGetSetDef binnormfield_pygetset[] = {
-#define GETSETNAME(op, name) pf##op##_##name
+#define GETSETNAME(op, name) bf##op##_##name
GET (p, "F.p -> field polynomial")
#undef GETSETNAME
#define GETSETNAME(op, name) bnf##op##_##name
Py_TPFLAGS_BASETYPE,
/* @tp_doc@ */
- "Binary fields with normal basis representation.",
+"BinNormField(P, BETA): binary fields with normal basis representation.",
0, /* @tp_traverse@ */
0, /* @tp_clear@ */