* (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,
#include <mLib/bits.h>
#include <mLib/dstr.h>
+#include "ct.h"
#include "gcipher.h"
#include "ghash.h"
#include "grand.h"
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;
q = b;
*q++ = 0; sz--;
mq = q + hsz;
- qq = q + sz;
GR_FILL(o->r, q, hsz);
/* --- Fill in the rest of the buffer --- */
* 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;
ghash *h;
octet *q, *mq, *qq;
octet *pp;
- unsigned bad = 0;
+ uint32 goodp = 1;
size_t n;
size_t hsz = o->ch->hashsz;
mp_storeb(m, b, sz);
q = b;
- bad = *q;
+ goodp &= ct_inteq(*q, 0);
q++; sz--;
mq = q + hsz;
qq = q + sz;
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 -------------------------------------------------*/