A number of small bug fixes, some motivated by compiler warnings.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 15 Feb 2007 16:36:42 +0000 (16:36 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 19 Feb 2007 12:37:43 +0000 (12:37 +0000)
  * key-data.c:key_nextsubkey -- explicitly return nonzero if we found
    something.

  * key-io.c:key_new -- cast the constant type pointer during the
    unpleasant hack.

  * mp-mem.c:mp_build -- store an arena in the built integer; otherwise
    pgen_primep (for example) gets confused later on.

  * mp-modsqrt.c:mp_modsqrt -- fix the maths in a comment; the code was
    fine.

  * oaep.c:oaep_decode -- don't try to do too much in one expression.

  * pgen-simul.c:pgen_simultest -- always return a sensible result code.

  * cc.h:sig -- hash classes are constant.

  * cc-{kem,sig}.c:get{kem,sig} -- initialize the kp structure member,
    just in case.

  * rijndael*.c, square.c -- fix const-correctness errors.

13 files changed:
cc-kem.c
cc-sig.c
cc.h
key-data.c
key-io.c
mp-mem.c
mp-modsqrt.c
oaep.c
pgen-simul.c
rijndael.c
rijndael192.c
rijndael256.c
square.c

index 360977a..28fcd4b 100644 (file)
--- a/cc-kem.c
+++ b/cc-kem.c
@@ -502,6 +502,7 @@ k_found:;
   if (!ko->kf) {
     kd = k->k;
     key_incref(kd);
   if (!ko->kf) {
     kd = k->k;
     key_incref(kd);
+    kp = 0;
   } else {
     kd = xmalloc(ko->kdsz);
     kp = key_fetchinit(ko->kf, 0, kd);
   } else {
     kd = xmalloc(ko->kdsz);
     kp = key_fetchinit(ko->kf, 0, kd);
index 5439408..eecda46 100644 (file)
--- a/cc-sig.c
+++ b/cc-sig.c
@@ -756,6 +756,7 @@ s_found:;
   if (!so->kf) {
     kd = k->k;
     key_incref(kd);
   if (!so->kf) {
     kd = k->k;
     key_incref(kd);
+    kp = 0;
   } else {
     kd = xmalloc(so->kdsz);
     kp = key_fetchinit(so->kf, 0, kd);
   } else {
     kd = xmalloc(so->kdsz);
     kp = key_fetchinit(so->kf, 0, kd);
diff --git a/cc.h b/cc.h
index f7b12d0..45e7eff 100644 (file)
--- a/cc.h
+++ b/cc.h
@@ -82,7 +82,7 @@ typedef struct sig {
   const struct sigops *ops;
   key_packdef *kp;
   void *kd;
   const struct sigops *ops;
   key_packdef *kp;
   void *kd;
-  gchash *ch;
+  const gchash *ch;
   ghash *h;
 } sig;
 
   ghash *h;
 } sig;
 
index 4b43a2c..c77b6a4 100644 (file)
@@ -328,6 +328,7 @@ int key_nextsubkey(key_subkeyiter *i, const char **tag, key_data **kd)
     return (0);
   if (tag) *tag = SYM_NAME(ks);
   if (kd) *kd = ks->k;
     return (0);
   if (tag) *tag = SYM_NAME(ks);
   if (kd) *kd = ks->k;
+  return (1);
 }
 
 /* --- @key_structset@, @key_structsteal@ --- *
 }
 
 /* --- @key_structset@, @key_structsteal@ --- *
index b77bab9..5c70909 100644 (file)
--- a/key-io.c
+++ b/key-io.c
@@ -553,7 +553,7 @@ int key_new(key_file *f, uint32 id, const char *type, time_t exp, key **kk)
     k->tag = 0;
     k->exp = k->del = exp;
     k->c = 0;
     k->tag = 0;
     k->exp = k->del = exp;
     k->c = 0;
-    k->type = type; /* temporarily */
+    k->type = (char *)type; /* temporarily */
     sym_create(&k->a);
     if ((e = insert(f, k)) != 0)
       DESTROY(k);
     sym_create(&k->a);
     if ((e = insert(f, k)) != 0)
       DESTROY(k);
index dc9804d..fcb6c4d 100644 (file)
--- a/mp-mem.c
+++ b/mp-mem.c
@@ -127,6 +127,7 @@ void mp_build(mp *m, mpw *v, mpw *vl)
   m->v = v;
   m->vl = vl;
   m->sz = vl - v;
   m->v = v;
   m->vl = vl;
   m->sz = vl - v;
+  m->a = MPARENA_GLOBAL;
   m->f = MP_CONST;
   m->ref = 1;
 }
   m->f = MP_CONST;
   m->ref = 1;
 }
index 3ec374c..1791185 100644 (file)
@@ -119,7 +119,7 @@ mp *mp_modsqrt(mp *d, mp *a, mp *p)
     dd = mpmont_reduce(&mm, dd, dd);
     dd = mpmont_mul(&mm, dd, dd, ainv);
 
     dd = mpmont_reduce(&mm, dd, dd);
     dd = mpmont_mul(&mm, dd, dd, ainv);
 
-    /* --- Now %$d = d_0^{s - i - 1}$% --- */
+    /* --- Now %$d = d_0^{2^{s - i - 1}}$% --- */
 
     for (j = i; j < s - 1; j++) {
       dd = mp_sqr(dd, dd);
 
     for (j = i; j < s - 1; j++) {
       dd = mp_sqr(dd, dd);
diff --git a/oaep.c b/oaep.c
index ab60b5e..d7570de 100644 (file)
--- a/oaep.c
+++ b/oaep.c
@@ -184,7 +184,8 @@ int oaep_decode(mp *m, octet *b, size_t sz, unsigned long nbits, void *p)
   pp = mq + hsz;
   while (*pp == 0 && pp < qq)
     pp++;
   pp = mq + hsz;
   while (*pp == 0 && pp < qq)
     pp++;
-  bad |= (pp >= qq) | (*pp++ != 1);
+  bad |= (pp >= qq) | (*pp != 1);
+  pp++;
   n = qq - pp;
   memmove(q, pp, n);
   return (bad ? -1 : n);
   n = qq - pp;
   memmove(q, pp, n);
   return (bad ? -1 : n);
index b7e8598..175b009 100644 (file)
@@ -161,6 +161,7 @@ int pgen_simultest(int rq, pgen_event *ev, void *p)
     case PGEN_DONE:
       for (i = 0; i < ss->n; i++)
        rabin_destroy(&ss->v[i].r);
     case PGEN_DONE:
       for (i = 0; i < ss->n; i++)
        rabin_destroy(&ss->v[i].r);
+      rc = PGEN_DONE;
       break;
   }
   return (rc);
       break;
   }
   return (rc);
index 261823c..9eb5f21 100644 (file)
@@ -89,7 +89,7 @@ void rijndael_eblk(const rijndael_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
-  uint32 *w = k->w;
+  const uint32 *w = k->w;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   aa = a; bb = b; cc = c; dd = d;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   aa = a; bb = b; cc = c; dd = d;
@@ -124,7 +124,7 @@ void rijndael_dblk(const rijndael_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
-  uint32 *w = k->wi;
+  const uint32 *w = k->wi;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   aa = a; bb = b; cc = c; dd = d;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   aa = a; bb = b; cc = c; dd = d;
index 4b4c034..aef5955 100644 (file)
@@ -94,7 +94,7 @@ void rijndael192_eblk(const rijndael_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3], e = s[4], f = s[5];
   uint32 aa, bb, cc, dd, ee, ff;
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3], e = s[4], f = s[5];
   uint32 aa, bb, cc, dd, ee, ff;
-  uint32 *w = k->w;
+  const uint32 *w = k->w;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++; e ^= *w++; f ^= *w++;
   aa = a; bb = b; cc = c; dd = d; ee = e; ff = f;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++; e ^= *w++; f ^= *w++;
   aa = a; bb = b; cc = c; dd = d; ee = e; ff = f;
@@ -127,7 +127,7 @@ void rijndael192_dblk(const rijndael_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3], e = s[4], f = s[5];
   uint32 aa, bb, cc, dd, ee, ff;
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3], e = s[4], f = s[5];
   uint32 aa, bb, cc, dd, ee, ff;
-  uint32 *w = k->wi;
+  const uint32 *w = k->wi;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++; e ^= *w++; f ^= *w++;
   aa = a; bb = b; cc = c; dd = d; ee = e; ff = f;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++; e ^= *w++; f ^= *w++;
   aa = a; bb = b; cc = c; dd = d; ee = e; ff = f;
index 3377009..27f06d7 100644 (file)
@@ -103,7 +103,7 @@ void rijndael256_eblk(const rijndael_ctx *k, const uint32 *s, uint32 *dst)
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 e = s[4], f = s[5], g = s[6], h = s[7];
   uint32 aa, bb, cc, dd, ee, ff, gg, hh;
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 e = s[4], f = s[5], g = s[6], h = s[7];
   uint32 aa, bb, cc, dd, ee, ff, gg, hh;
-  uint32 *w = k->w;
+  const uint32 *w = k->w;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   e ^= *w++; f ^= *w++; g ^= *w++; h ^= *w++;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   e ^= *w++; f ^= *w++; g ^= *w++; h ^= *w++;
@@ -132,7 +132,7 @@ void rijndael256_dblk(const rijndael_ctx *k, const uint32 *s, uint32 *dst)
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 e = s[4], f = s[5], g = s[6], h = s[7];
   uint32 aa, bb, cc, dd, ee, ff, gg, hh;
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 e = s[4], f = s[5], g = s[6], h = s[7];
   uint32 aa, bb, cc, dd, ee, ff, gg, hh;
-  uint32 *w = k->wi;
+  const uint32 *w = k->wi;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   e ^= *w++; f ^= *w++; g ^= *w++; h ^= *w++;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
   e ^= *w++; f ^= *w++; g ^= *w++; h ^= *w++;
index cb243b3..6ed8d86 100644 (file)
--- a/square.c
+++ b/square.c
@@ -155,7 +155,7 @@ void square_eblk(const square_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
-  uint32 *w = k->w;
+  const uint32 *w = k->w;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
 
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
 
@@ -175,7 +175,7 @@ void square_dblk(const square_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
-  uint32 *w = k->wi;
+  const uint32 *w = k->wi;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
 
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;