/* -*-c-*-
*
- * $Id: gcipher.h,v 1.2 2000/06/17 10:56:00 mdw Exp $
+ * $Id: gcipher.h,v 1.3 2004/04/04 19:42:30 mdw Exp $
*
* Generic symmetric cipher interface
*
/*----- Revision history --------------------------------------------------*
*
* $Log: gcipher.h,v $
+ * Revision 1.3 2004/04/04 19:42:30 mdw
+ * Make tables of standard encryption schemes etc.
+ *
* Revision 1.2 2000/06/17 10:56:00 mdw
* New key size interface.
*
gcipher *(*init)(const void */*k*/, size_t /*sz*/);
} gccipher;
+#define GC_INIT(cc, k, sz) (cc)->init((k), (sz))
+#define GC_CLASS(c) (c)->ops->c
+#define GC_ENCRYPT(c, s, t, sz) (c)->ops->encrypt((c), (s), (t), (sz))
+#define GC_DECRYPT(c, s, t, sz) (c)->ops->decrypt((c), (s), (t), (sz))
+#define GC_DESTROY(c) (c)->ops->destroy((c))
+#define GC_SETIV(c, iv) (c)->ops->setiv((c), (iv))
+#define GC_BDRY(c) (c)->ops->bdry((c))
+
/*----- Key size management -----------------------------------------------*/
/* --- Key size type constants --- *
#define KSZ_ASSERT(pre, sz) \
assert(((void)"Bad key size for " #pre, KSZ_CHECK(pre, sz)))
+/*----- Tables ------------------------------------------------------------*/
+
+extern const gccipher *const gciphertab[];
+
+/* --- @gcipher_byname@ --- *
+ *
+ * Arguments: @const char *p@ = pointer to name string
+ *
+ * Returns: The named cipher class, or null.
+ */
+
+extern const gccipher *gcipher_byname(const char */*p*/);
+
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus
--- /dev/null
+#! /bin/sh
+
+set -e
+type=$1
+include=$2
+list=$3
+
+cat <<EOF
+/* -*-c-*-
+ *
+ * ${include}tab.c [generated]
+ */
+
+#include <string.h>
+
+#include "$2.h"
+
+EOF
+for i in $list; do
+ echo "#include \"$i.h\""
+done
+
+cat <<EOF
+
+const $type *const ${include}tab[] = {
+EOF
+for i in $list; do
+ c=`echo $i | sed 's/[^A-Za-z0-9_][^A-Za-z0-9_]*/_/g'`
+ echo " &$c,"
+done
+cat <<EOF
+ 0
+};
+
+const $type *${include}_byname(const char *p)
+{
+ const $type *const *c;
+
+ for (c = ${include}tab; *c; c++) {
+ if (strcmp(p, (*c)->name) == 0)
+ return (*c);
+ }
+ return (0);
+}
+
+EOF
/* -*-c-*-
*
- * $Id: ghash.h,v 1.5 2000/07/15 10:00:58 mdw Exp $
+ * $Id: ghash.h,v 1.6 2004/04/04 19:42:30 mdw Exp $
*
* Generic hash function interface
*
/*----- Revision history --------------------------------------------------*
*
* $Log: ghash.h,v $
+ * Revision 1.6 2004/04/04 19:42:30 mdw
+ * Make tables of standard encryption schemes etc.
+ *
* Revision 1.5 2000/07/15 10:00:58 mdw
* New generic hash operation for copying hash contexts.
*
ghash *(*copy)(ghash */*h*/); /* Make a copy of the hash context */
} ghash_ops;
+#define GH_INIT(ch) (ch)->init()
+#define GH_CLASS(H) (h)->ops->c
+#define GH_HASH(h, p, sz) (h)->ops->hash((h), (p), (sz))
+#define GH_DONE(h, buf) (h)->ops->done((h), (buf))
+#define GH_DESTROY(h) (h)->ops->destroy((h))
+#define GH_COPY(h) (h)->ops->copy((h))
+
typedef struct gchash {
const char *name; /* Name of the hash function */
size_t hashsz; /* Size of output hash */
ghash *(*init)(void); /* Create a new hash instance */
+ size_t bufsz; /* Buffer size, or zero */
} gchash;
+/*----- Tables ------------------------------------------------------------*/
+
+extern const gchash *const ghashtab[];
+
+/* --- @ghash_byname@ --- *
+ *
+ * Arguments: @const char *p@ = pointer to name string
+ *
+ * Returns: The named cipher class, or null.
+ */
+
+extern const gchash *ghash_byname(const char */*p*/);
+
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus
/* -*-c-*-
*
- * $Id: gmac.h,v 1.2 2000/06/17 11:22:46 mdw Exp $
+ * $Id: gmac.h,v 1.3 2004/04/04 19:42:30 mdw Exp $
*
* Generic MAC function interface
*
/*----- Revision history --------------------------------------------------*
*
* $Log: gmac.h,v $
+ * Revision 1.3 2004/04/04 19:42:30 mdw
+ * Make tables of standard encryption schemes etc.
+ *
* Revision 1.2 2000/06/17 11:22:46 mdw
* Minor changes in the generic hash and MAC interfaces.
*
gmac *(*key)(const void */*k*/, size_t /*sz*/); /* Create key */
} gcmac;
+#define GM_KEY(cm, k, ksz) (cm)->key((k), (ksz))
+#define GM_CLASS(km) (km)->ops->c
+#define GM_INIT(km) (km)->ops->init((km))
+#define GM_DESTROY(km) (km)->ops->destroy((km))
+
+/*----- Tables ------------------------------------------------------------*/
+
+extern const gcmac *const gmactab[];
+
+/* --- @gmac_byname@ --- *
+ *
+ * Arguments: @const char *p@ = pointer to name string
+ *
+ * Returns: The named cipher class, or null.
+ */
+
+extern const gcmac *gmac_byname(const char */*p*/);
+
/*----- That's all, folks -------------------------------------------------*/
#ifdef __cplusplus