perftest: Optionally disable group checking.
[u/mdw/catacomb] / gdsa.c
diff --git a/gdsa.c b/gdsa.c
index 9b23f4f..83f4d06 100644 (file)
--- a/gdsa.c
+++ b/gdsa.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: gdsa.c,v 1.2 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
  *
  * Generalized version of DSA
  *
  * (c) 2004 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,
@@ -57,11 +57,11 @@ ghash *gdsa_beginhash(const gdsa *c) { return (GH_INIT(c->h)); }
  * Returns:    ---
  *
  * Use:                Does any final thing that DSA wants to do when hashing a
- *             message.  (Actually, there's nothing.)  The hashing context
+ *             message.  (Actually, there's nothing.)  The hashing context
  *             isn't finalized.
  */
 
-void gdsa_endhash(gdsa *c, ghash *h) { ; }
+void gdsa_endhash(const gdsa *c, ghash *h) { ; }
 
 /* --- @gdsa_sign@ --- *
  *
@@ -79,7 +79,7 @@ void gdsa_endhash(gdsa *c, ghash *h) { ; }
 void gdsa_sign(const gdsa *c, gdsa_sig *s, const void *m, mp *k)
 {
   group *g = c->g;
-  mp *mr = mp_loadb(MP_NEW, m, c->h->hashsz);
+  mp *mr = dsa_h2n(MP_NEW, g->r, m, c->h->hashsz);
   ge *z = G_CREATE(g);
   mp *sr = s->r, *ss = s->s;
   mpbarrett b;
@@ -88,10 +88,10 @@ void gdsa_sign(const gdsa *c, gdsa_sig *s, const void *m, mp *k)
 new_k:
   k = mprand_range(k, g->r, c->r, 0);
 have_k:
-  if (MP_ISZERO(k)) goto new_k;
+  if (MP_ZEROP(k)) goto new_k;
   G_EXP(g, z, g->g, k);
   sr = G_TOINT(g, sr, z); assert(sr);
-  if (MP_ISZERO(sr)) goto new_k;
+  if (MP_ZEROP(sr)) goto new_k;
 
   mp_div(0, &sr, sr, g->r);
   mpbarrett_create(&b, g->r);
@@ -128,7 +128,7 @@ int gdsa_verify(const gdsa *c, const gdsa_sig *s, const void *m)
     return (-1);
   mpbarrett_create(&b, g->r); h = mp_modinv(MP_NEW, s->s, g->r);
   e[0].base = g->g; e[1].base = c->p;
-  t = mp_loadb(MP_NEW, m, c->h->hashsz); mp_div(0, &t, t, g->r);
+  t = dsa_h2n(MP_NEW, g->r, m, c->h->hashsz); mp_div(0, &t, t, g->r);
   t = mp_mul(t, t, h); e[0].exp = t = mpbarrett_reduce(&b, t, t);
   h = mp_mul(h, s->r, h); e[1].exp = h = mpbarrett_reduce(&b, h, h);
   w = G_CREATE(g); G_MEXP(g, w, e, 2);
@@ -167,7 +167,7 @@ static void showge(group *g, const char *p, ge *x) {
 }
 
 static void showmp(const char *p, mp *x, int r) {
-  fprintf(stderr, "*** %s = ", p); mp_writefile(x, stderr, r); 
+  fprintf(stderr, "*** %s = ", p); mp_writefile(x, stderr, r);
   putc('\n', stderr);
 }