symm/: Allow block cipher and hash functions with strange names.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 10 May 2017 18:29:41 +0000 (19:29 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 14 May 2017 13:58:41 +0000 (14:58 +0100)
This is quite a performance, actually.

  * The `multigen' tool now has a modifier `:f' which makes a filename-
    safe version of a value.

  * The `multigen' input files and `Makefile.am' have been changed to
    use `:f' appropriately.

  * All of the `MUMBLE-def.h' header files have been changed to
    introduce a new macro `MUMBLE_DEFX' with two extra arguments: the
    thing's presentable name (for use in class structures), and a
    filename-safe version of it.  The old `MUMBLE_DEF' macro still
    exists for compatibility (has anyone else written a mode?).

  * Similar changes have been made to the testing machinery in `blkc.h'
    and `hash.h', but this still needs cleaning up somewhat.

16 files changed:
symm/Makefile.am
symm/blkc.h
symm/cbc-def.h
symm/cfb-def.h
symm/counter-def.h
symm/ecb-def.h
symm/ghash-def.h
symm/gthingtab.c.in
symm/hash.h
symm/hmac-def.h
symm/mgf-def.h
symm/mode.c.in
symm/mode.h.in
symm/modes.am.in
symm/multigen
symm/ofb-def.h

index c30fd7e..3cd98cf 100644 (file)
@@ -486,16 +486,16 @@ MAINTAINERCLEANFILES      += modes/gen-stamp
 modes/gen-stamp: Makefile.am
        $(AM_V_at)$(MKDIR_P) $(srcdir)/modes
        $(AM_V_GEN)$(multigen) -g $(srcdir)/mode.c.in \
-               $(srcdir)/modes/@base-@mode.c \
+               $(srcdir)/modes/@{base:f}-@mode.c \
                base="$(BLKCS)" mode="$(BLKCMODES)"
        $(AM_V_at)$(multigen) -g $(srcdir)/mode.h.in \
-               $(srcdir)/modes/@base-@mode.h \
+               $(srcdir)/modes/@{base:f}-@mode.h \
                base="$(BLKCS)" mode="$(BLKCMODES)"
        $(AM_V_at)$(multigen) -g $(srcdir)/mode.c.in \
-               $(srcdir)/modes/@base-@mode.c \
+               $(srcdir)/modes/@{base:f}-@mode.c \
                base="$(HASHES)" mode="$(HASHMODES)"
        $(AM_V_at)$(multigen) -g $(srcdir)/mode.h.in \
-               $(srcdir)/modes/@base-@mode.h \
+               $(srcdir)/modes/@{base:f}-@mode.h \
                base="$(HASHES)" mode="$(HASHMODES)"
        $(AM_V_at)touch $(srcdir)/modes/gen-stamp
 
index d6e3da0..e0374f1 100644 (file)
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
-#define BLKC_VERIFY(PRE, pre)                                          \
+#define BLKC_VERIFY(PRE, pre) BLKC_VERIFYX(PRE, pre, #pre)
+
+#define BLKC_VERIFYX(PRE, pre, name)                                   \
                                                                        \
 static int pre##_verify(dstr *v)                                       \
 {                                                                      \
@@ -316,26 +318,27 @@ static int pre##_verify(dstr *v)                                  \
   return (ok);                                                         \
 }
 
-#define BLKC_TEST(PRE, pre)                                            \
+#define BLKC_TESTX(PRE, pre, name, fname)                              \
                                                                        \
-BLKC_VERIFY(PRE, pre)                                                  \
+BLKC_VERIFYX(PRE, pre, name)                                           \
                                                                        \
 static const test_chunk defs[] = {                                     \
-  { #pre, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } },      \
+  { name, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } },      \
   { 0, 0, { 0 } }                                                      \
 };                                                                     \
                                                                        \
 int main(int argc, char *argv[])                                       \
 {                                                                      \
-  test_run(argc, argv, defs, SRCDIR"/t/" #pre);                                \
+  test_run(argc, argv, defs, SRCDIR"/t/" fname);                       \
   return (0);                                                          \
 }
 
 #else
-#  define BLKC_VERIFY(PRE, pre)
-#  define BLKC_TEST(PRE, pre)
+#  define BLKC_TESTX(PRE, pre, name, fname)
 #endif
 
+#define BLKC_TEST(PRE, pre) BLKC_TESTX(PRE, pre, #pre, #pre)
+
 /*----- That's all, folks -------------------------------------------------*/
 
 #ifdef __cplusplus
index 56c8f05..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 --- */                           \
                                                                        \
@@ -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);                                           \
@@ -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 -------------------------------------------------*/
index 4f0f38f..78aa6d9 100644 (file)
@@ -68,7 +68,9 @@
  * Use:                Creates an implementation for CFB mode.
  */
 
-#define CFB_DEF(PRE, pre)                                              \
+#define CFB_DEF(PRE, pre) CFB_DEFX(PRE, pre, #pre, #pre)
+
+#define CFB_DEFX(PRE, pre, name, fname)                                        \
                                                                        \
 /* --- @pre_cfbgetiv@ --- *                                            \
  *                                                                     \
@@ -389,14 +391,16 @@ static const gcipher_ops gops = {                                 \
 };                                                                     \
                                                                        \
 const gccipher pre##_cfb = {                                           \
-  #pre "-cfb", pre##_keysz, PRE##_BLKSZ,                               \
+  name "-cfb", pre##_keysz, PRE##_BLKSZ,                               \
   ginit                                                                        \
 };                                                                     \
                                                                        \
-CFB_TEST(PRE, pre)
+CFB_TESTX(PRE, pre, name, fname)
 
 /*----- Test rig ----------------------------------------------------------*/
 
+#define CFB_TEST(PRE, pre) CFB_TESTX(PRE, pre, #pre, #pre)
+
 #ifdef TEST_RIG
 
 #include <stdio.h>
@@ -410,7 +414,7 @@ CFB_TEST(PRE, pre)
  * Use:                Standard test rig for CFB functions.
  */
 
-#define CFB_TEST(PRE, pre)                                             \
+#define CFB_TESTX(PRE, pre, name, fname)                               \
                                                                        \
 /* --- Initial plaintext for the test --- */                           \
                                                                        \
@@ -447,7 +451,7 @@ int main(void)                                                              \
   size_t keysz = PRE##_KEYSZ ?                                         \
     PRE##_KEYSZ : strlen((const char *)key);                           \
                                                                        \
-  fputs(#pre "-cfb: ", stdout);                                                \
+  fputs(name "-cfb: ", stdout);                                                \
                                                                        \
   pre##_init(&k, key, keysz);                                          \
   pre##_cfbsetkey(&ctx, &k);                                           \
@@ -494,7 +498,7 @@ int main(void)                                                              \
 }
 
 #else
-#  define CFB_TEST(PRE, pre)
+#  define CFB_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/
index 4553679..ad955db 100644 (file)
@@ -65,7 +65,9 @@
  * Use:                Creates definitions for counter mode.
  */
 
-#define COUNTER_DEF(PRE, pre)                                          \
+#define COUNTER_DEF(PRE, pre) COUNTER_DEFX(PRE, pre, #pre, #pre)
+
+#define COUNTER_DEFX(PRE, pre, name, fname)                            \
                                                                        \
 /* --- @pre_countergetiv@ --- *                                                \
  *                                                                     \
@@ -299,7 +301,7 @@ static const gcipher_ops gops = {                                   \
 };                                                                     \
                                                                        \
 const gccipher pre##_counter = {                                       \
-  #pre "-counter", pre##_keysz, PRE##_BLKSZ,                           \
+  name "-counter", pre##_keysz, PRE##_BLKSZ,                           \
   ginit                                                                        \
 };                                                                     \
                                                                        \
@@ -395,7 +397,7 @@ static void grfill(grand *r, void *p, size_t sz)                    \
 }                                                                      \
                                                                        \
 static const grand_ops grops = {                                       \
-  #pre "-counter",                                                     \
+  name "-counter",                                                     \
   GRAND_CRYPTO, 0,                                                     \
   grmisc, grdestroy,                                                   \
   grword, grbyte, grword, grand_defaultrange, grfill                   \
@@ -420,10 +422,12 @@ grand *pre##_counterrand(const void *k, size_t sz)                        \
   return (&g->r);                                                      \
 }                                                                      \
                                                                        \
-COUNTER_TEST(PRE, pre)
+COUNTER_TESTX(PRE, pre, name, fname)
 
 /*----- Test rig ----------------------------------------------------------*/
 
+#define COUNTER_TEST(PRE, pre) COUNTER_TESTX(PRE, pre, #pre, #pre)
+
 #ifdef TEST_RIG
 
 #include <stdio.h>
@@ -437,7 +441,7 @@ COUNTER_TEST(PRE, pre)
  * Use:                Standard test rig for counter functions.
  */
 
-#define COUNTER_TEST(PRE, pre)                                         \
+#define COUNTER_TESTX(PRE, pre, name, fname)                           \
                                                                        \
 /* --- Initial plaintext for the test --- */                           \
                                                                        \
@@ -474,7 +478,7 @@ int main(void)                                                              \
   size_t keysz = PRE##_KEYSZ ?                                         \
     PRE##_KEYSZ : strlen((const char *)key);                           \
                                                                        \
-  fputs(#pre "-counter: ", stdout);                                    \
+  fputs(name "-counter: ", stdout);                                    \
                                                                        \
   pre##_init(&k, key, keysz);                                          \
   pre##_countersetkey(&ctx, &k);                                       \
@@ -521,7 +525,7 @@ int main(void)                                                              \
 }
 
 #else
-#  define COUNTER_TEST(PRE, pre)
+#  define COUNTER_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/
index 9f50292..568ffa1 100644 (file)
@@ -65,7 +65,9 @@
  * Use:                Creates an implementation for ECB stealing mode.
  */
 
-#define ECB_DEF(PRE, pre)                                              \
+#define ECB_DEF(PRE, pre) ECB_DEFX(PRE, pre, #pre, #pre)
+
+#define ECB_DEFX(PRE, pre, name, fname)                                        \
                                                                        \
 /* --- @pre_ecbsetkey@ --- *                                           \
  *                                                                     \
@@ -354,14 +356,16 @@ static const gcipher_ops gops = {                                 \
 };                                                                     \
                                                                        \
 const gccipher pre##_ecb = {                                           \
-  #pre "-ecb", pre##_keysz, PRE##_BLKSZ,                               \
+  name "-ecb", pre##_keysz, PRE##_BLKSZ,                               \
   ginit                                                                        \
 };                                                                     \
                                                                        \
-ECB_TEST(PRE, pre)
+ECB_TESTX(PRE, pre, name, fname)
 
 /*----- Test rig ----------------------------------------------------------*/
 
+#define ECB_TEST(PRE, pre) ECB_TESTX(PRE, pre, #pre, #pre)
+
 #ifdef TEST_RIG
 
 #include <stdio.h>
@@ -375,7 +379,7 @@ ECB_TEST(PRE, pre)
  * Use:                Standard test rig for ECB functions.
  */
 
-#define ECB_TEST(PRE, pre)                                             \
+#define ECB_TESTX(PRE, pre, name, fname)                               \
                                                                        \
 /* --- Initial plaintext for the test --- */                           \
                                                                        \
@@ -411,7 +415,7 @@ int main(void)                                                              \
   size_t keysz = PRE##_KEYSZ ?                                         \
     PRE##_KEYSZ : strlen((const char *)key);                           \
                                                                        \
-  fputs(#pre "-ecb: ", stdout);                                                \
+  fputs(name "-ecb: ", stdout);                                                \
                                                                        \
   pre##_ecbinit(&ctx, key, keysz, iv);                                 \
                                                                        \
@@ -459,7 +463,7 @@ int main(void)                                                              \
 }
 
 #else
-#  define ECB_TEST(PRE, pre)
+#  define ECB_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/
index 2ede96f..6aef117 100644 (file)
  * Use:                Defines the generic hash instance.
  */
 
-#define GHASH_DEF(PRE, pre)                                            \
+#define GHASH_DEF(PRE, pre) GHASH_DEFX(PRE, pre, #pre)
+#define GHASH_DEFX(PRE, pre, name)                                     \
                                                                        \
-static const ghash_ops gops;                                           \
+static const ghash_ops gops_##pre;                                     \
                                                                        \
-typedef struct gctx {                                                  \
+typedef struct gctx_##pre {                                            \
   ghash h;                                                             \
   pre##_ctx c;                                                         \
   octet buf[PRE##_HASHSZ];                                             \
-} gctx;                                                                        \
+} gctx_##pre;                                                          \
                                                                        \
-static ghash *ghinit(void)                                             \
+static ghash *ghinit_##pre(void)                                       \
 {                                                                      \
-  gctx *g = S_CREATE(gctx);                                            \
-  g->h.ops = &gops;                                                    \
+  gctx_##pre *g = S_CREATE(gctx_##pre);                                        \
+  g->h.ops = &gops_##pre;                                              \
   pre##_init(&g->c);                                                   \
   return (&g->h);                                                      \
 }                                                                      \
                                                                        \
-static void ghhash(ghash *h, const void *p, size_t sz)                 \
+static void ghhash_##pre(ghash *h, const void *p, size_t sz)           \
 {                                                                      \
-  gctx *g = (gctx *)h;                                                 \
+  gctx_##pre *g = (gctx_##pre *)h;                                     \
   pre##_hash(&g->c, p, sz);                                            \
 }                                                                      \
                                                                        \
-static octet *ghdone(ghash *h, void *buf)                              \
+static octet *ghdone_##pre(ghash *h, void *buf)                                \
 {                                                                      \
-  gctx *g = (gctx *)h;                                                 \
+  gctx_##pre *g = (gctx_##pre *)h;                                     \
   if (!buf)                                                            \
     buf = g->buf;                                                      \
   pre##_done(&g->c, buf);                                              \
   return (buf);                                                                \
 }                                                                      \
                                                                        \
-static void ghdestroy(ghash *h)                                                \
+static void ghdestroy_##pre(ghash *h)                                  \
 {                                                                      \
-  gctx *g = (gctx *)h;                                                 \
+  gctx_##pre *g = (gctx_##pre *)h;                                     \
   BURN(*g);                                                            \
   S_DESTROY(g);                                                                \
 }                                                                      \
                                                                        \
-static ghash *ghcopy(ghash *h)                                         \
+static ghash *ghcopy_##pre(ghash *h)                                   \
 {                                                                      \
-  gctx *g = (gctx *)h;                                                 \
-  gctx *gg = S_CREATE(gctx);                                           \
-  memcpy(gg, g, sizeof(gctx));                                         \
+  gctx_##pre *g = (gctx_##pre *)h;                                     \
+  gctx_##pre *gg = S_CREATE(gctx_##pre);                               \
+  memcpy(gg, g, sizeof(gctx_##pre));                                   \
   return (&gg->h);                                                     \
 }                                                                      \
                                                                        \
-static const ghash_ops gops =                                          \
-  { &pre, ghhash, ghdone, ghdestroy, ghcopy };                         \
-const gchash pre = { #pre, PRE##_HASHSZ, ghinit, PRE##_BUFSZ };
+static const ghash_ops gops_##pre =                                    \
+  { &pre, ghhash_##pre, ghdone_##pre, ghdestroy_##pre, ghcopy_##pre }; \
+const gchash pre = { name, PRE##_HASHSZ, ghinit_##pre, PRE##_BUFSZ };
 
 /*----- That's all, folks -------------------------------------------------*/
 
index 1c51520..29b733b 100644 (file)
@@ -12,7 +12,7 @@
 #include "@what.h"
 
 %repeat
-#include "@{thing:left}.h"
+#include "@{thing:left:f}.h"
 %end
 
 const @cls *const @{what}tab[] = {
index 31cf4a8..f492518 100644 (file)
 
 #define HASH_BUFLEN 100000
 
-#define HASH_TEST(PRE, pre)                                            \
+#define HASH_TESTX(PRE, pre, name, fname)                              \
                                                                        \
 static int verify(dstr *v)                                             \
 {                                                                      \
@@ -251,8 +251,8 @@ static int verifyrep(dstr *v)                                               \
 }                                                                      \
                                                                        \
 static test_chunk defs[] = {                                           \
-  { #pre, verify, { &type_string, &type_hex, 0 } },                    \
-  { #pre "-rep", verifyrep,                                            \
+  { name, verify, { &type_string, &type_hex, 0 } },                    \
+  { name "-rep", verifyrep,                                            \
     { &type_string, &type_int, &type_hex, 0 } },                       \
   { 0, 0, { 0 } }                                                      \
 };                                                                     \
@@ -260,14 +260,16 @@ static test_chunk defs[] = {                                              \
 int main(int argc, char *argv[])                                       \
 {                                                                      \
   ego(argv[0]);                                                                \
-  test_run(argc, argv, defs, SRCDIR"/t/" #pre);                                \
+  test_run(argc, argv, defs, SRCDIR"/t/" fname);                       \
   return (0);                                                          \
 }
 
 #else
-#  define HASH_TEST(PRE, pre)
+#  define HASH_TESTX(PRE, pre, name, fname)
 #endif
 
+#define HASH_TEST(PRE, pre) HASH_TESTX(PRE, pre, #pre, #pre)
+
 /*----- That's all, folks -------------------------------------------------*/
 
 #ifdef __cplusplus
index 032c69f..612cc99 100644 (file)
@@ -62,7 +62,8 @@
  * Use:                Creates implementations for the HMAC and NMAC functions.
  */
 
-#define HMAC_DEF(PRE, pre)                                             \
+#define HMAC_DEF(PRE, pre) HMAC_DEFX(PRE, pre, #pre, #pre)
+#define HMAC_DEFX(PRE, pre, name, fname)                               \
                                                                        \
 /* --- Useful constants --- */                                         \
                                                                        \
@@ -328,25 +329,27 @@ static ghash *ghinit(void)                                                \
 }                                                                      \
                                                                        \
 const gcmac pre##_nmac =                                               \
-  { #pre "-nmac", PRE##_HASHSZ, pre##_nmackeysz, gnkey };              \
+  { name "-nmac", PRE##_HASHSZ, pre##_nmackeysz, gnkey };              \
 const gcmac pre##_hmac =                                               \
-  { #pre "-hmac", PRE##_HASHSZ, pre##_hmackeysz, gkey };               \
+  { name "-hmac", PRE##_HASHSZ, pre##_hmackeysz, gkey };               \
 const gcmac pre##_sslmac =                                             \
-  { #pre "-sslmac", PRE##_HASHSZ, pre##_sslmackeysz, gsslkey };                \
+  { name "-sslmac", PRE##_HASHSZ, pre##_sslmackeysz, gsslkey };                \
 static const gmac_ops gkops = { &pre##_hmac, gkinit, gkdestroy };      \
 static const gmac_ops gnkops = { &pre##_nmac, gkinit, gkdestroy };     \
 static const gmac_ops gsslkops = { &pre##_sslmac, gkinit, gkdestroy }; \
-static const gchash gch = { #pre "-hmac", PRE##_HASHSZ, ghinit };      \
+static const gchash gch = { name "-hmac", PRE##_HASHSZ, ghinit };      \
 static const ghash_ops gops =                                          \
   { &gch, ghhash, ghdone, ghdestroy, ghcopy };                         \
-static const gchash gnch = { #pre "-nmac", PRE##_HASHSZ, ghinit };     \
+static const gchash gnch = { name "-nmac", PRE##_HASHSZ, ghinit };     \
 static const ghash_ops gnops =                                         \
   { &gch, ghhash, ghdone, ghdestroy, ghcopy };                         \
-static const gchash gsslch = { #pre "-sslmac", PRE##_HASHSZ, ghinit }; \
+static const gchash gsslch = { name "-sslmac", PRE##_HASHSZ, ghinit }; \
 static const ghash_ops gsslops =                                       \
   { &gch, ghhash, ghdone, ghdestroy, ghcopy };                         \
                                                                        \
-HMAC_TEST(PRE, pre)
+HMAC_TESTX(PRE, pre, name, fname)
+
+#define HMAC_TEST(PRE, pre) HMAC_TESTX(PRE, pre, #pre, #pre)
 
 /* --- @HMAC_TEST@ --- *
  *
@@ -363,7 +366,7 @@ HMAC_TEST(PRE, pre)
 #include <mLib/quis.h>
 #include <mLib/testrig.h>
 
-#define HMAC_TEST(PRE, pre)                                            \
+#define HMAC_TESTX(PRE, pre, name, fname)                              \
                                                                        \
 static int macverify(dstr *v)                                          \
 {                                                                      \
@@ -417,7 +420,7 @@ static int macverify(dstr *v)                                               \
 }                                                                      \
                                                                        \
 static test_chunk macdefs[] = {                                                \
-  { #pre "-hmac", macverify,                                           \
+  { name "-hmac", macverify,                                           \
     { &type_string, &type_hex, &type_hex, 0 } },                       \
   { 0, 0, { 0 } }                                                      \
 };                                                                     \
@@ -425,12 +428,12 @@ static test_chunk macdefs[] = {                                           \
 int main(int argc, char *argv[])                                       \
 {                                                                      \
   ego(argv[0]);                                                                \
-  test_run(argc, argv, macdefs, SRCDIR"/t/" #pre);                     \
+  test_run(argc, argv, macdefs, SRCDIR"/t/" fname);                    \
   return (0);                                                          \
 }
 
 #else
-#  define HMAC_TEST(PRE, pre)
+#  define HMAC_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/
index 529428f..832cd07 100644 (file)
@@ -59,7 +59,9 @@
 
 /*----- Macros ------------------------------------------------------------*/
 
-#define MGF_DEF(PRE, pre)                                              \
+#define MGF_DEF(PRE, pre) MGF_DEFX(PRE, pre, #pre, #pre)
+
+#define MGF_DEFX(PRE, pre, name, fname)                                        \
                                                                        \
 /* --- Useful constants --- */                                         \
                                                                        \
@@ -235,7 +237,7 @@ static const gcipher_ops gops = {                                   \
 };                                                                     \
                                                                        \
 const gccipher pre##_mgf = {                                           \
-  #pre "-mgf", pre##_mgfkeysz, 0,                                      \
+  name "-mgf", pre##_mgfkeysz, 0,                                      \
   ginit                                                                        \
 };                                                                     \
                                                                        \
@@ -324,7 +326,7 @@ static void grfill(grand *r, void *p, size_t sz)                    \
 }                                                                      \
                                                                        \
 static const grand_ops grops = {                                       \
-  #pre "-mgf",                                                         \
+  name "-mgf",                                                         \
   GRAND_CRYPTO, 0,                                                     \
   grmisc, grdestroy,                                                   \
   grword, grbyte, grword, grand_defaultrange, grfill                   \
@@ -349,10 +351,12 @@ extern grand *pre##_mgfrand(const void *k, size_t sz)                     \
   return (&g->r);                                                      \
 }                                                                      \
                                                                        \
-MGF_TEST(PRE, pre)
+MGF_TESTX(PRE, pre, name, fname)
 
 /*----- Test rig ----------------------------------------------------------*/
 
+#define MGF_TEST(PRE, pre) MGF_TESTX(PRE, pre, #pre, #pre)
+
 #ifdef TEST_RIG
 
 #include <stdio.h>
@@ -366,7 +370,7 @@ MGF_TEST(PRE, pre)
  * Use:                Standard test rig for MGF functions.
  */
 
-#define MGF_TEST(PRE, pre)                                             \
+#define MGF_TESTX(PRE, pre, name, fname)                               \
                                                                        \
 /* --- Initial plaintext for the test --- */                           \
                                                                        \
@@ -400,7 +404,7 @@ int main(void)                                                              \
                                                                        \
   size_t keysz = strlen((const char *)key);                            \
                                                                        \
-  fputs(#pre "-mgf: ", stdout);                                                \
+  fputs(name "-mgf: ", stdout);                                                \
                                                                        \
   pre##_mgfinit(&ctx, key, keysz);                                     \
                                                                        \
@@ -446,7 +450,7 @@ int main(void)                                                              \
 }
 
 #else
-#  define MGF_TEST(PRE, pre)
+#  define MGF_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/
index c46ef1c..e878c58 100644 (file)
@@ -4,9 +4,9 @@
 %#
 /* -*-c-*- GENERATED from mode.c.in
  *
- * @base-@mode.c
+ * @{base:f}-@mode.c
  */
 
-#include "@base-@mode.h"
+#include "@{base:f}-@mode.h"
 #include "@mode-def.h"
-@{mode:u}_DEF(@{base:u}, @base)
+@{mode:u}_DEFX(@{base:u:c}, @{base:c}, "@base", "@{base:f}")
index fc4fb95..56fa6e2 100644 (file)
@@ -4,11 +4,11 @@
 %#
 /* -*-c-*- GENERATED from mode.h.in
  *
- * @base-@mode.h
+ * @{base:f}-@mode.h
  */
 
-#ifndef CATACOMB_@{base:u}_@{mode:u}_H
-#define CATACOMB_@{base:u}_@{mode:u}_H
+#ifndef CATACOMB_@{base:u:c}_@{mode:u}_H
+#define CATACOMB_@{base:u:c}_@{mode:u}_H
 
 #ifdef __cplusplus
   extern "C" {
 #  include "@mode.h"
 #endif
 
-#ifndef CATACOMB_@{base:u}_H
-#  include "@base.h"
+#ifndef CATACOMB_@{base:u:c}_H
+#  include "@{base:f}.h"
 #endif
 
-@{mode:u}_DECL(@{base:u}, @base)
+@{mode:u}_DECL(@{base:u:c}, @{base:c})
 
 #ifdef __cplusplus
   }
index 73fb6db..395d06f 100644 (file)
@@ -13,16 +13,16 @@ GENMODES_H =
 
 ## Block cipher modes.
 %repeat
-GENMODES_C += modes/@blkc-@blkcmode.c
-GENMODES_H += modes/@blkc-@blkcmode.h
-SYMM_TESTS += modes/@blkc-@blkcmode.t$(EXEEXT)
+GENMODES_C += modes/@{blkc:f}-@blkcmode.c
+GENMODES_H += modes/@{blkc:f}-@blkcmode.h
+SYMM_TESTS += modes/@{blkc:f}-@blkcmode.t$(EXEEXT)
 %end
 
 ## Hash function modes.
 %repeat
-GENMODES_C += modes/@hash-@hashmode.c
-GENMODES_H += modes/@hash-@hashmode.h
-SYMM_TESTS += modes/@hash-@hashmode.t$(EXEEXT)
+GENMODES_C += modes/@{hash:f}-@hashmode.c
+GENMODES_H += modes/@{hash:f}-@hashmode.h
+SYMM_TESTS += modes/@{hash:f}-@hashmode.t$(EXEEXT)
 %end
 
 ## Interface and implementation headers for the various modes.
@@ -38,40 +38,40 @@ MODE_H += @hashmode.h @hashmode-def.h
 BLKC_C =
 BLKC_H =
 %repeat
-BLKC_C += @blkc.c
-BLKC_H += @blkc.h
-SYMM_TESTS += @blkc.t$(EXEEXT)
+BLKC_C += @{blkc:f}.c
+BLKC_H += @{blkc:f}.h
+SYMM_TESTS += @{blkc:f}.t$(EXEEXT)
 %end
 
 ## Hash function interfaces and implementations.
 HASH_C =
 HASH_H =
 %repeat
-HASH_C += @hash.c
-HASH_H += @hash.h
-SYMM_TESTS += @hash.t$(EXEEXT)
+HASH_C += @{hash:f}.c
+HASH_H += @{hash:f}.h
+SYMM_TESTS += @{hash:f}.t$(EXEEXT)
 %end
 
 ## Modes for symmetric encryption.
 CIPHER_MODES =
 %repeat
-CIPHER_MODES += @blkc-@blkcciphermode
+CIPHER_MODES += @{blkc:f}-@blkcciphermode
 %end
 %repeat
-CIPHER_MODES += @hash-@hashciphermode
+CIPHER_MODES += @{hash:f}-@hashciphermode
 %end
 
 ## Modes for message authentication.
 MAC_MODES =
 %repeat
-MAC_MODES += @hash-@hashmacmode
+MAC_MODES += @{hash:f}-@hashmacmode
 %end
 
 ## Test input files.
 SYMM_TEST_FILES =
 %repeat
-SYMM_TEST_FILES += t/@blkc
+SYMM_TEST_FILES += t/@{blkc:f}
 %end
 %repeat
-SYMM_TEST_FILES += t/@hash
+SYMM_TEST_FILES += t/@{hash:f}
 %end
index 241cd34..4c1921e 100755 (executable)
@@ -519,6 +519,11 @@ def op_l(val):
   """@{COLUMN:l} -- the item in upper case."""
   return val.lower()
 
+@defop
+def op_f(val):
+  """@{COLUMN:f} -- the item, with `/' characters replaced by `-'."""
+  return val.replace('/', '-')
+
 R_NOTIDENT = RX.compile(r'[^a-zA-Z0-9_]+')
 @defop
 def op_c(val):
index 358ee54..e9eb503 100644 (file)
@@ -65,7 +65,9 @@
  * Use:                Creates definitions for output feedback mode.
  */
 
-#define OFB_DEF(PRE, pre)                                              \
+#define OFB_DEF(PRE, pre) OFB_DEFX(PRE, pre, #pre, #pre)
+
+#define OFB_DEFX(PRE, pre, name, fname)                                        \
                                                                        \
 /* --- @pre_ofbgetiv@ --- *                                            \
  *                                                                     \
@@ -306,7 +308,7 @@ static const gcipher_ops gops = {                                   \
 };                                                                     \
                                                                        \
 const gccipher pre##_ofb = {                                           \
-  #pre "-ofb", pre##_keysz, PRE##_BLKSZ,                               \
+  name "-ofb", pre##_keysz, PRE##_BLKSZ,                               \
   ginit                                                                        \
 };                                                                     \
                                                                        \
@@ -407,7 +409,7 @@ static void grfill(grand *r, void *p, size_t sz)                    \
 }                                                                      \
                                                                        \
 static const grand_ops grops = {                                       \
-  #pre "-ofb",                                                         \
+  name "-ofb",                                                         \
   GRAND_CRYPTO, 0,                                                     \
   grmisc, grdestroy,                                                   \
   grword, grbyte, grword, grand_defaultrange, grfill                   \
@@ -432,10 +434,12 @@ grand *pre##_ofbrand(const void *k, size_t sz)                            \
   return (&g->r);                                                      \
 }                                                                      \
                                                                        \
-OFB_TEST(PRE, pre)
+OFB_TESTX(PRE, pre, name, name)
 
 /*----- Test rig ----------------------------------------------------------*/
 
+#define OFB_TEST(PRE, pre) OFB_TESTX(PRE, pre, #pre, #pre)
+
 #ifdef TEST_RIG
 
 #include <stdio.h>
@@ -449,7 +453,7 @@ OFB_TEST(PRE, pre)
  * Use:                Standard test rig for OFB functions.
  */
 
-#define OFB_TEST(PRE, pre)                                             \
+#define OFB_TESTX(PRE, pre, name, fname)                                       \
                                                                        \
 /* --- Initial plaintext for the test --- */                           \
                                                                        \
@@ -486,7 +490,7 @@ int main(void)                                                              \
   size_t keysz = PRE##_KEYSZ ?                                         \
     PRE##_KEYSZ : strlen((const char *)key);                           \
                                                                        \
-  fputs(#pre "-ofb: ", stdout);                                                \
+  fputs(name "-ofb: ", stdout);                                                \
                                                                        \
   pre##_init(&k, key, keysz);                                          \
   pre##_ofbsetkey(&ctx, &k);                                           \
@@ -533,7 +537,7 @@ int main(void)                                                              \
 }
 
 #else
-#  define OFB_TEST(PRE, pre)
+#  define OFB_TESTX(PRE, pre, name, fname)
 #endif
 
 /*----- That's all, folks -------------------------------------------------*/