#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();
*
* * @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
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++;
}
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
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);