From 12331b2df6b898d74eaee321eda4b0fe703031e5 Mon Sep 17 00:00:00 2001 Message-Id: <12331b2df6b898d74eaee321eda4b0fe703031e5.1718465994.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 21 May 2016 11:07:15 +0100 Subject: [PATCH] symm/BLKMODE-def.h: Fix alignment of separators in hexdump output. Organization: Straylight/Edgeware From: Mark Wooding Now the `:' markers actually correspond with the block boundaries. Amazing, no? --- symm/cbc-def.h | 16 ++++++++-------- symm/cfb-def.h | 16 ++++++++-------- symm/counter-def.h | 16 ++++++++-------- symm/ecb-def.h | 16 ++++++++-------- symm/ofb-def.h | 16 ++++++++-------- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/symm/cbc-def.h b/symm/cbc-def.h index f48ee460..56c8f054 100644 --- a/symm/cbc-def.h +++ b/symm/cbc-def.h @@ -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); \ } \ diff --git a/symm/cfb-def.h b/symm/cfb-def.h index 767f4c42..4f0f38f4 100644 --- a/symm/cfb-def.h +++ b/symm/cfb-def.h @@ -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); \ } \ diff --git a/symm/counter-def.h b/symm/counter-def.h index ead615a3..45536795 100644 --- a/symm/counter-def.h +++ b/symm/counter-def.h @@ -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); \ } \ diff --git a/symm/ecb-def.h b/symm/ecb-def.h index ea153a27..9f50292e 100644 --- a/symm/ecb-def.h +++ b/symm/ecb-def.h @@ -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); \ } \ diff --git a/symm/ofb-def.h b/symm/ofb-def.h index 7f111cb9..358ee54c 100644 --- a/symm/ofb-def.h +++ b/symm/ofb-def.h @@ -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); \ } \ -- [mdw]