key/key-io.c: Add low-level `key_mergeline' and `key_extractline' functions.
[catacomb] / symm / ghash-def.h
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 -------------------------------------------------*/