Deploy the new <ctype.h> and `foocmp' macros from mLib.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 1 Oct 2019 19:01:20 +0000 (20:01 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 9 May 2020 19:57:33 +0000 (20:57 +0100)
84 files changed:
base/dispatch.c
base/keysz-conv.c
base/rsvr.c
key/key-attr.c
key/key-binary.c
key/key-flags.c
key/key-io.c
key/key-misc.c
key/key-pass.c
key/key-text.c
key/passphrase.c
key/pixie-common.c
math/bittest.c
math/ec-test.c
math/f25519.c
math/fgoldi.c
math/g-ec.c
math/genprimes.c
math/genwheel.c
math/group-test.c
math/mp-arith.c
math/mpint.c
math/mptext.c
math/mpx.c
math/qdparse.c
misc/gfshare.c
progs/catcrypt.c
progs/catsign.c
progs/cc-enc.c
progs/cc-hash.c
progs/cc-kem.c
progs/cc-list.c
progs/cc-sig.c
progs/cc-subcmd.c
progs/cookie.c
progs/dsig.c
progs/factorial.c
progs/fibonacci.c
progs/hashsum.c
progs/key.c
progs/mkphrase.c
progs/perftest.c
progs/pixie.c
progs/rspit.c
pub/bbs-rand.c
pub/dh-param.c
pub/dsa-gen.c
pub/dsa-sign.c
pub/ed25519.c
pub/ed448.c
pub/gkcdsa.c
pub/pkcs1.c
pub/pss.c
pub/rsa-pub.c
pub/rsa-test.c
pub/x25519.c
pub/x448.c
rand/sslprf.c
rand/tlsprf.c
symm/blkc.h
symm/ccm-def.h
symm/chacha.c
symm/cmac-def.h
symm/eax-def.h
symm/gcm-def.h
symm/gcm.c
symm/gthingtab.c.in
symm/hash.h
symm/hmac-def.h
symm/keccak1600.c
symm/latinpoly-test.c
symm/modes-test.c
symm/ocb1-def.h
symm/ocb3-def.h
symm/pmac1-def.h
symm/poly1305.c
symm/rc2.c
symm/rc4.c
symm/salsa20.c
symm/seal.c
symm/serpent-check.c
symm/sha3.c
symm/strobe.c
utils/ecptdecompress.c

index db9c319..7806d40 100644 (file)
@@ -434,14 +434,14 @@ static int IGNORABLE check_env(const char *ftok)
   if (!p) return (-1);
 
   for (;;) {
-    while (isspace((unsigned char)*p)) p++;
+    while (ISSPACE(*p)) p++;
     if (!*p) return (-1);
     switch (*p) {
       case '+': d = +1; p++; break;
       case '-': d =  0; p++; break;
       default:  d = -1;      break;
     }
-    for (q = p; *q && !isspace((unsigned char)*q); q++);
+    for (q = p; *q && !ISSPACE(*q); q++);
     if (d >= 0) {
       for (pp = ftok; p < q && *pp && *p == *pp; p++, pp++);
       if ((p == q && !*pp) || (*p == '*' && p + 1 == q)) return (d);
index 2d40558..9ed9f58 100644 (file)
@@ -140,6 +140,8 @@ CONVERSIONS(DEFINE_TO)
 #include <stdlib.h>
 #include <string.h>
 
+#include <mLib/macros.h>
+
 static const struct entry {
   const char *name;
   double (*func)(double);
@@ -162,7 +164,7 @@ int main(int argc, char *argv[])
     putc('\n', stderr);
     return (1);
   }
-  for (e = tab; e->name && strcmp(e->name, argv[1]); e++);
+  for (e = tab; e->name && STRCMP(e->name, !=, argv[1]); e++);
   if (!e) {
     fprintf(stderr, "unknown conversion `%s'\n", argv[1]);
     return (1);
index a468db7..3be9ed1 100644 (file)
@@ -231,6 +231,7 @@ int rsvr_done(rsvr_state *st)
 #include <mLib/alloc.h>
 #include <mLib/bits.h>
 #include <mLib/darray.h>
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/testrig.h>
 
@@ -305,12 +306,12 @@ static void parse_intlist(uint_v *v, const char *p)
   int e = errno;
 
   for (;;) {
-    while (isspace((unsigned char)*p)) p++;
+    while (ISSPACE(*p)) p++;
     if (!*p) break;
     if (*p == ',') p++;
-    while (isspace((unsigned char)*p)) p++;
+    while (ISSPACE(*p)) p++;
     errno = 0; n = strtoul(p, &q, 0);
-    if (errno || (*q && *q != ',' && !isspace((unsigned char)*q)))
+    if (errno || (*q && *q != ',' && !ISSPACE(*q)))
       die(1, "invalid int list");
     p = q; DA_PUSH(v, n);
   }
index e884d69..567fb92 100644 (file)
@@ -34,6 +34,7 @@
 #include <time.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/sym.h>
 
 #include "key.h"
@@ -54,7 +55,7 @@ int key_chkident(const char *p)
   if (!p || !*p || strlen(p) > 255)
     return (-1);
   while (*p) {
-    if (*p == ':' || *p == '.' || isspace((unsigned char)*p))
+    if (*p == ':' || *p == '.' || ISSPACE(*p))
       return (-1);
     p++;
   }
@@ -252,8 +253,7 @@ int key_settag(key_file *f, key *k, const char *tag)
 
   /* --- See if the new tag is the same as the old one --- */
 
-  if ((!tag && !k->tag) ||
-      (tag && k->tag && strcmp(tag, k->tag) == 0))
+  if ((!tag && !k->tag) || (tag && k->tag && STRCMP(tag, ==, k->tag)))
     return (0);
 
   /* --- Allocate an entry for the new tag --- */
index 046819a..718dfb6 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/sub.h>
 #include <mLib/sym.h>
 
index 169de2c..7cedb85 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 
 #include "key-data.h"
 
@@ -104,10 +105,10 @@ int key_readflags(const char *p, char **pp, unsigned *ff, unsigned *mm)
 
     /* --- Look up the string in the flags table --- */
 
