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);
#include <stdlib.h>
#include <string.h>
+#include <mLib/macros.h>
+
static const struct entry {
const char *name;
double (*func)(double);
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);
#include <mLib/alloc.h>
#include <mLib/bits.h>
#include <mLib/darray.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/testrig.h>
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);
}
#include <time.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/sym.h>
#include "key.h"
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++;
}
/* --- 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 --- */
#include <mLib/bits.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/sub.h>
#include <mLib/sym.h>
#include <mLib/bits.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include "key-data.h"
/* --- 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;
#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>
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));
* maintained file I don't know.
*/
- while (isspace((unsigned char)*p))
+ while (ISSPACE(*p))
p++;
if (!*p || *p == '#')
goto skip;
/* --- 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);
#include <mLib/bits.h>
#include <mLib/hash.h>
+#include <mLib/macros.h>
#include <mLib/sub.h>
#include <mLib/sym.h>
#include <mLib/dstr.h>
+#include "ct.h"
#include "key-data.h"
#include "paranoia.h"
#include "passphrase.h"
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;
}
#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>
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++;
}
#include <unistd.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include "passphrase.h"
#include "pixie.h"
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;
}
#include <mLib/alloc.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/str.h>
#include "pixie.h"
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 --- */
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;
}
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;
}
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include "bitops.h"
#include "mpx.h"
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; \
} \
#ifdef TEST_RIG
+#include <mLib/macros.h>
+
static void ecdestroy(ec_curve *c)
{
field *f = c->f;
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);
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);
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);
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/str.h>
#include <mLib/testrig.h>
}
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 },
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/str.h>
#include <mLib/testrig.h>
}
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 },
#include <ctype.h>
+#include <mLib/macros.h>
#include <mLib/sub.h>
#define ge ec
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;
#include <mLib/darray.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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);
#include <mLib/darray.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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);
#include <stdarg.h>
+#include <mLib/macros.h>
#include <mLib/testrig.h>
#include "group.h"
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);
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);
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);
#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)) {
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) {
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/testrig.h>
static int fromuint(dstr *v)
#include <limits.h>
#include <stdio.h>
+#include <mLib/macros.h>
+
#include "mp.h"
#include "mptext.h"
#include "paranoia.h"
/* --- 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));
}
}
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)
}
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)
#include <mLib/alloc.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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;
}
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;
}
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;
}
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;
}
#include <ctype.h>
#include <string.h>
+#include <mLib/macros.h>
+
#include "qdparse.h"
/*----- Main code ---------------------------------------------------------*/
void qd_skipspc(qd_parse *qd)
{
- while (isspace((unsigned char)*qd->p))
+ while (ISSPACE(*qd->p))
qd->p++;
}
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);
}
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);
#ifdef TEST_RIG
+#include <mLib/macros.h>
+
#include "fibrand.h"
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");
};
#include <mLib/base64.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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",
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",
/* --- Now decrypt the main body --- */
- if (!of || strcmp(of, "-") == 0) {
+ if (!of || STRCMP(of, ==, "-")) {
ofp = stdout;
f |= f_buffer;
}
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++;
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)
}
} 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));
}
}
} 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));
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",
{
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);
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;
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",
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);
}
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)) {
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",
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",
}
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",
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) {
#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>
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)
{
/* --- 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 --- */
}
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);
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);
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",
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",
#include <mLib/alloc.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/str.h>
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];
const encodeops *e;
for (e = encodingtab; e->name; e++) {
- if (strcmp(ename, e->name) == 0)
+ if (STRCMP(ename, ==, e->name))
return (e);
}
return (0);
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;
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);
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 (;;) {
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);
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);
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);
}
again:
ch = nextch(in);
- while (isspace(ch))
+ while (ISSPACE(ch))
ch = nextch(in);
if (ch == '#') {
do ch = nextch(in); while (ch != '\n' && ch != eofch);
if (ch == q)
break;
- if (!q && isspace(ch))
+ if (!q && ISSPACE(ch))
break;
/* --- Otherwise contribute and continue --- */
qq = 0;
for (q = p; *q; q++) {
- if (isspace((unsigned char)*q)) {
+ if (ISSPACE(*q)) {
qq = '\"';
break;
}
#include <mLib/alloc.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/sub.h>
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'",
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
/* --- 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'",
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;
#define _FILE_OFFSET_BITS 64
+#include <mLib/macros.h>
#include <mLib/report.h>
#include "cc.h"
} 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;
}
#include <stdlib.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include "rand.h"
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
/* --- 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'",
#define _FILE_OFFSET_BITS 64
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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;
#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>
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
/* --- 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);
#include <mLib/alloc.h>
#include <mLib/base64.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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);
} 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);
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");
/* --- 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",
}
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;
#include <stdio.h>
#include <stdlib.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
}
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]);
#include <stdio.h>
#include <stdlib.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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);
#include <mLib/alloc.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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));
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
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));
{
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);
}
#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>
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);
/* --- 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);
/* --- 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);
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);
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;
/* --- 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);
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);
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)
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)
{
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);
}
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);
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)
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;
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",
#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>
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);
break;
continue;
}
- ch = tolower(ch);
+ ch = TOLOWER(ch);
if (strchr(wchars, ch)) {
DPUTC(&d, ch);
f = 1;
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++;
continue;
}
- if ((q = strchr(wchars, tolower(ch))) == 0)
+ if ((q = strchr(wchars, TOLOWER(ch))) == 0)
continue;
l = q - wchars;
n->count++;
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;
ctx = ops->init();
while (*argv) {
- if (strcmp(*argv, "-") == 0)
+ if (STRCMP(*argv, ==, "-"))
ops->scan(stdin, ctx);
else {
FILE *fp = fopen(*argv, "r");
#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>
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);
#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>
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);
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);
ok: {
char *p = buf;
size_t len;
- while (isspace((unsigned char)*p))
+ while (ISSPACE(*p))
p++;
len = strlen(p);
memmove(buf, p, len);
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);
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\
/* --- List the passphrases --- */
- else if (strcmp(q, "list") == 0) {
+ else if (STRCMP(q, ==, "list")) {
phrase *p;
for (p = p_head; p; p = p->next) {
/* --- 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;
/* --- 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;
/* --- 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) {
} 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 {
/* --- 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");
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);
#include <mLib/darray.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/mdwopt.h>
#include <mLib/quis.h>
#include <mLib/report.h>
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");
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;
#ifdef TEST_RIG
+#include <mLib/macros.h>
+
static int verify(dstr *v)
{
mp *n = *(mp **)v[0].buf;
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);
#ifdef TEST_RIG
+#include <mLib/macros.h>
+
#include "fibrand.h"
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;
#ifdef TEST_RIG
+#include <mLib/macros.h>
+
static int verify(dstr *v)
{
mp *q = *(mp **)v[4].buf;
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);
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/testrig.h>
#include "sha.h"
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);
#include <string.h>
+#include <mLib/macros.h>
+
#include "f25519.h"
#include "ed25519.h"
#include "scaf.h"
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);
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);
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);
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);
#include <string.h>
+#include <mLib/macros.h>
+
#include "fgoldi.h"
#include "ed448.h"
#include "scaf.h"
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);
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);
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);
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);
/*----- Header files ------------------------------------------------------*/
+#include <mLib/macros.h>
+
#include "dsa.h"
#include "gkcdsa.h"
#include "group.h"
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);
}
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);
#include <mLib/bits.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include "ct.h"
#include "grand.h"
/* --- 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;
#include <mLib/alloc.h>
#include <mLib/bits.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include "gcipher.h"
#include "ghash.h"
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);
#include <mLib/alloc.h>
#include <mLib/bits.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include "mp.h"
#include "mpmont.h"
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;
/*----- Header files ------------------------------------------------------*/
+#include <mLib/macros.h>
+
#include "fibrand.h"
#include "rsa.h"
#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,
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/testrig.h>
(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);
}
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);
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/report.h>
-#include <mLib/str.h>
#include <mLib/testrig.h>
#include "ct.h"
(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);
}
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);
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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 = ");
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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 = ");
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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 = "); \
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 = "); \
#include <stdio.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
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); \
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
} \
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" \
} \
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" \
#include <stdio.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
#include <stdio.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
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); \
#include <stdio.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
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); \
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
#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)
#include <string.h>
+#include <mLib/macros.h>
+
#include "@what.h"
%repeat
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);
}
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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 = "); \
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); \
#include <stdio.h>
+#include <mLib/macros.h>
#include <mLib/dstr.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
#include <stdio.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/report.h>
#include <mLib/testrig.h>
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);
/*----- Header files ------------------------------------------------------*/
+#include <mLib/macros.h>
+
#include "latinpoly-def.h"
/*----- Main code ---------------------------------------------------------*/
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);
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");
#include <mLib/bits.h>
#include <mLib/dstr.h>
#include <mLib/quis.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include "modes-test.h"
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();
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++;
}
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);
}
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);
#include <stdio.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
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); \
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); \
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); \
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); \
#include <stdio.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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); \
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/testrig.h>
#include "ct.h"
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);
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);
}
}
- 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);
#ifdef TEST_RIG
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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 = ");
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 = ");
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
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 = ");
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 = ");
#include <stdio.h>
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/quis.h>
#include <mLib/testrig.h>
} \
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" \
} \
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" \
#include <string.h>
+#include <mLib/macros.h>
#include <mLib/testrig.h>
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');
#include <string.h>
#include <mLib/bits.h>
+#include <mLib/macros.h>
#include "serpent-sbox.h"
*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 { \
#include <stdio.h>
+#include <mLib/macros.h>
#include <mLib/report.h>
#include <mLib/testrig.h>
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);
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);
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);
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);
#include <string.h>
#include <mLib/hex.h>
+#include <mLib/macros.h>
#include <mLib/testrig.h>
#define NSTATE 16
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 {
/* 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:
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);
#include <mLib/alloc.h>
#include <mLib/hex.h>
#include <mLib/dstr.h>
+#include <mLib/macros.h>
#include "ec.h"
#include "mp.h"
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);
}