blowfish-mktab.c: Remove the eye-candy progress meter.
[u/mdw/catacomb] / oaep.c
diff --git a/oaep.c b/oaep.c
index 2b9d779..dfcd41b 100644 (file)
--- a/oaep.c
+++ b/oaep.c
@@ -7,7 +7,7 @@
  * (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,
@@ -35,6 +35,7 @@
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
 
+#include "ct.h"
 #include "gcipher.h"
 #include "ghash.h"
 #include "grand.h"
@@ -64,7 +65,7 @@ mp *oaep_encode(mp *d, const void *m, size_t msz, octet *b, size_t sz,
   oaep *o = p;
   size_t hsz = o->ch->hashsz;
   ghash *h;
-  octet *q, *mq, *qq;
+  octet *q, *mq;
   octet *pp;
   gcipher *c;
   size_t n;
@@ -79,7 +80,6 @@ mp *oaep_encode(mp *d, const void *m, size_t msz, octet *b, size_t sz,
   q = b;
   *q++ = 0; sz--;
   mq = q + hsz;
-  qq = q + sz;
   GR_FILL(o->r, q, hsz);
 
   /* --- Fill in the rest of the buffer --- */
@@ -126,17 +126,6 @@ mp *oaep_encode(mp *d, const void *m, size_t msz, octet *b, size_t sz,
  *             PKCS#1 v. 2.0 (RFC2437).
  */
 
-static int memeq(const void *xx, const void *yy, size_t sz)
-{
-  int eq = 1;
-  const octet *x = xx, *y = yy;
-  while (sz) {                         /* Always check every byte */
-    if (*x++ != *y++) eq = 0;
-    sz--;
-  }
-  return (eq);
-}
-
 int oaep_decode(mp *m, octet *b, size_t sz, unsigned long nbits, void *p)
 {
   oaep *o = p;
@@ -144,7 +133,7 @@ int oaep_decode(mp *m, octet *b, size_t sz, unsigned long nbits, void *p)
   ghash *h;
   octet *q, *mq, *qq;
   octet *pp;
-  unsigned bad = 0;
+  uint32 goodp = 1;
   size_t n;
   size_t hsz = o->ch->hashsz;
 
@@ -157,7 +146,7 @@ int oaep_decode(mp *m, octet *b, size_t sz, unsigned long nbits, void *p)
 
   mp_storeb(m, b, sz);
   q = b;
-  bad = *q;
+  goodp &= ct_inteq(*q, 0);
   q++; sz--;
   mq = q + hsz;
   qq = q + sz;
@@ -177,17 +166,19 @@ int oaep_decode(mp *m, octet *b, size_t sz, unsigned long nbits, void *p)
   GH_HASH(h, o->ep, o->epsz);
   GH_DONE(h, q);
   GH_DESTROY(h);
-  bad |= !memeq(q, mq, hsz);
+  goodp &= ct_memeq(q, mq, hsz);
 
   /* --- Now find the start of the actual message --- */
 
   pp = mq + hsz;
   while (*pp == 0 && pp < qq)
     pp++;
-  bad |= (pp >= qq) | (*pp++ != 1);
+  goodp &= ~ct_intle(qq - b, pp - b);
+  goodp &= ct_inteq(*pp, 1);
+  pp++;
   n = qq - pp;
   memmove(q, pp, n);
-  return (bad ? -1 : n);
+  return (goodp ? n : -1);
 }
 
 /*----- That's all, folks -------------------------------------------------*/