progs/key.c: Use `HASH' rather than `HASHALG' to denote a hash-function name.
[catacomb] / progs / key.c
index 74060cd..9c9466b 100644 (file)
@@ -42,6 +42,7 @@
 #include <mLib/base32.h>
 #include <mLib/base64.h>
 #include <mLib/hex.h>
+#include <mLib/macros.h>
 #include <mLib/mdwopt.h>
 #include <mLib/quis.h>
 #include <mLib/report.h>
@@ -73,6 +74,7 @@
 #include "x25519.h"
 #include "x448.h"
 #include "ed25519.h"
+#include "ed448.h"
 
 #include "cc.h"
 #include "sha-mgf.h"
@@ -601,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);
@@ -769,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);
@@ -868,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);
@@ -975,7 +977,8 @@ XDHS(XDHALG)
 #undef XDHALG
 
 #define EDDSAS(_)                                                      \
-  _(ed25519, ED25519, "Ed25519")
+  _(ed25519, ED25519, "Ed25519")                                       \
+  _(ed448, ED448, "Ed448")
 
 #define EDDSAALG(ed, ED, name)                                         \
                                                                        \
@@ -1091,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);
@@ -1099,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;
@@ -1138,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);
@@ -1176,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);
@@ -1185,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)
@@ -1318,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)
@@ -1823,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);
 }
 
@@ -1868,7 +1871,7 @@ static int cmd_finger(int argc, char *argv[])
   argv += optind; argc -= optind;
   if (rc) {
     die(EXIT_FAILURE,
-       "Usage: fingerprint [-a HASHALG] [-p STYLE] [-f FILTER] [TAG...]");
+       "Usage: fingerprint [-a HASH] [-p STYLE] [-f FILTER] [TAG...]");
   }
 
   doopen(&f, KOPEN_READ);
@@ -1942,7 +1945,7 @@ static int cmd_verify(int argc, char *argv[])
   argv += optind; argc -= optind;
   if (rc || argc != 2) {
     die(EXIT_FAILURE,
-       "Usage: verify [-a HASHALG] [-p STYLE] [-f FILTER] TAG FINGERPRINT");
+       "Usage: verify [-a HASH] [-p STYLE] [-f FILTER] TAG FINGERPRINT");
   }
 
   doopen(&f, KOPEN_READ);
@@ -1967,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);
@@ -2026,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)
@@ -2120,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;
@@ -2176,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",
@@ -2231,7 +2234,7 @@ Options:\n\
 -v, --verbose          Show more information.\n\
 " },
   { "fingerprint", cmd_finger,
-    "fingerprint [-a HASHALG] [-p STYLE] [-f FILTER] [TAG...]", "\
+    "fingerprint [-a HASH] [-p STYLE] [-f FILTER] [TAG...]", "\
 Options:\n\
 \n\
 -f, --filter=FILT      Only hash key components matching FILT.\n\