-    if (sz == 4 && strncmp(p, "none", 4) == 0)
+    if (sz == 4 && STRNCMP(p, ==, "none", 4))
       goto next;
     for (e = flagtab; e->name; e++) {
-      if (strncmp(e->name, p, sz) == 0) {
+      if (STRNCMP(e->name, ==, p, sz)) {
        if (e->name[sz] == 0) {
          ee = e;
          break;
index bf3bf95..3bb8e1d 100644 (file)
@@ -38,6 +38,7 @@
 #include <mLib/crc32.h>
 #include <mLib/dstr.h>
 #include <mLib/hash.h>
+#include <mLib/macros.h>
 #include <mLib/str.h>
 #include <mLib/sub.h>
 #include <mLib/sym.h>
@@ -142,9 +143,9 @@ static int insert(key_file *f, key *k)
 static time_t exptime(const char *p)
 {
   size_t sz = strlen(p);
-  if (strncmp(p, "expired", sz) == 0)
+  if (STRNCMP(p, ==, "expired", sz))
     return (KEXP_EXPIRE);
-  else if (strncmp(p, "forever", sz) == 0)
+  else if (STRNCMP(p, ==, "forever", sz))
     return (KEXP_FOREVER);
   else
     return (atol(p));
@@ -182,7 +183,7 @@ static void merge_core(key_file *f, const char *file, int lno, char *p,
    * maintained file I don't know.
    */
 
-  while (isspace((unsigned char)*p))
+  while (ISSPACE(*p))
     p++;
   if (!*p || *p == '#')
     goto skip;
@@ -287,9 +288,9 @@ static void merge_core(key_file *f, const char *file, int lno, char *p,
 
   /* --- Parse up the attributes, if specified --- */
 
-  sym_create(&k->a);
-  if (vf[4] && strcmp(vf[4], "-") != 0) {
-    url_dctx uc;
+    sym_create(&k->a);
+    if (vf[4] && STRCMP(vf[4], !=, "-")) {
+      url_dctx uc;
     for (url_initdec(&uc, vf[4]); url_dec(&uc, n, v); ) {
       key_putattr(f, k, n->buf, v->buf);
       DRESET(n); DRESET(v);
index 0d969a8..b10879a 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <mLib/bits.h>
 #include <mLib/hash.h>
+#include <mLib/macros.h>
 #include <mLib/sub.h>
 #include <mLib/sym.h>
 
index 665030e..223486e 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <mLib/dstr.h>
 
+#include "ct.h"
 #include "key-data.h"
 #include "paranoia.h"
 #include "passphrase.h"
@@ -172,8 +173,8 @@ int key_unlock(key_data **kt, key_data *k, const void *e, size_t esz)
   rmd160_macinit(&mc, &mk);
   rmd160_machash(&mc, k->u.k.k + RMD160_HASHSZ * 2, sz);
   rmd160_macdone(&mc, b + RMD160_HASHSZ);
-  if (memcmp(b + RMD160_HASHSZ, k->u.k.k + RMD160_HASHSZ,
-            RMD160_HASHSZ) != 0) {
+  if (!ct_memeq(b + RMD160_HASHSZ,
+               k->u.k.k + RMD160_HASHSZ, RMD160_HASHSZ)) {
     rc = KERR_BADPASS;
     goto fail;
   }
index 98c1fba..ace69ce 100644 (file)
@@ -34,6 +34,7 @@
 #include <mLib/base64.h>
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/sub.h>
 #include <mLib/sym.h>
 #include <mLib/url.h>
@@ -298,7 +299,7 @@ int key_write(key_data *k, dstr *d, const key_filter *kf)
       DPUTC(d, ':');
       while (*p) {
        if (*p == ' ') DPUTC(d, '+');
-       else if (!isalnum((unsigned char)*p)) dstr_putf(d, "%%%02x", *p);
+       else if (!ISALNUM(*p)) dstr_putf(d, "%%%02x", *p);
        else DPUTC(d, *p);
        p++;
       }
index 6f0780f..3a287bd 100644 (file)
@@ -35,6 +35,7 @@
 #include <unistd.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 
 #include "passphrase.h"
 #include "pixie.h"
@@ -122,7 +123,7 @@ int passphrase_read(const char *tag, unsigned mode, char *buf, size_t sz)
     char b[1024];
     DRESET(&d);
     dstr_putf(&d, "Verify passphrase %s: ", tag);
-    if (pixie_getpass(d.buf, b, sizeof(b)) || strcmp(b, buf) != 0) {
+    if (pixie_getpass(d.buf, b, sizeof(b)) || STRCMP(b, !=, buf)) {
       memset(b, 0, sizeof(b));
       goto fail;
     }
index 2975c20..d3348bc 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <mLib/alloc.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/str.h>
 
 #include "pixie.h"
@@ -283,11 +284,11 @@ again:
   p = buf;
   if ((q = str_getword(&p)) == 0)
     return (-1);
-  if (strcmp(q, "INFO") == 0)
+  if (STRCMP(q, ==, "INFO"))
     goto again;
-  else if (strcmp(q, "MISSING") == 0)
+  else if (STRCMP(q, ==, "MISSING"))
     return (+1);
-  else if (strcmp(q, "OK") != 0)
+  else if (STRCMP(q, !=, "OK"))
     return (-1);
 
   /* --- Return the final answer --- */
@@ -336,7 +337,7 @@ void pixie_set(int fd, const char *tag, const char *phrase)
 again:
   pixie_fdline(fd, buf, sizeof(buf));
   p = buf;
-  if ((q = str_getword(&p)) != 0 && strcmp(q, "INFO") == 0)
+  if ((q = str_getword(&p)) != 0 && STRCMP(q, ==, "INFO"))
     goto again;
 }
 
@@ -367,7 +368,7 @@ void pixie_cancel(int fd, const char *tag)
 again:
   pixie_fdline(fd, buf, sizeof(buf));
   p = buf;
-  if ((q = str_getword(&p)) != 0 && strcmp(q, "INFO") == 0)
+  if ((q = str_getword(&p)) != 0 && STRCMP(q, ==, "INFO"))
     goto again;
 }
 
index 5f7b1d7..e335286 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <mLib/macros.h>
 #include "bitops.h"
 #include "mpx.h"
 
@@ -45,7 +46,7 @@ int main(void)
   buf[2] = B##string(1u, 0u) & 1u? '1' : '0';                          \
   buf[3] = B##string(1u, 1u) & 1u? '1' : '0';                          \
   buf[4] = 0;                                                          \
-  if (strcmp(buf, ref) != 0) {                                         \
+  if (STRCMP(buf, !=, ref)) {                                          \
     fprintf(stderr, "mismatch ref `%s' != buf `%s'\n", ref, buf);      \
     rc = 1;                                                            \
   }                                                                    \
index d9cda6f..ff01a2e 100644 (file)
@@ -215,6 +215,8 @@ const test_type type_ec = { eccvt, ecdump };
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
+
 static void ecdestroy(ec_curve *c)
 {
   field *f = c->f;
@@ -354,7 +356,7 @@ static int vec2osp(dstr v[])
   int ok = 1;
   int win, wantwin;
 
-  if (strcmp(v[3].buf, "FAIL") == 0) wantwin = 0;
+  if (STRCMP(v[3].buf, ==, "FAIL")) wantwin = 0;
   else { wantwin = 1; type_hex.cvt(v[3].buf, &d); }
 
   dstr_ensure(&dd, n); buf_init(&b, dd.buf, n);
@@ -362,7 +364,7 @@ static int vec2osp(dstr v[])
   win = !ec_ec2osp(e, f, &b, p);
   if (!win != !wantwin ||
       (win && (BLEN(&b) != d.len ||
-              memcmp(BBASE(&b), d.buf, BLEN(&b)) != 0))) {
+              MEMCMP(BBASE(&b), !=, d.buf, BLEN(&b))))) {
     ok = 0;
     fprintf(stderr, "ec2osp failed");
     fprintf(stderr, "\ncurve = "); type_ecurve.dump(v, stderr);
@@ -393,7 +395,7 @@ static int vos2ecp(dstr v[])
   int ok = 1;
   int win;
 
-  if (strcmp(v[3].buf, "FAIL") == 0) p = 0;
+  if (STRCMP(v[3].buf, ==, "FAIL")) p = 0;
   else { type_ec.cvt(v[3].buf, &d); p = (ec *)d.buf; }
 
   buf_init(&b, v[2].buf, v[2].len);
index e9a91f4..7f8e66f 100644 (file)
@@ -1178,6 +1178,7 @@ int f25519_quosqrt(f25519 *z, const f25519 *x, const f25519 *y)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/str.h>
 #include <mLib/testrig.h>
@@ -1218,7 +1219,7 @@ static void dump_f25519_ref(dstr *d, FILE *fp)
 }
 
 static int eq(const f25519 *x, dstr *d)
-  { octet b[32]; f25519_store(b, x); return (memcmp(b, d->buf, 32) == 0); }
+  { octet b[32]; f25519_store(b, x); return (MEMCMP(b, ==, d->buf, 32)); }
 
 static const test_type
   type_f25519 = { cvt_f25519, dump_f25519 },
index 1b09b58..43309dc 100644 (file)
@@ -962,6 +962,7 @@ int fgoldi_quosqrt(fgoldi *z, const fgoldi *x, const fgoldi *y)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/str.h>
 #include <mLib/testrig.h>
@@ -1002,7 +1003,7 @@ static void dump_fgoldi_ref(dstr *d, FILE *fp)
 }
 
 static int eq(const fgoldi *x, dstr *d)
-  { octet b[56]; fgoldi_store(b, x); return (memcmp(b, d->buf, 56) == 0); }
+  { octet b[56]; fgoldi_store(b, x); return (MEMCMP(b, ==, d->buf, 56)); }
 
 static const test_type
   type_fgoldi = { cvt_fgoldi, dump_fgoldi },
index 1b6c16e..5d922dd 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <ctype.h>
 
+#include <mLib/macros.h>
 #include <mLib/sub.h>
 
 #define ge ec
@@ -99,15 +100,15 @@ static int gread(group *gg, ec *d, const mptext_ops *ops, void *p) {
   int ch;
 
   ch = ops->get(p);
-  if (tolower(ch) == 'i') {
-    if (tolower(ops->get(p)) != 'n' || tolower(ops->get(p)) != 'f')
+  if (TOLOWER(ch) == 'i') {
+    if (TOLOWER(ops->get(p)) != 'n' || TOLOWER(ops->get(p)) != 'f')
       return (-1);
     EC_SETINF(d);
     return (0);
   }
   ops->unget(ch, p);
   if ((t.x = mp_read(MP_NEW, 0, ops, p)) == 0) goto done;
-  do ch = ops->get(p); while (ch == ',' || isspace(ch)); ops->unget(ch, p);
+  do ch = ops->get(p); while (ch == ',' || ISSPACE(ch)); ops->unget(ch, p);
   if ((t.y = mp_read(MP_NEW, 0, ops, p)) == 0) goto done;
   EC_IN(g->ei.c, &t, &t);
   if (EC_CHECK(g->ei.c, &t)) goto done;
index 8b47ac9..1ed7b4d 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -123,8 +124,8 @@ int main(int argc, char *argv[])
     if (!sym) {
       for (q = header; *q; q++) {
        int ch = (unsigned char)*q;
-       if (isalnum(ch))
-         ch = toupper(ch);
+       if (ISALNUM(ch))
+         ch = TOUPPER(ch);
        else
          ch = '_';
        DPUTC(&d, ch);
index 9bf3cbe..0354cc2 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -127,8 +128,8 @@ int main(int argc, char *argv[])
     if (!sym) {
       for (q = header; *q; q++) {
        int ch = (unsigned char)*q;
-       if (isalnum(ch))
-         ch = toupper(ch);
+       if (ISALNUM(ch))
+         ch = TOUPPER(ch);
        else
          ch = '_';
        DPUTC(&d, ch);
index 493ee2f..dfbc37f 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <stdarg.h>
 
+#include <mLib/macros.h>
 #include <mLib/testrig.h>
 
 #include "group.h"
@@ -108,7 +109,7 @@ static int vcheck(dstr *v)
   gr->ops->destroy(gr);
   if (!e) e = "ok";
   G_DESTROYGROUP(g);
-  if (strcmp(e, v[1].buf)) {
+  if (STRCMP(e, !=, v[1].buf)) {
     ok = 0;
     fprintf(stderr, "*** check failed\n");
     fprintf(stderr, "*** group: %s\n", v[0].buf);
@@ -390,7 +391,7 @@ static int vtobuf(dstr *v)
   ic = G_TOBUF(g, &b, x);
   c.len = BLEN(&b);
   if (ic != ir || (!ic && (c.len != v[3].len ||
-                          memcmp(c.buf, v[3].buf, c.len)))) {
+                          MEMCMP(c.buf, !=, v[3].buf, c.len)))) {
     ok = 0;
     fprintf(stderr, "*** tobuf failed\n");
     fprintf(stderr, "*** group: %s\n", v[0].buf);
@@ -455,7 +456,7 @@ static int vtoraw(dstr *v)
   ic = G_TORAW(g, &b, x);
   c.len = BLEN(&b);
   if (ic != ir || (!ic && (c.len != v[3].len ||
-                          memcmp(c.buf, v[3].buf, c.len)))) {
+                          MEMCMP(c.buf, !=, v[3].buf, c.len)))) {
     ok = 0;
     fprintf(stderr, "*** toraw failed\n");
     fprintf(stderr, "*** group: %s\n", v[0].buf);
index 470620e..048f4c6 100644 (file)
@@ -700,6 +700,8 @@ mp *mp_leastcongruent(mp *d, mp *b, mp *r, mp *m)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
+
 static int verify(const char *op, mp *expect, mp *result, mp *a, mp *b)
 {
   if (!MP_EQ(expect, result)) {
@@ -787,11 +789,11 @@ MPX_DOBIN(DO)
   mp *r = *(mp **)v[3].buf;
   mp *c;
 
-  if (strcmp(v[0].buf, "and") == 0) op = 1;
-  else if (strcmp(v[0].buf, "or") == 0) op = 7;
-  else if (strcmp(v[0].buf, "nand") == 0) op = 14;
-  else if (strcmp(v[0].buf, "nor") == 0) op = 8;
-  else if (strcmp(v[0].buf, "xor") == 0) op = 6;
+  if (STRCMP(v[0].buf, ==, "and")) op = 1;
+  else if (STRCMP(v[0].buf, ==, "or")) op = 7;
+  else if (STRCMP(v[0].buf, ==, "nand")) op = 14;
+  else if (STRCMP(v[0].buf, ==, "nor")) op = 8;
+  else if (STRCMP(v[0].buf, ==, "xor")) op = 6;
   else {
     char *p = v[0].buf;
     while (*p) {
index 3511f1e..971edab 100644 (file)
@@ -57,6 +57,7 @@ MPINT_CONVERSIONS(TO)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/testrig.h>
 
 static int fromuint(dstr *v)
index c902264..a5c77db 100644 (file)
@@ -31,6 +31,8 @@
 #include <limits.h>
 #include <stdio.h>
 
+#include <mLib/macros.h>
+
 #include "mp.h"
 #include "mptext.h"
 #include "paranoia.h"
@@ -340,10 +342,10 @@ mp *mp_read(mp *m, int radix, const mptext_ops *ops, void *p)
   /* --- If we're reading text, skip leading space, and maybe a sign --- */
 
   if (radix >= 0) {
-    while (isspace(ch)) ch = ops->get(p);
+    while (ISSPACE(ch)) ch = ops->get(p);
     switch (ch) {
       case '-': f |= f_neg; /* and on */
-      case '+': do ch = ops->get(p); while (isspace(ch));
+      case '+': do ch = ops->get(p); while (ISSPACE(ch));
     }
   }
 
@@ -705,7 +707,7 @@ static int verify(dstr *v)
       ok = 0;
     } else {
       mp_writedstr(m, &d, ob);
-      if (d.len != v[3].len || memcmp(d.buf, v[3].buf, d.len) != 0) {
+      if (d.len != v[3].len || MEMCMP(d.buf, !=, v[3].buf, d.len)) {
        fprintf(stderr, "*** failed read or write\n"
                        "*** input [%2i]      = ", ib);
        if (ib < 0)
@@ -746,7 +748,7 @@ static int verify(dstr *v)
   }
 
   if (v[1].len - off != v[4].len ||
-      memcmp(v[1].buf + off, v[4].buf, v[4].len) != 0) {
+      MEMCMP(v[1].buf + off, !=, v[4].buf, v[4].len)) {
     fprintf(stderr, "*** leftovers incorrect\n"
                    "*** input [%2i]    = ", ib);
     if (ib < 0)
index 741cd9d..07a6c20 100644 (file)
@@ -1274,6 +1274,7 @@ mpw mpx_udivn(mpw *qv, mpw *qvl, const mpw *rv, const mpw *rvl, mpw d)
 
 #include <mLib/alloc.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -1366,7 +1367,7 @@ static int loadstore(dstr *v)
       ok = 0;
     MPX_OCTETS(oct, m, ml);
     mpx_storel(m, ml, d.buf, d.sz);
-    if (memcmp(d.buf, v->buf, oct) != 0) {
+    if (MEMCMP(d.buf, !=, v->buf, oct)) {
       dumpbits("\n*** storel failed", d.buf, d.sz);
       ok = 0;
     }
@@ -1376,7 +1377,7 @@ static int loadstore(dstr *v)
       ok = 0;
     MPX_OCTETS(oct, m, ml);
     mpx_storeb(m, ml, d.buf, d.sz);
-    if (memcmp(d.buf + d.sz - oct, v->buf + v->len - oct, oct) != 0) {
+    if (MEMCMP(d.buf + d.sz - oct, !=, v->buf + v->len - oct, oct)) {
       dumpbits("\n*** storeb failed", d.buf, d.sz);
       ok = 0;
     }
@@ -1410,14 +1411,14 @@ static int twocl(dstr *v)
 
     mpx_loadl(m, ml0, v[0].buf, v[0].len);
     mpx_storel2cn(m, ml0, d.buf, v[1].len);
-    if (memcmp(d.buf, v[1].buf, v[1].len)) {
+    if (MEMCMP(d.buf, !=, v[1].buf, v[1].len)) {
       dumpbits("\n*** storel2cn failed", d.buf, v[1].len);
       ok = 0;
     }
 
     mpx_loadl2cn(m, ml1, v[1].buf, v[1].len);
     mpx_storel(m, ml1, d.buf, v[0].len);
-    if (memcmp(d.buf, v[0].buf, v[0].len)) {
+    if (MEMCMP(d.buf, !=, v[0].buf, v[0].len)) {
       dumpbits("\n*** loadl2cn failed", d.buf, v[0].len);
       ok = 0;
     }
@@ -1454,14 +1455,14 @@ static int twocb(dstr *v)
 
     mpx_loadb(m, ml0, v[0].buf, v[0].len);
     mpx_storeb2cn(m, ml0, d.buf, v[1].len);
-    if (memcmp(d.buf, v[1].buf, v[1].len)) {
+    if (MEMCMP(d.buf, !=, v[1].buf, v[1].len)) {
       dumpbits("\n*** storeb2cn failed", d.buf, v[1].len);
       ok = 0;
     }
 
     mpx_loadb2cn(m, ml1, v[1].buf, v[1].len);
     mpx_storeb(m, ml1, d.buf, v[0].len);
-    if (memcmp(d.buf, v[0].buf, v[0].len)) {
+    if (MEMCMP(d.buf, !=, v[0].buf, v[0].len)) {
       dumpbits("\n*** loadb2cn failed", d.buf, v[0].len);
       ok = 0;
     }
index 217cc62..9be9742 100644 (file)
@@ -30,6 +30,8 @@
 #include <ctype.h>
 #include <string.h>
 
+#include <mLib/macros.h>
+
 #include "qdparse.h"
 
 /*----- Main code ---------------------------------------------------------*/
@@ -45,7 +47,7 @@
 
 void qd_skipspc(qd_parse *qd)
 {
-  while (isspace((unsigned char)*qd->p))
+  while (ISSPACE(*qd->p))
     qd->p++;
 }
 
@@ -90,7 +92,7 @@ int qd_enum(qd_parse *qd, const char *e)
     e += strspn(e, ", ");
     if (!*e) break;
     n = strcspn(e, ", ");
-    if (strncmp(qd->p, e, n) == 0 && !isalnum((unsigned char)qd->p[n])) {
+    if (STRNCMP(qd->p, ==, e, n) && !ISALNUM(qd->p[n])) {
       qd->p += n;
       return (i);
     }
@@ -116,7 +118,7 @@ mp *qd_getmp(qd_parse *qd)
 
   qd_skipspc(qd);
   m = mp_readstring(MP_NEW, qd->p, &q, 0);
-  if (m && !isalnum((unsigned char)*q))
+  if (m && !ISALNUM(*q))
     qd->p = q;
   else {
     mp_drop(m);
index 80a6ef6..09acb40 100644 (file)
@@ -258,6 +258,8 @@ void gfshare_combine(gfshare *s, void *buf)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
+
 #include "fibrand.h"
 
 static int verify(grand *r)
@@ -298,7 +300,7 @@ static int verify(grand *r)
   gfshare_combine(&s, sbuf);
   gfshare_destroy(&s);
 
-  if (memcmp(sec, sbuf, len) != 0) {
+  if (MEMCMP(sec, !=, sbuf, len)) {
     ok = 0;
     fprintf(stderr, "\nbad recombination of shares\n");
   };
index c31a3d9..e4d974a 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <mLib/base64.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -194,14 +195,14 @@ static int encrypt(int argc, char *argv[])
     die(EXIT_FAILURE, "encoding `%s' not found", ef);
 
   fn = optind < argc ? argv[optind++] : "-";
-  if (strcmp(fn, "-") == 0)
+  if (STRCMP(fn, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(fn, "rb")) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s': %s",
        fn, strerror(errno));
   }
 
-  if (!of || strcmp(of, "-") == 0)
+  if (!of || STRCMP(of, ==, "-"))
     ofp = stdout;
   else if ((ofp = fopen(of, eo->wmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
@@ -366,7 +367,7 @@ static int decrypt(int argc, char *argv[])
     die(EXIT_FAILURE, "encoding `%s' not found", ef);
 
   fn = optind < argc ? argv[optind++] : "-";
-  if (strcmp(fn, "-") == 0)
+  if (STRCMP(fn, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(fn, eo->rmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s': %s",
@@ -472,7 +473,7 @@ static int decrypt(int argc, char *argv[])
 
   /* --- Now decrypt the main body --- */
 
-  if (!of || strcmp(of, "-") == 0) {
+  if (!of || STRCMP(of, ==, "-")) {
     ofp = stdout;
     f |= f_buffer;
   }
index 3cce9c9..d27016f 100644 (file)
@@ -161,7 +161,7 @@ static size_t textread(msgcanon *m, void *bp)
       if (n >= MSGBUFTHRESH) goto full;
       b[n++] = ch;
       f &= ~F_MIDLINE;
-    } else if (isspace(ch)) {
+    } else if (ISSPACE(ch)) {
       f |= F_MIDLINE;
       if (n >= MSGBUFSZ) goto full;
       b[n++] = ch; nsp++;
@@ -222,7 +222,7 @@ static void nullwrite(msgcanon *m, const void *bp, size_t n) { ; }
 static void mcsetup_readfile(msgcanon *m, unsigned f, const char *fn)
 {
   m->f = F_DETACH | (f & (F_BINARY | F_PROGRESS));
-  if (!fn || strcmp(fn, "-") == 0) {
+  if (!fn || STRCMP(fn, ==, "-")) {
     m->fp = stdin;
     m->f |= F_NOCLOSE;
   } else if ((m->fp = fopen(fn, (f & F_BINARY) ? "rb" : "r")) == 0)
@@ -260,7 +260,7 @@ static void mcsetup_read(msgcanon *m, unsigned f, enc **ee,
       }
     } else {
       m->read = binreaddetach;
-      if (!dfn || strcmp(dfn, "-") == 0)
+      if (!dfn || STRCMP(dfn, ==, "-"))
        m->fp = stdin;
       else if ((m->fp = fopen(dfn, "rb")) == 0)
        die(EXIT_FAILURE, "can't open `%s': %s", dfn, strerror(errno));
@@ -288,7 +288,7 @@ static void mcsetup_read(msgcanon *m, unsigned f, enc **ee,
        }
       }
     } else {
-      if (!dfn || strcmp(dfn, "-") == 0)
+      if (!dfn || STRCMP(dfn, ==, "-"))
        m->fp = stdin;
       else if ((m->fp = fopen(dfn, "r")) == 0)
        die(EXIT_FAILURE, "can't read file `%s': %s", dfn, strerror(errno));
@@ -533,7 +533,7 @@ static int sign(int argc, char *argv[])
 
   fn = (optind >= argc) ? 0 : argv[optind++];
 
-  if (!of || strcmp(of, "-") == 0)
+  if (!of || STRCMP(of, ==, "-"))
     ofp = stdout;
   else if ((ofp = fopen(of, eo->wmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
@@ -599,14 +599,14 @@ static int vrfbdry(const char *b, void *p)
 {
   vrfctx *v = p;
 
-  if (strcmp(b, "CATSIGN MESSAGE") == 0) {
+  if (STRCMP(b, ==, "CATSIGN MESSAGE")) {
     v->f |= F_BINARY;
     v->m |= F_BINARY | F_DETACH;
     return (1);
-  } else if (strcmp(b, "CATSIGN MESSAGE HEADER") == 0) {
+  } else if (STRCMP(b, ==, "CATSIGN MESSAGE HEADER")) {
     v->m |= F_BINARY | F_DETACH;
     return (1);
-  } else if (strcmp(b, "CATSIGN SIGNATURE") == 0) {
+  } else if (STRCMP(b, ==, "CATSIGN SIGNATURE")) {
     v->f |= F_DETACH;
     v->m |= F_DETACH;
     return (1);
@@ -668,7 +668,7 @@ static int verify(int argc, char *argv[])
       case 'u': v.f |= F_UTC; break;
       case 'C': v.f |= F_NOCHECK; break;
       case 't':
-       if (strcmp(optarg, "always") == 0) t_fresh = 0;
+       if (STRCMP(optarg, ==, "always")) t_fresh = 0;
        else if ((t_fresh = get_date(optarg, 0)) < 0)
          die(EXIT_FAILURE, "bad freshness time");
        break;
@@ -685,7 +685,7 @@ static int verify(int argc, char *argv[])
     die(EXIT_FAILURE, "encoding `%s' not found", ef);
 
   fn = optind < argc ? argv[optind++] : "-";
-  if (strcmp(fn, "-") == 0)
+  if (STRCMP(fn, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(fn, eo->rmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s': %s",
@@ -730,7 +730,7 @@ static int verify(int argc, char *argv[])
     printf("WARN verification key %s fails check: %s\n", d.buf, err);
 
   dstr_reset(&dd); keyhash(k, s.s, &dd);
-  if (dd.len != s.kh.len || memcmp(dd.buf, s.kh.buf, dd.len) != 0) {
+  if (dd.len != s.kh.len || MEMCMP(dd.buf, !=, s.kh.buf, dd.len)) {
     if (v.verb) printf("FAIL key hash mismatch\n");
     exit(EXIT_FAILURE);
   }
@@ -746,7 +746,7 @@ static int verify(int argc, char *argv[])
   if (!of && (v.f & F_DETACH)) {
     rfp = ofp = 0;
     v.f &= ~F_BUFFER;
-  } else if (!of || strcmp(of, "-") == 0) {
+  } else if (!of || STRCMP(of, ==, "-")) {
     v.f |= F_BUFFER;
     ofp = stdout;
   } else if (of && !(v.f & F_BUFFER)) {
@@ -893,7 +893,7 @@ static int format(int argc, char *argv[])
     die(EXIT_FAILURE, "encoding `%s' not found", oef);
 
   fn = optind < argc ? argv[optind++] : "-";
-  if (strcmp(fn, "-") == 0)
+  if (STRCMP(fn, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(fn, ieo->rmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s': %s",
@@ -927,7 +927,7 @@ static int format(int argc, char *argv[])
   if (!of)
     mcsetup_writenull(&mc_out);
   else {
-    if (strcmp(of, "-") == 0)
+    if (STRCMP(of, ==, "-"))
       ofp = stdout;
     else if ((ofp = fopen(of, oeo->wmode)) == 0) {
       die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
@@ -942,7 +942,7 @@ static int format(int argc, char *argv[])
   }
 
   if (mf) {
-    if (strcmp(mf, "-") == 0)
+    if (STRCMP(mf, ==, "-"))
       mfp = stdout;
     else if ((mfp = fopen(mf, (f & F_BINARY) ? "wb" : "w")) == 0) {
       die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
@@ -1037,7 +1037,7 @@ static int info(int argc, char *argv[])
 
   if (optind >= argc)
     fp = stdin;
-  else if (strcmp(argv[optind], "-") == 0) {
+  else if (STRCMP(argv[optind], ==, "-")) {
     fp = stdin;
     optind++;
   } else if ((fp = fopen(argv[optind], eo->rmode)) == 0) {
index f4b6119..a008fbb 100644 (file)
@@ -35,6 +35,7 @@
 #include <mLib/alloc.h>
 #include <mLib/base64.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/report.h>
 #include <mLib/sub.h>
@@ -94,7 +95,7 @@ static enc *pem_encinit(FILE *fp, const char *msg)
   return (&pe->e);
 }
 
-int checkbdry(const char *b, void *p) { return (!p || strcmp(b, p) == 0); }
+int checkbdry(const char *b, void *p) { return (!p || STRCMP(b, ==, p)); }
 
 static enc *pem_decinit(FILE *fp, encbdryp *func, void *p)
 {
@@ -133,7 +134,7 @@ banner:
   /* --- Check we have the right framing --- */
 
   if (d != 5) goto top;
-  if (strncmp(buf, "BEGIN ", 6) != 0 || (func && !func(buf + 6, p)))
+  if (STRNCMP(buf, !=, "BEGIN ", 6) || (func && !func(buf + 6, p)))
     goto top;
 
   /* --- Ready --- */
@@ -248,7 +249,7 @@ static int pem_decdone(enc *e)
   }
   if (d != 5) goto fail;
   buf[i] = 0;
-  if (strncmp(buf, "END ", 4) != 0 || strcmp(buf + 4, pe->msg) != 0)
+  if (STRNCMP(buf, !=, "END ", 4) || STRCMP(buf + 4, !=, pe->msg))
     goto fail;
   return (0);
 
@@ -295,7 +296,7 @@ const encops *getenc(const char *enc)
   const encops *eo;
 
   for (eo = enctab; eo->name; eo++) {
-    if (strcmp(eo->name, enc) == 0)
+    if (STRCMP(eo->name, ==, enc))
       goto e_found;
   }
   die(EXIT_FAILURE, "couldn't find encoding `%s'", enc);
@@ -399,14 +400,14 @@ int cmd_encode(int argc, char *argv[])
     die(EXIT_FAILURE, "encoding `%s' not found", ef);
 
   fn = optind < argc ? argv[optind++] : "-";
-  if (strcmp(fn, "-") == 0)
+  if (STRCMP(fn, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(fn, "rb")) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s': %s",
        fn, strerror(errno));
   }
 
-  if (!of || strcmp(of, "-") == 0)
+  if (!of || STRCMP(of, ==, "-"))
     ofp = stdout;
   else if ((ofp = fopen(of, eo->wmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
@@ -481,14 +482,14 @@ int cmd_decode(int argc, char *argv[])
     die(EXIT_FAILURE, "encoding `%s' not found", ef);
 
   fn = optind < argc ? argv[optind++] : "-";
-  if (strcmp(fn, "-") == 0)
+  if (STRCMP(fn, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(fn, eo->rmode)) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s': %s",
        fn, strerror(errno));
   }
 
-  if (!of || strcmp(of, "-") == 0)
+  if (!of || STRCMP(of, ==, "-"))
     ofp = stdout;
   else if ((ofp = fopen(of, "wb")) == 0) {
     die(EXIT_FAILURE, "couldn't open file `%s' for output: %s",
index 64fea0e..6d65f5b 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <mLib/alloc.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/str.h>
 
@@ -67,9 +68,7 @@ static void puthex(const octet *buf, size_t sz, FILE *fp)
 static size_t gethex(const char *p, octet *q, size_t sz, char **pp)
 {
   size_t i = 0;
-  while (sz > 0 &&
-        isxdigit((unsigned char)p[0]) &&
-        isxdigit((unsigned char)p[1])) {
+  while (sz > 0 && ISXDIGIT(p[0]) && ISXDIGIT(p[1])) {
     char buf[3];
     buf[0] = p[0];
     buf[1] = p[1];
@@ -164,7 +163,7 @@ const encodeops *getencoding(const char *ename)
   const encodeops *e;
 
   for (e = encodingtab; e->name; e++) {
-    if (strcmp(ename, e->name) == 0)
+    if (STRCMP(ename, ==, e->name))
       return (e);
   }
   return (0);
@@ -198,7 +197,7 @@ const gchash *gethash(const char *name)
   const gchash *const *g, *gg = 0;
   size_t sz = strlen(name);
   for (g = ghashtab; *g; g++) {
-    if (strncmp(name, (*g)->name, sz) == 0) {
+    if (STRNCMP(name, ==, (*g)->name, sz)) {
       if ((*g)->name[sz] == 0) {
        gg = *g;
        break;
@@ -292,7 +291,7 @@ int fhash(fhashstate *fh, const char *file, void *buf)
   size_t n;
   fprogress ff;
 
-  if (!file || strcmp(file, "-") == 0)
+  if (!file || STRCMP(file, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(file, fh->f & FHF_BINARY ? "rb" : "r")) == 0)
     return (-1);
@@ -303,7 +302,7 @@ int fhash(fhashstate *fh, const char *file, void *buf)
 
   if (fh->f & FHF_JUNK) {
     p = file;
-    if (strncmp(p, "./", 2) == 0) p += 2;
+    if (STRNCMP(p, ==, "./", 2)) p += 2;
     q = p;
     ffhe = &fh->ents;
     for (;;) {
@@ -311,7 +310,7 @@ int fhash(fhashstate *fh, const char *file, void *buf)
        n = q - p;
        for (; *ffhe; ffhe = &(*ffhe)->next) {
          fhe = *ffhe;
-         if (strncmp(p, fhe->name, n) == 0 && fhe->name[n] == 0)
+         if (STRNCMP(p, ==, fhe->name, n) && fhe->name[n] == 0)
            goto found;
        }
        fhe = xmalloc(offsetof(struct fhent, name) + n + 1);
@@ -383,10 +382,10 @@ static int fhjunk(struct fhjunk *fhj, struct fhent *ents)
     n++;
   }
   while (errno = 0, (d = readdir(dp)) != 0) {
-    if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0)
+    if (STRCMP(d->d_name, ==, ".") || STRCMP(d->d_name, ==, ".."))
       continue;
     for (fhe = ents; fhe; fhe = fhe->next) {
-      if (strcmp(d->d_name, fhe->name) == 0) goto found;
+      if (STRCMP(d->d_name, ==, fhe->name)) goto found;
     }
     fhj->d->len = n;
     dstr_puts(fhj->d, d->d_name);
@@ -464,17 +463,17 @@ int hfparse(hfpctx *hfp)
   if (*p == '#') {
     p++;
     if ((q = str_getword(&p)) == 0) return (HF_BAD);
-    if (strcmp(q, "hash") == 0) {
+    if (STRCMP(q, ==, "hash")) {
       if ((q = str_getword(&p)) == 0) return (HF_BAD);
       if ((gch = gethash(q)) == 0) return (HF_BAD);
       hfp->gch = gch;
       return (HF_HASH);
-    } else if (strcmp(q, "encoding") == 0) {
+    } else if (STRCMP(q, ==, "encoding")) {
       if ((q = str_getword(&p)) == 0) return (HF_BAD);
       if ((ee = getencoding(q)) == 0) return (HF_BAD);
       hfp->ee = ee;
       return (HF_ENC);
-    } else if (strcmp(q, "escape") == 0) {
+    } else if (STRCMP(q, ==, "escape")) {
       hfp->f |= HFF_ESCAPE;
       return (HF_ESC);
     }
@@ -556,7 +555,7 @@ int getstring(void *in, dstr *d, unsigned f)
 
 again:
   ch = nextch(in);
-  while (isspace(ch))
+  while (ISSPACE(ch))
     ch = nextch(in);
   if (ch == '#') {
     do ch = nextch(in); while (ch != '\n' && ch != eofch);
@@ -605,7 +604,7 @@ again:
 
     if (ch == q)
       break;
-    if (!q && isspace(ch))
+    if (!q && ISSPACE(ch))
       break;
 
     /* --- Otherwise contribute and continue --- */
@@ -649,7 +648,7 @@ void putstring(FILE *fp, const char *p, unsigned f)
 
   qq = 0;
   for (q = p; *q; q++) {
-    if (isspace((unsigned char)*q)) {
+    if (ISSPACE(*q)) {
       qq = '\"';
       break;
     }
index 9159ade..36dfdb3 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <mLib/alloc.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/sub.h>
 
@@ -210,12 +211,12 @@ static bulk *naclbox_init(key *k, const char *calg, const char *halg)
   key_fulltag(k, &t);
 
   if ((q = key_getattr(0, k, "cipher")) != 0) calg = q;
-  if (!calg || strcmp(calg, "salsa20") == 0) aec = &salsa20_naclbox;
-  else if (strcmp(calg, "salsa20/12") == 0) aec = &salsa2012_naclbox;
-  else if (strcmp(calg, "salsa20/8") == 0) aec = &salsa208_naclbox;
-  else if (strcmp(calg, "chacha20") == 0) aec = &chacha20_naclbox;
-  else if (strcmp(calg, "chacha12") == 0) aec = &chacha12_naclbox;
-  else if (strcmp(calg, "chacha8") == 0) aec = &chacha8_naclbox;
+  if (!calg || STRCMP(calg, ==, "salsa20")) aec = &salsa20_naclbox;
+  else if (STRCMP(calg, ==, "salsa20/12")) aec = &salsa2012_naclbox;
+  else if (STRCMP(calg, ==, "salsa20/8")) aec = &salsa208_naclbox;
+  else if (STRCMP(calg, ==, "chacha20")) aec = &chacha20_naclbox;
+  else if (STRCMP(calg, ==, "chacha12")) aec = &chacha12_naclbox;
+  else if (STRCMP(calg, ==, "chacha8")) aec = &chacha8_naclbox;
   else {
     die(EXIT_FAILURE,
        "unknown or inappropriate encryption scheme `%s' in key `%s'",
@@ -866,7 +867,7 @@ kem *getkem(key *k, const char *app, int wantpriv, bulk **bc)
   if ((q = key_getattr(0, k, "kem")) != 0) {
     dstr_puts(&d, q);
     p = d.buf;
-  } else if (strncmp(k->type, app, n) == 0 && k->type[n] == '-') {
+  } else if (STRNCMP(k->type, ==, app, n) && k->type[n] == '-') {
     dstr_puts(&d, k->type);
     p = d.buf + n + 1;
   } else
@@ -897,7 +898,7 @@ kem *getkem(key *k, const char *app, int wantpriv, bulk **bc)
   /* --- Instantiate the KEM --- */
 
   for (kt = kemtab; kt->name; kt++) {
-    if (strcmp(kt->name, kalg) == 0)
+    if (STRCMP(kt->name, ==, kalg))
       goto k_found;
   }
   die(EXIT_FAILURE, "key encapsulation mechanism `%s' not found in key `%s'",
@@ -934,10 +935,10 @@ k_found:;
     bt = bulktab;
   else {
     for (bt = bulktab, bo = 0; bt->name; bt++) {
-      if (strcmp(balg, bt->name) == 0)
+      if (STRCMP(balg, ==, bt->name))
        { balg = 0; goto b_found; }
       n = strlen(bt->name);
-      if (strncmp(balg, bt->name, n) == 0 && balg[n] == '-')
+      if (STRNCMP(balg, ==, bt->name, n) && balg[n] == '-')
        { balg += n + 1; goto b_found; }
     }
     bt = bulktab;
index 8bc2219..19ea7d5 100644 (file)
@@ -29,6 +29,7 @@
 
 #define _FILE_OFFSET_BITS 64
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
 
 #include "cc.h"
@@ -57,7 +58,7 @@ int displaylists(const struct listent *listtab, char *const argv[])
   } else {
     for (i = 0; argv[i]; i++) {
       for (li = listtab; li->name; li++) {
-       if (strcmp(li->name, argv[i]) == 0) {
+       if (STRCMP(li->name, ==, argv[i])) {
          li->list();
          goto cool;
        }
index a416c6e..4c1defc 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <stdlib.h>
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
 
 #include "rand.h"
@@ -809,7 +810,7 @@ sig *getsig(key *k, const char *app, int wantpriv)
   if ((q = key_getattr(0, k, "sig")) != 0) {
     dstr_puts(&d, q);
     p = d.buf;
-  } else if (strncmp(k->type, app, n) == 0 && k->type[n] == '-') {
+  } else if (STRNCMP(k->type, ==, app, n) && k->type[n] == '-') {
     dstr_puts(&d, k->type);
     p = d.buf + n + 1;
   } else
@@ -832,7 +833,7 @@ sig *getsig(key *k, const char *app, int wantpriv)
   /* --- Look up the algorithms in the table --- */
 
   for (st = sigtab; st->name; st++) {
-    if (strcmp(st->name, salg) == 0)
+    if (STRCMP(st->name, ==, salg))
       goto s_found;
   }
   die(EXIT_FAILURE, "signature algorithm `%s' not found in key `%s'",
index 83c4a78..d593a1a 100644 (file)
@@ -29,6 +29,7 @@
 
 #define _FILE_OFFSET_BITS 64
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
 
@@ -53,7 +54,7 @@ const cmd *findcmd(const cmd *cmds, const char *name)
   size_t sz = strlen(name);
 
   for (c = cmds; c->name; c++) {
-    if (strncmp(name, c->name, sz) == 0) {
+    if (STRNCMP(name, ==, c->name, sz)) {
       if (c->name[sz] == 0) {
        chosen = c;
        break;
index c6912ff..62e23b7 100644 (file)
@@ -39,6 +39,7 @@
 #include <mLib/base64.h>
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -178,7 +179,7 @@ static gmac *getmac(key *k, const char *app)
   if ((q = key_getattr(0, k, "mac")) != 0) {
     dstr_puts(&d, q);
     p = d.buf;
-  } else if (strncmp(k->type, app, n) == 0 && k->type[n] == '-') {
+  } else if (STRNCMP(k->type, ==, app, n) && k->type[n] == '-') {
     dstr_puts(&d, k->type);
     p = d.buf + n + 1;
   } else
@@ -258,7 +259,7 @@ static int cmd_gen(int argc, char *argv[])
       /* --- Fetch an expiry time --- */
 
       case 'e':
-       if (strcmp(optarg, "forever") == 0)
+       if (STRCMP(optarg, ==, "forever"))
          c.exp = KEXP_FOREVER;
        else if ((c.exp = get_date(optarg, 0)) == -1)
          die(EXIT_FAILURE, "bad expiry date: `%s'", optarg);
index 1377bca..3f217da 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <mLib/alloc.h>
 #include <mLib/base64.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -204,7 +205,7 @@ static int bget(block *b, FILE *fp, unsigned bin)
     if (getstring(fp, &d, GSF_FILE))
       return (E_EOF);
     for (tag = 0; tagtab[tag]; tag++) {
-      if (strcmp(tagtab[tag], d.buf) == 0)
+      if (STRCMP(tagtab[tag], ==, d.buf))
        goto done;
     }
     return (E_TAG);
@@ -239,7 +240,7 @@ static int bget(block *b, FILE *fp, unsigned bin)
       } else {
        if (getstring(fp, &b->d, GSF_FILE))
          return (E_EOF);
-       if (strcmp(b->d.buf, "forever") == 0)
+       if (STRCMP(b->d.buf, ==, "forever"))
          b->t = KEXP_FOREVER;
        else if ((b->t = get_date(b->d.buf, 0)) == -1)
          return (E_DATE);
@@ -536,7 +537,7 @@ static int sign(int argc, char *argv[])
        ki = optarg;
        break;
       case 'e':
-       if (strcmp(optarg, "forever") == 0)
+       if (STRCMP(optarg, ==, "forever"))
          exp = KEXP_FOREVER;
        else if ((exp = get_date(optarg, 0)) == -1)
          die(EXIT_FAILURE, "bad expiry time");
@@ -572,14 +573,14 @@ static int sign(int argc, char *argv[])
   /* --- Open files --- */
 
   if (hfile) ifile = hfile;
-  if (!ifile || strcmp(ifile, "-") == 0)
+  if (!ifile || STRCMP(ifile, ==, "-"))
     ifp = stdin;
   else if ((ifp = fopen(ifile, (f & f_bin) ? "rb" : "r")) == 0) {
     die(EXIT_FAILURE, "couldn't open input file `%s': %s",
        ifile, strerror(errno));
   }
 
-  if (!ofile || strcmp(ofile, "-") == 0)
+  if (!ofile || STRCMP(ofile, ==, "-"))
     ofp = stdout;
   else if ((ofp = fopen(ofile, (f & f_bin) ? "wb" : "w")) == 0) {
     die(EXIT_FAILURE, "couldn't open output file `%s': %s",
@@ -908,7 +909,7 @@ static int verify(int argc, char *argv[])
          }
          f |= f_bogus;
        } else if (b.b.len != GH_CLASS(s->h)->hashsz ||
-                  memcmp(d.buf, b.b.buf, b.b.len) != 0) {
+                  MEMCMP(d.buf, !=, b.b.buf, b.b.len)) {
          if (verb > 1)
            printf("BAD file `%s' has incorrect hash\n", b.d.buf);
          f |= f_bogus;
index 975c698..ece0b30 100644 (file)
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -130,10 +131,10 @@ int main(int argc, char *argv[])
   }
   ulmax = mp_fromulong(MP_NEW, ULONG_MAX);
   p = argv[optind];
-  while (isspace((unsigned char)*p))
+  while (ISSPACE(*p))
     p++;
   xx = mp_readstring(MP_NEW, argv[optind], &p, 0);
-  while (isspace((unsigned char)*p))
+  while (ISSPACE(*p))
     p++;
   if (!xx || *p || MP_CMP(xx, <, MP_ZERO) || MP_CMP(xx, >, ulmax))
     die(EXIT_FAILURE, "bad integer `%s'", argv[optind]);
index 4b5a958..a494f62 100644 (file)
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -128,9 +129,9 @@ int main(int argc, char *argv[])
   lmin = mp_fromlong(MP_NEW, LONG_MIN);
   lmax = mp_fromlong(MP_NEW, LONG_MAX);
   p = argv[optind];
-  while (isspace((unsigned char)*p)) p++;
+  while (ISSPACE(*p)) p++;
   nn = mp_readstring(MP_NEW, argv[optind], &p, 0);
-  while (isspace((unsigned char)*p)) p++;
+  while (ISSPACE(*p)) p++;
   if (!nn || *p || MP_CMP(lmin, >, nn) || MP_CMP(nn, >, lmax))
     die(EXIT_FAILURE, "bad integer `%s'", argv[optind]);
   n = mp_tolong(nn);
index df1fdae..deb27d5 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <mLib/alloc.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -97,7 +98,7 @@ static int checkhash(fhashstate *fh, const char *file, const encodeops *e)
   unsigned long n = 0, nfail = 0;
   int hf;
 
-  if (!file || strcmp(file, "-") == 0)
+  if (!file || STRCMP(file, ==, "-"))
     hfp.fp = stdin;
   else if ((hfp.fp = fopen(file, fh->f & GSF_RAW ? "r" : "rb")) == 0) {
     moan("couldn't open `%s': %s", file, strerror(errno));
@@ -124,8 +125,8 @@ static int checkhash(fhashstate *fh, const char *file, const encodeops *e)
          rc = EXIT_FAILURE;
          continue;
        }
-       if (memcmp(hfp.hbuf, hfp.hbuf + hfp.gch->hashsz,
-                  hfp.gch->hashsz) != 0) {
+       if (MEMCMP(hfp.hbuf, !=, hfp.hbuf + hfp.gch->hashsz,
+                  hfp.gch->hashsz)) {
          if (hfp.f & f_verbose)
            fprintf(stderr, "FAIL %s\n", df.buf);
          else
@@ -190,7 +191,7 @@ static int hashfiles(fhashstate *fh, const char *file, const encodeops *e)
   int rc = 0;
   int rrc;
 
-  if (!file || strcmp(file, "-") == 0)
+  if (!file || STRCMP(file, ==, "-"))
     fp = stdin;
   else if ((fp = fopen(file, fh->f & GSF_RAW ? "r" : "rb")) == 0) {
     moan("couldn't open `%s': %s", file, strerror(errno));
@@ -278,7 +279,7 @@ int main(int argc, char *argv[])
   {
     char *q = xstrdup(QUIS);
     size_t len = strlen(q);
-    if (len > 3 && strcmp(q + len - 3, "sum") == 0) {
+    if (len > 3 && STRCMP(q + len - 3, ==, "sum")) {
       q[len - 3] = 0;
       fh.gch = gethash(q);
     }
index 0c817d4..8cd43fe 100644 (file)
@@ -42,6 +42,7 @@
 #include <mLib/base32.h>
 #include <mLib/base64.h>
 #include <mLib/hex.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -602,7 +603,7 @@ static void alg_dhparam(keyopts *k)
       group *g;
       const char *e;
 
-      if (strcmp(k->curve, "list") == 0) {
+      if (STRCMP(k->curve, ==, "list")) {
        unsigned i, w;
        LIST("Built-in prime fields", stdout, ptab[i].name, ptab[i].name);
        exit(0);
@@ -770,7 +771,7 @@ static void alg_binparam(keyopts *k)
     /* --- Decide on a field --- */
 
     if (!k->bits) k->bits = 128;
-    if (k->curve && strcmp(k->curve, "list") == 0) {
+    if (k->curve && STRCMP(k->curve, ==, "list")) {
       unsigned i, w;
       LIST("Built-in binary fields", stdout,
           bintab[i].name, bintab[i].name);
@@ -869,7 +870,7 @@ static void alg_ecparam(keyopts *k)
     /* --- Decide on a curve --- */
 
     if (!k->bits) k->bits = 256;
-    if (k->curve && strcmp(k->curve, "list") == 0) {
+    if (k->curve && STRCMP(k->curve, ==, "list")) {
       unsigned i, w;
       LIST("Built-in elliptic curves", stdout,
           ectab[i].name, ectab[i].name);
@@ -1093,7 +1094,7 @@ static int cmd_add(int argc, char *argv[])
        keyalg *a;
        size_t sz = strlen(optarg);
 
-       if (strcmp(optarg, "list") == 0) {
+       if (STRCMP(optarg, ==, "list")) {
          for (a = algtab; a->name; a++)
            printf("%-10s %s\n", a->name, a->help);
          return (0);
@@ -1101,7 +1102,7 @@ static int cmd_add(int argc, char *argv[])
 
        alg = 0;
        for (a = algtab; a->name; a++) {
-         if (strncmp(optarg, a->name, sz) == 0) {
+         if (STRNCMP(optarg, ==, a->name, sz)) {
            if (a->name[sz] == 0) {
              alg = a;
              break;
@@ -1140,7 +1141,7 @@ static int cmd_add(int argc, char *argv[])
       /* --- Expiry dates get passed to @get_date@ for parsing --- */
 
       case 'e':
-       if (strcmp(optarg, "forever") == 0)
+       if (STRCMP(optarg, ==, "forever"))
          exp = KEXP_FOREVER;
        else {
          exp = get_date(optarg, 0);
@@ -1178,7 +1179,7 @@ static int cmd_add(int argc, char *argv[])
 
       case 'A': {
        const struct seedalg *ss;
-       if (strcmp(optarg, "list") == 0) {
+       if (STRCMP(optarg, ==, "list")) {
          printf("Seed algorithms:\n");
          for (ss = seedtab; ss->p; ss++)
            printf("  %s\n", ss->p);
@@ -1187,7 +1188,7 @@ static int cmd_add(int argc, char *argv[])
        if (seed) die(EXIT_FAILURE, "seed already set -- put -A first");
        sa = 0;
        for (ss = seedtab; ss->p; ss++) {
-         if (strcmp(optarg, ss->p) == 0)
+         if (STRCMP(optarg, ==, ss->p))
            sa = ss;
        }
        if (!sa)
@@ -1320,7 +1321,7 @@ static int cmd_add(int argc, char *argv[])
     if (k.f & f_retag) {
       if ((kk = key_bytag(&f, tag)) != 0 &&
          kk->tag &&
-         strcmp(kk->tag, tag) == 0)
+         STRCMP(kk->tag, ==, tag))
        key_settag(&f, kk, 0);
     }
     if ((err = key_settag(&f, k.k, tag)) != 0)
@@ -1825,7 +1826,7 @@ static const struct fpres *lookup_fpres(const char *name)
 {
   const struct fpres *fpres;
   for (fpres = fprestab; fpres->name; fpres++)
-    if (strcmp(fpres->name, name) == 0) return (fpres);
+    if (STRCMP(fpres->name, ==, name)) return (fpres);
   die(EXIT_FAILURE, "unknown presentation syle `%s'", name);
 }
 
@@ -1969,7 +1970,7 @@ static int cmd_verify(int argc, char *argv[])
   if (!key_fingerprint(k, h, &kf))
     die(EXIT_FAILURE, "key has no fingerprintable components (as filtered)");
   fpr = GH_DONE(h, 0);
-  if (memcmp(fpr, d.buf, ch->hashsz) != 0)
+  if (MEMCMP(fpr, !=, d.buf, ch->hashsz))
     die(EXIT_FAILURE, "key fingerprint mismatch");
   dstr_destroy(&d); dstr_destroy(&dd);
   doclose(&f);
@@ -2028,7 +2029,7 @@ static int cmd_tag(int argc, char *argv[])
     die(EXIT_FAILURE, "Usage: tag [-r] TAG [NEW-TAG]");
   doopen(&f, KOPEN_WRITE);
   if (flags & f_retag) {
-    if ((k = key_bytag(&f, argv[1])) != 0 && strcmp(k->tag, argv[1]) == 0)
+    if ((k = key_bytag(&f, argv[1])) != 0 && STRCMP(k->tag, ==, argv[1]))
       key_settag(&f, k, 0);
   }
   if ((k = key_bytag(&f, argv[0])) == 0)
@@ -2122,7 +2123,7 @@ static int cmd_extract(int argc, char *argv[])
   argv += optind; argc -= optind;
   if (rc || argc < 1)
     die(EXIT_FAILURE, "Usage: extract [-f FILTER] FILE [TAG...]");
-  if (strcmp(*argv, "-") == 0)
+  if (STRCMP(*argv, ==, "-"))
     fp = stdout;
   else {
     outfile = *argv;
@@ -2178,7 +2179,7 @@ static int cmd_merge(int argc, char *argv[])
 
   if (argc != 2)
     die(EXIT_FAILURE, "Usage: merge FILE");
-  if (strcmp(argv[1], "-") == 0)
+  if (STRCMP(argv[1], ==, "-"))
     fp = stdin;
   else if (!(fp = fopen(argv[1], "r"))) {
     die(EXIT_FAILURE, "couldn't open `%s' for reading: %s",
index b84d850..db27ba2 100644 (file)
@@ -40,6 +40,7 @@
 #include <mLib/bits.h>
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -99,7 +100,7 @@ static void wordlist_scan(FILE *fp, void *p)
 
   for (;;) {
     int ch = getc(fp);
-    if (ch == EOF || isspace(ch)) {
+    if (ch == EOF || ISSPACE(ch)) {
       DPUTZ(&d);
       if (f && d.len >= min && d.len <= max)
        sym_find(&w->tab, d.buf, d.len + 1, sizeof(sym_base), 0);
@@ -109,7 +110,7 @@ static void wordlist_scan(FILE *fp, void *p)
        break;
       continue;
     }
-    ch = tolower(ch);
+    ch = TOLOWER(ch);
     if (strchr(wchars, ch)) {
       DPUTC(&d, ch);
       f = 1;
@@ -204,7 +205,7 @@ static void markov_scan(FILE *fp, void *p)
     const char *q;
     node *n = &(*model)[i][j][k];
 
-    if (ch == EOF || isspace(ch)) {
+    if (ch == EOF || ISSPACE(ch)) {
       if (l != C_END) {
        l = C_END;
        n->count++;
@@ -216,7 +217,7 @@ static void markov_scan(FILE *fp, void *p)
       continue;
     }
 
-    if ((q = strchr(wchars, tolower(ch))) == 0)
+    if ((q = strchr(wchars, TOLOWER(ch))) == 0)
       continue;
     l = q - wchars;
     n->count++;
@@ -362,7 +363,7 @@ int main(int argc, char *argv[])
        size_t n = strlen(optarg);
        ops = 0;
        for (p = ppgentab; *p; p++) {
-         if (strncmp(optarg, (*p)->name, n) == 0) {
+         if (STRNCMP(optarg, ==, (*p)->name, n)) {
            if (!(*p)->name[n]) {
              ops = *p;
              break;
@@ -414,7 +415,7 @@ int main(int argc, char *argv[])
 
   ctx = ops->init();
   while (*argv) {
-    if (strcmp(*argv, "-") == 0)
+    if (STRCMP(*argv, ==, "-"))
       ops->scan(stdin, ctx);
     else {
       FILE *fp = fopen(*argv, "r");
index 6af4d51..b4a88ca 100644 (file)
@@ -51,6 +51,7 @@
 #include <mLib/alloc.h>
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -979,7 +980,7 @@ int main(int argc, char *argv[])
   if (optind + 1 != argc) { usage(stderr); exit(1); }
 
   for (j = jobtab; j->name; j++)
-    if (strcmp(j->name, argv[optind]) == 0) break;
+    if (STRCMP(j->name, ==, argv[optind])) break;
   if (!j->name) die(1, "unknown job type `%s'", argv[optind]);
   p = j->init(&o);
 
index 3fd3208..f827c20 100644 (file)
@@ -57,6 +57,7 @@
 #include <mLib/alloc.h>
 #include <mLib/dstr.h>
 #include <mLib/fdflags.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -229,7 +230,7 @@ static phrase *p_find(const char *tag)
   phrase *p;
 
   for (p = p_head; p; p = p->next) {
-    if (strcmp(p->tag, tag) == 0) {
+    if (STRCMP(p->tag, ==, tag)) {
       if (p->t) {
        struct timeval tv;
        sel_rmtimer(&p->timer);
@@ -311,7 +312,7 @@ static void p_flush(const char *tag)
     phrase *pp = p->next;
     if (!tag)
       p_free(p);
-    else if (strcmp(p->tag, tag) == 0) {
+    else if (STRCMP(p->tag, ==, tag)) {
       if (verbose > 1)
        pxlog("flushing passphrase `%s'", tag);
       p_free(p);
@@ -445,7 +446,7 @@ static int p_request(const char *msg, const char *tag, char *buf, size_t sz)
 ok: {
     char *p = buf;
     size_t len;
-    while (isspace((unsigned char)*p))
+    while (ISSPACE(*p))
       p++;
     len = strlen(p);
     memmove(buf, p, len);
@@ -517,7 +518,7 @@ static int p_get(const char **q, const char *tag, unsigned mode, time_t exp)
       goto fail;
     if (p_request("Verify passphrase", tag, pp, LBUFSZ) < 0)
       goto fail;
-    if (strcmp(pp, p->p) != 0) {
+    if (STRCMP(pp, !=, p->p)) {
       if (verbose)
        pxlog("passphrases for `%s' don't match", tag);
       p_free(p);
@@ -677,11 +678,11 @@ static void pixserv_line(char *s, size_t len, void *p)
   if ((q = str_getword(&s)) == 0)
     return;
   for (qq = q; *qq; qq++)
-    *qq = tolower((unsigned char)*qq);
+    *qq = TOLOWER(*qq);
 
   /* --- Handle a help request --- */
 
-  if (strcmp(q, "help") == 0) {
+  if (STRCMP(q, ==, "help")) {
     if (pixserv_write(px, "\
 INFO Commands supported:\n\
 INFO flush [TAG]\n\
@@ -698,7 +699,7 @@ OK\n\
 
   /* --- List the passphrases --- */
 
-  else if (strcmp(q, "list") == 0) {
+  else if (STRCMP(q, ==, "list")) {
     phrase *p;
 
     for (p = p_head; p; p = p->next) {
@@ -718,8 +719,8 @@ OK\n\
 
   /* --- Request a passphrase --- */
 
-  else if ((mode = PMODE_READ, strcmp(q, "pass") == 0) ||
-          (mode = PMODE_VERIFY, strcmp(q, "verify") == 0)) {
+  else if ((mode = PMODE_READ, STRCMP(q, ==, "pass")) ||
+          (mode = PMODE_VERIFY, STRCMP(q, ==, "verify"))) {
     unsigned long t;
     const char *p;
     int rc;
@@ -747,7 +748,7 @@ OK\n\
 
   /* --- Flush existing passphrases --- */
 
-  else if (strcmp(q, "flush") == 0) {
+  else if (STRCMP(q, ==, "flush")) {
     q = str_getword(&s);
     p_flush(q);
     if (pixserv_write(px, "OK\n")) goto close;
@@ -755,7 +756,7 @@ OK\n\
 
   /* --- Set a passphrase --- */
 
-  else if (strcmp(q, "set") == 0) {
+  else if (STRCMP(q, ==, "set")) {
     char *tag;
     unsigned long t;
     if ((tag = str_getword(&s)) == 0) {
@@ -763,14 +764,14 @@ OK\n\
     } else if ((q = str_getword(&s)) == 0) {
       if (pixserv_write(px, "FAIL no passphrase\n")) goto close;
     } else {
-      if (strcmp(q, "--") != 0) {
+      if (STRCMP(q, !=, "--")) {
        t = pixserv_timeout(q);
        q = str_getword(&s);
       } else
        t = pixserv_timeout(0);
       if (!q) {
        if (pixserv_write(px, "FAIL no passphrase\n")) goto close;
-      } else if (strcmp(q, "--") != 0) {
+      } else if (STRCMP(q, !=, "--")) {
        if (pixserv_write(px, "FAIL rubbish found before passphrase\n"))
          goto close;
       } else {
@@ -783,7 +784,7 @@ OK\n\
 
   /* --- Shut the server down --- */
 
-  else if (strcmp(q, "quit") == 0) {
+  else if (STRCMP(q, ==, "quit")) {
     if (verbose) {
       pxlog("%s client requested shutdown",
            px->f & px_stdin ? "local" : "remote");
@@ -1076,14 +1077,14 @@ static void c_sline(char *s, size_t len, void *p)
     puts(s);
   else {
     char *q = str_getword(&s);
-    if (strcmp(q, "FAIL") == 0)
+    if (STRCMP(q, ==, "FAIL"))
       die(1, "%s", s);
-    else if (strcmp(q, "INFO") == 0 ||
-            strcmp(q, "ITEM") == 0)
+    else if (STRCMP(q, ==, "INFO") ||
+            STRCMP(q, ==, "ITEM"))
       puts(s);
-    else if (strcmp(q, "OK") == 0) {
+    else if (STRCMP(q, ==, "OK")) {
       if (s && *s) puts(s);
-    } else if (strcmp(q, "MISSING") == 0)
+    } else if (STRCMP(q, ==, "MISSING"))
       ;
     else
       moan("unexpected output: %s %s", q, s);
index 66a0538..812525f 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <mLib/darray.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -435,7 +436,7 @@ static int opt(void)
       case 'o':
        if (flags & f_file)
          die(EXIT_FAILURE, "already set an output file");
-       if (strcmp(optarg, "-") == 0)
+       if (STRCMP(optarg, ==, "-"))
          outfp = stdout;
        else {
          outfp = fopen(optarg, "w");
@@ -1591,7 +1592,7 @@ int main(int ac, char *av[])
 
     g = 0;
     for (gg = generators; gg->name; gg++) {
-      if (strncmp(arg, gg->name, sz) == 0) {
+      if (STRNCMP(arg, ==, gg->name, sz)) {
        if (gg->name[sz] == 0) {
          g = gg;
          break;
index c7dc86e..c3ae268 100644 (file)
@@ -374,6 +374,8 @@ grand *bbs_rand(mp *m, mp *x)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
+
 static int verify(dstr *v)
 {
   mp *n = *(mp **)v[0].buf;
@@ -385,7 +387,7 @@ static int verify(dstr *v)
   dstr_ensure(&d, v[2].len);
   b->ops->fill(b, d.buf, v[2].len);
   d.len = v[2].len;
-  if (memcmp(d.buf, v[2].buf, v[2].len) != 0) {
+  if (MEMCMP(d.buf, !=, v[2].buf, v[2].len)) {
     fputs("\n*** bbs failure\n", stderr);
     fputs("n = ", stderr); mp_writefile(n, stderr, 10); fputc('\n', stderr);
     fputs("x = ", stderr); mp_writefile(x, stderr, 10); fputc('\n', stderr);
index 69e2437..5b5e403 100644 (file)
@@ -108,6 +108,8 @@ found:
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
+
 #include "fibrand.h"
 
 int main(int argc, char *argv[])
@@ -127,7 +129,7 @@ int main(int argc, char *argv[])
     dh_infofromdata(&dp, pe->data);
     g = group_prime(&dp);
     if (mp_bits(dp.p) > 3072 &&
-       (!argv[1] || strcmp(argv[1], "keen") != 0)) {
+       (!argv[1] || STRCMP(argv[1], !=, "keen"))) {
       printf(" [%s skipped]", pe->name);
       fflush(stdout);
       continue;
index 7c6c3ba..8802003 100644 (file)
@@ -215,6 +215,8 @@ fail_q:
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
+
 static int verify(dstr *v)
 {
   mp *q = *(mp **)v[4].buf;
@@ -231,7 +233,7 @@ static int verify(dstr *v)
 
   rc = dsa_gen(&dp, 160, l, 16, v[0].buf, v[0].len, &ds, pgen_evspin, 0);
   if (rc || ds.count != n || ds.sz != v[2].len ||
-      memcmp(ds.p, v[2].buf, v[2].len) != 0 ||
+      MEMCMP(ds.p, !=, v[2].buf, v[2].len) ||
       !MP_EQ(q, dp.q) || !MP_EQ(p, dp.p) || !MP_EQ(g, dp.g)) {
     fputs("\n*** gen failed", stderr);
     fputs("\nseed_in = ", stderr); type_hex.dump(&v[0], stderr);
index 7593a74..88054eb 100644 (file)
@@ -119,6 +119,7 @@ void dsa_sign(dsa_param *dp, mp *a,
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/testrig.h>
 
 #include "sha.h"
@@ -145,8 +146,8 @@ static int verify(dstr *v)
           s.r, sizeof(s.r), s.s, sizeof(s.s));
 
   if (v[6].len != sizeof(s.r) || v[7].len != sizeof(s.s) ||
-      memcmp(s.r, v[6].buf, sizeof(s.r)) != 0 ||
-      memcmp(s.s, v[7].buf, sizeof(s.s)) != 0) {
+      MEMCMP(s.r, !=, v[6].buf, sizeof(s.r)) ||
+      MEMCMP(s.s, !=, v[7].buf, sizeof(s.s))) {
     fputs("\n*** signature failed", stderr);
     fputs("\nq = ", stderr); mp_writefile(dp.q, stderr, 16);
     fputs("\np = ", stderr); mp_writefile(dp.p, stderr, 16);
index 676fe8c..8374109 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include <mLib/macros.h>
+
 #include "f25519.h"
 #include "ed25519.h"
 #include "scaf.h"
@@ -406,7 +408,7 @@ int ed25519ctx_verify(const octet K[ED25519_PUBSZ],
   scaf_loaddbl(tt, sig + 32, 32, 2*NPIECE, PIECEWD);
   scaf_reduce(s, tt, l, mu, NPIECE, PIECEWD, scratch);
   scaf_store(b, 32, s, NPIECE, PIECEWD);
-  if (memcmp(b, sig + 32, 32) != 0) return (-1);
+  if (MEMCMP(b, !=, sig + 32, 32)) return (-1);
 
   /* Check the signature. */
   psz = prefix(b, phflag, p, psz);
@@ -420,7 +422,7 @@ int ed25519ctx_verify(const octet K[ED25519_PUBSZ],
   scaf_reduce(t, tt, l, mu, NPIECE, PIECEWD, scratch);
   ptsimmul(&RX, &RY, &RZ, s, BX, BY, BZ, t, &AX, &AY, &AZ);
   ptencode(b, &RX, &RY, &RZ);
-  if (memcmp(b, sig, 32) != 0) return (-1);
+  if (MEMCMP(b, !=, sig, 32)) return (-1);
 
   /* All is good. */
   return (0);
@@ -454,7 +456,7 @@ static int vrf_pubkey(dstr dv[])
   dstr_ensure(&dpub, ED25519_PUBSZ); dpub.len = ED25519_PUBSZ;
   ed25519_pubkey((octet *)dpub.buf, dv[0].buf, dv[0].len);
   ct_remedy(dpub.buf, dpub.len);
-  if (memcmp(dpub.buf, dv[1].buf, ED25519_PUBSZ) != 0) {
+  if (MEMCMP(dpub.buf, !=, dv[1].buf, ED25519_PUBSZ)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\tpriv = "); type_hex.dump(&dv[0], stderr);
@@ -493,7 +495,7 @@ static int vrf_sign(dstr *priv, int phflag, dstr *perso,
                  phflag, perso ? perso->buf : 0, perso ? perso->len : 0,
                  m->buf, m->len);
   ct_remedy(dsig.buf, dsig.len);
-  if (memcmp(dsig.buf, want->buf, ED25519_SIGSZ) != 0) {
+  if (MEMCMP(dsig.buf, !=, want->buf, ED25519_SIGSZ)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\tpriv = "); type_hex.dump(priv, stderr);
index 6032802..681a3ca 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <string.h>
 
+#include <mLib/macros.h>
+
 #include "fgoldi.h"
 #include "ed448.h"
 #include "scaf.h"
@@ -394,7 +396,7 @@ int ed448_verify(const octet K[ED448_PUBSZ],
   scaf_loaddbl(tt, sig + 57, 57, 2*NPIECE, PIECEWD);
   scaf_reduce(s, tt, l, mu, NPIECE, PIECEWD, scratch);
   scaf_store(b, 57, s, NPIECE, PIECEWD);
-  if (memcmp(b, sig + 57, 57) != 0) return (-1);
+  if (MEMCMP(b, !=, sig + 57, 57)) return (-1);
 
   /* Check the signature. */
   psz = prefix(b, phflag, p, psz);
@@ -408,7 +410,7 @@ int ed448_verify(const octet K[ED448_PUBSZ],
   scaf_reduce(t, tt, l, mu, NPIECE, PIECEWD, scratch);
   ptsimmul(&RX, &RY, &RZ, s, BX, BY, BZ, t, &AX, &AY, &AZ);
   ptencode(b, &RX, &RY, &RZ);
-  if (memcmp(b, sig, 57) != 0) return (-1);
+  if (MEMCMP(b, !=, sig, 57)) return (-1);
 
   /* All is good. */
   return (0);
@@ -437,7 +439,7 @@ static int vrf_pubkey(dstr dv[])
   dstr_ensure(&dpub, ED448_PUBSZ); dpub.len = ED448_PUBSZ;
   ed448_pubkey((octet *)dpub.buf, dv[0].buf, dv[0].len);
   ct_remedy(dpub.buf, dpub.len);
-  if (memcmp(dpub.buf, dv[1].buf, ED448_PUBSZ) != 0) {
+  if (MEMCMP(dpub.buf, !=, dv[1].buf, ED448_PUBSZ)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\tpriv = "); type_hex.dump(&dv[0], stderr);
@@ -476,7 +478,7 @@ static int vrf_sign(dstr *priv, int phflag, dstr *perso,
             phflag, perso ? perso->buf : 0, perso ? perso->len : 0,
             m->buf, m->len);
   ct_remedy(dsig.buf, dsig.len);
-  if (memcmp(dsig.buf, want->buf, ED448_SIGSZ) != 0) {
+  if (MEMCMP(dsig.buf, !=, want->buf, ED448_SIGSZ)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\tpriv = "); type_hex.dump(priv, stderr);
index 94f22aa..2399425 100644 (file)
@@ -27,6 +27,8 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <mLib/macros.h>
+
 #include "dsa.h"
 #include "gkcdsa.h"
 #include "group.h"
@@ -175,7 +177,7 @@ int gkcdsa_verify(const gkcdsa *c, const gkcdsa_sig *s, const void *m)
   e[1].base = g->g; e[1].exp = x;
   z = G_CREATE(g); G_MEXP(g, z, e, 2);
   h = hashge(g, c->h, z); p = GH_DONE(h, 0);
-  if (memcmp(p, s->r, hsz) == 0) rc = 0;
+  if (MEMCMP(p, ==, s->r, hsz)) rc = 0;
   mp_drop(x); mp_drop(y); G_DESTROY(g, z); GH_DESTROY(h);
   return (rc);
 }
@@ -241,7 +243,7 @@ static int tsign(dstr *v)
   gkcdsa_endhash(&c, h);
   gkcdsa_sign(&c, &ss, GH_DONE(h, 0), k);
   GH_DESTROY(h);
-  if (memcmp(s.r, ss.r, c.h->hashsz) || !MP_EQ(s.s, ss.s)) {
+  if (MEMCMP(s.r, !=, ss.r, c.h->hashsz) || !MP_EQ(s.s, ss.s)) {
     ok = 0;
     fprintf(stderr, "*** sign failed!\n");
     fprintf(stderr, "*** group: %s\n", v[0].buf);
index 590c05e..bb33351 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 
 #include "ct.h"
 #include "grand.h"
@@ -245,7 +246,7 @@ int pkcs1_sigdecode(mp *s, const void *m, size_t msz, octet *b, size_t sz,
 
   /* --- Check the encoding parameters --- */
 
-  if (pp->ep && memcmp(q, pp->ep, pp->epsz) != 0)
+  if (pp->ep && MEMCMP(q, !=, pp->ep, pp->epsz))
     return (-1);
   q += pp->epsz;
 
index 8e77b78..137b876 100644 (file)
--- a/pub/pss.c
+++ b/pub/pss.c
@@ -32,6 +32,7 @@
 #include <mLib/alloc.h>
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 
 #include "gcipher.h"
 #include "ghash.h"
@@ -174,7 +175,7 @@ int pss_decode(mp *mi, const void *m, size_t msz, octet *b, size_t sz,
   GH_HASH(h, m, msz);
   GH_HASH(h, s, pp->ssz);
   s = GH_DONE(h, 0);
-  rc = !memcmp(s, r, hsz);
+  rc = MEMCMP(s, ==, r, hsz);
   GH_DESTROY(h);
   if (!rc) return (-1);
 
index 5e13182..bb402a3 100644 (file)
@@ -29,6 +29,7 @@
 #include <mLib/alloc.h>
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 
 #include "mp.h"
 #include "mpmont.h"
@@ -200,7 +201,7 @@ int rsa_verify(rsa_pubctx *rp, mp *s, const void *m, size_t msz,
   dstr_ensure(d, n);
   rc = e(p, m, msz, (octet *)d->buf + d->len, n, nb, earg);
   if (rc > 0 && m) {
-    if (rc != msz || memcmp(d->buf + d->len, m, msz) != 0)
+    if (rc != msz || MEMCMP(d->buf + d->len, !=, m, msz))
       rc = -1;
     else
       rc = 0;
index 34b2a1f..2ee6bbc 100644 (file)
@@ -27,6 +27,8 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <mLib/macros.h>
+
 #include "fibrand.h"
 #include "rsa.h"
 
@@ -69,7 +71,7 @@ static int tencpad(int nbits,
 #define tsigpad tencpad
 
 #define DSTR_EQ(x, y)                                                  \
-  ((x)->len == (y)->len && !memcmp((x)->buf, (y)->buf, (x)->len))
+  ((x)->len == (y)->len && MEMCMP((x)->buf, ==, (y)->buf, (x)->len))
 
 static int tdecpad(int nbits,
                   mp *c, int rc, dstr *p,
index f897129..cfdfea6 100644 (file)
@@ -111,6 +111,7 @@ void x25519(octet zz[X25519_OUTSZ],
 #include <stdio.h>
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/testrig.h>
 
@@ -131,7 +132,7 @@ static int vrf_x25519(dstr dv[])
         (const octet *)dv[0].buf,
         (const octet *)dv[1].buf);
   ct_remedy(dz.buf, dz.len);
-  if (memcmp(dz.buf, dv[2].buf, X25519_OUTSZ) != 0) {
+  if (MEMCMP(dz.buf, !=, dv[2].buf, X25519_OUTSZ)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\t   k = "); type_hex.dump(&dv[0], stderr);
@@ -167,7 +168,7 @@ static int vrf_mct(dstr dv[])
   }
   memcpy(d.buf, k, d.len);
 
-  if (memcmp(d.buf, dv[3].buf, d.len) != 0) {
+  if (MEMCMP(d.buf, !=, dv[3].buf, d.len)) {
     ok = 0;
     fprintf(stderr, "failed...");
     fprintf(stderr, "\n\tinitial k = "); type_hex.dump(&dv[0], stderr);
index 6bef9dd..70ec10f 100644 (file)
@@ -97,8 +97,8 @@ void x448(octet zz[X448_OUTSZ],
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
-#include <mLib/str.h>
 #include <mLib/testrig.h>
 
 #include "ct.h"
@@ -118,7 +118,7 @@ static int vrf_x448(dstr dv[])
        (const octet *)dv[0].buf,
        (const octet *)dv[1].buf);
   ct_remedy(dz.buf, dz.len);
-  if (memcmp(dz.buf, dv[2].buf, X448_OUTSZ) != 0) {
+  if (MEMCMP(dz.buf, !=, dv[2].buf, X448_OUTSZ)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\t   k = "); type_hex.dump(&dv[0], stderr);
@@ -153,7 +153,7 @@ static int vrf_mct(dstr dv[])
   }
   memcpy(d.buf, k, d.len);
 
-  if (memcmp(d.buf, dv[3].buf, d.len) != 0) {
+  if (MEMCMP(d.buf, !=, dv[3].buf, d.len)) {
     ok = 0;
     fprintf(stderr, "failed...");
     fprintf(stderr, "\n\tinitial k = "); type_hex.dump(&dv[0], stderr);
index 06187b3..9601f4e 100644 (file)
@@ -310,6 +310,7 @@ grand *sslprf_rand(const gchash *hco, const gchash *hci,
 #include <stdio.h>
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -327,7 +328,7 @@ static int v_generate(dstr *v)
   d.len = v[2].len;
   g->ops->fill(g, d.buf, d.len);
   g->ops->destroy(g);
-  if (memcmp(v[2].buf, d.buf, d.len) != 0) {
+  if (MEMCMP(v[2].buf, !=, d.buf, d.len)) {
     ok = 0;
     printf("\nfail sslprf:"
           "\n\tkey        = ");
index fa28faf..95f5b94 100644 (file)
@@ -493,6 +493,7 @@ grand *tlsprf_rand(const gcmac *mcx, const gcmac *mcy,
 #include <stdio.h>
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -511,7 +512,7 @@ static int v_generate(dstr *v)
   d.len = v[2].len;
   g->ops->fill(g, d.buf, d.len);
   g->ops->destroy(g);
-  if (memcmp(v[2].buf, d.buf, d.len) != 0) {
+  if (MEMCMP(v[2].buf, !=, d.buf, d.len)) {
     ok = 0;
     printf("\nfail tlsprf:"
           "\n\tkey        = ");
index bbba763..069c1da 100644 (file)
 
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -429,7 +430,7 @@ static int pre##_verify(dstr *v)                                    \
   BLKC_MOVE(PRE, d, p);                                                        \
   pre##_eblk(&k, d, d);                                                        \
   BLKC_STORE(PRE, b.buf, d);                                           \
-  if (memcmp(b.buf, v[2].buf, PRE##_BLKSZ)) {                          \
+  if (MEMCMP(b.buf, !=, v[2].buf, PRE##_BLKSZ)) {                      \
     ok = 0;                                                            \
     printf("\nfail encryption:"                                                \
           "\n\tkey        = ");                                        \
@@ -445,7 +446,7 @@ static int pre##_verify(dstr *v)                                    \
   BLKC_MOVE(PRE, d, c);                                                        \
   pre##_dblk(&k, d, d);                                                        \
   BLKC_STORE(PRE, b.buf, d);                                           \
-  if (memcmp(b.buf, v[1].buf, PRE##_BLKSZ)) {                          \
+  if (MEMCMP(b.buf, !=, v[1].buf, PRE##_BLKSZ)) {                      \
     ok = 0;                                                            \
     printf("\nfail decryption:"                                                \
           "\n\tkey        = ");                                        \
index 2d864fa..fda5179 100644 (file)
@@ -742,6 +742,7 @@ CCM_TESTX(PRE, pre, name, fname)
 #include <stdio.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -802,8 +803,8 @@ static int ccmverify(dstr *v)                                               \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[4].len ||                                           \
-       memcmp(d.buf, v[4].buf, v[4].len) != 0 ||                       \
-       memcmp(t.buf, v[5].buf, v[5].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[4].buf, v[4].len) ||                        \
+       MEMCMP(t.buf, !=, v[5].buf, v[5].len)) {                        \
     fail_enc:                                                          \
       printf("\nfail encrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
@@ -855,7 +856,7 @@ static int ccmverify(dstr *v)                                               \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[3].len || !win ||                                   \
-       memcmp(d.buf, v[3].buf, v[3].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[3].buf, v[3].len)) {                        \
     fail_dec:                                                          \
       printf("\nfail decrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
index 90a4c67..b06deae 100644 (file)
@@ -849,6 +849,7 @@ CHACHA_VARS(DEFXGRAND)
 #include <stdio.h>
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -870,7 +871,7 @@ CHACHA_VARS(DEFXGRAND)
     }                                                                  \
     for (i = 0; i < CHACHA_OUTSZ/4; i++) STORE32_L(d.buf + 4*i, a[i]); \
                                                                        \
-    if (d.len != v[2].len || memcmp(d.buf, v[2].buf, v[2].len) != 0) { \
+    if (d.len != v[2].len || MEMCMP(d.buf, !=, v[2].buf, v[2].len)) {  \
       ok = 0;                                                          \
       printf("\nfail core:"                                            \
             "\n\titerations = %d"                                      \
@@ -940,7 +941,7 @@ CHACHA_VARS(DEFVCORE)
       }                                                                        \
       if (sz) BASE##_ENCRYPT(r, &ctx, p, q, sz);                       \
                                                                        \
-      if (d.len != v[5].len || memcmp(d.buf, v[5].buf, v[5].len) != 0) { \
+      if (d.len != v[5].len || MEMCMP(d.buf, !=, v[5].buf, v[5].len)) {        \
        ok = 0;                                                         \
        printf("\nfail encrypt:"                                        \
               "\n\tstep           = %lu"                               \
index 701d3b5..ee8040a 100644 (file)
@@ -323,6 +323,7 @@ CMAC_TESTX(PRE, pre, name, fname)
 #include <stdio.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -362,7 +363,7 @@ static int macverify(dstr *v)                                               \
       csz -= i;                                                                \
     }                                                                  \
     pre##_cmacdone(&cctx, d.buf);                                      \
-    if (memcmp(d.buf, v[2].buf, PRE##_BLKSZ) != 0) {                   \
+    if (MEMCMP(d.buf, !=, v[2].buf, PRE##_BLKSZ)) {                    \
       printf("\nfail:\n\tstep = %i\n\tkey = ", *ip);                   \
       type_hex.dump(&v[0], stdout);                                    \
       fputs("\n\tinput = ", stdout);                                   \
index 6e1c7ca..cf4c001 100644 (file)
@@ -700,6 +700,7 @@ EAX_TESTX(PRE, pre, name, fname)
 #include <stdio.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -761,8 +762,8 @@ static int eaxverify(dstr *v)                                               \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[4].len ||                                           \
-       memcmp(d.buf, v[4].buf, v[4].len) != 0 ||                       \
-       memcmp(t.buf, v[5].buf, v[5].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[4].buf, v[4].len) ||                        \
+       MEMCMP(t.buf, !=, v[5].buf, v[5].len)) {                        \
     fail_enc:                                                          \
       printf("\nfail encrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
@@ -803,7 +804,7 @@ static int eaxverify(dstr *v)                                               \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[3].len || !win ||                                   \
-       memcmp(d.buf, v[3].buf, v[3].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[3].buf, v[3].len)) {                        \
     fail_dec:                                                          \
       printf("\nfail decrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
index 34f95aa..6ca5895 100644 (file)
@@ -815,6 +815,7 @@ GCM_TESTX(PRE, pre, name, fname)
 #include <stdio.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -876,8 +877,8 @@ static int gcmverify(dstr *v)                                               \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[4].len ||                                           \
-       memcmp(d.buf, v[4].buf, v[4].len) != 0 ||                       \
-       memcmp(t.buf, v[5].buf, v[5].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[4].buf, v[4].len) ||                        \
+       MEMCMP(t.buf, !=, v[5].buf, v[5].len)) {                        \
     fail_enc:                                                          \
       printf("\nfail encrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
@@ -918,7 +919,7 @@ static int gcmverify(dstr *v)                                               \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[3].len || !win ||                                   \
-       memcmp(d.buf, v[3].buf, v[3].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[3].buf, v[3].len)) {                        \
     fail_dec:                                                          \
       printf("\nfail decrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
index 73b2851..9571894 100644 (file)
@@ -778,6 +778,7 @@ void gcm_concat(const gcm_params *p, uint32 *z, const uint32 *x,
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -820,7 +821,7 @@ static int test_mul(uint32 poly, dstr v[])
 
 #define CHECK(E, what, ref) do {                                       \
   for (i = 0; i < nbits/32; i++) STORE32_##E(d.buf + 4*i, z[i]);       \
-  if (memcmp(d.buf, v[I_##ref].buf, nbits/8) != 0)                     \
+  if (MEMCMP(d.buf, !=, v[I_##ref].buf, nbits/8))                      \
     { ok = 0; report_failure(what, nbits, #ref, v, &d); }              \
 } while (0)
 
index 29b733b..92fe792 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <string.h>
 
+#include <mLib/macros.h>
+
 #include "@what.h"
 
 %repeat
@@ -27,6 +29,6 @@ const @cls *@{what}_byname(const char *p)
   const @cls *const *c;
 
   for (c = @{what}tab; *c; c++)
-    if (strcmp(p, (*c)->name) == 0) return (*c);
+    if (STRCMP(p, ==, (*c)->name)) return (*c);
   return (0);
 }
index 3d0c117..5b2e7fb 100644 (file)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -178,7 +179,7 @@ static int vrf_##pre(dstr *v, const test_type *msgty)                       \
       sz -= i;                                                         \
     }                                                                  \
     pre##_done(&ctx, d.buf);                                           \
-    if (memcmp(d.buf, v[1].buf, PRE##_HASHSZ) != 0) {                  \
+    if (MEMCMP(d.buf, !=, v[1].buf, PRE##_HASHSZ)) {                   \
       printf("\nfail:\n\tstep = %i\n\tinput = ", *ip);                 \
       msgty->dump(&v[0], stdout);                                      \
       printf("\n\texpected = ");                                       \
@@ -222,7 +223,7 @@ static int vrf_##pre##_rep(dstr *v)                                 \
   while (n--) pre##_hash(&ctx, p, len);                                        \
   pre##_done(&ctx, d.buf);                                             \
                                                                        \
-  if (memcmp(d.buf, v[2].buf, PRE##_HASHSZ) != 0) {                    \
+  if (MEMCMP(d.buf, !=, v[2].buf, PRE##_HASHSZ)) {                     \
     printf("\nfail:\n\tinput = `%s'\n\treps = `%i'\n\texpected = ",    \
             v[0].buf, *(int *)v[1].buf);                               \
     type_hex.dump(&v[2], stdout);                                      \
index 9ac8fb9..76d578d 100644 (file)
@@ -359,6 +359,7 @@ HMAC_TESTX(PRE, pre, name, fname)
 
 #include <stdio.h>
 
+#include <mLib/macros.h>
 #include <mLib/dstr.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
@@ -399,7 +400,7 @@ static int macverify(dstr *v)                                               \
       csz -= i;                                                                \
     }                                                                  \
     pre##_macdone(&cctx, d.buf);                                       \
-    if (memcmp(d.buf, v[2].buf, PRE##_HASHSZ) != 0) {                  \
+    if (MEMCMP(d.buf, !=, v[2].buf, PRE##_HASHSZ)) {                   \
       printf("\nfail:\n\tstep = %i\n\tinput = `%s'\n\tkey = ",         \
             *ip, v[0].buf);                                            \
       type_hex.dump(&v[1], stdout);                                    \
index c2d8292..cfbfdef 100644 (file)
@@ -649,6 +649,7 @@ void keccak1600_extract(const keccak1600_state *s, kludge64 *p, size_t n)
 
 #include <stdio.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
 #include <mLib/testrig.h>
@@ -673,7 +674,7 @@ static int vrf_p(dstr v[])
   keccak1600_p(&u, &u, n);
   keccak1600_extract(&u, t, 25);
   for (i = 0; i < 25; i++) STORE64_L_(d.buf + 8*i, t[i]);
-  if (memcmp(d.buf, v[2].buf, 200) != 0) {
+  if (MEMCMP(d.buf, !=, v[2].buf, 200)) {
     ok = 0;
     fprintf(stderr, "failed!");
     fprintf(stderr, "\n\t     input = "); type_hex.dump(&v[0], stderr);
index 5a914e5..f7a2076 100644 (file)
@@ -27,6 +27,8 @@
 
 /*----- Header files ------------------------------------------------------*/
 
+#include <mLib/macros.h>
+
 #include "latinpoly-def.h"
 
 /*----- Main code ---------------------------------------------------------*/
@@ -62,8 +64,9 @@ int latinpoly_test(const gcaead *aec, dstr *v)
   if (rc) { printf("!! encryptdone reports failure\n"); goto encfail; }
 
   out.len = BLEN(&b); tag.len = POLY1305_TAGSZ;
-  if (out.len != v[4].len || memcmp(out.buf, v[4].buf, v[4].len) ||
-      memcmp(tag.buf, v[5].buf, v[5].len)) {
+  if (out.len != v[4].len ||
+      MEMCMP(out.buf, !=, v[4].buf, v[4].len) ||
+      MEMCMP(tag.buf, !=, v[5].buf, v[5].len)) {
   encfail:
     ok = 0;
     printf("\n%s encrypt FAILED", aec->name);
@@ -91,7 +94,8 @@ int latinpoly_test(const gcaead *aec, dstr *v)
   if (rc < 0) { printf("!! decryptdone reports failure\n"); goto decfail; }
 
   out.len = BLEN(&b); tag.len = POLY1305_TAGSZ;
-  if (out.len != v[3].len || memcmp(out.buf, v[3].buf, v[3].len) || !rc) {
+  if (out.len != v[3].len || MEMCMP(out.buf, !=, v[3].buf, v[3].len) ||
+      !rc) {
   decfail:
     ok = 0;
     printf("\ndecrypt FAILED");
index b06d230..a6c28ba 100644 (file)
@@ -38,6 +38,7 @@
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
 #include <mLib/quis.h>
+#include <mLib/macros.h>
 #include <mLib/report.h>
 
 #include "modes-test.h"
@@ -164,7 +165,7 @@ static int regress_data(int rmode, FILE *fp, const char *what,
       if (!fread(t, sz, 1, fp))
        die(1, "failed to read %s: %s", what,
            ferror(fp) ? strerror(errno) : "unexpected eof");
-      if (memcmp(p, t, sz) != 0) return (-1);
+      if (MEMCMP(p, !=, t, sz)) return (-1);
       return (0);
     default:
       abort();
@@ -372,7 +373,7 @@ int test_encmode(const char *name,
     if (!p || !*p) {
       if (i >= argc) break;
       p = argv[i++];
-      if (strcmp(p, "--") == 0) break;
+      if (STRCMP(p, ==, "--")) break;
       if (p[0] != '-' || p[1] == 0) { i--; break; }
       p++;
     }
@@ -478,7 +479,7 @@ int test_encmode(const char *name,
     regr = 0;
     if ((f&TEMF_REFALIGN) && (sz0%blksz || sz1%blksz)) regr = 1;
     else if (!refp) { memcpy(ref, ct, TEXTSZ); regr = 1; refp = 1; }
-    else if (memcmp(ref, ct, TEXTSZ) != 0) {
+    else if (MEMCMP(ref, !=, ct, TEXTSZ)) {
       ok = 0;
       printf("\nConsistency failure (split = %lu/%lu/%lu)\n",
             (unsigned long)sz0, (unsigned long)sz1, (unsigned long)sz2);
@@ -509,7 +510,7 @@ int test_encmode(const char *name,
     }
     if (sz2)
       dec(ct + sz0 + sz1, pt + sz0 + sz1, sz2);
-    if (memcmp(text, pt, TEXTSZ) != 0) {
+    if (MEMCMP(text, !=, pt, TEXTSZ)) {
       ok = 0;
       printf("\nRound-trip failure (split = %lu/%lu/%lu)\n",
             (unsigned long)sz0, (unsigned long)sz1, (unsigned long)sz2);
index 7c7eb29..2820aae 100644 (file)
@@ -520,6 +520,7 @@ OCB1_TESTX(PRE, pre, name, fname)
 #include <stdio.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -581,8 +582,8 @@ static int ocb1verify(dstr *v)                                              \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[4].len ||                                           \
-       memcmp(d.buf, v[4].buf, v[4].len) != 0 ||                       \
-       memcmp(t.buf, v[5].buf, v[5].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[4].buf, v[4].len) ||                        \
+       MEMCMP(t.buf, !=, v[5].buf, v[5].len)) {                        \
     fail_enc:                                                          \
       printf("\nfail encrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
@@ -623,7 +624,7 @@ static int ocb1verify(dstr *v)                                              \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[3].len || !win ||                                   \
-       memcmp(d.buf, v[3].buf, v[3].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[3].buf, v[3].len)) {                        \
     fail_dec:                                                          \
       printf("\nfail decrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
index 14a22f6..31293cb 100644 (file)
@@ -854,8 +854,8 @@ static int ocb3verify(dstr *v)                                              \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[4].len ||                                           \
-       memcmp(d.buf, v[4].buf, v[4].len) != 0 ||                       \
-       memcmp(t.buf, v[5].buf, v[5].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[4].buf, v[4].len) ||                        \
+       MEMCMP(t.buf, !=, v[5].buf, v[5].len)) {                        \
     fail_enc:                                                          \
       printf("\nfail encrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
@@ -896,7 +896,7 @@ static int ocb3verify(dstr *v)                                              \
     d.len = BLEN(&b);                                                  \
                                                                        \
     if (d.len != v[3].len || !win ||                                   \
-       memcmp(d.buf, v[3].buf, v[3].len) != 0) {                       \
+       MEMCMP(d.buf, !=, v[3].buf, v[3].len)) {                        \
     fail_dec:                                                          \
       printf("\nfail decrypt:\n\tstep = %i", *ip);                     \
       fputs("\n\tkey = ", stdout); type_hex.dump(&v[0], stdout);       \
@@ -965,7 +965,7 @@ static int ocb3mct(dstr *v)                                         \
   if (rc) goto fail;                                                   \
                                                                        \
   d.len = tsz;                                                         \
-  if (memcmp(d.buf, v[1].buf, tsz) != 0) {                             \
+  if (MEMCMP(d.buf, !=, v[1].buf, tsz)) {                              \
   fail:                                                                        \
     printf("\nfail mct: ksz = %u, tsz = %u", ksz, tsz);                        \
     fputs("\n\texp tag = ", stdout); type_hex.dump(&v[1], stdout);     \
index 4b0da04..5df9338 100644 (file)
@@ -288,6 +288,7 @@ PMAC1_TESTX(PRE, pre, name, fname)
 #include <stdio.h>
 
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -327,7 +328,7 @@ static int macverify(dstr *v)                                               \
       csz -= i;                                                                \
     }                                                                  \
     pre##_pmac1done(&cctx, d.buf);                                     \
-    if (memcmp(d.buf, v[2].buf, PRE##_BLKSZ) != 0) {                   \
+    if (MEMCMP(d.buf, !=, v[2].buf, PRE##_BLKSZ)) {                    \
       printf("\nfail:\n\tstep = %i\n\tkey = ", *ip);                   \
       type_hex.dump(&v[0], stdout);                                    \
       fputs("\n\tinput = ", stdout);                                   \
index c4a88a8..da4594f 100644 (file)
@@ -861,6 +861,7 @@ void poly1305_done(poly1305_ctx *ctx, void *h)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/testrig.h>
 
 #include "ct.h"
@@ -888,7 +889,7 @@ static int vrf_hash(dstr v[])
       poly1305_hash(&ctx, v[2].buf + j, v[2].len - j);
       poly1305_done(&ctx, t.buf);
       ct_remedy(t.buf, t.len);
-      if (memcmp(t.buf, v[3].buf, 16) != 0) {
+      if (MEMCMP(t.buf, !=, v[3].buf, 16)) {
        fprintf(stderr, "failed...");
        fprintf(stderr, "\n\tkey    = "); type_hex.dump(&v[0], stderr);
        fprintf(stderr, "\n\tmask   = "); type_hex.dump(&v[1], stderr);
@@ -932,7 +933,7 @@ static int vrf_cat(dstr v[])
       poly1305_concat(&ctx, &ctx, &cc[2]);
     }
     poly1305_done(&ctx, t.buf);
-    if (memcmp(t.buf, v[5].buf, 16) != 0) {
+    if (MEMCMP(t.buf, !=, v[5].buf, 16)) {
       fprintf(stderr, "failed...");
       fprintf(stderr, "\n\tkey    = "); type_hex.dump(&v[0], stderr);
       fprintf(stderr, "\n\tmask   = "); type_hex.dump(&v[1], stderr);
@@ -997,7 +998,7 @@ static int vrf_mct(dstr v[])
     }
   }
 
-  if (memcmp(t, v[4].buf, 16) != 0) {
+  if (MEMCMP(t, !=, v[4].buf, 16)) {
     ok = 0;
     fprintf(stderr, "failed...");
     fprintf(stderr, "\n\tinitial k = "); type_hex.dump(&v[0], stderr);
index df59425..97963fe 100644 (file)
@@ -250,6 +250,7 @@ void rc2_dblk(const rc2_ctx *k, const uint32 *s, uint32 *dst)
 
 #ifdef TEST_RIG
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -276,7 +277,7 @@ static int verify(dstr *v)
   BLKC_MOVE(RC2, d, p);
   rc2_eblk(&k, d, d);
   BLKC_STORE(RC2, b.buf, d);
-  if (memcmp(b.buf, v[3].buf, RC2_BLKSZ)) {
+  if (MEMCMP(b.buf, !=, v[3].buf, RC2_BLKSZ)) {
     ok = 0;
     printf("\nfail encryption:"
           "\n\tkey        = ");
@@ -293,7 +294,7 @@ static int verify(dstr *v)
   BLKC_MOVE(RC2, d, c);
   rc2_dblk(&k, d, d);
   BLKC_STORE(RC2, b.buf, d);
-  if (memcmp(b.buf, v[2].buf, RC2_BLKSZ)) {
+  if (MEMCMP(b.buf, !=, v[2].buf, RC2_BLKSZ)) {
     ok = 0;
     printf("\nfail decryption:"
           "\n\tkey        = ");
index 214dbc1..4cb0e87 100644 (file)
@@ -296,6 +296,7 @@ grand *rc4_rand(const void *k, size_t sz)
 #include <stdio.h>
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -310,7 +311,7 @@ static int v_encrypt(dstr *v)
   d.len = v[1].len;
   rc4_encrypt(&ctx, v[1].buf, d.buf, d.len);
 
-  if (memcmp(v[2].buf, d.buf, d.len) != 0) {
+  if (MEMCMP(v[2].buf, !=, d.buf, d.len)) {
     ok = 0;
     printf("\nfail encryption:"
           "\n\tkey        = ");
@@ -336,7 +337,7 @@ static int v_generate(dstr *v)
   d.len = v[2].len;
   rc4_encrypt(&ctx, 0, d.buf, d.len);
 
-  if (memcmp(v[2].buf, d.buf, d.len) != 0) {
+  if (MEMCMP(v[2].buf, !=, d.buf, d.len)) {
     ok = 0;
     printf("\nfail generation:"
           "\n\tkey        = ");
index e7c35f4..7806e6c 100644 (file)
@@ -871,6 +871,7 @@ SALSA20_VARS(DEFXGRAND)
 #include <stdio.h>
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
@@ -900,7 +901,7 @@ static const int perm[] = {
     }                                                                  \
     for (i = 0; i < SALSA20_OUTSZ/4; i++) STORE32_L(d.buf + 4*i, b[i]);        \
                                                                        \
-    if (d.len != v[2].len || memcmp(d.buf, v[2].buf, v[2].len) != 0) { \
+    if (d.len != v[2].len || MEMCMP(d.buf, !=, v[2].buf, v[2].len)) {  \
       ok = 0;                                                          \
       printf("\nfail core:"                                            \
             "\n\titerations = %d"                                      \
@@ -970,7 +971,7 @@ SALSA20_VARS(DEFVCORE)
       }                                                                        \
       if (sz) BASE##_ENCRYPT(r, &ctx, p, q, sz);                       \
                                                                        \
-      if (d.len != v[5].len || memcmp(d.buf, v[5].buf, v[5].len) != 0) { \
+      if (d.len != v[5].len || MEMCMP(d.buf, !=, v[5].buf, v[5].len)) {        \
        ok = 0;                                                         \
        printf("\nfail encrypt:"                                        \
               "\n\tstep           = %lu"                               \
index a4a0a3f..070550d 100644 (file)
@@ -521,6 +521,7 @@ grand *seal_rand(const void *k, size_t sz, uint32 n)
 
 #include <string.h>
 
+#include <mLib/macros.h>
 #include <mLib/testrig.h>
 
 static int verify(dstr *v)
@@ -543,7 +544,7 @@ static int verify(dstr *v)
     seal_initctx(&c, &k, n);
     seal_encrypt(&c, 0, d.buf, i);
     seal_encrypt(&c, z.buf, d.buf + i, d.len - i);
-    if (memcmp(d.buf, v[2].buf, d.len) != 0) {
+    if (MEMCMP(d.buf, !=, v[2].buf, d.len)) {
       ok = 0;
       printf("*** seal failure\n");
       printf("*** k = "); type_hex.dump(&v[0], stdout); putchar('\n');
index 7f95ffc..190096f 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include <mLib/bits.h>
+#include <mLib/macros.h>
 
 #include "serpent-sbox.h"
 
@@ -71,7 +72,7 @@ static int check(unsigned a, unsigned b, unsigned c, unsigned d,
     *q++ = (a & 1) | ((b & 1) << 1) | ((c & 1) << 2) | ((d & 1) << 3);
     a >>= 1; b >>= 1; c >>= 1; d >>= 1;
   }
-  return (memcmp(buf, p, sizeof(buf)));
+  return (MEMCMP(buf, ==, p, sizeof(buf)) ? 0 : -1);
 }
 
 #define CHECK(i) do {                                                  \
index 1696762..36bd430 100644 (file)
@@ -957,6 +957,7 @@ grand *kmac256_rand(const void *perso, size_t psz, const void *k, size_t sz)
 
 #include <stdio.h>
 
+#include <mLib/macros.h>
 #include <mLib/report.h>
 #include <mLib/testrig.h>
 
@@ -979,7 +980,7 @@ static int vrf_sha3_mct(void (*initfn)(sha3_ctx *),
     sha3_done(&ctx, d.buf);
   }
 
-  if (memcmp(d.buf, out->buf, out->len) != 0) {
+  if (MEMCMP(d.buf, !=, out->buf, out->len)) {
     ok = 0;
     printf("\nfail\n\tsteps = %d\n\tinput = ", n);
     type_hex.dump(in, stdout);
@@ -1037,7 +1038,7 @@ static int vrf_shaky(void (*initfn)(shake_ctx *,
       p += i; sz -= i;
     }
 
-    if (memcmp(d.buf, want->buf, want->len) != 0) {
+    if (MEMCMP(d.buf, !=, want->buf, want->len)) {
       ok = 0;
       printf("\nfail (get):\n\tstep = %i\n\tinput = ", *ip);
       type_hex.dump(m, stdout);
@@ -1071,7 +1072,7 @@ static int vrf_shaky(void (*initfn)(shake_ctx *,
       p += i; sz -= i;
     }
 
-    if (memcmp(d.buf, want->buf, want->len) != 0) {
+    if (MEMCMP(d.buf, !=, want->buf, want->len)) {
       ok = 0;
       printf("\nfail (mask):\n\tstep = %i\n\tinput = ", *ip);
       type_hex.dump(m, stdout);
@@ -1131,7 +1132,7 @@ static int vrf_kmac(void (*initfn)(kmac_ctx *, const void *, size_t,
   if (tsz) kmac_done(&ctx, d.buf, tsz);
   else { kmac_xof(&ctx); kmac_get(&ctx, d.buf, d.len); }
 
-  if (memcmp(d.buf, want->buf, want->len) != 0) {
+  if (MEMCMP(d.buf, !=, want->buf, want->len)) {
     ok = 0;
     printf("\nfail");
     printf("\n\tperso = `%s'", perso->buf);
index 8d4d42d..de4dbb2 100644 (file)
@@ -468,6 +468,7 @@ void strobe_ratchet(strobe_ctx *ctx, unsigned f, size_t sz)
 #include <string.h>
 
 #include <mLib/hex.h>
+#include <mLib/macros.h>
 #include <mLib/testrig.h>
 
 #define NSTATE 16
@@ -487,7 +488,7 @@ static void dump(int rc, char win, const void *p, size_t sz)
     else putchar('-');
   } else {
     for (i = 0, printable = 1; i < sz; i++)
-      if (!isprint((unsigned char)q[i])) { printable = 0; break; }
+      if (!ISPRINT(q[i])) { printable = 0; break; }
     if (printable)
       printf("`%s'", q);
     else {
@@ -601,7 +602,7 @@ static int verify(dstr v[])
   /* Next job is to parse the command and flags. */
   q = v[1].buf; p = q; q += strcspn(q, "/"); if (*q) *q++ = 0;
   for (op = optab; op->name; op++)
-    if (!strcmp(op->name, p)) goto found_op;
+    if (STRCMP(op->name, ==, p)) goto found_op;
   abort();
 found_op:
 
@@ -654,7 +655,7 @@ found_op:
   rc = op->op(ctx, f, src, dest, sz);
 
   /* Check we got the right answer. */
-  ok = (rc == rcref && (!destref || !memcmp(dest, destref, sz)));
+  ok = (rc == rcref && (!destref || MEMCMP(dest, ==, destref, sz)));
   if (!ok) {
     printf("failed test\n");
     printf("       state = %d\n", r);
index e438696..61fb79f 100644 (file)
@@ -5,6 +5,7 @@
 #include <mLib/alloc.h>
 #include <mLib/hex.h>
 #include <mLib/dstr.h>
+#include <mLib/macros.h>
 
 #include "ec.h"
 #include "mp.h"
@@ -129,7 +130,7 @@ int main(int argc, char *argv[])
   if ((err = ec_checkinfo(&ei, &rand_global)) != 0)
     fprintf(stderr, "bad curve: %s\n", err);
   puthex("p", ei.c->f->m, 0);
-  if (strcmp(F_NAME(ei.c->f), "binnorm") == 0) {
+  if (STRCMP(F_NAME(ei.c->f), ==, "binnorm")) {
     fctx_binnorm *fc = (fctx_binnorm *)ei.c->f;
     puthex("beta", fc->ntop.r[fc->ntop.n - 1], c->f->noctets);
   }