symm/ecb-def.h: Simplify the discarding-output path.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 30 Oct 2018 10:26:05 +0000 (10:26 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 25 Nov 2018 11:38:04 +0000 (11:38 +0000)
Because ECB is stateless, there is nothing to do if we discard the
output.

symm/ecb-def.h

index 957a16e..c69790d 100644 (file)
@@ -126,9 +126,9 @@ void pre##_ecbencrypt(pre##_ecbctx *ctx,                            \
   octet y;                                                             \
   unsigned i;                                                          \
                                                                        \
-  /* --- Empty blocks are trivial --- */                               \
+  /* --- Empty blocks are trivial, and ECB is stateless --- */         \
                                                                        \
-  if (!sz) return;                                                     \
+  if (!sz || !d) return;                                               \
                                                                        \
   /* --- Short blocks aren't allowed in ECB --- *                      \
    *                                                                   \
@@ -149,7 +149,7 @@ void pre##_ecbencrypt(pre##_ecbctx *ctx,                            \
     if (!s) BLKC_ZERO(PRE, t);                                         \
     else { BLKC_LOAD(PRE, t, s); s += PRE##_BLKSZ; }                   \
     pre##_eblk(&ctx->ctx, t, t);                                       \
-    if (d) { BLKC_STORE(PRE, d, t); d += PRE##_BLKSZ; }                        \
+    BLKC_STORE(PRE, d, t); d += PRE##_BLKSZ;                           \
     sz -= PRE##_BLKSZ;                                                 \
   }                                                                    \
                                                                        \
@@ -183,11 +183,11 @@ void pre##_ecbencrypt(pre##_ecbctx *ctx,                          \
      * ciphertext block.                                               \
      */                                                                        \
                                                                        \
-    if (d) d += PRE##_BLKSZ;                                           \
-    for (i = 0; i < sz; i++) { y = b[i]; b[i] = s[i]; if (d) d[i] = y; } \
+    d += PRE##_BLKSZ;                                                  \
+    for (i = 0; i < sz; i++) { y = b[i]; b[i] = s[i]; d[i] = y; }      \
     BLKC_LOAD(PRE, t, b);                                              \
     pre##_eblk(&ctx->ctx, t, t);                                       \
-    if (d) BLKC_STORE(PRE, d - PRE##_BLKSZ, t);                                \
+    BLKC_STORE(PRE, d - PRE##_BLKSZ, t);                               \
   }                                                                    \
                                                                        \
   /* --- Done --- */                                                   \