X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/432c4e184d44704511a5991b80224a87cb1d4613..b817bfc642225b8c3c0b6a7e42d1fb949b61a606:/ec.c diff --git a/ec.c b/ec.c index d4dfafb..a84dd7a 100644 --- a/ec.c +++ b/ec.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: ec.c,v 1.7 2004/03/27 17:54:11 mdw Exp $ + * $Id: ec.c,v 1.10 2004/04/08 01:36:15 mdw Exp $ * * Elliptic curve definitions * @@ -27,46 +27,28 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: ec.c,v $ - * Revision 1.7 2004/03/27 17:54:11 mdw - * Standard curves and curve checking. - * - * Revision 1.6 2004/03/23 15:19:32 mdw - * Test elliptic curves more thoroughly. - * - * Revision 1.5 2004/03/21 22:52:06 mdw - * Merge and close elliptic curve branch. - * - * Revision 1.4.4.2 2004/03/20 00:13:31 mdw - * Projective coordinates for prime curves - * - * Revision 1.4.4.1 2003/06/10 13:43:53 mdw - * Simple (non-projective) curves over prime fields now seem to work. - * - * Revision 1.4 2003/05/15 23:25:59 mdw - * Make elliptic curve stuff build. - * - * Revision 1.3 2002/01/13 13:48:44 mdw - * Further progress. - * - * Revision 1.2 2001/05/07 17:29:44 mdw - * Treat projective coordinates as an internal representation. Various - * minor interface changes. - * - * Revision 1.1 2001/04/29 18:12:33 mdw - * Prototype version. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "ec.h" -#include "ec-exp.h" /*----- Trivial wrappers --------------------------------------------------*/ +/* --- @ec_samep@ --- * + * + * Arguments: @ec_curve *c, *d@ = two elliptic curves + * + * Returns: Nonzero if the curves are identical (not just isomorphic). + * + * Use: Checks for sameness of curves. This function does the full + * check, not just the curve-type-specific check done by the + * @sampep@ field operation. + */ + +int ec_samep(ec_curve *c, ec_curve *d) +{ + return (field_samep(c->f, d->f) && c->ops == d->ops && EC_SAMEP(c, d)); +} + /* --- @ec_create@ --- * * * Arguments: @ec *p@ = pointer to an elliptic-curve point @@ -135,6 +117,20 @@ int ec_eq(const ec *p, const ec *q) { return (EC_EQ(p, q)); } /*----- Standard curve operations -----------------------------------------*/ +/* --- @ec_stdsamep@ --- * + * + * Arguments: @ec_curve *c, *d@ = two elliptic curves + * + * Returns: Nonzero if the curves are identical (not just isomorphic). + * + * Use: Simple sameness check on @a@ and @b@ curve members. + */ + +int ec_stdsamep(ec_curve *c, ec_curve *d) +{ + return (MP_EQ(c->a, d->a) && MP_EQ(c->b, d->b)); +} + /* --- @ec_idin@, @ec_idout@, @ec_idfix@ --- * * * Arguments: @ec_curve *c@ = pointer to an elliptic curve @@ -180,7 +176,7 @@ ec *ec_idfix(ec_curve *c, ec *d, const ec *p) return (d); } -/* --- @ec_projin@, @ec_projout@ --- * +/* --- @ec_projin@, @ec_projout@, @ec_projfix@ --- * * * Arguments: @ec_curve *c@ = pointer to an elliptic curve * @ec *d@ = pointer to the destination @@ -246,7 +242,7 @@ ec *ec_projfix(ec_curve *c, ec *d, const ec *p) mp_drop(d->z); d->z = MP_COPY(f->one); } - return (d); + return (d); } /* --- @ec_stdsub@ --- * @@ -432,48 +428,4 @@ ec *ec_rand(ec_curve *c, ec *d, grand *r) return (EC_OUT(c, d, d)); } -/* --- @ec_imul@, @ec_mul@ --- * - * - * Arguments: @ec_curve *c@ = pointer to an elliptic curve - * @ec *d@ = pointer to the destination point - * @const ec *p@ = pointer to the generator point - * @mp *n@ = integer multiplier - * - * Returns: The destination @d@. - * - * Use: Multiplies a point by a scalar, returning %$n p$%. The - * @imul@ variant uses internal representations for argument - * and result. - */ - -ec *ec_imul(ec_curve *c, ec *d, const ec *p, mp *n) -{ - ec t = EC_INIT; - - EC_COPY(&t, p); - if (t.x && (n->f & MP_BURN)) - t.x->f |= MP_BURN; - MP_SHRINK(n); - EC_SETINF(d); - if (MP_LEN(n) == 0) - ; - else { - if (n->f & MP_NEG) - EC_NEG(c, &t, &t); - if (MP_LEN(n) < EXP_THRESH) - EXP_SIMPLE(*d, t, n); - else - EXP_WINDOW(*d, t, n); - } - EC_DESTROY(&t); - return (d); -} - -ec *ec_mul(ec_curve *c, ec *d, const ec *p, mp *n) -{ - EC_IN(c, d, p); - ec_imul(c, d, d, n); - return (EC_OUT(c, d, d)); -} - /*----- That's all, folks -------------------------------------------------*/