chiark / gitweb /
symm/BLKMODE-def.h: Fix alignment of separators in hexdump output.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 21 May 2016 10:07:15 +0000 (11:07 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 21 May 2016 16:50:26 +0000 (17:50 +0100)
Now the `:' markers actually correspond with the block boundaries.
Amazing, no?

symm/cbc-def.h
symm/cfb-def.h
symm/counter-def.h
symm/ecb-def.h
symm/ofb-def.h

index f48ee460c46783730871c28424c48e5605c08344..56c8f0542eaaf4b4409d811fe08fc074f2f4a402 100644 (file)
@@ -467,12 +467,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(':');                                                    \
   }                                                                    \
 }                                                                      \
@@ -513,14 +513,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);                                             \
     }                                                                  \
index 767f4c42b58f00407801c6b6c77024d1184f94cf..4f0f38f4438bd205f874f6ab640e58e33bde0fff 100644 (file)
@@ -426,12 +426,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(':');                                                    \
   }                                                                    \
 }                                                                      \
@@ -472,14 +472,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);                                             \
     }                                                                  \
index ead615a3a5938960ddfd2b58f9a0c490e372e215..455367956804c5712a886a9086d52b73784c7479 100644 (file)
@@ -453,12 +453,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(':');                                                    \
   }                                                                    \
 }                                                                      \
@@ -499,14 +499,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);                                             \
     }                                                                  \
index ea153a27a0b475449ae31df98b9c43ce753ca803..9f50292e529dec2f369805262a4fd88339beb980 100644 (file)
@@ -391,12 +391,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(':');                                                    \
   }                                                                    \
 }                                                                      \
@@ -436,14 +436,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);                                             \
     }                                                                  \
index 7f111cb910f155182adee2dc710d54aea5dd697a..358ee54c12ff9323438b0fc483369346b966d037 100644 (file)
@@ -465,12 +465,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(':');                                                    \
   }                                                                    \
 }                                                                      \
@@ -511,14 +511,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);                                             \
     }                                                                  \