From: mdw Date: Sun, 4 Apr 2004 19:42:30 +0000 (+0000) Subject: Make tables of standard encryption schemes etc. X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/commitdiff_plain/59919ae4b1721ca271c3d3e5955c09d322573821 Make tables of standard encryption schemes etc. --- diff --git a/gcipher.h b/gcipher.h index b8c34bf..f25fb93 100644 --- a/gcipher.h +++ b/gcipher.h @@ -1,6 +1,6 @@ /* -*-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 * @@ -30,6 +30,9 @@ /*----- 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. * @@ -75,6 +78,14 @@ typedef struct gccipher { 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 --- * @@ -120,6 +131,19 @@ extern size_t keysz(size_t /*sz*/, const octet */*ksz*/); #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 diff --git a/gengctab b/gengctab new file mode 100755 index 0000000..3211b42 --- /dev/null +++ b/gengctab @@ -0,0 +1,46 @@ +#! /bin/sh + +set -e +type=$1 +include=$2 +list=$3 + +cat < + +#include "$2.h" + +EOF +for i in $list; do + echo "#include \"$i.h\"" +done + +cat <name) == 0) + return (*c); + } + return (0); +} + +EOF diff --git a/ghash.h b/ghash.h index 61f8aae..9d63419 100644 --- a/ghash.h +++ b/ghash.h @@ -1,6 +1,6 @@ /* -*-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 * @@ -30,6 +30,9 @@ /*----- 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. * @@ -77,12 +80,33 @@ typedef struct ghash_ops { 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 diff --git a/gmac.h b/gmac.h index 1a89be9..cf134ac 100644 --- a/gmac.h +++ b/gmac.h @@ -1,6 +1,6 @@ /* -*-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 * @@ -30,6 +30,9 @@ /*----- 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. * @@ -76,6 +79,24 @@ typedef struct gcmac { 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