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 PyObject
*ecptnc_pynew(PyTypeObject
*ty
, PyObject
*arg
, PyObject
*kw
)
477 PyObject
*x
= 0, *y
= 0, *z
= 0;
479 char *kwlist
[] = { "x", "y", 0 };
481 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|OO:new", kwlist
, &x
, &y
) ||
482 ecptxl(0, &p
, x
, y
, z
))
484 return (ecpt_pywrapout(ty
, &p
));
490 static PyObject
*ecpt_pyint(PyObject
*me
)
495 if (EC_ATINF(ECPT_P(me
))) VALERR("point at infinity");
497 if (mp_tolong_checked(p
.x
, &l
)) goto end
;
498 rc
= PyInt_FromLong(l
);
504 static PyObject
*ecpt_pylong(PyObject
*me
)
508 if (EC_ATINF(ECPT_P(me
))) VALERR("point at infinity");
510 rc
= mp_topylong(p
.x
);
516 static PyObject
*ecpt_pynew(PyTypeObject
*ty
, PyObject
*arg
, PyObject
*kw
)
518 PyObject
*x
= 0, *y
= 0, *z
= 0;
520 char *kwlist
[] = { "x", "y", "z", 0 };
522 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|OOO:new", kwlist
,
524 ecptxl(ECCURVE_C(ty
), &p
, x
, y
, z
))
526 return (ecpt_pywrap((PyObject
*)ty
, &p
));
532 static PyGetSetDef ecptnc_pygetset
[] = {
533 #define GETSETNAME(op, name) epnc##op##_##name
534 GET (ix
, "P.ix -> integer x coordinate of P")
535 GET (iy
, "P.iy -> integer y coordinate of P")
536 GET (point
, "P.point -> standalone curve point (no-op)")
541 static PyMethodDef ecptnc_pymethods
[] = {
542 #define METHNAME(func) epmeth_##func
543 METH (tobuf
, "X.tobuf() -> BIN")
548 static PyNumberMethods ecpt_pynumber
= {
550 0, /* @nb_subtract@ */
551 0, /* @nb_multiply@ */
553 0, /* @nb_remainder@ */
556 0, /* @nb_negative@ */
557 0, /* @nb_positive@ */
558 0, /* @nb_absolute@ */
559 ecpt_pynonzerop
, /* @nb_nonzero@ */
567 ecpt_pyint
, /* @nb_int@ */
568 ecpt_pylong
, /* @nb_long@ */
573 0, /* @nb_inplace_add@ */
574 0, /* @nb_inplace_subtract@ */
575 0, /* @nb_inplace_multiply@ */
576 0, /* @nb_inplace_divide@ */
577 0, /* @nb_inplace_remainder@ */
578 0, /* @nb_inplace_power@ */
579 0, /* @nb_inplace_lshift@ */
580 0, /* @nb_inplace_rshift@ */
581 0, /* @nb_inplace_and@ */
582 0, /* @nb_inplace_xor@ */
583 0, /* @nb_inplace_or@ */
585 0, /* @nb_floor_divide@ */
586 0, /* @nb_true_divide@ */
587 0, /* @nb_inplace_floor_divide@ */
588 0, /* @nb_inplace_true_divide@ */
591 static PyTypeObject ecpt_pytype_skel
= {
592 PyObject_HEAD_INIT(0) 0, /* Header */
593 "catacomb.ECPt", /* @tp_name@ */
594 sizeof(ecpt_pyobj
), /* @tp_basicsize@ */
595 0, /* @tp_itemsize@ */
597 ecpt_pydealloc
, /* @tp_dealloc@ */
599 0, /* @tp_getattr@ */
600 0, /* @tp_setattr@ */
601 0, /* @tp_compare@ */
603 &ecpt_pynumber
, /* @tp_as_number@ */
604 0, /* @tp_as_sequence@ */
605 0, /* @tp_as_mapping@ */
606 ecpt_pyhash
, /* @tp_hash@ */
609 0, /* @tp_getattro@ */
610 0, /* @tp_setattro@ */
611 0, /* @tp_as_buffer@ */
612 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
613 Py_TPFLAGS_CHECKTYPES
|
617 "Elliptic curve points, not associated with any curve.",
619 0, /* @tp_traverse@ */
621 ecpt_pyrichcompare
, /* @tp_richcompare@ */
622 0, /* @tp_weaklistoffset@ */
624 0, /* @tp_iternext@ */
625 ecptnc_pymethods
, /* @tp_methods@ */
626 0, /* @tp_members@ */
627 ecptnc_pygetset
, /* @tp_getset@ */
630 0, /* @tp_descr_get@ */
631 0, /* @tp_descr_set@ */
632 0, /* @tp_dictoffset@ */
634 PyType_GenericAlloc
, /* @tp_alloc@ */
635 ecptnc_pynew
, /* @tp_new@ */
640 static PyGetSetDef ecpt_pygetset
[] = {
641 #define GETSETNAME(op, name) ep##op##_##name
642 GET (curve
, "P.curve -> elliptic curve containing P")
643 GET (point
, "P.point -> standalone curve point")
644 GET (x
, "P.x -> Cartesian x coordinate of P")
645 GET (y
, "P.y -> Cartesian y coordinate of P")
646 GET (_x
, "P._x -> internal x coordinate of P")
647 GET (_y
, "P._y -> internal y coordinate of P")
648 GET (_z
, "P._z -> internal z coordinate of P, or None")
653 static PyMethodDef ecpt_pymethods
[] = {
654 #define METHNAME(func) epmeth_##func
655 METH (toraw
, "X.toraw() -> BIN")
656 METH (dbl
, "X.dbl() -> X + X")
657 METH (oncurvep
, "X.oncurvep() -> BOOL")
662 static PyNumberMethods ecptcurve_pynumber
= {
663 ecpt_pyadd
, /* @nb_add@ */
664 ecpt_pysub
, /* @nb_subtract@ */
665 ecpt_pymul
, /* @nb_multiply@ */
667 0, /* @nb_remainder@ */
670 ecpt_pyneg
, /* @nb_negative@ */
671 ecpt_pyid
, /* @nb_positive@ */
672 0, /* @nb_absolute@ */
673 0, /* @nb_nonzero@ */
687 0, /* @nb_inplace_add@ */
688 0, /* @nb_inplace_subtract@ */
689 0, /* @nb_inplace_multiply@ */
690 0, /* @nb_inplace_divide@ */
691 0, /* @nb_inplace_remainder@ */
692 0, /* @nb_inplace_power@ */
693 0, /* @nb_inplace_lshift@ */
694 0, /* @nb_inplace_rshift@ */
695 0, /* @nb_inplace_and@ */
696 0, /* @nb_inplace_xor@ */
697 0, /* @nb_inplace_or@ */
699 0, /* @nb_floor_divide@ */
700 0, /* @nb_true_divide@ */
701 0, /* @nb_inplace_floor_divide@ */
702 0, /* @nb_inplace_true_divide@ */
705 static PyTypeObject ecptcurve_pytype_skel
= {
706 PyObject_HEAD_INIT(0) 0, /* Header */
707 "catacomb.ECPtCurve", /* @tp_name@ */
708 sizeof(ecpt_pyobj
), /* @tp_basicsize@ */
709 0, /* @tp_itemsize@ */
711 ecpt_pydealloc
, /* @tp_dealloc@ */
713 0, /* @tp_getattr@ */
714 0, /* @tp_setattr@ */
715 0, /* @tp_compare@ */
717 &ecptcurve_pynumber
, /* @tp_as_number@ */
718 0, /* @tp_as_sequence@ */
719 0, /* @tp_as_mapping@ */
723 0, /* @tp_getattro@ */
724 0, /* @tp_setattro@ */
725 0, /* @tp_as_buffer@ */
726 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
727 Py_TPFLAGS_CHECKTYPES
|
731 "Elliptic curve points; abstract base class for points on given curves.",
733 0, /* @tp_traverse@ */
735 0, /* @tp_richcompare@ */
736 0, /* @tp_weaklistoffset@ */
738 0, /* @tp_iternext@ */
739 ecpt_pymethods
, /* @tp_methods@ */
740 0, /* @tp_members@ */
741 ecpt_pygetset
, /* @tp_getset@ */
744 0, /* @tp_descr_get@ */
745 0, /* @tp_descr_set@ */
746 0, /* @tp_dictoffset@ */
748 PyType_GenericAlloc
, /* @tp_alloc@ */
749 abstract_pynew
, /* @tp_new@ */
754 /*----- Elliptic curves themselves ----------------------------------------*/
756 static PyObject
*eccurve_pyrichcompare(PyObject
*x
, PyObject
*y
, int op
)
758 int b
= ec_samep(ECCURVE_C(x
), ECCURVE_C(y
));
762 default: TYERR("can't order elliptic curves");
769 static PyObject
*ecmmul_id(PyObject
*me
)
770 { ec p
= EC_INIT
; return (ecpt_pywrap(me
, &p
)); }
772 static int ecmmul_fill(void *pp
, PyObject
*me
, PyObject
*x
, PyObject
*m
)
774 ec_mulfactor
*f
= pp
;
776 if (getecpt(ECCURVE_C(me
), &f
->base
, x
) ||
777 (f
->exp
= getmp(m
)) == 0)
779 f
->base
= *ECPT_P(x
);
783 static PyObject
*ecmmul_exp(PyObject
*me
, void *pp
, int n
)
786 ec_immul(ECCURVE_C(me
), &p
, pp
, n
);
787 return (ecpt_pywrap(me
, &p
));
790 static void ecmmul_drop(void *pp
)
792 ec_mulfactor
*f
= pp
;
793 EC_DESTROY(&f
->base
);
797 static PyObject
*ecmeth_mmul(PyObject
*me
, PyObject
*arg
)
799 return (mexp_common(me
, arg
, sizeof(ec_mulfactor
),
800 ecmmul_id
, ecmmul_fill
, ecmmul_exp
, ecmmul_drop
));
803 static PyObject
*meth__ECPtCurve_fromraw(PyObject
*me
, PyObject
*arg
)
812 if (!PyArg_ParseTuple(arg
, "Os#:fromraw", &me
, &p
, &len
))
814 buf_init(&b
, p
, len
);
816 if (ec_getraw(cc
, &b
, &pp
))
819 rc
= Py_BuildValue("(NN)", ecpt_pywrap(me
, &pp
), bytestring_pywrapbuf(&b
));
824 static PyObject
*meth__ECPt_frombuf(PyObject
*me
, PyObject
*arg
)
832 if (!PyArg_ParseTuple(arg
, "Os#:frombuf", &me
, &p
, &sz
)) goto end
;
834 if (buf_getec(&b
, &pp
)) VALERR("malformed data");
835 rc
= Py_BuildValue("(NN)", ecpt_pywrapout(me
, &pp
),
836 bytestring_pywrapbuf(&b
));
841 static PyObject
*meth__ECPt_parse(PyObject
*me
, PyObject
*arg
)
848 if (!PyArg_ParseTuple(arg
, "Os:parse", &me
, &p
)) goto end
;
851 if (!ec_ptparse(&qd
, &pp
)) SYNERR(qd
.e
);
852 rc
= Py_BuildValue("(Ns)", ecpt_pywrapout(me
, &pp
), qd
.p
);
857 static void eccurve_pydealloc(PyObject
*me
)
859 ec_destroycurve(ECCURVE_C(me
));
860 Py_DECREF(ECCURVE_FOBJ(me
));
861 PyType_Type
.tp_dealloc(me
);
864 static PyObject
*ecmeth_find(PyObject
*me
, PyObject
*arg
)
871 if (!PyArg_ParseTuple(arg
, "O:find", &x
)) goto end
;
872 if (FIELD_PYCHECK(x
) && FE_F(x
) == ECCURVE_C(me
)->f
)
873 xx
= MP_COPY(FE_X(x
));
874 else if ((xx
= getmp(x
)) == 0)
877 xx
= F_IN(ECCURVE_C(me
)->f
, xx
, xx
);
878 if (EC_FIND(ECCURVE_C(me
), &p
, xx
) == 0)
879 VALERR("not on the curve");
880 rc
= ecpt_pywrap(me
, &p
);
886 static PyObject
*ecmeth_rand(PyObject
*me
, PyObject
*arg
, PyObject
*kw
)
888 char *kwlist
[] = { "rng", 0 };
889 grand
*r
= &rand_global
;
892 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|O&:rand", kwlist
,
895 ec_rand(ECCURVE_C(me
), &p
, r
);
896 EC_IN(ECCURVE_C(me
), &p
, &p
);
897 return (ecpt_pywrap(me
, &p
));
900 static PyObject
*eccurve_dopywrap(PyTypeObject
*ty
,
901 PyObject
*fobj
, ec_curve
*c
)
903 eccurve_pyobj
*cobj
= newtype(ty
, 0, c
->ops
->name
);
906 cobj
->ty
.ht_type
.tp_basicsize
= sizeof(ecpt_pyobj
);
907 cobj
->ty
.ht_type
.tp_base
= ecptcurve_pytype
;
908 Py_INCREF(ecptcurve_pytype
);
909 cobj
->ty
.ht_type
.tp_flags
= (Py_TPFLAGS_DEFAULT
|
910 Py_TPFLAGS_BASETYPE
|
911 Py_TPFLAGS_CHECKTYPES
|
912 Py_TPFLAGS_HEAPTYPE
);
913 cobj
->ty
.ht_type
.tp_alloc
= PyType_GenericAlloc
;
914 cobj
->ty
.ht_type
.tp_free
= 0;
915 cobj
->ty
.ht_type
.tp_new
= ecpt_pynew
;
916 PyType_Ready(&cobj
->ty
.ht_type
);
917 return ((PyObject
*)cobj
);
920 PyObject
*eccurve_pywrap(PyObject
*fobj
, ec_curve
*c
)
925 fobj
= field_pywrap(c
->f
);
928 assert(FIELD_F(fobj
) == c
->f
);
929 if (strcmp(EC_NAME(c
), "prime") == 0)
930 ty
= ecprimecurve_pytype
;
931 else if (strcmp(EC_NAME(c
), "primeproj") == 0)
932 ty
= ecprimeprojcurve_pytype
;
933 else if (strcmp(EC_NAME(c
), "bin") == 0)
934 ty
= ecbincurve_pytype
;
935 else if (strcmp(EC_NAME(c
), "binproj") == 0)
936 ty
= ecbinprojcurve_pytype
;
939 return (eccurve_dopywrap(ty
, fobj
, c
));
942 static PyObject
*eccurve_pynew(PyTypeObject
*ty
,
943 ec_curve
*(*make
)(field
*, mp
*, mp
*),
944 PyObject
*arg
, PyObject
*kw
)
948 char *kwlist
[] = { "field", "a", "b", 0 };
951 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "O!O&O&", kwlist
,
953 convmp
, &aa
, convmp
, &bb
))
956 cobj
= eccurve_dopywrap(ty
, fobj
, make(FIELD_F(fobj
), aa
, bb
));
963 static PyObject
*meth__ECCurve_parse(PyObject
*me
, PyObject
*arg
)
970 if (!PyArg_ParseTuple(arg
, "Os:parse", &me
, &p
))
974 if ((c
= ec_curveparse(&qd
)) == 0)
976 rc
= eccurve_pywrap(0, c
);
981 static PyObject
*ecget_name(PyObject
*me
, void *hunoz
)
982 { return (PyString_FromString(EC_NAME(ECCURVE_C(me
)))); }
984 static PyObject
*ecget_a(PyObject
*me
, void *hunoz
)
985 { return (fe_pywrap(ECCURVE_FOBJ(me
), MP_COPY(ECCURVE_C(me
)->a
))); }
987 static PyObject
*ecget_b(PyObject
*me
, void *hunoz
)
988 { return (fe_pywrap(ECCURVE_FOBJ(me
), MP_COPY(ECCURVE_C(me
)->b
))); }
990 static PyObject
*ecget_field(PyObject
*me
, void *hunoz
)
991 { RETURN_OBJ(ECCURVE_FOBJ(me
)); }
993 static PyObject
*ecget_inf(PyObject
*me
, void *hunoz
)
994 { ec inf
= EC_INIT
; return (ecpt_pywrap(me
, &inf
)); }
996 static PyGetSetDef eccurve_pygetset
[] = {
997 #define GETSETNAME(op, name) ec##op##_##name
998 GET (name
, "E.name -> name of this kind of curve")
999 GET (a
, "E.a -> first parameter of curve")
1000 GET (b
, "E.b -> second parameter of curve")
1001 GET (field
, "E.field -> finite field containing this curve")
1002 GET (inf
, "E.inf -> point at infinity of this curve")
1007 static PyMethodDef eccurve_pymethods
[] = {
1008 #define METHNAME(name) ecmeth_##name
1010 E.mmul([(P0, N0), (P1, N1), ...]) = N0 P0 + N1 P1 + ...")
1011 METH (find
, "E.find(X) -> P")
1012 KWMETH(rand
, "E.rand(rng = rand) ->P")
1017 static PyTypeObject eccurve_pytype_skel
= {
1018 PyObject_HEAD_INIT(0) 0, /* Header */
1019 "catacomb.ECCurve", /* @tp_name@ */
1020 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1021 0, /* @tp_itemsize@ */
1023 eccurve_pydealloc
, /* @tp_dealloc@ */
1025 0, /* @tp_getattr@ */
1026 0, /* @tp_setattr@ */
1027 0, /* @tp_compare@ */
1029 0, /* @tp_as_number@ */
1030 0, /* @tp_as_sequence@ */
1031 0, /* @tp_as_mapping@ */
1035 0, /* @tp_getattro@ */
1036 0, /* @tp_setattro@ */
1037 0, /* @tp_as_buffer@ */
1038 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1039 Py_TPFLAGS_BASETYPE
,
1042 "An elliptic curve. Abstract class.",
1044 0, /* @tp_traverse@ */
1046 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1047 0, /* @tp_weaklistoffset@ */
1049 0, /* @tp_iternext@ */
1050 eccurve_pymethods
, /* @tp_methods@ */
1051 0, /* @tp_members@ */
1052 eccurve_pygetset
, /* @tp_getset@ */
1055 0, /* @tp_descr_get@ */
1056 0, /* @tp_descr_set@ */
1057 0, /* @tp_dictoffset@ */
1059 PyType_GenericAlloc
, /* @tp_alloc@ */
1060 abstract_pynew
, /* @tp_new@ */
1065 static PyObject
*ecprimecurve_pynew(PyTypeObject
*ty
,
1066 PyObject
*arg
, PyObject
*kw
)
1068 return (eccurve_pynew(ty
, ec_prime
, arg
, kw
));
1071 static PyTypeObject ecprimecurve_pytype_skel
= {
1072 PyObject_HEAD_INIT(0) 0, /* Header */
1073 "catacomb.ECPrimeCurve", /* @tp_name@ */
1074 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1075 0, /* @tp_itemsize@ */
1077 eccurve_pydealloc
, /* @tp_dealloc@ */
1079 0, /* @tp_getattr@ */
1080 0, /* @tp_setattr@ */
1081 0, /* @tp_compare@ */
1083 0, /* @tp_as_number@ */
1084 0, /* @tp_as_sequence@ */
1085 0, /* @tp_as_mapping@ */
1089 0, /* @tp_getattro@ */
1090 0, /* @tp_setattro@ */
1091 0, /* @tp_as_buffer@ */
1092 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1093 Py_TPFLAGS_BASETYPE
,
1096 "An elliptic curve over a prime field. Use ecprimeprojcurve.",
1098 0, /* @tp_traverse@ */
1100 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1101 0, /* @tp_weaklistoffset@ */
1103 0, /* @tp_iternext@ */
1104 0, /* @tp_methods@ */
1105 0, /* @tp_members@ */
1106 0, /* @tp_getset@ */
1109 0, /* @tp_descr_get@ */
1110 0, /* @tp_descr_set@ */
1111 0, /* @tp_dictoffset@ */
1113 PyType_GenericAlloc
, /* @tp_alloc@ */
1114 ecprimecurve_pynew
, /* @tp_new@ */
1119 static PyObject
*ecprimeprojcurve_pynew(PyTypeObject
*ty
,
1120 PyObject
*arg
, PyObject
*kw
)
1122 return (eccurve_pynew(ty
, ec_primeproj
, arg
, kw
));
1125 static PyTypeObject ecprimeprojcurve_pytype_skel
= {
1126 PyObject_HEAD_INIT(0) 0, /* Header */
1127 "catacomb.ECPrimeProjCurve", /* @tp_name@ */
1128 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1129 0, /* @tp_itemsize@ */
1131 eccurve_pydealloc
, /* @tp_dealloc@ */
1133 0, /* @tp_getattr@ */
1134 0, /* @tp_setattr@ */
1135 0, /* @tp_compare@ */
1137 0, /* @tp_as_number@ */
1138 0, /* @tp_as_sequence@ */
1139 0, /* @tp_as_mapping@ */
1143 0, /* @tp_getattro@ */
1144 0, /* @tp_setattro@ */
1145 0, /* @tp_as_buffer@ */
1146 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1147 Py_TPFLAGS_BASETYPE
,
1150 "An elliptic curve over a prime field, using projective coordinates.",
1152 0, /* @tp_traverse@ */
1154 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1155 0, /* @tp_weaklistoffset@ */
1157 0, /* @tp_iternext@ */
1158 0, /* @tp_methods@ */
1159 0, /* @tp_members@ */
1160 0, /* @tp_getset@ */
1163 0, /* @tp_descr_get@ */
1164 0, /* @tp_descr_set@ */
1165 0, /* @tp_dictoffset@ */
1167 PyType_GenericAlloc
, /* @tp_alloc@ */
1168 ecprimeprojcurve_pynew
, /* @tp_new@ */
1173 static PyObject
*ecbincurve_pynew(PyTypeObject
*ty
,
1174 PyObject
*arg
, PyObject
*kw
)
1176 return (eccurve_pynew(ty
, ec_bin
, arg
, kw
));
1179 static PyTypeObject ecbincurve_pytype_skel
= {
1180 PyObject_HEAD_INIT(0) 0, /* Header */
1181 "catacomb.ECBinCurve", /* @tp_name@ */
1182 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1183 0, /* @tp_itemsize@ */
1185 eccurve_pydealloc
, /* @tp_dealloc@ */
1187 0, /* @tp_getattr@ */
1188 0, /* @tp_setattr@ */
1189 0, /* @tp_compare@ */
1191 0, /* @tp_as_number@ */
1192 0, /* @tp_as_sequence@ */
1193 0, /* @tp_as_mapping@ */
1197 0, /* @tp_getattro@ */
1198 0, /* @tp_setattro@ */
1199 0, /* @tp_as_buffer@ */
1200 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1201 Py_TPFLAGS_BASETYPE
,
1204 "An elliptic curve over a binary field. Use ecbinprojcurve.",
1206 0, /* @tp_traverse@ */
1208 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1209 0, /* @tp_weaklistoffset@ */
1211 0, /* @tp_iternext@ */
1212 0, /* @tp_methods@ */
1213 0, /* @tp_members@ */
1214 0, /* @tp_getset@ */
1217 0, /* @tp_descr_get@ */
1218 0, /* @tp_descr_set@ */
1219 0, /* @tp_dictoffset@ */
1221 PyType_GenericAlloc
, /* @tp_alloc@ */
1222 ecbincurve_pynew
, /* @tp_new@ */
1227 static PyObject
*ecbinprojcurve_pynew(PyTypeObject
*ty
,
1228 PyObject
*arg
, PyObject
*kw
)
1230 return (eccurve_pynew(ty
, ec_binproj
, arg
, kw
));
1233 static PyTypeObject ecbinprojcurve_pytype_skel
= {
1234 PyObject_HEAD_INIT(0) 0, /* Header */
1235 "catacomb.ECBinProjCurve", /* @tp_name@ */
1236 sizeof(eccurve_pyobj
), /* @tp_basicsize@ */
1237 0, /* @tp_itemsize@ */
1239 eccurve_pydealloc
, /* @tp_dealloc@ */
1241 0, /* @tp_getattr@ */
1242 0, /* @tp_setattr@ */
1243 0, /* @tp_compare@ */
1245 0, /* @tp_as_number@ */
1246 0, /* @tp_as_sequence@ */
1247 0, /* @tp_as_mapping@ */
1251 0, /* @tp_getattro@ */
1252 0, /* @tp_setattro@ */
1253 0, /* @tp_as_buffer@ */
1254 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1255 Py_TPFLAGS_BASETYPE
,
1258 "An elliptic curve over a binary field, using projective coordinates.",
1260 0, /* @tp_traverse@ */
1262 eccurve_pyrichcompare
, /* @tp_richcompare@ */
1263 0, /* @tp_weaklistoffset@ */
1265 0, /* @tp_iternext@ */
1266 0, /* @tp_methods@ */
1267 0, /* @tp_members@ */
1268 0, /* @tp_getset@ */
1271 0, /* @tp_descr_get@ */
1272 0, /* @tp_descr_set@ */
1273 0, /* @tp_dictoffset@ */
1275 PyType_GenericAlloc
, /* @tp_alloc@ */
1276 ecbinprojcurve_pynew
, /* @tp_new@ */
1281 /*----- Curve info --------------------------------------------------------*/
1283 static int ncurves
= -1;
1285 void ecinfo_copy(ec_info
*eic
, const ec_info
*ei
)
1287 eic
->c
= eccurve_copy(ei
->c
);
1289 EC_COPY(&eic
->g
, &ei
->g
);
1290 eic
->r
= MP_COPY(ei
->r
);
1291 eic
->h
= MP_COPY(ei
->h
);
1294 PyObject
*ecinfo_pywrap(ec_info
*ei
)
1298 o
= PyObject_NEW(ecinfo_pyobj
, ecinfo_pytype
);
1300 o
->cobj
= eccurve_pywrap(0, o
->ei
.c
);
1302 return ((PyObject
*)o
);
1305 static void ecinfo_pydealloc(PyObject
*me
)
1307 ec_info
*ei
= ECINFO_EI(me
);
1311 Py_DECREF(ECINFO_COBJ(me
));
1315 static PyObject
*ecinfo_pynew(PyTypeObject
*ty
, PyObject
*arg
, PyObject
*kw
)
1319 char *kwlist
[] = { "curve", "G", "r", "h", 0 };
1320 ecinfo_pyobj
*rc
= 0;
1322 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "O!O!O&O&:new", kwlist
,
1323 eccurve_pytype
, &e
, ecpt_pytype
, &g
,
1324 convmp
, &ei
.r
, convmp
, &ei
.h
))
1326 if (ECPT_C(g
) != ECCURVE_C(e
) && !ec_samep(ECPT_C(g
), ECCURVE_C(e
)))
1327 TYERR("point not from this curve");
1328 ei
.c
= ECCURVE_C(e
);
1330 EC_OUT(ei
.c
, &ei
.g
, ECPT_P(g
));
1331 rc
= (ecinfo_pyobj
*)ty
->tp_alloc(ty
, 0);
1334 Py_INCREF(rc
->cobj
);
1335 return ((PyObject
*)rc
);
1343 static PyObject
*meth__ECInfo_parse(PyObject
*me
, PyObject
*arg
)
1350 if (!PyArg_ParseTuple(arg
, "Os:parse", &me
, &p
))
1354 if (ec_infoparse(&qd
, &ei
))
1356 rc
= Py_BuildValue("(Ns)", ecinfo_pywrap(&ei
), qd
.p
);
1361 static PyObject
*meth__ECInfo__curven(PyObject
*me
, PyObject
*arg
)
1367 if (!PyArg_ParseTuple(arg
, "Oi:_curven", &me
, &i
)) goto end
;
1368 if (i
< 0 || i
>= ncurves
) VALERR("curve index out of range");
1369 ec_infofromdata(&ei
, ectab
[i
].data
);
1370 rc
= ecinfo_pywrap(&ei
);
1375 static PyObject
*ecinfo_pyrichcompare(PyObject
*x
, PyObject
*y
, int op
)
1377 int b
= ec_sameinfop(ECINFO_EI(x
), ECINFO_EI(y
));
1381 default: TYERR("can't order elliptic curve infos");
1383 return (getbool(b
));
1388 static PyObject
*eimeth_check(PyObject
*me
, PyObject
*arg
, PyObject
*kw
)
1390 char *kwlist
[] = { "rng", 0 };
1391 grand
*r
= &rand_global
;
1394 if (!PyArg_ParseTupleAndKeywords(arg
, kw
, "|O&:check", kwlist
,
1397 if ((p
= ec_checkinfo(ECINFO_EI(me
), r
)) != 0)
1404 static PyObject
*eiget_curve(PyObject
*me
, void *hunoz
)
1405 { RETURN_OBJ(ECINFO_COBJ(me
)); }
1407 static PyObject
*eiget_G(PyObject
*me
, void *hunoz
)
1409 ec_info
*ei
= ECINFO_EI(me
);
1411 EC_IN(ei
->c
, &p
, &ei
->g
);
1412 return (ecpt_pywrap(ECINFO_COBJ(me
), &p
));
1415 static PyObject
*eiget_r(PyObject
*me
, void *hunoz
)
1416 { return (mp_pywrap(MP_COPY(ECINFO_EI(me
)->r
))); }
1418 static PyObject
*eiget_h(PyObject
*me
, void *hunoz
)
1419 { return (mp_pywrap(MP_COPY(ECINFO_EI(me
)->h
))); }
1421 static PyGetSetDef ecinfo_pygetset
[] = {
1422 #define GETSETNAME(op, name) ei##op##_##name
1423 GET (curve
, "I.curve -> the elliptic curve")
1424 GET (G
, "I.G -> generator point for the group")
1425 GET (r
, "I.r -> order of the group (and hence of G")
1426 GET (h
, "I.h -> cofactor of the group")
1431 static PyMethodDef ecinfo_pymethods
[] = {
1432 #define METHNAME(name) eimeth_##name
1433 KWMETH(check
, "I.check() -> None")
1438 static PyTypeObject ecinfo_pytype_skel
= {
1439 PyObject_HEAD_INIT(0) 0, /* Header */
1440 "catacomb.ECInfo", /* @tp_name@ */
1441 sizeof(ecinfo_pyobj
), /* @tp_basicsize@ */
1442 0, /* @tp_itemsize@ */
1444 ecinfo_pydealloc
, /* @tp_dealloc@ */
1446 0, /* @tp_getattr@ */
1447 0, /* @tp_setattr@ */
1448 0, /* @tp_compare@ */
1450 0, /* @tp_as_number@ */
1451 0, /* @tp_as_sequence@ */
1452 0, /* @tp_as_mapping@ */
1456 0, /* @tp_getattro@ */
1457 0, /* @tp_setattro@ */
1458 0, /* @tp_as_buffer@ */
1459 Py_TPFLAGS_DEFAULT
| /* @tp_flags@ */
1460 Py_TPFLAGS_BASETYPE
,
1463 "Elliptic curve domain parameters.",
1465 0, /* @tp_traverse@ */
1467 ecinfo_pyrichcompare
, /* @tp_richcompare@ */
1468 0, /* @tp_weaklistoffset@ */
1470 0, /* @tp_iternext@ */
1471 ecinfo_pymethods
, /* @tp_methods@ */
1472 0, /* @tp_members@ */
1473 ecinfo_pygetset
, /* @tp_getset@ */
1476 0, /* @tp_descr_get@ */
1477 0, /* @tp_descr_set@ */
1478 0, /* @tp_dictoffset@ */
1480 PyType_GenericAlloc
, /* @tp_alloc@ */
1481 ecinfo_pynew
, /* @tp_new@ */
1486 /*----- Setup -------------------------------------------------------------*/
1488 static PyMethodDef methods
[] = {
1489 #define METHNAME(func) meth_##func
1490 METH (_ECPt_frombuf
, "frombuf(E, STR) -> (P, REST)")
1491 METH (_ECPtCurve_fromraw
, "fromraw(E, STR) -> (P, REST)")
1492 METH (_ECPt_parse
, "parse(E, STR) -> (P, REST)")
1493 METH (_ECCurve_parse
, "parse(STR) -> (E, REST)")
1494 METH (_ECInfo_parse
, "parse(STR) -> (I, REST)")
1495 METH (_ECInfo__curven
, "_curven(N) -> I")
1500 void ec_pyinit(void)
1502 INITTYPE(ecpt
, root
);
1503 INITTYPE(ecptcurve
, ecpt
);
1504 INITTYPE(eccurve
, type
);
1505 INITTYPE(ecprimecurve
, eccurve
);
1506 INITTYPE(ecprimeprojcurve
, ecprimecurve
);
1507 INITTYPE(ecbincurve
, eccurve
);
1508 INITTYPE(ecbinprojcurve
, ecbincurve
);
1509 INITTYPE(ecinfo
, root
);
1510 addmethods(methods
);
1513 static PyObject
*namedcurves(void)
1520 for (i
= 0; ectab
[i
].name
; i
++) {
1522 for (j
= 0; j
< i
; j
++) {
1523 if (ectab
[i
].data
== ectab
[j
].data
) {
1524 c
= PyDict_GetItemString(d
, (/*unconst*/ char *)ectab
[j
].name
);
1529 c
= PyInt_FromLong(i
);
1531 PyDict_SetItemString(d
, (/*unconst*/ char *)ectab
[i
].name
, c
);
1538 void ec_pyinsert(PyObject
*mod
)
1540 INSERT("ECPt", ecpt_pytype
);
1541 INSERT("ECPtCurve", ecptcurve_pytype
);
1542 INSERT("ECCurve", eccurve_pytype
);
1543 INSERT("ECPrimeCurve", ecprimecurve_pytype
);
1544 INSERT("ECPrimeProjCurve", ecprimeprojcurve_pytype
);
1545 INSERT("ECBinCurve", ecbincurve_pytype
);
1546 INSERT("ECBinProjCurve", ecbinprojcurve_pytype
);
1547 INSERT("ECInfo", ecinfo_pytype
);
1548 INSERT("_eccurves", namedcurves());
1551 /*----- That's all, folks -------------------------------------------------*/