/* -*-apcalc-*-
*
- * $Id: ecp.cal,v 1.1.4.2 2004/03/20 00:13:31 mdw Exp $
- *
* Testbed for elliptic curve arithmetic over prime fields
*
* (c) 2000 Straylight/Edgeware
*/
-/*----- Licensing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
*
* This file is part of Catacomb.
*
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
- *
+ *
* Catacomb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Library General Public
* License along with Catacomb; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: ecp.cal,v $
- * Revision 1.1.4.2 2004/03/20 00:13:31 mdw
- * Projective coordinates for prime curves
- *
- * Revision 1.1.4.1 2003/06/10 13:43:53 mdw
- * Simple (non-projective) curves over prime fields now seem to work.
- *
- * Revision 1.1 2000/10/08 16:01:37 mdw
- * Prototypes of various bits of code.
- *
- */
-
/*----- Object types ------------------------------------------------------*/
obj ecp_curve { a, b, p };
obj ecp_pt { x, y, e };
-obj ecpp_pt { x, y, z, e };
/*----- Main code ---------------------------------------------------------*/
return (p);
}
-define ecpp_pt(p)
-{
- local obj ecpp_pt pp;
- if (istype(p, 1))
- return (0);
- pp.x = p.x;
- pp.y = p.y;
- pp.z = 1;
- pp.e = p.e;
- return (pp);
-}
-
-define ecpp_fix(pp)
-{
- local obj ecp_pt p;
- local e, zi, z2, z3;
- if (istype(pp, 1) || pp.z == 0)
- return (0);
- e = pp.e;
- zi = minv(pp.z, e.p);
- z2 = zi * zi;
- z3 = zi * z2;
- p.x = pp.x * z2 % e.p;
- p.y = pp.y * z3 % e.p;
- p.e = e;
- return (p);
-}
-
-define ecpp_dbl(a)
-{
- local m, s, t, y2;
- local e;
- local obj ecpp_pt d;
- if (istype(a, 1) || a.y == 0)
- return (0);
- e = a.e;
- if (e.a % e.p == e.p - 3) {
- m = a.z^3 % e.p;
- m = 3 * (a.x + t4) * (a.x - t4) % e.p;
- } else {
- m = (3 * a.x^2 - e.a * a.z^4) % e.p;
- }
- d.z = 2 * a.y * a.z % e.p;
- y2 = a.y^2 % e.p;
- s = 4 * a.x * a.y % e.p;
- d.x = (m^2 - 2 * s) % e.p;
- d.y = (m * (s - d.x) - y * y2^2) % e.p;
- d.e = e;
- return (d);
-}
-
-define ecpp_add(a, b)
-{
- if (a == 0)
- d = b;
- else if (b == 0)
- d = a;
- else if (!istype(a, b))
- quit "bad type arguments to ecp_pt_add";
- else if (a.e != b.e)
- quit "points from different curves in ecp_pt_add";
- else {
- e = a.e;
-
-}
-
define ecp_pt_print(a)
{
print "(" : a.x : ", " : a.y : ")" :;
e = a.e;
if (a.x == b.x) {
if (a.y != b.y) {
- return (0);
+ return (0);
}
alpha = (3 * a.x^2 + e.a) * minv(2 * a.y, e.p) % e.p;
} else
{
local obj ecp_pt d;
d.x = a.x;
- d.y = -a.y;
+ d.y = a.e.p - a.y;
d.e = a.e;
return (d);
}
0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811, p192);
/*----- That's all, folks -------------------------------------------------*/
-