X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/72a6efc4d59568868fc6bbe05d343f777fc1a159..5c3f75ec49019d160806489824fc76652a2ef444:/cc.h diff --git a/cc.h b/cc.h new file mode 100644 index 00000000..7c2c092b --- /dev/null +++ b/cc.h @@ -0,0 +1,216 @@ +/* -*-c-*- + * + * $Id: cc.h,v 1.1 2004/04/17 09:58:37 mdw Exp $ + * + * Catcrypt common stuff + * + * (c) 2004 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of Catacomb. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#ifndef CATACOMB_CC_H +#define CATACOMB_CC_H + +#ifdef __cplusplus + extern "C" { +#endif + +/*----- Header files ------------------------------------------------------*/ + +#include + +#include + +#include "key.h" +#include "gcipher.h" +#include "ghash.h" +#include "gmac.h" + +/*----- Data structures ---------------------------------------------------*/ + +/* --- Key encapsulation --- */ + +typedef struct kem { + const struct kemops *ops; + key_packdef *kp; + void *kd; + const gchash *h; + const gccipher *c, *cx; + const gcmac *m; +} kem; + +typedef struct kemops { + const key_fetchdef *kf; /* Key fetching structure */ + size_t kdsz; /* Size of the key-data structure */ + kem *(*init)(key */*k*/, void */*kd*/); + int (*doit)(kem */*k*/, dstr */*d*/, ghash */*h*/); + const char *(*check)(kem */*k*/); + void (*destroy)(kem */*k*/); +} kemops; + +/* --- Signing --- */ + +typedef struct sig { + const struct sigops *ops; + key_packdef *kp; + void *kd; + ghash *h; +} sig; + +typedef struct sigops { + const key_fetchdef *kf; /* Key fetching structure */ + size_t kdsz; /* Size of the key-data structure */ + sig *(*init)(key */*k*/, void */*kd*/, const gchash */*hc*/); + int (*doit)(sig */*s*/, dstr */*d*/); + const char *(*check)(sig */*s*/); + void (*destroy)(sig */*s*/); +} sigops; + +/* --- Data encoding --- */ + +typedef struct enc { + const struct encops *ops; + FILE *fp; +} enc; + +typedef struct encops { + const char *name; + const char *rmode, *wmode; + enc *(*initenc)(FILE */*fp*/, const char */*msg*/); + enc *(*initdec)(FILE */*fp*/, const char */*msg*/); + int (*read)(enc */*e*/, void */*p*/, size_t /*sz*/); + int (*write)(enc */*e*/, const void */*p*/, size_t /*sz*/); + int (*encdone)(enc */*e*/); + int (*decdone)(enc */*e*/); + void (*destroy)(enc */*e*/); +} encops; + +/*----- Functions provided ------------------------------------------------*/ + +/* --- @getkem@ --- * + * + * Arguments: @key *k@ = the key to load + * @const char *app@ = application name + * @int wantpriv@ = nonzero if we want to decrypt + * + * Returns: A key-encapsulating thing. + * + * Use: Loads a key. + */ + +extern kem *getkem(key */*k*/, const char */*app*/, int /*wantpriv*/); + +/* --- @setupkem@ --- * + * + * Arguments: @kem *k@ = key-encapsulation thing + * @dstr *d@ = key-encapsulation data + * @gcipher **cx@ = key-expansion function (for IVs) + * @gcipher **c@ = where to put initialized encryption scheme + * @gmac **m@ = where to put initialized MAC + * + * Returns: Zero for success, nonzero on faliure. + * + * Use: Initializes all the various symmetric things from a KEM. + */ + +extern int setupkem(kem */*k*/, dstr */*d*/, + gcipher **/*cx*/, gcipher **/*c*/, gmac **/*m*/); + +/* --- @freekem@ --- * + * + * Arguments: @kem *k@ = key-encapsulation thing + * + * Returns: --- + * + * Use: Frees up a key-encapsulation thing. + */ + +extern void freekem(kem */*k*/); + +/* --- @getsig@ --- * + * + * Arguments: @key *k@ = the key to load + * @const char *app@ = application name + * @int wantpriv@ = nonzero if we want to sign + * + * Returns: A signature-making thing. + * + * Use: Loads a key and starts hashing. + */ + +extern sig *getsig(key */*k*/, const char */*app*/, int /*wantpriv*/); + +/* --- @freesig@ --- * + * + * Arguments: @sig *s@ = signature-making thing + * + * Returns: --- + * + * Use: Frees up a signature-making thing + */ + +extern void freesig(sig */*s*/); + +/* --- @getenc@ --- * + * + * Arguments: @const char *enc@ = name of wanted encoding + * + * Returns: Pointer to encoder operations. + * + * Use: Finds a named encoder or decoder. + */ + +extern const encops *getenc(const char */*enc*/); + +/* --- @initenc@ --- * + * + * Arguments: @const encops *eo@ = operations (from @getenc@) + * @FILE *fp@ = file handle to attach + * @const char *msg@ = banner message + * @int wantenc@ = nonzero if we want to encode + * + * Returns: The encoder object. + * + * Use: Initializes an encoder. + */ + +extern enc *initenc(const encops */*eo*/, FILE */*fp*/, + const char */*msg*/, int /*wantenc*/); + +/* --- @freeenc@ --- * + * + * Arguments: @enc *e@ = encoder object + * + * Returns: --- + * + * Use: Frees an encoder object. + */ + +extern void freeenc(enc */*e*/); + +/*----- That's all, folks -------------------------------------------------*/ + +#ifdef __cplusplus + } +#endif + +#endif