Commit | Line | Data |
---|---|---|
d7ab1bab | 1 | /* -*-c-*- |
2 | * | |
d7ab1bab | 3 | * Abstract fields |
4 | * | |
5 | * (c) 2004 Straylight/Edgeware | |
6 | */ | |
7 | ||
b2687a0a | 8 | /*----- Licensing notice --------------------------------------------------* |
d7ab1bab | 9 | * |
10 | * This file is part of the Python interface to Catacomb. | |
11 | * | |
12 | * Catacomb/Python is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
b2687a0a | 16 | * |
d7ab1bab | 17 | * Catacomb/Python is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
b2687a0a | 21 | * |
d7ab1bab | 22 | * You should have received a copy of the GNU General Public License |
23 | * along with Catacomb/Python; if not, write to the Free Software Foundation, | |
24 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
25 | */ | |
26 | ||
27 | /*----- Header files ------------------------------------------------------*/ | |
28 | ||
29 | #include "catacomb-python.h" | |
30 | ||
31 | /*----- Various utilities -------------------------------------------------*/ | |
32 | ||
33 | PyTypeObject *field_pytype; | |
34 | PyTypeObject *primefield_pytype; | |
35 | PyTypeObject *niceprimefield_pytype; | |
36 | PyTypeObject *binfield_pytype; | |
37 | PyTypeObject *binpolyfield_pytype; | |
38 | PyTypeObject *binnormfield_pytype; | |
39 | PyTypeObject *fe_pytype; | |
40 | ||
41 | static PyObject *fe_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw) | |
42 | { | |
43 | PyObject *x; | |
44 | mp *z; | |
827f89d7 | 45 | static const char *const kwlist[] = { "x", 0 }; |
d7ab1bab | 46 | |
827f89d7 | 47 | if (!PyArg_ParseTupleAndKeywords(arg, kw, "O:fe", KWLIST, &x)) |
d7ab1bab | 48 | return (0); |
49 | if (FE_PYCHECK(x) && FE_F(x) == FIELD_F(ty)) RETURN_OBJ(x); | |
50 | if ((z = getmp(x)) == 0) return (0); | |
51 | z = F_IN(FIELD_F(ty), z, z); | |
52 | return (fe_pywrap((PyObject *)ty, z)); | |
53 | } | |
54 | ||
55 | static PyObject *field_dopywrap(PyTypeObject *ty, field *f) | |
56 | { | |
df9f8366 | 57 | field_pyobj *fobj = newtype(ty, 0, f->ops->name); |
d7ab1bab | 58 | fobj->f = f; |
24b3d57b MW |
59 | fobj->ty.ht_type.tp_basicsize = sizeof(fe_pyobj); |
60 | fobj->ty.ht_type.tp_base = fe_pytype; | |
d7ab1bab | 61 | Py_INCREF(fe_pytype); |
24b3d57b MW |
62 | fobj->ty.ht_type.tp_flags = (Py_TPFLAGS_DEFAULT | |
63 | Py_TPFLAGS_BASETYPE | | |
64 | Py_TPFLAGS_CHECKTYPES | | |
65 | Py_TPFLAGS_HEAPTYPE); | |
66 | fobj->ty.ht_type.tp_alloc = PyType_GenericAlloc; | |
67 | fobj->ty.ht_type.tp_free = 0; | |
68 | fobj->ty.ht_type.tp_new = fe_pynew; | |
dc075750 | 69 | typeready(&fobj->ty.ht_type); |
d7ab1bab | 70 | return ((PyObject *)fobj); |
71 | } | |
72 | ||
73 | PyObject *field_pywrap(field *f) | |
74 | { | |
75 | PyTypeObject *ty; | |
76 | ||
20441612 MW |
77 | if (STRCMP(F_NAME(f), ==, "prime")) ty = primefield_pytype; |
78 | else if (STRCMP(F_NAME(f), ==, "niceprime")) ty = niceprimefield_pytype; | |
79 | else if (STRCMP(F_NAME(f), ==, "binpoly")) ty = binpolyfield_pytype; | |
80 | else if (STRCMP(F_NAME(f), ==, "binnorm")) ty = binnormfield_pytype; | |
d7ab1bab | 81 | else abort(); |
82 | return (field_dopywrap(ty, f)); | |
83 | } | |
84 | ||
85 | field *field_copy(field *f) | |
86 | { | |
20441612 | 87 | if (STRCMP(F_NAME(f), ==, "prime")) |
d7ab1bab | 88 | f = field_prime(f->m); |
20441612 | 89 | else if (STRCMP(F_NAME(f), ==, "niceprime")) |
d7ab1bab | 90 | f = field_niceprime(f->m); |
20441612 | 91 | else if (STRCMP(F_NAME(f), ==, "binpoly")) |
d7ab1bab | 92 | f = field_binpoly(f->m); |
20441612 | 93 | else if (STRCMP(F_NAME(f), ==, "binnorm")) { |
d7ab1bab | 94 | fctx_binnorm *fc = (fctx_binnorm *)f; |
95 | f = field_binnorm(f->m, fc->ntop.r[fc->ntop.n - 1]); | |
96 | } else | |
97 | abort(); | |
98 | return (f); | |
99 | } | |
100 | ||
101 | PyObject *fe_pywrap(PyObject *fobj, mp *x) | |
102 | { | |
103 | fe_pyobj *z = PyObject_New(fe_pyobj, (PyTypeObject *)fobj); | |
104 | z->f = FIELD_F(fobj); | |
105 | Py_INCREF(fobj); | |
106 | z->x = x; | |
107 | return ((PyObject *)z); | |
108 | } | |
109 | ||
110 | static mp *tofe(field *f, PyObject *o) | |
111 | { | |
112 | mp *x = 0, *y = 0; | |
113 | ||
114 | if (FE_PYCHECK(o)) { | |
115 | if (FE_F(o) != f && !field_samep(FE_F(o), f)) return (0); | |
c62f9ebf MW |
116 | y = MP_COPY(FE_X(o)); |
117 | } else if ((x = tomp(o)) != 0) { | |
d7ab1bab | 118 | if (MP_ZEROP(x)) |
c62f9ebf | 119 | y = MP_COPY(f->zero); |
d7ab1bab | 120 | else if (MP_EQ(x, MP_ONE)) |
c62f9ebf MW |
121 | y = MP_COPY(f->one); |
122 | else | |
123 | y = F_IN(f, MP_NEW, x); | |
124 | MP_DROP(x); | |
d7ab1bab | 125 | } |
d7ab1bab | 126 | return (y); |
127 | } | |
128 | ||
d7ab1bab | 129 | /*----- Field elements ----------------------------------------------------*/ |
130 | ||
131 | static int febinop(PyObject *x, PyObject *y, | |
132 | field **f, PyObject **fobj, mp **xx, mp **yy) | |
133 | { | |
134 | if (FE_PYCHECK(x)) *fobj = FE_FOBJ(x); | |
135 | else if (FE_PYCHECK(y)) *fobj = FE_FOBJ(y); | |
136 | else return (-1); | |
137 | *f = FIELD_F(*fobj); | |
138 | if ((*xx = tofe(*f, x)) == 0) | |
139 | return (-1); | |
140 | if ((*yy = tofe(*f, y)) == 0) { | |
141 | MP_DROP(*xx); | |
142 | return (-1); | |
143 | } | |
144 | return (0); | |
145 | } | |
146 | ||
147 | #define BINOP(name) \ | |
148 | static PyObject *fe_py##name(PyObject *x, PyObject *y) { \ | |
149 | PyObject *fobj; \ | |
150 | field *ff; \ | |
151 | mp *xx, *yy, *zz; \ | |
152 | if (febinop(x, y, &ff, &fobj, &xx, &yy)) RETURN_NOTIMPL; \ | |
153 | zz = ff->ops->name(ff, MP_NEW, xx, yy); \ | |
154 | MP_DROP(xx); MP_DROP(yy); \ | |
155 | return (fe_pywrap(fobj, zz)); \ | |
156 | } | |
157 | BINOP(add) | |
158 | BINOP(sub) | |
159 | BINOP(mul) | |
160 | #undef BINOP | |
161 | ||
162 | static PyObject *fe_pydiv(PyObject *x, PyObject *y) | |
163 | { | |
164 | PyObject *fobj; | |
165 | field *ff; | |
166 | mp *xx, *yy; | |
167 | PyObject *z = 0; | |
168 | if (febinop(x, y, &ff, &fobj, &xx, &yy)) RETURN_NOTIMPL; | |
169 | if (F_ZEROP(ff, yy)) ZDIVERR("division by zero"); | |
170 | yy = F_INV(ff, yy, yy); | |
171 | z = fe_pywrap(fobj, F_MUL(ff, MP_NEW, xx, yy)); | |
172 | end: | |
173 | MP_DROP(xx); MP_DROP(yy); | |
174 | return (z); | |
175 | } | |
176 | ||
177 | static PyObject *fe_pyexp(PyObject *x, PyObject *y, PyObject *z) | |
178 | { | |
179 | field *ff; | |
180 | mp *xx, *yy; | |
181 | ||
182 | if (z != Py_None || !FE_PYCHECK(x) || (yy = tomp(y)) == 0) | |
183 | RETURN_NOTIMPL; | |
184 | ff = FE_F(x); xx = FE_X(x); MP_COPY(xx); | |
185 | if (MP_NEGP(yy) && F_ZEROP(ff, xx)) ZDIVERR("division by zero"); | |
186 | z = fe_pywrap(FE_FOBJ(x), field_exp(ff, MP_NEW, xx, yy)); | |
187 | end: | |
188 | MP_DROP(xx); MP_DROP(yy); | |
189 | return (z); | |
190 | } | |
191 | ||
192 | static PyObject *fe_pyneg(PyObject *x) | |
193 | { | |
194 | return fe_pywrap(FE_FOBJ(x), FE_F(x)->ops->neg(FE_F(x), MP_NEW, FE_X(x))); | |
195 | } | |
196 | ||
197 | static PyObject *fe_pyid(PyObject *x) { RETURN_OBJ(x); } | |
198 | ||
199 | static int fe_pynonzerop(PyObject *x) { return !F_ZEROP(FE_F(x), FE_X(x)); } | |
200 | ||
201 | static PyObject *fe_pyrichcompare(PyObject *x, PyObject *y, int op) | |
202 | { | |
203 | PyObject *fobj; | |
204 | field *ff; | |
205 | mp *xx, *yy; | |
206 | int b; | |
207 | PyObject *rc = 0; | |
208 | ||
209 | if (febinop(x, y, &ff, &fobj, &xx, &yy)) RETURN_NOTIMPL; | |
210 | switch (op) { | |
211 | case Py_EQ: b = MP_EQ(xx, yy); break; | |
212 | case Py_NE: b = !MP_EQ(xx, yy); break; | |
213 | default: TYERR("field elements are unordered"); | |
214 | } | |
215 | rc = getbool(b); | |
216 | end: | |
217 | MP_DROP(xx); MP_DROP(yy); | |
218 | return (rc); | |
219 | } | |
220 | ||
620169ae | 221 | static Py_hash_t fe_pyhash(PyObject *me) |
ab723d73 | 222 | { return (mphash(FE_X(me))); } |
d7ab1bab | 223 | |
224 | static int fe_pycoerce(PyObject **x, PyObject **y) | |
225 | { | |
226 | mp *z; | |
227 | ||
228 | if (FE_PYCHECK(*y)) { | |
229 | if (FE_F(*x) != FE_F(*y) && !field_samep(FE_F(*x), FE_F(*y))) | |
230 | TYERR("field mismatch"); | |
231 | Py_INCREF(*x); Py_INCREF(*y); | |
232 | return (0); | |
233 | } | |
234 | if ((z = tofe(FE_F(*x), *y)) != 0) { | |
235 | Py_INCREF(*x); | |
236 | *y = fe_pywrap(FE_FOBJ(*x), z); | |
237 | return (0); | |
238 | } | |
239 | return (1); | |
240 | ||
241 | end: | |
242 | return (-1); | |
243 | } | |
244 | ||
245 | static PyObject *fe_pyint(PyObject *x) | |
246 | { | |
247 | long l; | |
bc243788 | 248 | PyObject *rc; |
d7ab1bab | 249 | mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); |
bc243788 MW |
250 | if (!mp_tolong_checked(xx, &l, 0)) rc = PyInt_FromLong(l); |
251 | else rc = mp_topylong(xx); | |
d7ab1bab | 252 | MP_DROP(xx); |
bc243788 | 253 | return (rc); |
d7ab1bab | 254 | } |
255 | ||
256 | static PyObject *fe_pylong(PyObject *x) | |
257 | { | |
258 | mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); | |
f368b46e | 259 | PyObject *rc = mp_topylong(xx); |
d7ab1bab | 260 | MP_DROP(xx); |
261 | return (rc); | |
262 | } | |
263 | ||
264 | #define BASEOP(name, radix, pre) \ | |
265 | static PyObject *fe_py##name(PyObject *x) { \ | |
266 | mp *xx = F_OUT(FE_F(x), MP_NEW, FE_X(x)); \ | |
d9782ff0 | 267 | PyObject *rc = mp_topystring(xx, radix, 0, pre, 0); \ |
d7ab1bab | 268 | MP_DROP(xx); \ |
269 | return (rc); \ | |
270 | } | |
271 | BASEOP(oct, 8, "0"); | |
272 | BASEOP(hex, 16, "0x"); | |
273 | #undef BASEOP | |
274 | ||
275 | static void fe_pydealloc(PyObject *me) | |
276 | { | |
277 | Py_DECREF(FE_FOBJ(me)); | |
278 | MP_DROP(FE_X(me)); | |
3aa33042 | 279 | FREEOBJ(me); |
d7ab1bab | 280 | } |
281 | ||
282 | #define UNOP(name, check) \ | |
7a75bb76 | 283 | static PyObject *femeth_##name(PyObject *me) { \ |
d7ab1bab | 284 | field *f = FE_F(me); \ |
285 | mp *x = FE_X(me); \ | |
d7ab1bab | 286 | if (!f->ops->name) TYERR(#name " not supported for this field"); \ |
287 | check \ | |
288 | x = f->ops->name(f, MP_NEW, x); \ | |
289 | if (!x) RETURN_NONE; \ | |
290 | return (fe_pywrap(FE_FOBJ(me), x)); \ | |
291 | end: \ | |
292 | return (0); \ | |
293 | } | |
294 | UNOP(inv, if (F_ZEROP(f, x)) ZDIVERR("division by zero"); ) | |
295 | UNOP(sqr, ; ) | |
296 | UNOP(sqrt, ; ) | |
297 | UNOP(quadsolve, ; ) | |
298 | UNOP(dbl, ; ) | |
299 | UNOP(tpl, ; ) | |
300 | UNOP(qdl, ; ) | |
301 | UNOP(hlv, ; ) | |
302 | #undef UNOP | |
303 | ||
d7ab1bab | 304 | static PyObject *feget_value(PyObject *me, void *hunoz) |
305 | { | |
306 | mp *x = F_OUT(FE_F(me), MP_NEW, FE_X(me)); | |
307 | if (F_TYPE(FE_F(me)) == FTY_BINARY) | |
308 | return (gf_pywrap(x)); | |
309 | else | |
310 | return (mp_pywrap(x)); | |
311 | } | |
312 | ||
313 | static PyObject *feget__value(PyObject *me, void *hunoz) | |
314 | { | |
315 | mp *x = FE_X(me); | |
316 | MP_COPY(x); | |
317 | if (F_TYPE(FE_F(me)) == FTY_BINARY) | |
318 | return (gf_pywrap(x)); | |
319 | else | |
320 | return (mp_pywrap(x)); | |
321 | } | |
322 | ||
3ed16ce3 MW |
323 | static const PyMemberDef fe_pymembers[] = { |
324 | #define MEMBERSTRUCT fe_pyobj | |
325 | MEMRNM(field, T_OBJECT, ob_type, READONLY, | |
326 | "X.field -> field containing X") | |
327 | #undef MEMBERSTRUCT | |
328 | { 0 } | |
329 | }; | |
330 | ||
637b9140 | 331 | static const PyGetSetDef fe_pygetset[] = { |
d7ab1bab | 332 | #define GETSETNAME(op, name) fe##op##_##name |
45c4c120 MW |
333 | GET (value, "X.value -> `natural' MP/GF representation of X") |
334 | GET (_value, "X._value -> internal MP/GF representation of X") | |
d7ab1bab | 335 | #undef GETSETNAME |
336 | { 0 } | |
337 | }; | |
338 | ||
637b9140 | 339 | static const PyMethodDef fe_pymethods[] = { |
d7ab1bab | 340 | #define METHNAME(func) femeth_##func |
7a75bb76 MW |
341 | NAMETH(inv, "X.inv() -> X^{-1}") |
342 | NAMETH(sqr, "X.sqr() -> X^2") | |
343 | NAMETH(sqrt, "X.sqrt() -> sqrt(X)") | |
344 | NAMETH(quadsolve, "X.quadsolve() -> Y where Y^2 + Y = X (binary only)") | |
345 | NAMETH(dbl, "X.dbl() -> 2 * X (prime only)") | |
346 | NAMETH(tpl, "X.tpl() -> 3 * X (prime only)") | |
347 | NAMETH(qdl, "X.qdl() -> 4 * X (prime only)") | |
348 | NAMETH(hlv, "X.hlv() -> X/2 (prime only)") | |
d7ab1bab | 349 | #undef METHNAME |
350 | { 0 } | |
351 | }; | |
352 | ||
637b9140 | 353 | static const PyNumberMethods fe_pynumber = { |
d7ab1bab | 354 | fe_pyadd, /* @nb_add@ */ |
355 | fe_pysub, /* @nb_subtract@ */ | |
356 | fe_pymul, /* @nb_multiply@ */ | |
357 | fe_pydiv, /* @nb_divide@ */ | |
358 | 0, /* @nb_remainder@ */ | |
359 | 0, /* @nb_divmod@ */ | |
360 | fe_pyexp, /* @nb_power@ */ | |
361 | fe_pyneg, /* @nb_negative@ */ | |
362 | fe_pyid, /* @nb_positive@ */ | |
363 | 0, /* @nb_absolute@ */ | |
364 | fe_pynonzerop, /* @nb_nonzero@ */ | |
365 | 0, /* @nb_invert@ */ | |
366 | 0, /* @nb_lshift@ */ | |
367 | 0, /* @nb_rshift@ */ | |
368 | 0, /* @nb_and@ */ | |
369 | 0, /* @nb_xor@ */ | |
370 | 0, /* @nb_or@ */ | |
371 | fe_pycoerce, /* @nb_coerce@ */ | |
372 | fe_pyint, /* @nb_int@ */ | |
373 | fe_pylong, /* @nb_long@ */ | |
374 | 0 /* meaningless */, /* @nb_float@ */ | |
375 | fe_pyoct, /* @nb_oct@ */ | |
376 | fe_pyhex, /* @nb_hex@ */ | |
377 | ||
378 | 0, /* @nb_inplace_add@ */ | |
379 | 0, /* @nb_inplace_subtract@ */ | |
380 | 0, /* @nb_inplace_multiply@ */ | |
381 | 0, /* @nb_inplace_divide@ */ | |
382 | 0, /* @nb_inplace_remainder@ */ | |
383 | 0, /* @nb_inplace_power@ */ | |
384 | 0, /* @nb_inplace_lshift@ */ | |
385 | 0, /* @nb_inplace_rshift@ */ | |
386 | 0, /* @nb_inplace_and@ */ | |
387 | 0, /* @nb_inplace_xor@ */ | |
388 | 0, /* @nb_inplace_or@ */ | |
389 | ||
390 | 0, /* @nb_floor_divide@ */ | |
391 | fe_pydiv, /* @nb_true_divide@ */ | |
392 | 0, /* @nb_inplace_floor_divide@ */ | |
393 | 0, /* @nb_inplace_true_divide@ */ | |
394 | }; | |
395 | ||
ddd4720b | 396 | static const PyTypeObject fe_pytype_skel = { |
4648f560 | 397 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 398 | "FE", /* @tp_name@ */ |
d7ab1bab | 399 | sizeof(fe_pyobj), /* @tp_basicsize@ */ |
400 | 0, /* @tp_itemsize@ */ | |
401 | ||
402 | fe_pydealloc, /* @tp_dealloc@ */ | |
403 | 0, /* @tp_print@ */ | |
404 | 0, /* @tp_getattr@ */ | |
405 | 0, /* @tp_setattr@ */ | |
406 | 0, /* @tp_compare@ */ | |
407 | 0, /* @tp_repr@ */ | |
637b9140 | 408 | PYNUMBER(fe), /* @tp_as_number@ */ |
d7ab1bab | 409 | 0, /* @tp_as_sequence@ */ |
410 | 0, /* @tp_as_mapping@ */ | |
411 | fe_pyhash, /* @tp_hash@ */ | |
412 | 0, /* @tp_call@ */ | |
413 | fe_pyhex, /* @tp_str@ */ | |
414 | 0, /* @tp_getattro@ */ | |
415 | 0, /* @tp_setattro@ */ | |
416 | 0, /* @tp_as_buffer@ */ | |
417 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
418 | Py_TPFLAGS_CHECKTYPES | | |
419 | Py_TPFLAGS_BASETYPE, | |
420 | ||
421 | /* @tp_doc@ */ | |
ef783f91 | 422 | "Finite field elements, abstract base class.", |
d7ab1bab | 423 | |
424 | 0, /* @tp_traverse@ */ | |
425 | 0, /* @tp_clear@ */ | |
426 | fe_pyrichcompare, /* @tp_richcompare@ */ | |
427 | 0, /* @tp_weaklistoffset@ */ | |
428 | 0, /* @tp_iter@ */ | |
963a6148 | 429 | 0, /* @tp_iternext@ */ |
637b9140 | 430 | PYMETHODS(fe), /* @tp_methods@ */ |
3ed16ce3 | 431 | PYMEMBERS(fe), /* @tp_members@ */ |
637b9140 | 432 | PYGETSET(fe), /* @tp_getset@ */ |
d7ab1bab | 433 | 0, /* @tp_base@ */ |
434 | 0, /* @tp_dict@ */ | |
435 | 0, /* @tp_descr_get@ */ | |
436 | 0, /* @tp_descr_set@ */ | |
437 | 0, /* @tp_dictoffset@ */ | |
438 | 0, /* @tp_init@ */ | |
439 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
440 | abstract_pynew, /* @tp_new@ */ | |
3aa33042 | 441 | 0, /* @tp_free@ */ |
d7ab1bab | 442 | 0 /* @tp_is_gc@ */ |
443 | }; | |
444 | ||
445 | /*----- Fields ------------------------------------------------------------*/ | |
446 | ||
447 | static PyObject *field_pyrichcompare(PyObject *x, PyObject *y, int op) | |
448 | { | |
449 | int b = field_samep(FIELD_F(x), FIELD_F(y)); | |
450 | switch (op) { | |
451 | case Py_EQ: break; | |
452 | case Py_NE: b = !b; | |
453 | default: TYERR("can't order fields"); | |
454 | } | |
455 | return (getbool(b)); | |
456 | end: | |
457 | return (0); | |
458 | } | |
459 | ||
460 | static PyObject *fmeth_rand(PyObject *me, PyObject *arg, PyObject *kw) | |
461 | { | |
827f89d7 | 462 | static const char *const kwlist[] = { "rng", 0 }; |
d7ab1bab | 463 | grand *r = &rand_global; |
464 | ||
827f89d7 | 465 | if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:rand", KWLIST, |
d7ab1bab | 466 | convgrand, &r)) |
467 | return (0); | |
468 | return (fe_pywrap(me, F_RAND(FIELD_F(me), MP_NEW, r))); | |
469 | } | |
470 | ||
471 | static PyObject *fmeth__adopt(PyObject *me, PyObject *arg) | |
472 | { | |
473 | mp *xx; | |
474 | if (!PyArg_ParseTuple(arg, "O&:_adopt", convmp, &xx)) return (0); | |
475 | return (fe_pywrap(me, xx)); | |
476 | } | |
477 | ||
b16009b0 | 478 | static PyObject *fmeth_parse(PyObject *me, PyObject *arg) |
27cbcf9d MW |
479 | { |
480 | field *f; | |
481 | char *p; | |
482 | PyObject *rc = 0; | |
483 | qd_parse qd; | |
484 | ||
b16009b0 | 485 | if (!PyArg_ParseTuple(arg, "s:parse", &p)) goto end; |
27cbcf9d MW |
486 | qd.p = p; qd.e = 0; |
487 | if ((f = field_parse(&qd)) == 0) VALERR(qd.e); | |
488 | rc = Py_BuildValue("(Ns)", field_pywrap(f), qd.p); | |
489 | end: | |
490 | return (rc); | |
491 | } | |
492 | ||
d7ab1bab | 493 | static void field_pydealloc(PyObject *me) |
494 | { | |
495 | F_DESTROY(FIELD_F(me)); | |
496 | PyType_Type.tp_dealloc(me); | |
497 | } | |
498 | ||
499 | static PyObject *fget_zero(PyObject *me, void *hunoz) | |
500 | { return (fe_pywrap(me, MP_COPY(FIELD_F(me)->zero))); } | |
501 | ||
502 | static PyObject *fget_one(PyObject *me, void *hunoz) | |
503 | { return (fe_pywrap(me, MP_COPY(FIELD_F(me)->one))); } | |
504 | ||
505 | static PyObject *fget_q(PyObject *me, void *hunoz) | |
506 | { return (mp_pywrap(MP_COPY(FIELD_F(me)->q))); } | |
507 | ||
508 | static PyObject *fget_nbits(PyObject *me, void *hunoz) | |
509 | { return (PyInt_FromLong(FIELD_F(me)->nbits)); } | |
510 | ||
511 | static PyObject *fget_noctets(PyObject *me, void *hunoz) | |
512 | { return (PyInt_FromLong(FIELD_F(me)->noctets)); } | |
513 | ||
514 | static PyObject *fget_name(PyObject *me, void *hunoz) | |
515 | { return (PyString_FromString(F_NAME(FIELD_F(me)))); } | |
516 | ||
517 | static PyObject *fget_type(PyObject *me, void *hunoz) | |
518 | { return (PyInt_FromLong(F_TYPE(FIELD_F(me)))); } | |
519 | ||
637b9140 | 520 | static const PyGetSetDef field_pygetset[] = { |
d7ab1bab | 521 | #define GETSETNAME(op, name) f##op##_##name |
522 | GET (zero, "F.zero -> field additive identity") | |
523 | GET (one, "F.one -> field multiplicative identity") | |
524 | GET (q, "F.q -> number of elements in field") | |
525 | GET (nbits, "F.nbits -> bits needed to represent element") | |
526 | GET (noctets, "F.noctets -> octetss needed to represent element") | |
527 | GET (name, "F.name -> name of this kind of field") | |
528 | GET (type, "F.type -> type code of this kind of field") | |
529 | #undef GETSETNAME | |
530 | { 0 } | |
531 | }; | |
532 | ||
637b9140 | 533 | static const PyMethodDef field_pymethods[] = { |
d7ab1bab | 534 | #define METHNAME(name) fmeth_##name |
535 | METH (_adopt, "F._adopt(X) -> FE") | |
1df8d5fe | 536 | KWMETH(rand, "F.rand([rng = rand]) -> FE, uniformly distributed") |
b16009b0 | 537 | SMTH (parse, "parse(STR) -> F, REST") |
d7ab1bab | 538 | #undef METHNAME |
539 | { 0 } | |
540 | }; | |
541 | ||
ddd4720b | 542 | static const PyTypeObject field_pytype_skel = { |
4648f560 | 543 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 544 | "Field", /* @tp_name@ */ |
d7ab1bab | 545 | sizeof(field_pyobj), /* @tp_basicsize@ */ |
546 | 0, /* @tp_itemsize@ */ | |
547 | ||
548 | field_pydealloc, /* @tp_dealloc@ */ | |
549 | 0, /* @tp_print@ */ | |
550 | 0, /* @tp_getattr@ */ | |
551 | 0, /* @tp_setattr@ */ | |
552 | 0, /* @tp_compare@ */ | |
553 | 0, /* @tp_repr@ */ | |
554 | 0, /* @tp_as_number@ */ | |
555 | 0, /* @tp_as_sequence@ */ | |
556 | 0, /* @tp_as_mapping@ */ | |
557 | 0, /* @tp_hash@ */ | |
558 | 0, /* @tp_call@ */ | |
559 | 0, /* @tp_str@ */ | |
560 | 0, /* @tp_getattro@ */ | |
561 | 0, /* @tp_setattro@ */ | |
562 | 0, /* @tp_as_buffer@ */ | |
563 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
564 | Py_TPFLAGS_BASETYPE, | |
565 | ||
566 | /* @tp_doc@ */ | |
ef783f91 | 567 | "An abstract field. This is an abstract type.", |
d7ab1bab | 568 | |
569 | 0, /* @tp_traverse@ */ | |
570 | 0, /* @tp_clear@ */ | |
571 | field_pyrichcompare, /* @tp_richcompare@ */ | |
572 | 0, /* @tp_weaklistoffset@ */ | |
573 | 0, /* @tp_iter@ */ | |
963a6148 | 574 | 0, /* @tp_iternext@ */ |
637b9140 | 575 | PYMETHODS(field), /* @tp_methods@ */ |
d7ab1bab | 576 | 0, /* @tp_members@ */ |
637b9140 | 577 | PYGETSET(field), /* @tp_getset@ */ |
d7ab1bab | 578 | 0, /* @tp_base@ */ |
579 | 0, /* @tp_dict@ */ | |
580 | 0, /* @tp_descr_get@ */ | |
581 | 0, /* @tp_descr_set@ */ | |
582 | 0, /* @tp_dictoffset@ */ | |
583 | 0, /* @tp_init@ */ | |
584 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
585 | abstract_pynew, /* @tp_new@ */ | |
3aa33042 | 586 | 0, /* @tp_free@ */ |
d7ab1bab | 587 | 0 /* @tp_is_gc@ */ |
588 | }; | |
589 | ||
590 | /*----- Prime fields ------------------------------------------------------*/ | |
591 | ||
592 | static PyObject *primefield_pynew(PyTypeObject *ty, | |
593 | PyObject *arg, PyObject *kw) | |
594 | { | |
595 | mp *xx = 0; | |
596 | field *f; | |
827f89d7 | 597 | static const char *const kwlist[] = { "p", 0 }; |
d7ab1bab | 598 | |
827f89d7 | 599 | if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:primefield", KWLIST, |
d7ab1bab | 600 | convmp, &xx)) |
601 | goto end; | |
602 | if ((f = field_prime(xx)) == 0) | |
603 | VALERR("bad prime for primefield"); | |
604 | MP_DROP(xx); | |
605 | return (field_dopywrap(ty, f)); | |
606 | end: | |
607 | mp_drop(xx); | |
608 | return (0); | |
609 | } | |
610 | ||
611 | static PyObject *pfget_p(PyObject *me, void *hunoz) | |
612 | { return (mp_pywrap(MP_COPY(FIELD_F(me)->m))); } | |
613 | ||
637b9140 | 614 | static const PyGetSetDef primefield_pygetset[] = { |
d7ab1bab | 615 | #define GETSETNAME(op, name) pf##op##_##name |
b2687a0a | 616 | GET (p, "F.p -> prime field characteristic") |
d7ab1bab | 617 | #undef GETSETNAME |
618 | }; | |
619 | ||
ddd4720b | 620 | static const PyTypeObject primefield_pytype_skel = { |
4648f560 | 621 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 622 | "PrimeField", /* @tp_name@ */ |
d7ab1bab | 623 | sizeof(field_pyobj), /* @tp_basicsize@ */ |
624 | 0, /* @tp_itemsize@ */ | |
625 | ||
626 | field_pydealloc, /* @tp_dealloc@ */ | |
627 | 0, /* @tp_print@ */ | |
628 | 0, /* @tp_getattr@ */ | |
629 | 0, /* @tp_setattr@ */ | |
630 | 0, /* @tp_compare@ */ | |
631 | 0, /* @tp_repr@ */ | |
632 | 0, /* @tp_as_number@ */ | |
633 | 0, /* @tp_as_sequence@ */ | |
634 | 0, /* @tp_as_mapping@ */ | |
635 | 0, /* @tp_hash@ */ | |
636 | 0, /* @tp_call@ */ | |
637 | 0, /* @tp_str@ */ | |
638 | 0, /* @tp_getattro@ */ | |
639 | 0, /* @tp_setattro@ */ | |
640 | 0, /* @tp_as_buffer@ */ | |
641 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
642 | Py_TPFLAGS_BASETYPE, | |
643 | ||
644 | /* @tp_doc@ */ | |
ef783f91 | 645 | "PrimeField(P): prime fields.", |
d7ab1bab | 646 | |
647 | 0, /* @tp_traverse@ */ | |
648 | 0, /* @tp_clear@ */ | |
649 | field_pyrichcompare, /* @tp_richcompare@ */ | |
650 | 0, /* @tp_weaklistoffset@ */ | |
651 | 0, /* @tp_iter@ */ | |
963a6148 | 652 | 0, /* @tp_iternext@ */ |
d7ab1bab | 653 | 0, /* @tp_methods@ */ |
654 | 0, /* @tp_members@ */ | |
637b9140 | 655 | PYGETSET(primefield), /* @tp_getset@ */ |
d7ab1bab | 656 | 0, /* @tp_base@ */ |
657 | 0, /* @tp_dict@ */ | |
658 | 0, /* @tp_descr_get@ */ | |
659 | 0, /* @tp_descr_set@ */ | |
660 | 0, /* @tp_dictoffset@ */ | |
661 | 0, /* @tp_init@ */ | |
662 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
663 | primefield_pynew, /* @tp_new@ */ | |
3aa33042 | 664 | 0, /* @tp_free@ */ |
d7ab1bab | 665 | 0 /* @tp_is_gc@ */ |
666 | }; | |
667 | ||
668 | static PyObject *niceprimefield_pynew(PyTypeObject *ty, | |
669 | PyObject *arg, PyObject *kw) | |
670 | { | |
671 | mp *xx = 0; | |
672 | field *f; | |
827f89d7 | 673 | static const char *const kwlist[] = { "p", 0 }; |
d7ab1bab | 674 | |
675 | if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:niceprimefield", | |
827f89d7 | 676 | KWLIST, convmp, &xx)) |
d7ab1bab | 677 | goto end; |
678 | if ((f = field_niceprime(xx)) == 0) | |
679 | VALERR("bad prime for niceprimefield"); | |
680 | MP_DROP(xx); | |
681 | return (field_dopywrap(ty, f)); | |
682 | end: | |
683 | mp_drop(xx); | |
684 | return (0); | |
685 | } | |
686 | ||
ddd4720b | 687 | static const PyTypeObject niceprimefield_pytype_skel = { |
4648f560 | 688 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 689 | "NicePrimeField", /* @tp_name@ */ |
d7ab1bab | 690 | sizeof(field_pyobj), /* @tp_basicsize@ */ |
691 | 0, /* @tp_itemsize@ */ | |
692 | ||
693 | field_pydealloc, /* @tp_dealloc@ */ | |
694 | 0, /* @tp_print@ */ | |
695 | 0, /* @tp_getattr@ */ | |
696 | 0, /* @tp_setattr@ */ | |
697 | 0, /* @tp_compare@ */ | |
698 | 0, /* @tp_repr@ */ | |
699 | 0, /* @tp_as_number@ */ | |
700 | 0, /* @tp_as_sequence@ */ | |
701 | 0, /* @tp_as_mapping@ */ | |
702 | 0, /* @tp_hash@ */ | |
703 | 0, /* @tp_call@ */ | |
704 | 0, /* @tp_str@ */ | |
705 | 0, /* @tp_getattro@ */ | |
706 | 0, /* @tp_setattro@ */ | |
707 | 0, /* @tp_as_buffer@ */ | |
708 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
709 | Py_TPFLAGS_BASETYPE, | |
710 | ||
711 | /* @tp_doc@ */ | |
ef783f91 | 712 | "NicePrimeField(P): prime field using Solinas reduction.", |
d7ab1bab | 713 | |
714 | 0, /* @tp_traverse@ */ | |
715 | 0, /* @tp_clear@ */ | |
716 | field_pyrichcompare, /* @tp_richcompare@ */ | |
717 | 0, /* @tp_weaklistoffset@ */ | |
718 | 0, /* @tp_iter@ */ | |
963a6148 | 719 | 0, /* @tp_iternext@ */ |
d7ab1bab | 720 | 0, /* @tp_methods@ */ |
721 | 0, /* @tp_members@ */ | |
722 | 0, /* @tp_getset@ */ | |
723 | 0, /* @tp_base@ */ | |
724 | 0, /* @tp_dict@ */ | |
725 | 0, /* @tp_descr_get@ */ | |
726 | 0, /* @tp_descr_set@ */ | |
727 | 0, /* @tp_dictoffset@ */ | |
728 | 0, /* @tp_init@ */ | |
729 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
730 | niceprimefield_pynew, /* @tp_new@ */ | |
3aa33042 | 731 | 0, /* @tp_free@ */ |
d7ab1bab | 732 | 0 /* @tp_is_gc@ */ |
733 | }; | |
734 | ||
735 | /*----- Binary fields -----------------------------------------------------*/ | |
736 | ||
737 | static PyObject *bfget_m(PyObject *me, void *hunoz) | |
738 | { return (PyInt_FromLong(FIELD_F(me)->nbits)); } | |
739 | ||
c6e445a7 MW |
740 | static PyObject *bfget_p(PyObject *me, void *hunoz) |
741 | { return (gf_pywrap(MP_COPY(FIELD_F(me)->m))); } | |
742 | ||
637b9140 | 743 | static const PyGetSetDef binfield_pygetset[] = { |
d7ab1bab | 744 | #define GETSETNAME(op, name) bf##op##_##name |
b2687a0a | 745 | GET (m, "F.m -> field polynomial degree") |
c6e445a7 | 746 | GET (p, "F.p -> field polynomial") |
d7ab1bab | 747 | #undef GETSETNAME |
748 | { 0 } | |
749 | }; | |
750 | ||
ddd4720b | 751 | static const PyTypeObject binfield_pytype_skel = { |
4648f560 | 752 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 753 | "BinField", /* @tp_name@ */ |
d7ab1bab | 754 | sizeof(field_pyobj), /* @tp_basicsize@ */ |
755 | 0, /* @tp_itemsize@ */ | |
756 | ||
757 | field_pydealloc, /* @tp_dealloc@ */ | |
758 | 0, /* @tp_print@ */ | |
759 | 0, /* @tp_getattr@ */ | |
760 | 0, /* @tp_setattr@ */ | |
761 | 0, /* @tp_compare@ */ | |
762 | 0, /* @tp_repr@ */ | |
763 | 0, /* @tp_as_number@ */ | |
764 | 0, /* @tp_as_sequence@ */ | |
765 | 0, /* @tp_as_mapping@ */ | |
766 | 0, /* @tp_hash@ */ | |
767 | 0, /* @tp_call@ */ | |
768 | 0, /* @tp_str@ */ | |
769 | 0, /* @tp_getattro@ */ | |
770 | 0, /* @tp_setattro@ */ | |
771 | 0, /* @tp_as_buffer@ */ | |
772 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
773 | Py_TPFLAGS_BASETYPE, | |
774 | ||
775 | /* @tp_doc@ */ | |
ef783f91 | 776 | "Binary fields. Abstract class.", |
d7ab1bab | 777 | |
778 | 0, /* @tp_traverse@ */ | |
779 | 0, /* @tp_clear@ */ | |
780 | field_pyrichcompare, /* @tp_richcompare@ */ | |
781 | 0, /* @tp_weaklistoffset@ */ | |
782 | 0, /* @tp_iter@ */ | |
963a6148 | 783 | 0, /* @tp_iternext@ */ |
d7ab1bab | 784 | 0, /* @tp_methods@ */ |
785 | 0, /* @tp_members@ */ | |
637b9140 | 786 | PYGETSET(binfield), /* @tp_getset@ */ |
d7ab1bab | 787 | 0, /* @tp_base@ */ |
788 | 0, /* @tp_dict@ */ | |
789 | 0, /* @tp_descr_get@ */ | |
790 | 0, /* @tp_descr_set@ */ | |
791 | 0, /* @tp_dictoffset@ */ | |
792 | 0, /* @tp_init@ */ | |
793 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
794 | abstract_pynew, /* @tp_new@ */ | |
3aa33042 | 795 | 0, /* @tp_free@ */ |
d7ab1bab | 796 | 0 /* @tp_is_gc@ */ |
797 | }; | |
798 | ||
799 | static PyObject *binpolyfield_pynew(PyTypeObject *ty, | |
800 | PyObject *arg, PyObject *kw) | |
801 | { | |
802 | mp *xx = 0; | |
803 | field *f; | |
827f89d7 | 804 | static const char *const kwlist[] = { "p", 0 }; |
d7ab1bab | 805 | |
827f89d7 | 806 | if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&:binpolyfield", KWLIST, |
d7ab1bab | 807 | convgf, &xx)) |
808 | goto end; | |
809 | if ((f = field_binpoly(xx)) == 0) VALERR("bad poly for binpolyfield"); | |
810 | MP_DROP(xx); | |
811 | return (field_dopywrap(ty, f)); | |
812 | end: | |
813 | mp_drop(xx); | |
814 | return (0); | |
815 | } | |
816 | ||
ddd4720b | 817 | static const PyTypeObject binpolyfield_pytype_skel = { |
4648f560 | 818 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 819 | "BinPolyField", /* @tp_name@ */ |
d7ab1bab | 820 | sizeof(field_pyobj), /* @tp_basicsize@ */ |
821 | 0, /* @tp_itemsize@ */ | |
822 | ||
823 | field_pydealloc, /* @tp_dealloc@ */ | |
824 | 0, /* @tp_print@ */ | |
825 | 0, /* @tp_getattr@ */ | |
826 | 0, /* @tp_setattr@ */ | |
827 | 0, /* @tp_compare@ */ | |
828 | 0, /* @tp_repr@ */ | |
829 | 0, /* @tp_as_number@ */ | |
830 | 0, /* @tp_as_sequence@ */ | |
831 | 0, /* @tp_as_mapping@ */ | |
832 | 0, /* @tp_hash@ */ | |
833 | 0, /* @tp_call@ */ | |
834 | 0, /* @tp_str@ */ | |
835 | 0, /* @tp_getattro@ */ | |
836 | 0, /* @tp_setattro@ */ | |
837 | 0, /* @tp_as_buffer@ */ | |
838 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
839 | Py_TPFLAGS_BASETYPE, | |
840 | ||
841 | /* @tp_doc@ */ | |
ef783f91 | 842 | "BinPolyField(P): binary fields with polynomial basis representation.", |
d7ab1bab | 843 | |
844 | 0, /* @tp_traverse@ */ | |
845 | 0, /* @tp_clear@ */ | |
846 | field_pyrichcompare, /* @tp_richcompare@ */ | |
847 | 0, /* @tp_weaklistoffset@ */ | |
848 | 0, /* @tp_iter@ */ | |
963a6148 | 849 | 0, /* @tp_iternext@ */ |
d7ab1bab | 850 | 0, /* @tp_methods@ */ |
851 | 0, /* @tp_members@ */ | |
c6e445a7 | 852 | 0, /* @tp_getset@ */ |
d7ab1bab | 853 | 0, /* @tp_base@ */ |
854 | 0, /* @tp_dict@ */ | |
855 | 0, /* @tp_descr_get@ */ | |
856 | 0, /* @tp_descr_set@ */ | |
857 | 0, /* @tp_dictoffset@ */ | |
858 | 0, /* @tp_init@ */ | |
859 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
860 | binpolyfield_pynew, /* @tp_new@ */ | |
3aa33042 | 861 | 0, /* @tp_free@ */ |
d7ab1bab | 862 | 0 /* @tp_is_gc@ */ |
863 | }; | |
864 | ||
865 | static PyObject *binnormfield_pynew(PyTypeObject *ty, | |
866 | PyObject *arg, PyObject *kw) | |
867 | { | |
868 | mp *xx = 0, *yy = 0; | |
869 | field *f; | |
827f89d7 | 870 | static const char *const kwlist[] = { "p", "beta", 0 }; |
d7ab1bab | 871 | |
872 | if (!PyArg_ParseTupleAndKeywords(arg, kw, "O&O&:binnormfield", | |
827f89d7 | 873 | KWLIST, convgf, &xx, convgf, &yy)) |
d7ab1bab | 874 | goto end; |
875 | if ((f = field_binnorm(xx, yy)) == 0) VALERR("bad args for binnormfield"); | |
876 | MP_DROP(xx); MP_DROP(yy); | |
877 | return (field_dopywrap(ty, f)); | |
878 | end: | |
879 | mp_drop(xx); mp_drop(yy); | |
880 | return (0); | |
881 | } | |
882 | ||
883 | static PyObject *bnfget_beta(PyObject *me, void *hunoz) | |
884 | { | |
885 | fctx_binnorm *fc = (fctx_binnorm *)FIELD_F(me); | |
886 | return (gf_pywrap(MP_COPY(fc->ntop.r[fc->ntop.n - 1]))); | |
887 | } | |
888 | ||
637b9140 | 889 | static const PyGetSetDef binnormfield_pygetset[] = { |
d7ab1bab | 890 | #define GETSETNAME(op, name) bnf##op##_##name |
b2687a0a | 891 | GET (beta, "F.beta -> conversion factor") |
d7ab1bab | 892 | #undef GETSETNAME |
893 | { 0 } | |
894 | }; | |
895 | ||
ddd4720b | 896 | static const PyTypeObject binnormfield_pytype_skel = { |
4648f560 | 897 | PyVarObject_HEAD_INIT(0, 0) /* Header */ |
c461c9b3 | 898 | "BinNormField", /* @tp_name@ */ |
d7ab1bab | 899 | sizeof(field_pyobj), /* @tp_basicsize@ */ |
900 | 0, /* @tp_itemsize@ */ | |
901 | ||
902 | field_pydealloc, /* @tp_dealloc@ */ | |
903 | 0, /* @tp_print@ */ | |
904 | 0, /* @tp_getattr@ */ | |
905 | 0, /* @tp_setattr@ */ | |
906 | 0, /* @tp_compare@ */ | |
907 | 0, /* @tp_repr@ */ | |
908 | 0, /* @tp_as_number@ */ | |
909 | 0, /* @tp_as_sequence@ */ | |
910 | 0, /* @tp_as_mapping@ */ | |
911 | 0, /* @tp_hash@ */ | |
912 | 0, /* @tp_call@ */ | |
913 | 0, /* @tp_str@ */ | |
914 | 0, /* @tp_getattro@ */ | |
915 | 0, /* @tp_setattro@ */ | |
916 | 0, /* @tp_as_buffer@ */ | |
917 | Py_TPFLAGS_DEFAULT | /* @tp_flags@ */ | |
918 | Py_TPFLAGS_BASETYPE, | |
919 | ||
920 | /* @tp_doc@ */ | |
ef783f91 | 921 | "BinNormField(P, BETA): binary fields with normal basis representation.", |
d7ab1bab | 922 | |
923 | 0, /* @tp_traverse@ */ | |
924 | 0, /* @tp_clear@ */ | |
925 | field_pyrichcompare, /* @tp_richcompare@ */ | |
926 | 0, /* @tp_weaklistoffset@ */ | |
927 | 0, /* @tp_iter@ */ | |
963a6148 | 928 | 0, /* @tp_iternext@ */ |
d7ab1bab | 929 | 0, /* @tp_methods@ */ |
930 | 0, /* @tp_members@ */ | |
637b9140 | 931 | PYGETSET(binnormfield), /* @tp_getset@ */ |
d7ab1bab | 932 | 0, /* @tp_base@ */ |
933 | 0, /* @tp_dict@ */ | |
934 | 0, /* @tp_descr_get@ */ | |
935 | 0, /* @tp_descr_set@ */ | |
936 | 0, /* @tp_dictoffset@ */ | |
937 | 0, /* @tp_init@ */ | |
938 | PyType_GenericAlloc, /* @tp_alloc@ */ | |
939 | binnormfield_pynew, /* @tp_new@ */ | |
3aa33042 | 940 | 0, /* @tp_free@ */ |
d7ab1bab | 941 | 0 /* @tp_is_gc@ */ |
942 | }; | |
943 | ||
944 | /*----- Setup -------------------------------------------------------------*/ | |
945 | ||
cc36f2d8 MW |
946 | static const struct nameval consts[] = { |
947 | CONST(FTY_PRIME), CONST(FTY_BINARY), | |
948 | { 0 } | |
949 | }; | |
950 | ||
d7ab1bab | 951 | void field_pyinit(void) |
952 | { | |
953 | INITTYPE(fe, root); | |
954 | INITTYPE(field, type); | |
955 | INITTYPE(primefield, field); | |
956 | INITTYPE(niceprimefield, primefield); | |
957 | INITTYPE(binfield, field); | |
958 | INITTYPE(binpolyfield, binfield); | |
959 | INITTYPE(binnormfield, binfield); | |
d7ab1bab | 960 | } |
961 | ||
962 | void field_pyinsert(PyObject *mod) | |
963 | { | |
964 | INSERT("FE", fe_pytype); | |
965 | INSERT("Field", field_pytype); | |
966 | INSERT("PrimeField", primefield_pytype); | |
967 | INSERT("NicePrimeField", niceprimefield_pytype); | |
968 | INSERT("BinField", binfield_pytype); | |
969 | INSERT("BinPolyField", binpolyfield_pytype); | |
970 | INSERT("BinNormField", binnormfield_pytype); | |
cc36f2d8 | 971 | setconstants(mod, consts); |
d7ab1bab | 972 | } |
973 | ||
974 | /*----- That's all, folks -------------------------------------------------*/ |