| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: cc.h,v 1.1 2004/04/17 09:58:37 mdw Exp $ |
| 4 | * |
| 5 | * Catcrypt common stuff |
| 6 | * |
| 7 | * (c) 2004 Straylight/Edgeware |
| 8 | */ |
| 9 | |
| 10 | /*----- Licensing notice --------------------------------------------------* |
| 11 | * |
| 12 | * This file is part of Catacomb. |
| 13 | * |
| 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. |
| 18 | * |
| 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. |
| 23 | * |
| 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, |
| 27 | * MA 02111-1307, USA. |
| 28 | */ |
| 29 | |
| 30 | #ifndef CATACOMB_CC_H |
| 31 | #define CATACOMB_CC_H |
| 32 | |
| 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
| 37 | /*----- Header files ------------------------------------------------------*/ |
| 38 | |
| 39 | #include <stdio.h> |
| 40 | |
| 41 | #include <mLib/dstr.h> |
| 42 | |
| 43 | #include "key.h" |
| 44 | #include "gcipher.h" |
| 45 | #include "ghash.h" |
| 46 | #include "gmac.h" |
| 47 | |
| 48 | /*----- Data structures ---------------------------------------------------*/ |
| 49 | |
| 50 | /* --- Key encapsulation --- */ |
| 51 | |
| 52 | typedef struct kem { |
| 53 | const struct kemops *ops; |
| 54 | key_packdef *kp; |
| 55 | void *kd; |
| 56 | const gchash *h; |
| 57 | const gccipher *c, *cx; |
| 58 | const gcmac *m; |
| 59 | } kem; |
| 60 | |
| 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*/); |
| 68 | } kemops; |
| 69 | |
| 70 | /* --- Signing --- */ |
| 71 | |
| 72 | typedef struct sig { |
| 73 | const struct sigops *ops; |
| 74 | key_packdef *kp; |
| 75 | void *kd; |
| 76 | ghash *h; |
| 77 | } sig; |
| 78 | |
| 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*/); |
| 86 | } sigops; |
| 87 | |
| 88 | /* --- Data encoding --- */ |
| 89 | |
| 90 | typedef struct enc { |
| 91 | const struct encops *ops; |
| 92 | FILE *fp; |
| 93 | } enc; |
| 94 | |
| 95 | typedef struct encops { |
| 96 | const char *name; |
| 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*/); |
| 105 | } encops; |
| 106 | |
| 107 | /*----- Functions provided ------------------------------------------------*/ |
| 108 | |
| 109 | /* --- @getkem@ --- * |
| 110 | * |
| 111 | * Arguments: @key *k@ = the key to load |
| 112 | * @const char *app@ = application name |
| 113 | * @int wantpriv@ = nonzero if we want to decrypt |
| 114 | * |
| 115 | * Returns: A key-encapsulating thing. |
| 116 | * |
| 117 | * Use: Loads a key. |
| 118 | */ |
| 119 | |
| 120 | extern kem *getkem(key */*k*/, const char */*app*/, int /*wantpriv*/); |
| 121 | |
| 122 | /* --- @setupkem@ --- * |
| 123 | * |
| 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 |
| 129 | * |
| 130 | * Returns: Zero for success, nonzero on faliure. |
| 131 | * |
| 132 | * Use: Initializes all the various symmetric things from a KEM. |
| 133 | */ |
| 134 | |
| 135 | extern int setupkem(kem */*k*/, dstr */*d*/, |
| 136 | gcipher **/*cx*/, gcipher **/*c*/, gmac **/*m*/); |
| 137 | |
| 138 | /* --- @freekem@ --- * |
| 139 | * |
| 140 | * Arguments: @kem *k@ = key-encapsulation thing |
| 141 | * |
| 142 | * Returns: --- |
| 143 | * |
| 144 | * Use: Frees up a key-encapsulation thing. |
| 145 | */ |
| 146 | |
| 147 | extern void freekem(kem */*k*/); |
| 148 | |
| 149 | /* --- @getsig@ --- * |
| 150 | * |
| 151 | * Arguments: @key *k@ = the key to load |
| 152 | * @const char *app@ = application name |
| 153 | * @int wantpriv@ = nonzero if we want to sign |
| 154 | * |
| 155 | * Returns: A signature-making thing. |
| 156 | * |
| 157 | * Use: Loads a key and starts hashing. |
| 158 | */ |
| 159 | |
| 160 | extern sig *getsig(key */*k*/, const char */*app*/, int /*wantpriv*/); |
| 161 | |
| 162 | /* --- @freesig@ --- * |
| 163 | * |
| 164 | * Arguments: @sig *s@ = signature-making thing |
| 165 | * |
| 166 | * Returns: --- |
| 167 | * |
| 168 | * Use: Frees up a signature-making thing |
| 169 | */ |
| 170 | |
| 171 | extern void freesig(sig */*s*/); |
| 172 | |
| 173 | /* --- @getenc@ --- * |
| 174 | * |
| 175 | * Arguments: @const char *enc@ = name of wanted encoding |
| 176 | * |
| 177 | * Returns: Pointer to encoder operations. |
| 178 | * |
| 179 | * Use: Finds a named encoder or decoder. |
| 180 | */ |
| 181 | |
| 182 | extern const encops *getenc(const char */*enc*/); |
| 183 | |
| 184 | /* --- @initenc@ --- * |
| 185 | * |
| 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 |
| 190 | * |
| 191 | * Returns: The encoder object. |
| 192 | * |
| 193 | * Use: Initializes an encoder. |
| 194 | */ |
| 195 | |
| 196 | extern enc *initenc(const encops */*eo*/, FILE */*fp*/, |
| 197 | const char */*msg*/, int /*wantenc*/); |
| 198 | |
| 199 | /* --- @freeenc@ --- * |
| 200 | * |
| 201 | * Arguments: @enc *e@ = encoder object |
| 202 | * |
| 203 | * Returns: --- |
| 204 | * |
| 205 | * Use: Frees an encoder object. |
| 206 | */ |
| 207 | |
| 208 | extern void freeenc(enc */*e*/); |
| 209 | |
| 210 | /*----- That's all, folks -------------------------------------------------*/ |
| 211 | |
| 212 | #ifdef __cplusplus |
| 213 | } |
| 214 | #endif |
| 215 | |
| 216 | #endif |