3 * $Id: cc.h,v 1.1 2004/04/17 09:58:37 mdw Exp $
5 * Catcrypt common stuff
7 * (c) 2004 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
37 /*----- Header files ------------------------------------------------------*/
41 #include <mLib/dstr.h>
48 /*----- Data structures ---------------------------------------------------*/
50 /* --- Key encapsulation --- */
53 const struct kemops
*ops
;
57 const gccipher
*c
, *cx
;
61 typedef struct kemops
{
62 const key_fetchdef
*kf
; /* Key fetching structure */
63 size_t kdsz
; /* Size of the key-data structure */
64 kem
*(*init
)(key */
*k*/
, void */
*kd*/
);
65 int (*doit
)(kem */
*k*/
, dstr */
*d*/
, ghash */
*h*/
);
66 const char *(*check
)(kem */
*k*/
);
67 void (*destroy
)(kem */
*k*/
);
73 const struct sigops
*ops
;
79 typedef struct sigops
{
80 const key_fetchdef
*kf
; /* Key fetching structure */
81 size_t kdsz
; /* Size of the key-data structure */
82 sig
*(*init
)(key */
*k*/
, void */
*kd*/
, const gchash */
*hc*/
);
83 int (*doit
)(sig */
*s*/
, dstr */
*d*/
);
84 const char *(*check
)(sig */
*s*/
);
85 void (*destroy
)(sig */
*s*/
);
88 /* --- Data encoding --- */
91 const struct encops
*ops
;
95 typedef struct encops
{
97 const char *rmode
, *wmode
;
98 enc
*(*initenc
)(FILE */
*fp*/
, const char */
*msg*/
);
99 enc
*(*initdec
)(FILE */
*fp*/
, const char */
*msg*/
);
100 int (*read
)(enc */
*e*/
, void */
*p*/
, size_t /*sz*/);
101 int (*write
)(enc */
*e*/
, const void */
*p*/
, size_t /*sz*/);
102 int (*encdone
)(enc */
*e*/
);
103 int (*decdone
)(enc */
*e*/
);
104 void (*destroy
)(enc */
*e*/
);
107 /*----- Functions provided ------------------------------------------------*/
109 /* --- @getkem@ --- *
111 * Arguments: @key *k@ = the key to load
112 * @const char *app@ = application name
113 * @int wantpriv@ = nonzero if we want to decrypt
115 * Returns: A key-encapsulating thing.
120 extern kem
*getkem(key */
*k*/
, const char */
*app*/
, int /*wantpriv*/);
122 /* --- @setupkem@ --- *
124 * Arguments: @kem *k@ = key-encapsulation thing
125 * @dstr *d@ = key-encapsulation data
126 * @gcipher **cx@ = key-expansion function (for IVs)
127 * @gcipher **c@ = where to put initialized encryption scheme
128 * @gmac **m@ = where to put initialized MAC
130 * Returns: Zero for success, nonzero on faliure.
132 * Use: Initializes all the various symmetric things from a KEM.
135 extern int setupkem(kem */
*k*/
, dstr */
*d*/
,
136 gcipher
**/
*cx*/
, gcipher
**/
*c*/
, gmac
**/
*m*/
);
138 /* --- @freekem@ --- *
140 * Arguments: @kem *k@ = key-encapsulation thing
144 * Use: Frees up a key-encapsulation thing.
147 extern void freekem(kem */
*k*/
);
149 /* --- @getsig@ --- *
151 * Arguments: @key *k@ = the key to load
152 * @const char *app@ = application name
153 * @int wantpriv@ = nonzero if we want to sign
155 * Returns: A signature-making thing.
157 * Use: Loads a key and starts hashing.
160 extern sig
*getsig(key */
*k*/
, const char */
*app*/
, int /*wantpriv*/);
162 /* --- @freesig@ --- *
164 * Arguments: @sig *s@ = signature-making thing
168 * Use: Frees up a signature-making thing
171 extern void freesig(sig */
*s*/
);
173 /* --- @getenc@ --- *
175 * Arguments: @const char *enc@ = name of wanted encoding
177 * Returns: Pointer to encoder operations.
179 * Use: Finds a named encoder or decoder.
182 extern const encops
*getenc(const char */
*enc*/
);
184 /* --- @initenc@ --- *
186 * Arguments: @const encops *eo@ = operations (from @getenc@)
187 * @FILE *fp@ = file handle to attach
188 * @const char *msg@ = banner message
189 * @int wantenc@ = nonzero if we want to encode
191 * Returns: The encoder object.
193 * Use: Initializes an encoder.
196 extern enc
*initenc(const encops */
*eo*/
, FILE */
*fp*/
,
197 const char */
*msg*/
, int /*wantenc*/);
199 /* --- @freeenc@ --- *
201 * Arguments: @enc *e@ = encoder object
205 * Use: Frees an encoder object.
208 extern void freeenc(enc */
*e*/
);
210 /*----- That's all, folks -------------------------------------------------*/