symm/...: Reformat encryption mode loops and related code.
[catacomb] / symm / blkc.h
index e0374f1..608dfcd 100644 (file)
 
 #define BLKC_SHOW(PRE, tag, w) do {                                    \
   fputs(tag ": ", stdout);                                             \
-  BLKC_SKEL_X(PRE, BLKC_W(w);, printf("%08x ", *_w++););               \
+  BLKC_SKEL_X(PRE, const BLKC_W(w);, printf("%08x ", *_w++););         \
   fputc('\n', stdout);                                                 \
 } while (0)
 
   guts                                                                 \
 } while (0)
 
-#define BLKC_P(p) register octet *_p = (octet *)(p)
-#define BLKC_W(w) register uint32 *_w = (w)
-#define BLKC_WX(wx) register uint32 *_wx = (wx)
+#define BLKC_P(p) octet *_p = (octet *)(p)
+#define BLKC_W(w) uint32 *_w = (w)
+#define BLKC_WX(wx) uint32 *_wx = (wx)
 
 /* --- Implementation for unusual block sizes --- */
 
 #define BLKC_SKEL_X(PRE, decl, guts)                                   \
   BLKC_SKEL(PRE, unsigned _i; decl,                                    \
-           for (_i = 0; _i < PRE##_BLKSZ / 4; _i++) {                  \
+           for (_i = 0; _i < PRE##_BLKSZ/4; _i++) {                    \
              guts                                                      \
            })
 
   BLKC_SKEL_X(PRE, BLKC_W(w);, *_w++ = 0;)
 
 #define BLKC_STEP_X_B(PRE, w) do {                                     \
-  unsigned _i = PRE##_BLKSZ / 4; BLKC_W(w); uint32 _x = 0;             \
+  unsigned _i = PRE##_BLKSZ/4; BLKC_W(w); uint32 _x = 0;               \
   while (_i && !_x) { _i--; _w[_i] = _x = U32(_w[_i] + 1); }           \
 } while (0)
 
 #define BLKC_STEP_X_L(PRE, w) do {                                     \
   unsigned _i = 0; BLKC_W(w); uint32 _x = 0;                           \
-  while (_i < PRE##_BLKSZ / 4 && !_x)                                  \
+  while (_i < PRE##_BLKSZ/4 && !_x)                                    \
     { _w[_i] = _x = U32(_w[_i] + 1); _i++; }                           \
 } while (0)
 
 #define BLKC_SET_X_B(PRE, w, x) do {                                   \
   unsigned _i; BLKC_W(w); unsigned long _x = x;                                \
-  for (_i = 0; _i < PRE##_BLKSZ / 4; _i++) {                           \
+  for (_i = 0; _i < PRE##_BLKSZ/4; _i++) {                             \
     *_w++ = U32(_x);                                                   \
-    _x = ((_x & ~MASK32) >> 16) >> 16;                                 \
+    _x = ((_x & ~(unsigned long)MASK32) >> 16) >> 16;                  \
   }                                                                    \
 } while (0)
 
 #define BLKC_SET_X_L(PRE, w, x) do {                                   \
-  unsigned _i; BLKC_W(w); unsigned long _x = x;        _w += PRE##_BLKSZ / 4;  \
-  for (_i = 0; _i < PRE##_BLKSZ / 4; _i++) {                           \
+  unsigned _i; BLKC_W(w); unsigned long _x = x; _w += PRE##_BLKSZ/4;   \
+  for (_i = 0; _i < PRE##_BLKSZ/4; _i++) {                             \
     *--_w = U32(_x);                                                   \
-    _x = ((_x & ~MASK32) >> 16) >> 16;                                 \
+    _x = ((_x & ~(unsigned long)MASK32) >> 16) >> 16;                  \
   }                                                                    \
 } while (0)
 
 static int pre##_verify(dstr *v)                                       \
 {                                                                      \
   pre##_ctx k;                                                         \
-  uint32 p[PRE##_BLKSZ / 4];                                           \
-  uint32 c[PRE##_BLKSZ / 4];                                           \
-  uint32 d[PRE##_BLKSZ / 4];                                           \
+  uint32 p[PRE##_BLKSZ/4];                                             \
+  uint32 c[PRE##_BLKSZ/4];                                             \
+  uint32 d[PRE##_BLKSZ/4];                                             \
   dstr b = DSTR_INIT;                                                  \
   int ok = 1;                                                          \
                                                                        \
@@ -318,12 +318,17 @@ static int pre##_verify(dstr *v)                                  \
   return (ok);                                                         \
 }
 
+#define BLKC_TESTDEFS(PRE, pre) BLKC_TESTDEFSX(PRE, pre, #pre)
+
+#define BLKC_TESTDEFSX(PRE, pre, name)                                 \
+  { name, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } },
+
 #define BLKC_TESTX(PRE, pre, name, fname)                              \
                                                                        \
 BLKC_VERIFYX(PRE, pre, name)                                           \
                                                                        \
 static const test_chunk defs[] = {                                     \
-  { name, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } },      \
+  BLKC_TESTDEFSX(PRE, pre, name)                                       \
   { 0, 0, { 0 } }                                                      \
 };                                                                     \
                                                                        \