7 * (c) 2004 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the Python interface to Catacomb.
14 * Catacomb/Python is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Catacomb/Python is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Catacomb/Python; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
31 #include "catacomb-python.h"
33 /*----- Utility functions -------------------------------------------------*/
35 PyTypeObject
*ecpt_pytype
;
36 PyTypeObject
*ecptcurve_pytype
;
37 PyTypeObject
*eccurve_pytype
;
38 PyTypeObject
*ecprimecurve_pytype
;
39 PyTypeObject
*ecprimeprojcurve_pytype
;
40 PyTypeObject
*ecbincurve_pytype
;
41 PyTypeObject
*ecbinprojcurve_pytype
;
42 PyTypeObject
*ecinfo_pytype
;
44 ec_curve
*eccurve_copy(ec_curve
*c
)
49 if ((f
= field_copy(c
->f
)) == 0)
51 a
= F_OUT(f
, MP_NEW
, c
->a
);
52 b
= F_OUT(f
, MP_NEW
, c
->b
);
53 if (strcmp(EC_NAME(c
), "prime") == 0)
54 c
= ec_prime(f
, a
, b
);
55 else if (strcmp(EC_NAME(c
), "primeproj") == 0)
56 c
= ec_primeproj(f
, a
, b
);
57 else if (strcmp(EC_NAME(c
), "bin") == 0)
59 else if (strcmp(EC_NAME(c
), "binproj") == 0)
60 c
= ec_binproj(f
, a
, b
);
69 static PyObject
*ecpt_dopywrap(PyObject
*cobj
, ec_curve
*c
, ec
*p
)
71 ecpt_pyobj
*z
= PyObject_New(ecpt_pyobj
, (PyTypeObject
*)cobj
);
75 return ((PyObject
*)z
);
78 PyObject
*ecpt_pywrap(PyObject
*cobj
, ec
*p
)
79 { return (ecpt_dopywrap(cobj
, ECCURVE_C(cobj
), p
)); }
81 PyObject
*ecpt_pywrapout(void *cobj
, ec
*p
)
85 if (!PyType_IsSubtype(cobj
, ecptcurve_pytype
))
89 EC_IN(ECCURVE_C(cobj
), p
, p
);
91 return (ecpt_dopywrap(cobj
, c
, p
));
94 int toecpt(ec_curve
*c
, ec
*d
, PyObject
*p
)
96 if (ECPTCURVE_PYCHECK(p
)) {
97 if (ECPT_C(p
) != c
&& !ec_samep(ECPT_C(p
), c
))
99 EC_COPY(d
, ECPT_P(p
));
100 } else if (ECPT_PYCHECK(p
))
101 EC_IN(c
, d
, ECPT_P(p
));
107 int getecpt(ec_curve
*c
, ec
*d
, PyObject
*p
)
109 if (toecpt(c
, d
, p
)) {
110 PyErr_Format(PyExc_TypeError
, "can't convert %.100s to ecpt",
111 p
->ob_type
->tp_name
);
117 void getecptout(ec
*d
, PyObject
*p
)
119 if (ECPTCURVE_PYCHECK(p
))
120 EC_OUT(ECPT_C(p
), d
, ECPT_P(p
));
122 assert(ECPT_PYCHECK(p
));
123 EC_COPY(d
, ECPT_P(p
));
127 int convecpt(PyObject
*o
, void *p
)
129 if (!ECPT_PYCHECK(o
))
130 TYERR("want elliptic curve point");
137 /*----- Curve points ------------------------------------------------------*/
139 static int ecbinop(PyObject
*x
, PyObject
*y
,
140 ec_curve
**c
, PyObject
**cobj
, ec
*xx
, ec
*yy
)
142 if (ECPTCURVE_PYCHECK(x
)) *cobj
= ECPT_COBJ(x
);
143 else if (ECPTCURVE_PYCHECK(y
)) *cobj
= ECPT_COBJ(y
);
145 *c
= ECCURVE_C(*cobj
);
146 if (toecpt(*c
, xx
, x
) || toecpt(*c
, yy
, y
)) return (-1);
150 #define BINOP(name) \
151 static PyObject *ecpt_py##name(PyObject *x, PyObject *y) { \
152 ec xx = EC_INIT, yy = EC_INIT, zz = EC_INIT; \
155 if (ecbinop(x, y, &c, &cobj, &xx, &yy)) RETURN_NOTIMPL; \
156 c->ops->name(c, &zz, &xx, &yy); \
157 EC_DESTROY(&xx); EC_DESTROY(&yy); \
158 return (ecpt_pywrap(ECPT_COBJ(x), &zz)); \
165 static PyObject *ecpt_py##name(PyObject *x) { \
167 ec_curve *c = ECPT_C(x); \
168 c->ops->name(c, &zz, ECPT_P(x)); \
169 return (ecpt_pywrap(ECPT_COBJ(x), &zz)); \
174 static PyObject
*ecpt_pyid(PyObject
*x
) { RETURN_OBJ(x
); }
176 static int ecpt_pynonzerop(PyObject
*x
) { return (!EC_ATINF(ECPT_P(x
))); }
178 static void ecpt_pydealloc(PyObject
*x
)
180 EC_DESTROY(ECPT_P(x
));
181 Py_DECREF(ECPT_COBJ(x
));
185 static PyObject
*ecpt_pymul(PyObject
*x
, PyObject
*y
)
190 if (ECPT_PYCHECK(x
)) { PyObject
*t
; t
= x
; x
= y
; y
= t
; }
191 if (!ECPT_PYCHECK(y
) || (xx
= tomp(x
)) == 0) RETURN_NOTIMPL
;
192 ec_imul(ECPT_C(y
), &zz
, ECPT_P(y
), xx
);
193 return (ecpt_pywrap(ECPT_COBJ(y
), &zz
));
196 static long ecpt_pyhash(PyObject
*me
)
201 EC_OUT(ECPT_C(me
), &p
, ECPT_P(me
));
202 i
= 0xe0fdd039; /* random perturbance */
203 if (p
.x
) i
^= mp_tolong(p
.x
);
204 if (p
.y
) i
^= mp_tolong(p
.y
);
210 static PyObject
*ecpt_pyrichcompare(PyObject
*x
, PyObject
*y
, int op
)
214 ec p
= EC_INIT
, q
= EC_INIT
;
218 if (ecbinop(x
, y
, &c
, &cobj
, &p
, &q
)) RETURN_NOTIMPL
;
222 case Py_EQ
: b
= EC_EQ(&p
, &q
); break;
223 case Py_NE
: b
= !EC_EQ(&p
, &q
); break;
224 default: TYERR("elliptic curve points are unordered");
233 static PyObject
*epmeth_oncurvep(PyObject
*me
, PyObject
*arg
)
235 if (!PyArg_ParseTuple(arg
, ":oncurvep")) return (0);
236 return (getbool(!ec_check(ECPT_C(me
), ECPT_P(me
))));
239 static PyObject
*epmeth_dbl(PyObject
*me
, PyObject
*arg
)
242 if (!PyArg_ParseTuple(arg
, ":dbl")) return (0);
243 EC_DBL(ECPT_C(me
), &p
, ECPT_P(me
));
244 return (ecpt_pywrap(ECPT_COBJ(me
), &p
));
247 static PyObject
*epmeth_tobuf(PyObject
*me
, PyObject
*arg
)
254 if (!PyArg_ParseTuple(arg
, ":tobuf")) return (0);
259 n
= mp_octets(p
.x
) + mp_octets(p
.y
) + 4;
260 rc
= bytestring_pywrap(0, n
);
261 buf_init(&b
, PyString_AS_STRING(rc
), n
);
264 _PyString_Resize(&rc
, BLEN(&b
));
269 static PyObject
*epmeth_toraw(PyObject
*me
, PyObject
*arg
)
274 ec_curve
*c
= ECPT_C(me
);
278 if (!PyArg_ParseTuple(arg
, ":toraw")) return (0);
279 len
= c
->f
->noctets
* 2 + 1;
280 rc
= bytestring_pywrap(0, len
);
281 p
= PyString_AS_STRING(rc
);
282 buf_init(&b
, p
, len
);
283 EC_OUT(c
, &pp
, ECPT_P(me
));
284 ec_putraw(c
, &b
, &pp
);
286 _PyString_Resize(&rc
, BLEN(&b
));
290 static PyObject
*epget_curve(PyObject
*me
, void *hunoz
)
291 { RETURN_OBJ(ECPT_COBJ(me
)); }
293 static PyObject
*epncget_ix(PyObject
*me
, void *hunoz
)
297 if (EC_ATINF(ECPT_P(me
))) RETURN_NONE
;
299 rc
= mp_pywrap(MP_COPY(p
.x
));
304 static PyObject
*epncget_iy(PyObject
*me
, void *hunoz
)
308 if (EC_ATINF(ECPT_P(me
))) RETURN_NONE
;
310 rc
= mp_pywrap(MP_COPY(p
.y
));
315 static PyObject
*epncget_point(PyObject
*me
, void *hunoz
)
318 static PyObject
*epget_point(PyObject
*me
, void *hunoz
)
322 return (ecpt_pywrapout(ecpt_pytype
, &p
));
325 static PyObject
*epget_x(PyObject
*me
, void *hunoz
)
327 ec_curve
*c
= ECPT_C(me
);
329 PyObject
*fobj
= ECPT_FOBJ(me
);
333 if (EC_ATINF(pp
)) RETURN_NONE
;
335 rc
= fe_pywrap(fobj
, F_IN(c
->f
, MP_NEW
, p
.x
));
340 static PyObject
*epget_y(PyObject
*me
, void *hunoz
)
342 ec_curve
*c
= ECPT_C(me
);
344 PyObject
*fobj
= ECPT_FOBJ(me
);
348 if (EC_ATINF(pp
)) RETURN_NONE
;
350 rc
= fe_pywrap(fobj
, F_IN(c
->f
, MP_NEW
, p
.y
));
355 static PyObject
*epget__x(PyObject
*me
, void *hunoz
)
357 if (EC_ATINF(ECPT_P(me
))) RETURN_NONE
;
358 return (fe_pywrap(ECPT_FOBJ(me
), MP_COPY(ECPT_P(me
)->x
)));
361 static PyObject
*epget__y(PyObject
*me
, void *hunoz
)
363 if (EC_ATINF(ECPT_P(me
))) RETURN_NONE
;
364 return (fe_pywrap(ECPT_FOBJ(me
), MP_COPY(ECPT_P(me
)->y
)));
367 static PyObject
*epget__z(PyObject
*me
, void *hunoz
)
369 if (EC_ATINF(ECPT_P(me
)) || !ECPT_P(me
)->z
) RETURN_NONE
;
370 return (fe_pywrap(ECPT_FOBJ(me
), MP_COPY(ECPT_P(me
)->z
)));
373 static mp
*coord_in(field
*f
, PyObject
*x
)
376 if (FE_PYCHECK(x
) && FE_F(x
) == f
)
377 return (MP_COPY(FE_X(x
)));
378 else if ((xx
= getmp(x
)) == 0)
381 return (F_IN(f
, xx
, xx
));
384 static int ecptxl_3(ec_curve
*c
, ec
*p
,
385 PyObject
*x
, PyObject
*y
, PyObject
*z
)
389 if (!x
|| !y
|| !z
) TYERR("missing argument");
390 if (!c
) VALERR("internal form with no curve!");
391 if ((p
->x
== coord_in(c
->f
, x
)) == 0 ||
392 (p
->y
== coord_in(c
->f
, y
)) == 0 ||
393 (z
!= Py_None
&& (p
->z
= coord_in(c
->f
, z
))) == 0)
395 if (!p
->z
) p
->z
= MP_COPY(c
->f
->one
); /* just in case */
401 static int ecptxl_2(ec_curve
*c
, ec
*p
, PyObject
*x
, PyObject
*y
)
405 if (!x
|| !y
) TYERR("missing argument");
406 if ((p
->x
= getmp(x
)) == 0 ||
407 (p
->y
= getmp(y
)) == 0)
409 if (c
) EC_IN(c
, p
, p
);
415 static int ecptxl_1(ec_curve
*c
, ec
*p
, PyObject
*x
)
418 PyObject
*y
= 0, *z
= 0, *t
= 0;
425 if (!x
|| x
== Py_None
)
427 else if (ECPT_PYCHECK(x
)) {
430 } else if (PyString_Check(x
)) {
431 if (PyObject_AsReadBuffer(x
, &q
, 0))
435 if (!ec_ptparse(&qd
, p
))
438 } else if (c
&& (xx
= tomp(x
)) != 0) {
439 xx
= F_IN(c
->f
, xx
, xx
);
440 if (!EC_FIND(c
, p
, xx
)) VALERR("not on the curve");
441 } else if (PySequence_Check(x
)) {
443 n
= PySequence_Size(t
);
444 if (n
!= 2 && (n
!= 3 || !c
))
445 TYERR("want sequence of two or three items");
446 if ((x
= PySequence_GetItem(t
, 0)) == 0 ||
447 (y
= PySequence_GetItem(t
, 1)) == 0 ||
448 (n
== 3 && (z
= PySequence_GetItem(t
, 2)) == 0))
450 rc
= (n
== 2) ?
ecptxl_2(c
, p
, x
, y
) : ecptxl_3(c
, p
, x
, y
, z
);
452 TYERR("can't convert to curve point");
456 if (c
) EC_IN(c
, p
, p
);
460 Py_XDECREF(x
); Py_XDECREF(y
); Py_XDECREF(z
); Py_XDECREF(t
);
465 static int ecptxl(ec_curve
*c
, ec
*p
, PyObject
*x
, PyObject
*y
, PyObject
*z
)
468 return (ecptxl_3(c
, p
, x
, y
, z
));
470 return (ecptxl_2(c
, p
, x
, y
));
472 return (ecptxl_1(c
, p
, x
));
475 static int ecpt_fromobjects(PyObject
*cc
, ec
*p
,
476 PyObject
*x
, PyObject
*y
, PyObject
*z
)
480 if (cc
&& PyType_IsSubtype((PyTypeObject
*)cc
, ecptcurve_pytype
))
482 return (ecptxl(c
, p
, x
, y
, z
));
485 static PyObject
*ecptnc_pynew(PyTypeObject
*ty
, PyObject
*arg
, PyObject
*kw
)
487 PyObject
*x
= 0, *y
= 0, *z
= 0;
489 char *kwlist
[] = { "x", "y", 0 };
491 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|OO:new", kwlist
, &x
, &y
) ||
492 ecptxl(0, &p
, x
, y
, z
))
494 return (ecpt_pywrapout(ty
, &p
));
500 static PyObject
*ecpt_pyint(PyObject
*me
)
505 if (EC_ATINF(ECPT_P(me
))) VALERR("point at infinity");
507 if (mp_tolong_checked(p
.x
, &l
)) goto end
;
508 rc
= PyInt_FromLong(l
);
514 static PyObject
*ecpt_pylong(PyObject
*me
)
518 if (EC_ATINF(ECPT_P(me
))) VALERR("point at infinity");
520 rc
= (PyObject
*)mp_topylong(p
.x
);
526 static PyObject
*ecpt_pynew(PyTypeObject
*ty
, PyObject
*arg
, PyObject
*kw
)
528 PyObject
*x
= 0, *y
= 0, *z
= 0;
530 char *kwlist
[] = { "x", "y", "z", 0 };
532 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|OOO:new", kwlist
,
534 ecptxl(ECCURVE_C(ty
), &p
, x
, y
, z
))
536 return (ecpt_pywrap((PyObject
*)ty
, &p
));
542 static PyGetSetDef ecptnc_pygetset
[] = {
543 #define GETSETNAME(op, name) epnc##op##_##name
544 GET (ix
, "P.ix -> integer x coordinate of P")
545 GET (iy
, "P.iy -> integer y coordinate of P")
546 GET (point
, "P.point -> standalone curve point (no-op)")
551 static PyMethodDef ecptnc_pymethods
[] = {
552 #define METHNAME(func) epmeth_##func
553 METH (tobuf
, "X.tobuf() -> BIN")
558 static PyNumberMethods ecpt_pynumber
= {
560 0, /* @nb_subtract@ */
561 0, /* @nb_multiply@ */
563 0, /* @nb_remainder@ */
566 0, /* @nb_negative@ */
567 0, /* @nb_positive@ */
568 0, /* @nb_absolute@ */
569 ecpt_pynonzerop
, /* @nb_nonzero@ */
577 ecpt_pyint
, /* @nb_int@ */
578 ecpt_pylong
, /* @nb_long@ */
583 0, /* @nb_inplace_add@ */
584 0, /* @nb_inplace_subtract@ */
585 0, /* @nb_inplace_multiply@ */
586 0, /* @nb_inplace_divide@ */
587 0, /* @nb_inplace_remainder@ */
588 0, /* @nb_inplace_power@ */
589 0, /* @nb_inplace_lshift@ */
590 0, /* @nb_inplace_rshift@ */
591 0, /* @nb_inplace_and@ */
592 0, /* @nb_inplace_xor@ */
593 0, /* @nb_inplace_or@ */
595 0, /* @nb_floor_divide@ */
596 0, /* @nb_true_divide@ */
597 0, /* @nb_inplace_floor_divide@ */
598 0, /* @nb_inplace_true_divide@ */
601 static PyTypeObject ecpt_pytype_skel
= {
602 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
603 "catacomb.ECPt", /* @tp_name@ */
604 sizeof(ecpt_pyobj
), /* @tp_basicsize@ */
605 0, /* @tp_itemsize@ */
607 ecpt_pydealloc
, /* @tp_dealloc@ */
609 0, /* @tp_getattr@ */
610 0, /* @tp_setattr@ */
611 0, /* @tp_compare@ */
613 &ecpt_pynumber
, /* @tp_as_number@ */
614 0, /* @tp_as_sequence@ */
615 0, /* @tp_as_mapping@ */
616 ecpt_pyhash
, /* @tp_hash@ */
619 0, /* @tp_getattro@ */
620 0, /* @tp_setattro@ */
621 0, /* @tp_as_buffer@ */
622 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
623 Py_TPFLAGS_CHECKTYPES
|
627 "Elliptic curve points, not associated with any curve.",
629 0, /* @tp_traverse@ */
631 ecpt_pyrichcompare
, /* @tp_richcompare@ */
632 0, /* @tp_weaklistoffset@ */
634 0, /* @tp_iternexr@ */
635 ecptnc_pymethods
, /* @tp_methods@ */
636 0, /* @tp_members@ */
637 ecptnc_pygetset
, /* @tp_getset@ */
640 0, /* @tp_descr_get@ */
641 0, /* @tp_descr_set@ */
642 0, /* @tp_dictoffset@ */
644 PyType_GenericAlloc
, /* @tp_alloc@ */
645 ecptnc_pynew
, /* @tp_new@ */
646 _PyObject_Del
, /* @tp_free@ */
650 static PyGetSetDef ecpt_pygetset
[] = {
651 #define GETSETNAME(op, name) ep##op##_##name
652 GET (curve
, "P.curve -> elliptic curve containing P")
653 GET (point
, "P.point -> standalone curve point")
654 GET (x
, "P.x -> Cartesian x coordinate of P")
655 GET (y
, "P.y -> Cartesian y coordinate of P")
656 GET (_x
, "P._x -> internal x coordinate of P")
657 GET (_y
, "P._y -> internal y coordinate of P")
658 GET (_z
, "P._z -> internal z coordinate of P, or None")
663 static PyMethodDef ecpt_pymethods
[] = {
664 #define METHNAME(func) epmeth_##func
665 METH (toraw
, "X.toraw() -> BIN")
666 METH (dbl
, "X.dbl() -> X + X")
671 static PyNumberMethods ecptcurve_pynumber
= {
672 ecpt_pyadd
, /* @nb_add@ */
673 ecpt_pysub
, /* @nb_subtract@ */
674 ecpt_pymul
, /* @nb_multiply@ */
676 0, /* @nb_remainder@ */
679 ecpt_pyneg
, /* @nb_negative@ */
680 ecpt_pyid
, /* @nb_positive@ */
681 0, /* @nb_absolute@ */
682 0, /* @nb_nonzero@ */
696 0, /* @nb_inplace_add@ */
697 0, /* @nb_inplace_subtract@ */
698 0, /* @nb_inplace_multiply@ */
699 0, /* @nb_inplace_divide@ */
700 0, /* @nb_inplace_remainder@ */
701 0, /* @nb_inplace_power@ */
702 0, /* @nb_inplace_lshift@ */
703 0, /* @nb_inplace_rshift@ */
704 0, /* @nb_inplace_and@ */
705 0, /* @nb_inplace_xor@ */
706 0, /* @nb_inplace_or@ */
708 0, /* @nb_floor_divide@ */
709 0, /* @nb_true_divide@ */
710 0, /* @nb_inplace_floor_divide@ */
711 0, /* @nb_inplace_true_divide@ */
714 static PyTypeObject ecptcurve_pytype_skel
= {
715 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
716 "catacomb.ECPtCurve", /* @tp_name@ */
717 sizeof(ecpt_pyobj
), /* @tp_basicsize@ */
718 0, /* @tp_itemsize@ */
720 ecpt_pydealloc
, /* @tp_dealloc@ */
722 0, /* @tp_getattr@ */
723 0, /* @tp_setattr@ */
724 0, /* @tp_compare@ */
726 &ecptcurve_pynumber
, /* @tp_as_number@ */
727 0, /* @tp_as_sequence@ */
728 0, /* @tp_as_mapping@ */
732 0, /* @tp_getattro@ */
733 0, /* @tp_setattro@ */
734 0, /* @tp_as_buffer@ */
735 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
736 Py_TPFLAGS_CHECKTYPES
|
740 "Elliptic curve points; abstract base class for points on given curves.",
742 0, /* @tp_traverse@ */
744 0, /* @tp_richcompare@ */
745 0, /* @tp_weaklistoffset@ */
747 0, /* @tp_iternexr@ */
748 ecpt_pymethods
, /* @tp_methods@ */
749 0, /* @tp_members@ */
750 ecpt_pygetset
, /* @tp_getset@ */
753 0, /* @tp_descr_get@ */
754 0, /* @tp_descr_set@ */
755 0, /* @tp_dictoffset@ */
757 PyType_GenericAlloc
, /* @tp_alloc@ */
758 abstract_pynew
, /* @tp_new@ */
759 _PyObject_Del
, /* @tp_free@ */
763 /*----- Elliptic curves themselves ----------------------------------------*/
765 static PyObject
*eccurve_pyrichcompare(PyObject
*x
, PyObject
*y
, int op
)
767 int b
= ec_samep(ECCURVE_C(x
), ECCURVE_C(y
));
771 default: TYERR("can't order elliptic curves");
778 static PyObject
*ecmmul_id(PyObject
*me
)
779 { ec p
= EC_INIT
; return (ecpt_pywrap(me
, &p
)); }
781 static int ecmmul_fill(void *pp
, PyObject
*me
, PyObject
*x
, PyObject
*m
)
783 ec_mulfactor
*f
= pp
;
785 if (getecpt(ECCURVE_C(me
), &f
->base
, x
) ||
786 (f
->exp
= getmp(m
)) == 0)
788 f
->base
= *ECPT_P(x
);
792 static PyObject
*ecmmul_exp(PyObject
*me
, void *pp
, int n
)
795 ec_immul(ECCURVE_C(me
), &p
, pp
, n
);
796 return (ecpt_pywrap(me
, &p
));
799 static void ecmmul_drop(void *pp
)
801 ec_mulfactor
*f
= pp
;
802 EC_DESTROY(&f
->base
);
806 static PyObject
*ecmeth_mmul(PyObject
*me
, PyObject
*arg
)
808 return (mexp_common(me
, arg
, sizeof(ec_mulfactor
),
809 ecmmul_id
, ecmmul_fill
, ecmmul_exp
, ecmmul_drop
));
812 static PyObject
*meth__ECPtCurve_fromraw(PyObject
*me
, PyObject
*arg
)
821 if (!PyArg_ParseTuple(arg
, "Os#:fromraw", &me
, &p
, &len
))
823 buf_init(&b
, p
, len
);
825 if (ec_getraw(cc
, &b
, &pp
))
828 rc
= Py_BuildValue("(NN)", ecpt_pywrap(me
, &pp
), bytestring_pywrapbuf(&b
));
833 static PyObject
*meth__ECPt_frombuf(PyObject
*me
, PyObject
*arg
)
841 if (!PyArg_ParseTuple(arg
, "Os#:frombuf", &me
, &p
, &sz
)) goto end
;
843 if (buf_getec(&b
, &pp
)) VALERR("malformed data");
844 rc
= Py_BuildValue("(NN)", ecpt_pywrapout(me
, &pp
),
845 bytestring_pywrapbuf(&b
));
850 static PyObject
*meth__ECPt_parse(PyObject
*me
, PyObject
*arg
)
857 if (!PyArg_ParseTuple(arg
, "Os:parse", &me
, &p
)) goto end
;
860 if (!ec_ptparse(&qd
, &pp
)) SYNERR(qd
.e
);
861 rc
= Py_BuildValue("(Ns)", ecpt_pywrapout(me
, &pp
), qd
.p
);
866 static void eccurve_pydealloc(PyObject
*me
)
868 ec_destroycurve(ECCURVE_C(me
));
869 Py_DECREF(ECCURVE_FOBJ(me
));
870 PyType_Type
.tp_dealloc(me
);
873 static PyObject
*ecmeth_find(PyObject
*me
, PyObject
*arg
)
880 if (!PyArg_ParseTuple(arg
, "O:find", &x
)) goto end
;
881 if (FIELD_PYCHECK(x
) && FE_F(x
) == ECCURVE_C(me
)->f
)
882 xx
= MP_COPY(FE_X(x
));
883 else if ((xx
= getmp(x
)) == 0)
886 xx
= F_IN(ECCURVE_C(me
)->f
, xx
, xx
);
887 if (EC_FIND(ECCURVE_C(me
), &p
, xx
) == 0)
888 VALERR("not on the curve");
889 rc
= ecpt_pywrap(me
, &p
);
895 static PyObject
*ecmeth_rand(PyObject
*me
, PyObject
*arg
, PyObject
*kw
)
897 char *kwlist
[] = { "rng", 0 };
898 grand
*r
= &rand_global
;
901 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|O&:rand", kwlist
,
904 ec_rand(ECCURVE_C(me
), &p
, r
);
905 EC_IN(ECCURVE_C(me
), &p
, &p
);
906 return (ecpt_pywrap(me
, &p
));
909 static PyObject
*eccurve_dopywrap(PyTypeObject
*ty
,
910 PyObject
*fobj
, ec_curve
*c
)
912 eccurve_pyobj
*cobj
= newtype(ty
, 0);
915 cobj
->ty
.tp_name
= (/*unconst*/ char *)c
->ops
->name
;
916 cobj
->ty
.tp_basicsize
= sizeof(ecpt_pyobj
);
917 cobj
->ty
.tp_base
= ecptcurve_pytype
;
918 Py_INCREF(ecptcurve_pytype
);
919 cobj
->ty
.tp_flags
= (Py_TPFLAGS_DEFAULT
|
920 Py_TPFLAGS_BASETYPE
|
921 Py_TPFLAGS_CHECKTYPES
|
922 Py_TPFLAGS_HEAPTYPE
);
923 cobj
->ty
.tp_alloc
= PyType_GenericAlloc
;
924 cobj
->ty
.tp_free
=_PyObject_Del
;
925 cobj
->ty
.tp_new
= ecpt_pynew
;
926 PyType_Ready(&cobj
->ty
);
927 return ((PyObject
*)cobj
);
930 PyObject
*eccurve_pywrap(PyObject
*fobj
, ec_curve
*c
)
935 fobj
= field_pywrap(c
->f
);
938 assert(FIELD_F(fobj
) == c
->f
);
939 if (strcmp(EC_NAME(c
), "prime") == 0)
940 ty
= ecprimecurve_pytype
;
941 else if (strcmp(EC_NAME(c
), "primeproj") == 0)
942 ty
= ecprimeprojcurve_pytype
;
943 else if (strcmp(EC_NAME(c
), "bin") == 0)
944 ty
= ecbincurve_pytype
;
945 else if (strcmp(EC_NAME(c
), "binproj") == 0)
946 ty
= ecbinprojcurve_pytype
;
949 return (eccurve_dopywrap(ty
, fobj
, c
));
952 static PyObject
*eccurve_pynew(PyTypeObject
*ty
,
953 ec_curve
*(*make
)(field
*, mp
*, mp
*),
954 PyObject
*arg
, PyObject
*kw
)
958 char *kwlist
[] = { "field", "a", "b", 0 };
961 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "O!OO", kwlist
,
963 convmp
, &aa
, convmp
, &bb
))
966 cobj
= eccurve_dopywrap(ty
, fobj
, make(FIELD_F(fobj
), aa
, bb
));
973 static PyObject
*meth__ECCurve_parse(PyObject
*me
, PyObject
*arg
)
980 if (!PyArg_ParseTuple(arg
, "Os", &me
, &p
))
984 if ((c
= ec_curveparse(&qd
)) == 0)
986 rc
= eccurve_pywrap(0, c
);
991 static PyObject
*ecget_name(PyObject
*me
, void *hunoz
)
992 { return (PyString_FromString(EC_NAME(ECCURVE_C(me
)))); }
994 static PyObject
*ecget_a(PyObject
*me
, void *hunoz
)
995 { return (fe_pywrap(ECCURVE_FOBJ(me
), MP_COPY(ECCURVE_C(me
)->a
))); }
997 static PyObject
*ecget_b(PyObject
*me
, void *hunoz
)
998 { return (fe_pywrap(ECCURVE_FOBJ(me
), MP_COPY(ECCURVE_C(me
)->b
))); }
1000 static PyObject
*ecget_field(PyObject
*me
, void *hunoz
)
1001 { RETURN_OBJ(ECCURVE_FOBJ(me
)); }
1003 static PyObject
*ecget_inf(PyObject
*me
, void *hunoz
)
1004 { ec inf
= EC_INIT
; return (ecpt_pywrap(me
, &inf
)); }
1006 static PyGetSetDef eccurve_pygetset
[] = {
1007 #define GETSETNAME(op, name) ec##op##_##name
1008 GET (name
, "E.name -> name of this kind of curve")
1009 GET (a
, "E.a -> first parameter of curve")
1010 GET (b
, "E.b -> second parameter of curve")
1011 GET (field
, "E.field -> finite field containing this curve")
1012 GET (inf
, "E.inf -> point at infinity of this curve")
1017 static PyMethodDef eccurve_pymethods
[] = {
1018 #define METHNAME(name) ecmeth_##name
1020 E.mmul([(P0, N0), (P1, N1), ...]) = N0 P0 + N1 P1 + ...")
1021 METH (find
, "E.find(X) -> P")
1022 KWMETH(rand
, "E.rand(rng = rand) ->P")
1027 static PyTypeObject eccurve_pytype_skel
= {
1028 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
1029 "catacomb.ECCurve", /* @tp_name@ */
1030 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1031 0, /* @tp_itemsize@ */
1033 eccurve_pydealloc
, /* @tp_dealloc@ */
1035 0, /* @tp_getattr@ */
1036 0, /* @tp_setattr@ */
1037 0, /* @tp_compare@ */
1039 0, /* @tp_as_number@ */
1040 0, /* @tp_as_sequence@ */
1041 0, /* @tp_as_mapping@ */
1045 0, /* @tp_getattro@ */
1046 0, /* @tp_setattro@ */
1047 0, /* @tp_as_buffer@ */
1048 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1049 Py_TPFLAGS_BASETYPE
,
1052 "An elliptic curve. Abstract class.",
1054 0, /* @tp_traverse@ */
1056 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1057 0, /* @tp_weaklistoffset@ */
1059 0, /* @tp_iternexr@ */
1060 eccurve_pymethods
, /* @tp_methods@ */
1061 0, /* @tp_members@ */
1062 eccurve_pygetset
, /* @tp_getset@ */
1065 0, /* @tp_descr_get@ */
1066 0, /* @tp_descr_set@ */
1067 0, /* @tp_dictoffset@ */
1069 PyType_GenericAlloc
, /* @tp_alloc@ */
1070 abstract_pynew
, /* @tp_new@ */
1071 _PyObject_Del
, /* @tp_free@ */
1075 static PyObject
*ecprimecurve_pynew(PyTypeObject
*ty
,
1076 PyObject
*arg
, PyObject
*kw
)
1078 return (eccurve_pynew(ty
, ec_prime
, arg
, kw
));
1081 static PyTypeObject ecprimecurve_pytype_skel
= {
1082 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
1083 "catacomb.ECPrimeCurve", /* @tp_name@ */
1084 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1085 0, /* @tp_itemsize@ */
1087 eccurve_pydealloc
, /* @tp_dealloc@ */
1089 0, /* @tp_getattr@ */
1090 0, /* @tp_setattr@ */
1091 0, /* @tp_compare@ */
1093 0, /* @tp_as_number@ */
1094 0, /* @tp_as_sequence@ */
1095 0, /* @tp_as_mapping@ */
1099 0, /* @tp_getattro@ */
1100 0, /* @tp_setattro@ */
1101 0, /* @tp_as_buffer@ */
1102 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1103 Py_TPFLAGS_BASETYPE
,
1106 "An elliptic curve over a prime field. Use ecprimeprojcurve.",
1108 0, /* @tp_traverse@ */
1110 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1111 0, /* @tp_weaklistoffset@ */
1113 0, /* @tp_iternexr@ */
1114 0, /* @tp_methods@ */
1115 0, /* @tp_members@ */
1116 0, /* @tp_getset@ */
1119 0, /* @tp_descr_get@ */
1120 0, /* @tp_descr_set@ */
1121 0, /* @tp_dictoffset@ */
1123 PyType_GenericAlloc
, /* @tp_alloc@ */
1124 ecprimecurve_pynew
, /* @tp_new@ */
1125 _PyObject_Del
, /* @tp_free@ */
1129 static PyObject
*ecprimeprojcurve_pynew(PyTypeObject
*ty
,
1130 PyObject
*arg
, PyObject
*kw
)
1132 return (eccurve_pynew(ty
, ec_primeproj
, arg
, kw
));
1135 static PyTypeObject ecprimeprojcurve_pytype_skel
= {
1136 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
1137 "catacomb.ECPrimeProjCurve", /* @tp_name@ */
1138 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1139 0, /* @tp_itemsize@ */
1141 eccurve_pydealloc
, /* @tp_dealloc@ */
1143 0, /* @tp_getattr@ */
1144 0, /* @tp_setattr@ */
1145 0, /* @tp_compare@ */
1147 0, /* @tp_as_number@ */
1148 0, /* @tp_as_sequence@ */
1149 0, /* @tp_as_mapping@ */
1153 0, /* @tp_getattro@ */
1154 0, /* @tp_setattro@ */
1155 0, /* @tp_as_buffer@ */
1156 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1157 Py_TPFLAGS_BASETYPE
,
1160 "An elliptic curve over a prime field, using projective coordinates.",
1162 0, /* @tp_traverse@ */
1164 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1165 0, /* @tp_weaklistoffset@ */
1167 0, /* @tp_iternexr@ */
1168 0, /* @tp_methods@ */
1169 0, /* @tp_members@ */
1170 0, /* @tp_getset@ */
1173 0, /* @tp_descr_get@ */
1174 0, /* @tp_descr_set@ */
1175 0, /* @tp_dictoffset@ */
1177 PyType_GenericAlloc
, /* @tp_alloc@ */
1178 ecprimeprojcurve_pynew
, /* @tp_new@ */
1179 _PyObject_Del
, /* @tp_free@ */
1183 static PyObject
*ecbincurve_pynew(PyTypeObject
*ty
,
1184 PyObject
*arg
, PyObject
*kw
)
1186 return (eccurve_pynew(ty
, ec_bin
, arg
, kw
));
1189 static PyTypeObject ecbincurve_pytype_skel
= {
1190 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
1191 "catacomb.ECBinCurve", /* @tp_name@ */
1192 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1193 0, /* @tp_itemsize@ */
1195 eccurve_pydealloc
, /* @tp_dealloc@ */
1197 0, /* @tp_getattr@ */
1198 0, /* @tp_setattr@ */
1199 0, /* @tp_compare@ */
1201 0, /* @tp_as_number@ */
1202 0, /* @tp_as_sequence@ */
1203 0, /* @tp_as_mapping@ */
1207 0, /* @tp_getattro@ */
1208 0, /* @tp_setattro@ */
1209 0, /* @tp_as_buffer@ */
1210 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1211 Py_TPFLAGS_BASETYPE
,
1214 "An elliptic curve over a binary field. Use ecbinprojcurve.",
1216 0, /* @tp_traverse@ */
1218 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1219 0, /* @tp_weaklistoffset@ */
1221 0, /* @tp_iternexr@ */
1222 0, /* @tp_methods@ */
1223 0, /* @tp_members@ */
1224 0, /* @tp_getset@ */
1227 0, /* @tp_descr_get@ */
1228 0, /* @tp_descr_set@ */
1229 0, /* @tp_dictoffset@ */
1231 PyType_GenericAlloc
, /* @tp_alloc@ */
1232 ecbincurve_pynew
, /* @tp_new@ */
1233 _PyObject_Del
, /* @tp_free@ */
1237 static PyObject
*ecbinprojcurve_pynew(PyTypeObject
*ty
,
1238 PyObject
*arg
, PyObject
*kw
)
1240 return (eccurve_pynew(ty
, ec_binproj
, arg
, kw
));
1243 static PyTypeObject ecbinprojcurve_pytype_skel
= {
1244 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
1245 "catacomb.ECBinProjCurve", /* @tp_name@ */
1246 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1247 0, /* @tp_itemsize@ */
1249 eccurve_pydealloc
, /* @tp_dealloc@ */
1251 0, /* @tp_getattr@ */
1252 0, /* @tp_setattr@ */
1253 0, /* @tp_compare@ */
1255 0, /* @tp_as_number@ */
1256 0, /* @tp_as_sequence@ */
1257 0, /* @tp_as_mapping@ */
1261 0, /* @tp_getattro@ */
1262 0, /* @tp_setattro@ */
1263 0, /* @tp_as_buffer@ */
1264 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1265 Py_TPFLAGS_BASETYPE
,
1268 "An elliptic curve over a binary field, using projective coordinates.",
1270 0, /* @tp_traverse@ */
1272 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1273 0, /* @tp_weaklistoffset@ */
1275 0, /* @tp_iternexr@ */
1276 0, /* @tp_methods@ */
1277 0, /* @tp_members@ */
1278 0, /* @tp_getset@ */
1281 0, /* @tp_descr_get@ */
1282 0, /* @tp_descr_set@ */
1283 0, /* @tp_dictoffset@ */
1285 PyType_GenericAlloc
, /* @tp_alloc@ */
1286 ecbinprojcurve_pynew
, /* @tp_new@ */
1287 _PyObject_Del
, /* @tp_free@ */
1291 /*----- Curve info --------------------------------------------------------*/
1293 static int ncurves
= -1;
1295 void ecinfo_copy(ec_info
*eic
, const ec_info
*ei
)
1297 eic
->c
= eccurve_copy(ei
->c
);
1299 EC_COPY(&eic
->g
, &ei
->g
);
1300 eic
->r
= MP_COPY(ei
->r
);
1301 eic
->h
= MP_COPY(ei
->h
);
1304 PyObject
*ecinfo_pywrap(ec_info
*ei
)
1308 o
= PyObject_NEW(ecinfo_pyobj
, ecinfo_pytype
);
1310 o
->cobj
= eccurve_pywrap(0, o
->ei
.c
);
1312 return ((PyObject
*)o
);
1315 static void ecinfo_pydealloc(PyObject
*me
)
1317 ec_info
*ei
= ECINFO_EI(me
);
1321 Py_DECREF(ECINFO_COBJ(me
));
1325 static PyObject
*ecinfo_pynew(PyTypeObject
*ty
, PyObject
*arg
, PyObject
*kw
)
1329 char *kwlist
[] = { "curve", "G", "r", "h", 0 };
1330 ecinfo_pyobj
*rc
= 0;
1332 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "O!O!O&O&:new", kwlist
,
1333 eccurve_pytype
, &e
, ecpt_pytype
, &g
,
1334 convmp
, &ei
.r
, convmp
, &ei
.h
))
1336 if (ECPT_C(g
) != ECCURVE_C(e
) && !ec_samep(ECPT_C(g
), ECCURVE_C(e
)))
1337 TYERR("point not from this curve");
1338 ei
.c
= ECCURVE_C(e
);
1340 EC_COPY(&ei
.g
, ECPT_P(g
));
1341 rc
= (ecinfo_pyobj
*)ty
->tp_alloc(ty
, 0);
1344 Py_INCREF(rc
->cobj
);
1345 return ((PyObject
*)rc
);
1353 static PyObject
*meth__ECInfo_parse(PyObject
*me
, PyObject
*arg
)
1360 if (!PyArg_ParseTuple(arg
, "Os:parse", &me
, &p
))
1364 if (ec_infoparse(&qd
, &ei
))
1366 rc
= Py_BuildValue("(Ns)", ecinfo_pywrap(&ei
), qd
.p
);
1371 static PyObject
*meth__ECInfo__curven(PyObject
*me
, PyObject
*arg
)
1377 if (!PyArg_ParseTuple(arg
, "Oi:_curven", &me
, &i
)) goto end
;
1378 if (i
< 0 || i
>= ncurves
) VALERR("curve index out of range");
1379 ec_infofromdata(&ei
, ectab
[i
].data
);
1380 rc
= ecinfo_pywrap(&ei
);
1385 static PyObject
*ecinfo_pyrichcompare(PyObject
*x
, PyObject
*y
, int op
)
1387 int b
= ec_sameinfop(ECINFO_EI(x
), ECINFO_EI(y
));
1391 default: TYERR("can't order elliptic curve infos");
1393 return (getbool(b
));
1398 static PyObject
*eimeth_check(PyObject
*me
, PyObject
*arg
, PyObject
*kw
)
1400 char *kwlist
[] = { "rng", 0 };
1401 grand
*r
= &rand_global
;
1404 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|O&:check", kwlist
,
1407 if ((p
= ec_checkinfo(ECINFO_EI(me
), r
)) != 0)
1414 static PyObject
*eiget_curve(PyObject
*me
, void *hunoz
)
1415 { RETURN_OBJ(ECINFO_COBJ(me
)); }
1417 static PyObject
*eiget_G(PyObject
*me
, void *hunoz
)
1419 ec_info
*ei
= ECINFO_EI(me
);
1421 EC_IN(ei
->c
, &p
, &ei
->g
);
1422 return (ecpt_pywrap(ECINFO_COBJ(me
), &p
));
1425 static PyObject
*eiget_r(PyObject
*me
, void *hunoz
)
1426 { return (mp_pywrap(MP_COPY(ECINFO_EI(me
)->r
))); }
1428 static PyObject
*eiget_h(PyObject
*me
, void *hunoz
)
1429 { return (mp_pywrap(MP_COPY(ECINFO_EI(me
)->h
))); }
1431 static PyGetSetDef ecinfo_pygetset
[] = {
1432 #define GETSETNAME(op, name) ei##op##_##name
1433 GET (curve
, "I.curve -> the elliptic curve")
1434 GET (G
, "I.G -> generator point for the group")
1435 GET (r
, "I.r -> order of the group (and hence of G")
1436 GET (h
, "I.h -> cofactor of the group")
1441 static PyMethodDef ecinfo_pymethods
[] = {
1442 #define METHNAME(name) eimeth_##name
1443 KWMETH(check
, "I.check() -> None")
1448 static PyTypeObject ecinfo_pytype_skel
= {
1449 PyObject_HEAD_INIT(&PyType_Type
) 0, /* Header */
1450 "catacomb.ECInfo", /* @tp_name@ */
1451 sizeof(ecinfo_pyobj
), /* @tp_basicsize@ */
1452 0, /* @tp_itemsize@ */
1454 ecinfo_pydealloc
, /* @tp_dealloc@ */
1456 0, /* @tp_getattr@ */
1457 0, /* @tp_setattr@ */
1458 0, /* @tp_compare@ */
1460 0, /* @tp_as_number@ */
1461 0, /* @tp_as_sequence@ */
1462 0, /* @tp_as_mapping@ */
1466 0, /* @tp_getattro@ */
1467 0, /* @tp_setattro@ */
1468 0, /* @tp_as_buffer@ */
1469 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1470 Py_TPFLAGS_BASETYPE
,
1473 "Elliptic curve domain parameters.",
1475 0, /* @tp_traverse@ */
1477 ecinfo_pyrichcompare
, /* @tp_richcompare@ */
1478 0, /* @tp_weaklistoffset@ */
1480 0, /* @tp_iternexr@ */
1481 ecinfo_pymethods
, /* @tp_methods@ */
1482 0, /* @tp_members@ */
1483 ecinfo_pygetset
, /* @tp_getset@ */
1486 0, /* @tp_descr_get@ */
1487 0, /* @tp_descr_set@ */
1488 0, /* @tp_dictoffset@ */
1490 PyType_GenericAlloc
, /* @tp_alloc@ */
1491 ecinfo_pynew
, /* @tp_new@ */
1492 _PyObject_Del
, /* @tp_free@ */
1496 /*----- Setup -------------------------------------------------------------*/
1498 static PyMethodDef methods
[] = {
1499 #define METHNAME(func) meth_##func
1500 METH (_ECPt_frombuf
, "frombuf(E, STR) -> (P, REST)")
1501 METH (_ECPtCurve_fromraw
, "fromraw(E, STR) -> (P, REST)")
1502 METH (_ECPt_parse
, "parse(E, STR) -> (P, REST)")
1503 METH (_ECCurve_parse
, "parse(STR) -> (E, REST)")
1504 METH (_ECInfo_parse
, "parse(STR) -> (I, REST)")
1505 METH (_ECInfo__curven
, "_curven(N) -> I")
1510 void ec_pyinit(void)
1512 INITTYPE(ecpt
, root
);
1513 INITTYPE(ecptcurve
, ecpt
);
1514 INITTYPE(eccurve
, type
);
1515 INITTYPE(ecprimecurve
, eccurve
);
1516 INITTYPE(ecprimeprojcurve
, ecprimecurve
);
1517 INITTYPE(ecbincurve
, eccurve
);
1518 INITTYPE(ecbinprojcurve
, ecbincurve
);
1519 INITTYPE(ecinfo
, root
);
1520 addmethods(methods
);
1523 static PyObject
*namedcurves(void)
1530 for (i
= 0; ectab
[i
].name
; i
++) {
1532 for (j
= 0; j
< i
; j
++) {
1533 if (ectab
[i
].data
== ectab
[j
].data
) {
1534 c
= PyDict_GetItemString(d
, (/*unconst*/ char *)ectab
[j
].name
);
1539 c
= PyInt_FromLong(i
);
1541 PyDict_SetItemString(d
, (/*unconst*/ char *)ectab
[i
].name
, c
);
1548 void ec_pyinsert(PyObject
*mod
)
1550 INSERT("ECPt", ecpt_pytype
);
1551 INSERT("ECPtCurve", ecptcurve_pytype
);
1552 INSERT("ECCurve", eccurve_pytype
);
1553 INSERT("ECPrimeCurve", ecprimecurve_pytype
);
1554 INSERT("ECPrimeProjCurve", ecprimeprojcurve_pytype
);
1555 INSERT("ECBinCurve", ecbincurve_pytype
);
1556 INSERT("ECBinProjCurve", ecbinprojcurve_pytype
);
1557 INSERT("ECInfo", ecinfo_pytype
);
1558 INSERT("_eccurves", namedcurves());
1561 /*----- That's all, folks -------------------------------------------------*/