From 141c12847a1c2f8cc8db03d420551584e689fb87 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 1 Oct 2019 20:01:20 +0100 Subject: [PATCH] Deploy the new and `foocmp' macros from mLib. --- base/dispatch.c | 4 ++-- base/keysz-conv.c | 4 +++- base/rsvr.c | 7 ++++--- key/key-attr.c | 6 +++--- key/key-binary.c | 1 + key/key-flags.c | 5 +++-- key/key-io.c | 13 +++++++------ key/key-misc.c | 1 + key/key-pass.c | 5 +++-- key/key-text.c | 3 ++- key/passphrase.c | 3 ++- key/pixie-common.c | 11 ++++++----- math/bittest.c | 3 ++- math/ec-test.c | 8 +++++--- math/f25519.c | 3 ++- math/fgoldi.c | 3 ++- math/g-ec.c | 7 ++++--- math/genprimes.c | 5 +++-- math/genwheel.c | 5 +++-- math/group-test.c | 7 ++++--- math/mp-arith.c | 12 +++++++----- math/mpint.c | 1 + math/mptext.c | 10 ++++++---- math/mpx.c | 13 +++++++------ math/qdparse.c | 8 +++++--- misc/gfshare.c | 4 +++- progs/catcrypt.c | 9 +++++---- progs/catsign.c | 32 ++++++++++++++++---------------- progs/cc-enc.c | 17 +++++++++-------- progs/cc-hash.c | 31 +++++++++++++++---------------- progs/cc-kem.c | 21 +++++++++++---------- progs/cc-list.c | 3 ++- progs/cc-sig.c | 5 +++-- progs/cc-subcmd.c | 3 ++- progs/cookie.c | 5 +++-- progs/dsig.c | 13 +++++++------ progs/factorial.c | 5 +++-- progs/fibonacci.c | 5 +++-- progs/hashsum.c | 11 ++++++----- progs/key.c | 29 +++++++++++++++-------------- progs/mkphrase.c | 13 +++++++------ progs/perftest.c | 3 ++- progs/pixie.c | 39 ++++++++++++++++++++------------------- progs/rspit.c | 5 +++-- pub/bbs-rand.c | 4 +++- pub/dh-param.c | 4 +++- pub/dsa-gen.c | 4 +++- pub/dsa-sign.c | 5 +++-- pub/ed25519.c | 10 ++++++---- pub/ed448.c | 10 ++++++---- pub/gkcdsa.c | 6 ++++-- pub/pkcs1.c | 3 ++- pub/pss.c | 3 ++- pub/rsa-pub.c | 3 ++- pub/rsa-test.c | 4 +++- pub/x25519.c | 5 +++-- pub/x448.c | 6 +++--- rand/sslprf.c | 3 ++- rand/tlsprf.c | 3 ++- symm/blkc.h | 5 +++-- symm/ccm-def.h | 7 ++++--- symm/chacha.c | 5 +++-- symm/cmac-def.h | 3 ++- symm/eax-def.h | 7 ++++--- symm/gcm-def.h | 7 ++++--- symm/gcm.c | 3 ++- symm/gthingtab.c.in | 4 +++- symm/hash.h | 5 +++-- symm/hmac-def.h | 3 ++- symm/keccak1600.c | 3 ++- symm/latinpoly-test.c | 10 +++++++--- symm/modes-test.c | 9 +++++---- symm/ocb1-def.h | 7 ++++--- symm/ocb3-def.h | 8 ++++---- symm/pmac1-def.h | 3 ++- symm/poly1305.c | 7 ++++--- symm/rc2.c | 5 +++-- symm/rc4.c | 5 +++-- symm/salsa20.c | 5 +++-- symm/seal.c | 3 ++- symm/serpent-check.c | 3 ++- symm/sha3.c | 9 +++++---- symm/strobe.c | 7 ++++--- utils/ecptdecompress.c | 3 ++- 84 files changed, 352 insertions(+), 258 deletions(-) diff --git a/base/dispatch.c b/base/dispatch.c index db9c3199..7806d405 100644 --- a/base/dispatch.c +++ b/base/dispatch.c @@ -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); diff --git a/base/keysz-conv.c b/base/keysz-conv.c index 2d405588..9ed9f582 100644 --- a/base/keysz-conv.c +++ b/base/keysz-conv.c @@ -140,6 +140,8 @@ CONVERSIONS(DEFINE_TO) #include #include +#include + 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); diff --git a/base/rsvr.c b/base/rsvr.c index a468db76..3be9ed15 100644 --- a/base/rsvr.c +++ b/base/rsvr.c @@ -231,6 +231,7 @@ int rsvr_done(rsvr_state *st) #include #include #include +#include #include #include @@ -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); } diff --git a/key/key-attr.c b/key/key-attr.c index e884d699..567fb92f 100644 --- a/key/key-attr.c +++ b/key/key-attr.c @@ -34,6 +34,7 @@ #include #include +#include #include #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 --- */ diff --git a/key/key-binary.c b/key/key-binary.c index 046819a4..718dfb60 100644 --- a/key/key-binary.c +++ b/key/key-binary.c @@ -32,6 +32,7 @@ #include #include +#include #include #include diff --git a/key/key-flags.c b/key/key-flags.c index 169de2c5..7cedb856 100644 --- a/key/key-flags.c +++ b/key/key-flags.c @@ -32,6 +32,7 @@ #include #include +#include #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; diff --git a/key/key-io.c b/key/key-io.c index bf3bf95f..3bb8e1d0 100644 --- a/key/key-io.c +++ b/key/key-io.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/key/key-misc.c b/key/key-misc.c index 0d969a87..b10879ac 100644 --- a/key/key-misc.c +++ b/key/key-misc.c @@ -34,6 +34,7 @@ #include #include +#include #include #include diff --git a/key/key-pass.c b/key/key-pass.c index 665030e4..223486eb 100644 --- a/key/key-pass.c +++ b/key/key-pass.c @@ -29,6 +29,7 @@ #include +#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; } diff --git a/key/key-text.c b/key/key-text.c index 98c1fba1..ace69ce1 100644 --- a/key/key-text.c +++ b/key/key-text.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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++; } diff --git a/key/passphrase.c b/key/passphrase.c index 6f0780f9..3a287bde 100644 --- a/key/passphrase.c +++ b/key/passphrase.c @@ -35,6 +35,7 @@ #include #include +#include #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; } diff --git a/key/pixie-common.c b/key/pixie-common.c index 2975c205..d3348bcf 100644 --- a/key/pixie-common.c +++ b/key/pixie-common.c @@ -44,6 +44,7 @@ #include #include +#include #include #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; } diff --git a/math/bittest.c b/math/bittest.c index 5f7b1d76..e335286e 100644 --- a/math/bittest.c +++ b/math/bittest.c @@ -29,6 +29,7 @@ #include #include +#include #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; \ } \ diff --git a/math/ec-test.c b/math/ec-test.c index d9cda6ff..ff01a2ea 100644 --- a/math/ec-test.c +++ b/math/ec-test.c @@ -215,6 +215,8 @@ const test_type type_ec = { eccvt, ecdump }; #ifdef TEST_RIG +#include + 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); diff --git a/math/f25519.c b/math/f25519.c index e9a91f41..7f8e66fc 100644 --- a/math/f25519.c +++ b/math/f25519.c @@ -1178,6 +1178,7 @@ int f25519_quosqrt(f25519 *z, const f25519 *x, const f25519 *y) #ifdef TEST_RIG +#include #include #include #include @@ -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 }, diff --git a/math/fgoldi.c b/math/fgoldi.c index 1b09b58e..43309dcd 100644 --- a/math/fgoldi.c +++ b/math/fgoldi.c @@ -962,6 +962,7 @@ int fgoldi_quosqrt(fgoldi *z, const fgoldi *x, const fgoldi *y) #ifdef TEST_RIG +#include #include #include #include @@ -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 }, diff --git a/math/g-ec.c b/math/g-ec.c index 1b6c16e3..5d922ddd 100644 --- a/math/g-ec.c +++ b/math/g-ec.c @@ -29,6 +29,7 @@ #include +#include #include #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; diff --git a/math/genprimes.c b/math/genprimes.c index 8b47ac94..1ed7b4d1 100644 --- a/math/genprimes.c +++ b/math/genprimes.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/math/genwheel.c b/math/genwheel.c index 9bf3cbe1..0354cc28 100644 --- a/math/genwheel.c +++ b/math/genwheel.c @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/math/group-test.c b/math/group-test.c index 493ee2f7..dfbc37f1 100644 --- a/math/group-test.c +++ b/math/group-test.c @@ -29,6 +29,7 @@ #include +#include #include #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); diff --git a/math/mp-arith.c b/math/mp-arith.c index 470620ef..048f4c66 100644 --- a/math/mp-arith.c +++ b/math/mp-arith.c @@ -700,6 +700,8 @@ mp *mp_leastcongruent(mp *d, mp *b, mp *r, mp *m) #ifdef TEST_RIG +#include + 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) { diff --git a/math/mpint.c b/math/mpint.c index 3511f1ee..971edabb 100644 --- a/math/mpint.c +++ b/math/mpint.c @@ -57,6 +57,7 @@ MPINT_CONVERSIONS(TO) #ifdef TEST_RIG +#include #include static int fromuint(dstr *v) diff --git a/math/mptext.c b/math/mptext.c index c902264d..a5c77db0 100644 --- a/math/mptext.c +++ b/math/mptext.c @@ -31,6 +31,8 @@ #include #include +#include + #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) diff --git a/math/mpx.c b/math/mpx.c index 741cd9dc..07a6c20f 100644 --- a/math/mpx.c +++ b/math/mpx.c @@ -1274,6 +1274,7 @@ mpw mpx_udivn(mpw *qv, mpw *qvl, const mpw *rv, const mpw *rvl, mpw d) #include #include +#include #include #include @@ -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; } diff --git a/math/qdparse.c b/math/qdparse.c index 217cc628..9be97427 100644 --- a/math/qdparse.c +++ b/math/qdparse.c @@ -30,6 +30,8 @@ #include #include +#include + #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); diff --git a/misc/gfshare.c b/misc/gfshare.c index 80a6ef6f..09acb401 100644 --- a/misc/gfshare.c +++ b/misc/gfshare.c @@ -258,6 +258,8 @@ void gfshare_combine(gfshare *s, void *buf) #ifdef TEST_RIG +#include + #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"); }; diff --git a/progs/catcrypt.c b/progs/catcrypt.c index c31a3d93..e4d974aa 100644 --- a/progs/catcrypt.c +++ b/progs/catcrypt.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/progs/catsign.c b/progs/catsign.c index 3cce9c93..d27016ff 100644 --- a/progs/catsign.c +++ b/progs/catsign.c @@ -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) { diff --git a/progs/cc-enc.c b/progs/cc-enc.c index f4b6119f..a008fbbf 100644 --- a/progs/cc-enc.c +++ b/progs/cc-enc.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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", diff --git a/progs/cc-hash.c b/progs/cc-hash.c index 64fea0ec..6d65f5bd 100644 --- a/progs/cc-hash.c +++ b/progs/cc-hash.c @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -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; } diff --git a/progs/cc-kem.c b/progs/cc-kem.c index 9159ade7..36dfdb3d 100644 --- a/progs/cc-kem.c +++ b/progs/cc-kem.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -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; diff --git a/progs/cc-list.c b/progs/cc-list.c index 8bc22192..19ea7d5a 100644 --- a/progs/cc-list.c +++ b/progs/cc-list.c @@ -29,6 +29,7 @@ #define _FILE_OFFSET_BITS 64 +#include #include #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; } diff --git a/progs/cc-sig.c b/progs/cc-sig.c index a416c6e5..4c1defc1 100644 --- a/progs/cc-sig.c +++ b/progs/cc-sig.c @@ -31,6 +31,7 @@ #include +#include #include #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'", diff --git a/progs/cc-subcmd.c b/progs/cc-subcmd.c index 83c4a789..d593a1a3 100644 --- a/progs/cc-subcmd.c +++ b/progs/cc-subcmd.c @@ -29,6 +29,7 @@ #define _FILE_OFFSET_BITS 64 +#include #include #include @@ -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; diff --git a/progs/cookie.c b/progs/cookie.c index c6912ffd..62e23b79 100644 --- a/progs/cookie.c +++ b/progs/cookie.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/progs/dsig.c b/progs/dsig.c index 1377bcaa..3f217da6 100644 --- a/progs/dsig.c +++ b/progs/dsig.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/progs/factorial.c b/progs/factorial.c index 975c698c..ece0b305 100644 --- a/progs/factorial.c +++ b/progs/factorial.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -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]); diff --git a/progs/fibonacci.c b/progs/fibonacci.c index 4b5a9585..a494f625 100644 --- a/progs/fibonacci.c +++ b/progs/fibonacci.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/progs/hashsum.c b/progs/hashsum.c index df1fdaea..deb27d50 100644 --- a/progs/hashsum.c +++ b/progs/hashsum.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -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); } diff --git a/progs/key.c b/progs/key.c index 0c817d4d..8cd43fe7 100644 --- a/progs/key.c +++ b/progs/key.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -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", diff --git a/progs/mkphrase.c b/progs/mkphrase.c index b84d850b..db27ba26 100644 --- a/progs/mkphrase.c +++ b/progs/mkphrase.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -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"); diff --git a/progs/perftest.c b/progs/perftest.c index 6af4d515..b4a88ca9 100644 --- a/progs/perftest.c +++ b/progs/perftest.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/progs/pixie.c b/progs/pixie.c index 3fd32081..f827c201 100644 --- a/progs/pixie.c +++ b/progs/pixie.c @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/progs/rspit.c b/progs/rspit.c index 66a05389..812525fc 100644 --- a/progs/rspit.c +++ b/progs/rspit.c @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/pub/bbs-rand.c b/pub/bbs-rand.c index c7dc86e6..c3ae2682 100644 --- a/pub/bbs-rand.c +++ b/pub/bbs-rand.c @@ -374,6 +374,8 @@ grand *bbs_rand(mp *m, mp *x) #ifdef TEST_RIG +#include + 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); diff --git a/pub/dh-param.c b/pub/dh-param.c index 69e24376..5b5e403b 100644 --- a/pub/dh-param.c +++ b/pub/dh-param.c @@ -108,6 +108,8 @@ found: #ifdef TEST_RIG +#include + #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; diff --git a/pub/dsa-gen.c b/pub/dsa-gen.c index 7c6c3ba8..8802003f 100644 --- a/pub/dsa-gen.c +++ b/pub/dsa-gen.c @@ -215,6 +215,8 @@ fail_q: #ifdef TEST_RIG +#include + 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); diff --git a/pub/dsa-sign.c b/pub/dsa-sign.c index 7593a741..88054ebb 100644 --- a/pub/dsa-sign.c +++ b/pub/dsa-sign.c @@ -119,6 +119,7 @@ void dsa_sign(dsa_param *dp, mp *a, #ifdef TEST_RIG +#include #include #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); diff --git a/pub/ed25519.c b/pub/ed25519.c index 676fe8ca..83741091 100644 --- a/pub/ed25519.c +++ b/pub/ed25519.c @@ -29,6 +29,8 @@ #include +#include + #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); diff --git a/pub/ed448.c b/pub/ed448.c index 60328021..681a3ca2 100644 --- a/pub/ed448.c +++ b/pub/ed448.c @@ -29,6 +29,8 @@ #include +#include + #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); diff --git a/pub/gkcdsa.c b/pub/gkcdsa.c index 94f22aa0..23994259 100644 --- a/pub/gkcdsa.c +++ b/pub/gkcdsa.c @@ -27,6 +27,8 @@ /*----- Header files ------------------------------------------------------*/ +#include + #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); diff --git a/pub/pkcs1.c b/pub/pkcs1.c index 590c05e1..bb333514 100644 --- a/pub/pkcs1.c +++ b/pub/pkcs1.c @@ -31,6 +31,7 @@ #include #include +#include #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; diff --git a/pub/pss.c b/pub/pss.c index 8e77b78e..137b876f 100644 --- a/pub/pss.c +++ b/pub/pss.c @@ -32,6 +32,7 @@ #include #include #include +#include #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); diff --git a/pub/rsa-pub.c b/pub/rsa-pub.c index 5e13182d..bb402a3a 100644 --- a/pub/rsa-pub.c +++ b/pub/rsa-pub.c @@ -29,6 +29,7 @@ #include #include #include +#include #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; diff --git a/pub/rsa-test.c b/pub/rsa-test.c index 34b2a1f7..2ee6bbc8 100644 --- a/pub/rsa-test.c +++ b/pub/rsa-test.c @@ -27,6 +27,8 @@ /*----- Header files ------------------------------------------------------*/ +#include + #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, diff --git a/pub/x25519.c b/pub/x25519.c index f8971298..cfdfea6f 100644 --- a/pub/x25519.c +++ b/pub/x25519.c @@ -111,6 +111,7 @@ void x25519(octet zz[X25519_OUTSZ], #include #include +#include #include #include @@ -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); diff --git a/pub/x448.c b/pub/x448.c index 6bef9dd3..70ec10f4 100644 --- a/pub/x448.c +++ b/pub/x448.c @@ -97,8 +97,8 @@ void x448(octet zz[X448_OUTSZ], #ifdef TEST_RIG +#include #include -#include #include #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); diff --git a/rand/sslprf.c b/rand/sslprf.c index 06187b39..9601f4ec 100644 --- a/rand/sslprf.c +++ b/rand/sslprf.c @@ -310,6 +310,7 @@ grand *sslprf_rand(const gchash *hco, const gchash *hci, #include #include +#include #include #include @@ -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 = "); diff --git a/rand/tlsprf.c b/rand/tlsprf.c index fa28faf4..95f5b945 100644 --- a/rand/tlsprf.c +++ b/rand/tlsprf.c @@ -493,6 +493,7 @@ grand *tlsprf_rand(const gcmac *mcx, const gcmac *mcy, #include #include +#include #include #include @@ -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 = "); diff --git a/symm/blkc.h b/symm/blkc.h index bbba7631..069c1da2 100644 --- a/symm/blkc.h +++ b/symm/blkc.h @@ -400,6 +400,7 @@ #include +#include #include #include @@ -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 = "); \ diff --git a/symm/ccm-def.h b/symm/ccm-def.h index 2d864fa6..fda51795 100644 --- a/symm/ccm-def.h +++ b/symm/ccm-def.h @@ -742,6 +742,7 @@ CCM_TESTX(PRE, pre, name, fname) #include #include +#include #include #include @@ -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); \ diff --git a/symm/chacha.c b/symm/chacha.c index 90a4c674..b06deaed 100644 --- a/symm/chacha.c +++ b/symm/chacha.c @@ -849,6 +849,7 @@ CHACHA_VARS(DEFXGRAND) #include #include +#include #include #include @@ -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" \ diff --git a/symm/cmac-def.h b/symm/cmac-def.h index 701d3b52..ee8040a7 100644 --- a/symm/cmac-def.h +++ b/symm/cmac-def.h @@ -323,6 +323,7 @@ CMAC_TESTX(PRE, pre, name, fname) #include #include +#include #include #include @@ -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); \ diff --git a/symm/eax-def.h b/symm/eax-def.h index 6e1c7ca4..cf4c0010 100644 --- a/symm/eax-def.h +++ b/symm/eax-def.h @@ -700,6 +700,7 @@ EAX_TESTX(PRE, pre, name, fname) #include #include +#include #include #include @@ -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); \ diff --git a/symm/gcm-def.h b/symm/gcm-def.h index 34f95aa1..6ca58953 100644 --- a/symm/gcm-def.h +++ b/symm/gcm-def.h @@ -815,6 +815,7 @@ GCM_TESTX(PRE, pre, name, fname) #include #include +#include #include #include @@ -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); \ diff --git a/symm/gcm.c b/symm/gcm.c index 73b28517..95718945 100644 --- a/symm/gcm.c +++ b/symm/gcm.c @@ -778,6 +778,7 @@ void gcm_concat(const gcm_params *p, uint32 *z, const uint32 *x, #ifdef TEST_RIG +#include #include #include @@ -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) diff --git a/symm/gthingtab.c.in b/symm/gthingtab.c.in index 29b733b3..92fe792b 100644 --- a/symm/gthingtab.c.in +++ b/symm/gthingtab.c.in @@ -9,6 +9,8 @@ #include +#include + #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); } diff --git a/symm/hash.h b/symm/hash.h index 3d0c1179..5b2e7fb8 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -138,6 +138,7 @@ #ifdef TEST_RIG +#include #include #include @@ -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); \ diff --git a/symm/hmac-def.h b/symm/hmac-def.h index 9ac8fb9b..76d578d8 100644 --- a/symm/hmac-def.h +++ b/symm/hmac-def.h @@ -359,6 +359,7 @@ HMAC_TESTX(PRE, pre, name, fname) #include +#include #include #include #include @@ -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); \ diff --git a/symm/keccak1600.c b/symm/keccak1600.c index c2d82926..cfbfdefe 100644 --- a/symm/keccak1600.c +++ b/symm/keccak1600.c @@ -649,6 +649,7 @@ void keccak1600_extract(const keccak1600_state *s, kludge64 *p, size_t n) #include +#include #include #include #include @@ -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); diff --git a/symm/latinpoly-test.c b/symm/latinpoly-test.c index 5a914e50..f7a20763 100644 --- a/symm/latinpoly-test.c +++ b/symm/latinpoly-test.c @@ -27,6 +27,8 @@ /*----- Header files ------------------------------------------------------*/ +#include + #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"); diff --git a/symm/modes-test.c b/symm/modes-test.c index b06d230a..a6c28bad 100644 --- a/symm/modes-test.c +++ b/symm/modes-test.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #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); diff --git a/symm/ocb1-def.h b/symm/ocb1-def.h index 7c7eb295..2820aae1 100644 --- a/symm/ocb1-def.h +++ b/symm/ocb1-def.h @@ -520,6 +520,7 @@ OCB1_TESTX(PRE, pre, name, fname) #include #include +#include #include #include @@ -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); \ diff --git a/symm/ocb3-def.h b/symm/ocb3-def.h index 14a22f61..31293cb4 100644 --- a/symm/ocb3-def.h +++ b/symm/ocb3-def.h @@ -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); \ diff --git a/symm/pmac1-def.h b/symm/pmac1-def.h index 4b0da048..5df93385 100644 --- a/symm/pmac1-def.h +++ b/symm/pmac1-def.h @@ -288,6 +288,7 @@ PMAC1_TESTX(PRE, pre, name, fname) #include #include +#include #include #include @@ -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); \ diff --git a/symm/poly1305.c b/symm/poly1305.c index c4a88a84..da4594fa 100644 --- a/symm/poly1305.c +++ b/symm/poly1305.c @@ -861,6 +861,7 @@ void poly1305_done(poly1305_ctx *ctx, void *h) #ifdef TEST_RIG +#include #include #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); diff --git a/symm/rc2.c b/symm/rc2.c index df594251..97963fef 100644 --- a/symm/rc2.c +++ b/symm/rc2.c @@ -250,6 +250,7 @@ void rc2_dblk(const rc2_ctx *k, const uint32 *s, uint32 *dst) #ifdef TEST_RIG +#include #include #include @@ -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 = "); diff --git a/symm/rc4.c b/symm/rc4.c index 214dbc17..4cb0e87d 100644 --- a/symm/rc4.c +++ b/symm/rc4.c @@ -296,6 +296,7 @@ grand *rc4_rand(const void *k, size_t sz) #include #include +#include #include #include @@ -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 = "); diff --git a/symm/salsa20.c b/symm/salsa20.c index e7c35f4f..7806e6ca 100644 --- a/symm/salsa20.c +++ b/symm/salsa20.c @@ -871,6 +871,7 @@ SALSA20_VARS(DEFXGRAND) #include #include +#include #include #include @@ -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" \ diff --git a/symm/seal.c b/symm/seal.c index a4a0a3f8..070550dd 100644 --- a/symm/seal.c +++ b/symm/seal.c @@ -521,6 +521,7 @@ grand *seal_rand(const void *k, size_t sz, uint32 n) #include +#include #include 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'); diff --git a/symm/serpent-check.c b/symm/serpent-check.c index 7f95ffc7..190096fb 100644 --- a/symm/serpent-check.c +++ b/symm/serpent-check.c @@ -32,6 +32,7 @@ #include #include +#include #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 { \ diff --git a/symm/sha3.c b/symm/sha3.c index 16967629..36bd430b 100644 --- a/symm/sha3.c +++ b/symm/sha3.c @@ -957,6 +957,7 @@ grand *kmac256_rand(const void *perso, size_t psz, const void *k, size_t sz) #include +#include #include #include @@ -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); diff --git a/symm/strobe.c b/symm/strobe.c index 8d4d42da..de4dbb2d 100644 --- a/symm/strobe.c +++ b/symm/strobe.c @@ -468,6 +468,7 @@ void strobe_ratchet(strobe_ctx *ctx, unsigned f, size_t sz) #include #include +#include #include #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); diff --git a/utils/ecptdecompress.c b/utils/ecptdecompress.c index e4386964..61fb79f2 100644 --- a/utils/ecptdecompress.c +++ b/utils/ecptdecompress.c @@ -5,6 +5,7 @@ #include #include #include +#include #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); } -- 2.11.0