progs/perftest.c: Use from Glibc syscall numbers.
[catacomb] / symm / modes-test.c
index bbda53b..a6c28ba 100644 (file)
@@ -38,6 +38,7 @@
 #include <mLib/bits.h>
 #include <mLib/dstr.h>
 #include <mLib/quis.h>
+#include <mLib/macros.h>
 #include <mLib/report.h>
 
 #include "modes-test.h"
@@ -164,7 +165,7 @@ static int regress_data(int rmode, FILE *fp, const char *what,
       if (!fread(t, sz, 1, fp))
        die(1, "failed to read %s: %s", what,
            ferror(fp) ? strerror(errno) : "unexpected eof");
-      if (memcmp(p, t, sz) != 0) return (-1);
+      if (MEMCMP(p, !=, t, sz)) return (-1);
       return (0);
     default:
       abort();
@@ -303,7 +304,8 @@ static int step(size_t *sz_inout, size_t max)
  *
  *               * @enc@ is called to encrypt a source buffer @s@ and write
  *                 the ciphertext to a destination @d@; @sz@ is the common
- *                 size of these buffers.
+ *                 size of these buffers.  @d@ might be null, to discard
+ *                 output; @s@ might be null, to process all-zero input.
  *
  *               * @dec@ is called to decrypt a source buffer @s@ and write
  *                 the recovered plaintext to a destination @d@; @sz@ is the
@@ -371,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++;
     }
@@ -451,15 +453,21 @@ int test_encmode(const char *name,
     sz2 = TEXTSZ - sz1 - sz0;
     ok = 1;
 
-    /* Encrypt the three fragments. */
+    /* Encrypt the last fragment first, to check discarding behaviour. */
+    if (sz2) {
+      reset(iv);
+      enc(text, 0, sz0);
+      enc(text + sz0, 0, sz1);
+      enc(text + sz0 + sz1, ct + sz0 + sz1, sz2);
+    }
+
+    /* Encrypt the first two fragments. */
     reset(iv);
     enc(text, ct, sz0);
     if (sz1) {
       memcpy(ct + sz0, text + sz0, sz1);
       enc(ct + sz0, ct + sz0, sz1);
     }
-    if (sz2)
-      enc(text + sz0 + sz1, ct + sz0 + sz1, sz2);
 
     /* Try to check consistency.  We can't do this if (a) the mode is
      * non-resumable and the fragments sizes are misaligned, or (b) this is
@@ -471,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);
@@ -502,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);