*.c: Check for ARM64 SIMD before using the accelerated code.
[catacomb] / symm / cbc-def.h
index f48ee46..907a5db 100644 (file)
@@ -64,7 +64,9 @@
  * Use:                Creates an implementation for CBC stealing mode.
  */
 
-#define CBC_DEF(PRE, pre)                                              \
+#define CBC_DEF(PRE, pre) CBC_DEFX(PRE, pre, #pre, #pre)
+
+#define CBC_DEFX(PRE, pre, name, fname)                                        \
                                                                        \
 /* --- @pre_cbcgetiv@ --- *                                            \
  *                                                                     \
@@ -430,14 +432,16 @@ static const gcipher_ops gops = {                                 \
 };                                                                     \
                                                                        \
 const gccipher pre##_cbc = {                                           \
-  #pre "-cbc", pre##_keysz, PRE##_BLKSZ,                               \
+  name "-cbc", pre##_keysz, PRE##_BLKSZ,                               \
   ginit                                                                        \
 };                                                                     \
                                                                        \
-CBC_TEST(PRE, pre)
+CBC_TESTX(PRE, pre, name, fname)
 
 /*----- Test rig ----------------------------------------------------------*/
 
+#define CBC_TEST(PRE, pre) CBC_TESTX(PRE, pre, #pre, #pre)
+
 #ifdef TEST_RIG
 
 #include <stdio.h>
@@ -451,7 +455,7 @@ CBC_TEST(PRE, pre)
  * Use:                Standard test rig for CBC functions.
  */
 
-#define CBC_TEST(PRE, pre)                                             \
+#define CBC_TESTX(PRE, pre, name, fname)                               \
                                                                        \
 /* --- Initial plaintext for the test --- */                           \
                                                                        \
@@ -467,12 +471,12 @@ static const octet iv[] = IV;                                             \
 static octet ct[sizeof(text)];                                         \
 static octet pt[sizeof(text)];                                         \
                                                                        \
-static void hexdump(const octet *p, size_t sz)                         \
+static void hexdump(const octet *p, size_t sz, size_t off)             \
 {                                                                      \
   const octet *q = p + sz;                                             \
   for (sz = 0; p < q; p++, sz++) {                                     \
     printf("%02x", *p);                                                        \
-    if ((sz + 1) % PRE##_BLKSZ == 0)                                   \
+    if ((off + sz + 1) % PRE##_BLKSZ == 0)                             \
       putchar(':');                                                    \
   }                                                                    \
 }                                                                      \
@@ -488,7 +492,7 @@ int main(void)                                                              \
   size_t keysz = PRE##_KEYSZ ?                                         \
     PRE##_KEYSZ : strlen((const char *)key);                           \
                                                                        \
-  fputs(#pre "-cbc: ", stdout);                                                \
+  fputs(name "-cbc: ", stdout);                                                \
                                                                        \
   pre##_init(&k, key, keysz);                                          \
   pre##_cbcsetkey(&ctx, &k);                                           \
@@ -513,14 +517,14 @@ int main(void)                                                            \
     } else {                                                           \
       printf("\nError (sz = %lu)\n", (unsigned long)sz);               \
       status = 1;                                                      \
-      printf("\tplaintext      = "); hexdump(text, sz);                        \
-       printf(", "); hexdump(text + sz, rest);                         \
+      printf("\tplaintext      = "); hexdump(text, sz, 0);             \
+       printf(", "); hexdump(text + sz, rest, sz);                     \
        fputc('\n', stdout);                                            \
-      printf("\tciphertext     = "); hexdump(ct, sz);                  \
-       printf(", "); hexdump(ct + sz, rest);                           \
+      printf("\tciphertext     = "); hexdump(ct, sz, 0);               \
+       printf(", "); hexdump(ct + sz, rest, sz);                       \
        fputc('\n', stdout);                                            \
-      printf("\trecovered text = "); hexdump(pt, sz);                  \
-       printf(", "); hexdump(pt + sz, rest);                           \
+      printf("\trecovered text = "); hexdump(pt, sz, 0);               \
+       printf(", "); hexdump(pt + sz, rest, sz);                       \
        fputc('\n', stdout);                                            \
       fputc('\n', stdout);                                             \
     }                                                                  \
@@ -535,7 +539,7 @@ int main(void)                                                              \
 }
 
 #else
-#  define CBC_TEST(PRE, pre)
+#  define CBC_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/