projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Simple (non-projective) curves over prime fields now seem to work.
[u/mdw/catacomb]
/
ec-prime.c
diff --git
a/ec-prime.c
b/ec-prime.c
index
4611855
..
b2bfd52
100644
(file)
--- a/
ec-prime.c
+++ b/
ec-prime.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: ec-prime.c,v 1.3
2003/05/15 23:25:59
mdw Exp $
+ * $Id: ec-prime.c,v 1.3
.4.1 2003/06/10 13:43:53
mdw Exp $
*
* Elliptic curves over prime fields
*
*
* Elliptic curves over prime fields
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: ec-prime.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: ec-prime.c,v $
+ * Revision 1.3.4.1 2003/06/10 13:43:53 mdw
+ * Simple (non-projective) curves over prime fields now seem to work.
+ *
* Revision 1.3 2003/05/15 23:25:59 mdw
* Make elliptic curve stuff build.
*
* Revision 1.3 2003/05/15 23:25:59 mdw
* Make elliptic curve stuff build.
*
@@
-54,7
+57,7
@@
typedef struct ecctx {
mp *a, *b;
} ecctx;
mp *a, *b;
} ecctx;
-/*-----
Main code ----------
-----------------------------------------------*/
+/*-----
Simple prime curves
-----------------------------------------------*/
static const ec_ops ec_primeops;
static const ec_ops ec_primeops;
@@
-157,7
+160,7
@@
static void ecdestroy(ec_curve *c)
/* --- @ec_prime@, @ec_primeproj@ --- *
*
/* --- @ec_prime@, @ec_primeproj@ --- *
*
- * Arguments: @field *f@ = the under
yl
ing field for this elliptic curve
+ * Arguments: @field *f@ = the under
ly
ing field for this elliptic curve
* @mp *a, *b@ = the coefficients for this curve
*
* Returns: A pointer to the curve.
* @mp *a, *b@ = the coefficients for this curve
*
* Returns: A pointer to the curve.
@@
-172,8
+175,8
@@
extern ec_curve *ec_prime(field *f, mp *a, mp *b)
ecctx *cc = CREATE(ecctx);
cc->c.ops = &ec_primeops;
cc->c.f = f;
ecctx *cc = CREATE(ecctx);
cc->c.ops = &ec_primeops;
cc->c.f = f;
- cc->a =
MP_COPY(
a);
- cc->b =
MP_COPY(
b);
+ cc->a =
F_IN(f, MP_NEW,
a);
+ cc->b =
F_IN(f, MP_NEW,
b);
return (&cc->c);
}
return (&cc->c);
}
@@
-194,10
+197,12
@@
int main(void)
ec g = EC_INIT, d = EC_INIT;
mp *p, *a, *b, *r;
ec g = EC_INIT, d = EC_INIT;
mp *p, *a, *b, *r;
+ printf("ec-prime: ");
+ fflush(stdout);
a = MP(-3);
b = MP(0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1);
p = MP(6277101735386680763835789423207666416083908700390324961279);
a = MP(-3);
b = MP(0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1);
p = MP(6277101735386680763835789423207666416083908700390324961279);
- r = MP(627710173538668076383578942317605901376719477318284228408
1
);
+ r = MP(627710173538668076383578942317605901376719477318284228408
0
);
f = field_prime(p);
c = ec_prime(f, a, b);
f = field_prime(p);
c = ec_prime(f, a, b);
@@
-206,14
+211,25
@@
int main(void)
g.y = MP(0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811);
ec_mul(c, &d, &g, r);
g.y = MP(0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811);
ec_mul(c, &d, &g, r);
- MP_PRINT("d.x", d.x);
- MP_PRINT("d.y", d.y);
+ if (EC_ATINF(&d)) {
+ fprintf(stderr, "zero too early\n");
+ return (1);
+ }
+ ec_add(c, &d, &d, &g);
+ if (!EC_ATINF(&d)) {
+ fprintf(stderr, "didn't reach zero\n");
+ MP_EPRINT("d.x", d.x);
+ MP_EPRINT("d.y", d.y);
+ return (1);
+ }
ec_destroy(&d);
ec_destroy(&g);
ec_destroycurve(c);
F_DESTROY(f);
ec_destroy(&d);
ec_destroy(&g);
ec_destroycurve(c);
F_DESTROY(f);
-
+ MP_DROP(p); MP_DROP(a); MP_DROP(b); MP_DROP(r);
+ assert(!mparena_count(&mparena_global));
+ printf("ok\n");
return (0);
}
return (0);
}