From aaae9cab01b8d7a0e6cf0c273182a51fd03a9d61 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 10 May 2017 19:29:41 +0100 Subject: [PATCH] symm/: Allow block cipher and hash functions with strange names. 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. --- symm/Makefile.am | 8 ++++---- symm/blkc.h | 17 ++++++++++------- symm/cbc-def.h | 16 ++++++++++------ symm/cfb-def.h | 16 ++++++++++------ symm/counter-def.h | 18 +++++++++++------- symm/ecb-def.h | 16 ++++++++++------ symm/ghash-def.h | 41 +++++++++++++++++++++-------------------- symm/gthingtab.c.in | 2 +- symm/hash.h | 12 +++++++----- symm/hmac-def.h | 27 +++++++++++++++------------ symm/mgf-def.h | 18 +++++++++++------- symm/mode.c.in | 6 +++--- symm/mode.h.in | 12 ++++++------ symm/modes.am.in | 34 +++++++++++++++++----------------- symm/multigen | 5 +++++ symm/ofb-def.h | 18 +++++++++++------- 16 files changed, 152 insertions(+), 114 deletions(-) diff --git a/symm/Makefile.am b/symm/Makefile.am index c30fd7e5..3cd98cf1 100644 --- a/symm/Makefile.am +++ b/symm/Makefile.am @@ -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 diff --git a/symm/blkc.h b/symm/blkc.h index d6e3da0f..e0374f1a 100644 --- a/symm/blkc.h +++ b/symm/blkc.h @@ -260,7 +260,9 @@ #include #include -#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 diff --git a/symm/cbc-def.h b/symm/cbc-def.h index 56c8f054..907a5dba 100644 --- a/symm/cbc-def.h +++ b/symm/cbc-def.h @@ -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 @@ -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 -------------------------------------------------*/ diff --git a/symm/cfb-def.h b/symm/cfb-def.h index 4f0f38f4..78aa6d98 100644 --- a/symm/cfb-def.h +++ b/symm/cfb-def.h @@ -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 @@ -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 -------------------------------------------------*/ diff --git a/symm/counter-def.h b/symm/counter-def.h index 45536795..ad955dba 100644 --- a/symm/counter-def.h +++ b/symm/counter-def.h @@ -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 @@ -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 -------------------------------------------------*/ diff --git a/symm/ecb-def.h b/symm/ecb-def.h index 9f50292e..568ffa1e 100644 --- a/symm/ecb-def.h +++ b/symm/ecb-def.h @@ -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 @@ -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 -------------------------------------------------*/ diff --git a/symm/ghash-def.h b/symm/ghash-def.h index 2ede96f3..6aef1175 100644 --- a/symm/ghash-def.h +++ b/symm/ghash-def.h @@ -58,57 +58,58 @@ * 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 -------------------------------------------------*/ diff --git a/symm/gthingtab.c.in b/symm/gthingtab.c.in index 1c515205..29b733b3 100644 --- a/symm/gthingtab.c.in +++ b/symm/gthingtab.c.in @@ -12,7 +12,7 @@ #include "@what.h" %repeat -#include "@{thing:left}.h" +#include "@{thing:left:f}.h" %end const @cls *const @{what}tab[] = { diff --git a/symm/hash.h b/symm/hash.h index 31cf4a85..f4925184 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -165,7 +165,7 @@ #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 diff --git a/symm/hmac-def.h b/symm/hmac-def.h index 032c69f2..612cc996 100644 --- a/symm/hmac-def.h +++ b/symm/hmac-def.h @@ -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 #include -#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 -------------------------------------------------*/ diff --git a/symm/mgf-def.h b/symm/mgf-def.h index 529428f9..832cd074 100644 --- a/symm/mgf-def.h +++ b/symm/mgf-def.h @@ -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 @@ -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 -------------------------------------------------*/ diff --git a/symm/mode.c.in b/symm/mode.c.in index c46ef1cd..e878c58f 100644 --- a/symm/mode.c.in +++ b/symm/mode.c.in @@ -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}") diff --git a/symm/mode.h.in b/symm/mode.h.in index fc4fb954..56fa6e2c 100644 --- a/symm/mode.h.in +++ b/symm/mode.h.in @@ -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" { @@ -18,11 +18,11 @@ # 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 } diff --git a/symm/modes.am.in b/symm/modes.am.in index 73fb6dbd..395d06f7 100644 --- a/symm/modes.am.in +++ b/symm/modes.am.in @@ -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 diff --git a/symm/multigen b/symm/multigen index 241cd34c..4c1921ea 100755 --- a/symm/multigen +++ b/symm/multigen @@ -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): diff --git a/symm/ofb-def.h b/symm/ofb-def.h index 358ee54c..e9eb5034 100644 --- a/symm/ofb-def.h +++ b/symm/ofb-def.h @@ -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 @@ -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 -------------------------------------------------*/ -- 2.11.0