3 * $Id: ecp.cal,v 1.1 2000/10/08 16:01:37 mdw Exp $
5 * Testbed for elliptic curve arithmetic over prime fields
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb 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 Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2000/10/08 16:01:37 mdw
34 * Prototypes of various bits of code.
38 /*----- Object types ------------------------------------------------------*/
40 obj ecp_curve { a, b, p };
41 obj ecp_pt { x, y, e };
43 /*----- Main code ---------------------------------------------------------*/
45 define ecp_curve(a, b, p)
47 local obj ecp_curve e;
54 define ecp_pt(x, y, e)
63 define ecp_pt_print(a)
65 print "(" : a.x : ", " : a.y : ")" :;
68 define ecp_pt_add(a, b)
77 else if (!istype(a, b))
78 quit "bad type arguments to ecp_pt_add";
80 quit "points from different curves in ecp_pt_add";
87 alpha = (3 * a.x^2 + e.a) * minv(2 * a.y, e.p) % e.p;
89 alpha = (b.y - a.y) * minv(b.x - a.x, e.p) % e.p;
91 d.x = (alpha^2 - a.x - b.x) % e.p;
92 d.y = (-a.y + alpha * (a.x - d.x)) % e.p;
108 define ecp_pt_mul(a, b)
116 } else if (istype(b, 1)) {
120 return (newerror("bad arguments to ecp_pt_mul"));
132 /*----- That's all, folks -------------------------------------------------*/