3 * Generic symmetric cipher interface
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #ifndef CATACOMB_GCIPHER_H
29 #define CATACOMB_GCIPHER_H
35 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/bits.h>
41 #ifndef CATACOMB_KEYSZ_H
45 /*----- Generic symmetric cipher interface --------------------------------*/
47 typedef struct gcipher {
48 const struct gcipher_ops *ops; /* Pointer to cipher operations */
51 typedef struct gcipher_ops {
52 const struct gccipher *c; /* Pointer to cipher class */
53 void (*encrypt)(gcipher */*c*/, const void */*s*/,
54 void */*t*/, size_t /*sz*/);
55 void (*decrypt)(gcipher */*c*/, const void */*s*/,
56 void */*t*/, size_t /*sz*/);
57 void (*destroy)(gcipher */*c*/);
58 void (*setiv)(gcipher */*c*/, const void */*iv*/);
59 void (*bdry)(gcipher */*c*/);
62 typedef struct gccipher {
63 const char *name; /* Cipher name */
64 const octet *keysz; /* Preferred key size table */
65 size_t blksz; /* Block size or zero if none */
66 gcipher *(*init)(const void */*k*/, size_t /*sz*/);
69 #define GC_INIT(cc, k, sz) (cc)->init((k), (sz))
70 #define GC_CLASS(cc) (cc)->ops->c
71 #define GC_ENCRYPT(c, s, t, sz) (c)->ops->encrypt((c), (s), (t), (sz))
72 #define GC_DECRYPT(c, s, t, sz) (c)->ops->decrypt((c), (s), (t), (sz))
73 #define GC_DESTROY(c) (c)->ops->destroy((c))
74 #define GC_SETIV(c, iv) (c)->ops->setiv((c), (iv))
75 #define GC_BDRY(c) (c)->ops->bdry((c))
77 /*----- Tables ------------------------------------------------------------*/
79 extern const gccipher *const gciphertab[];
81 /* --- @gcipher_byname@ --- *
83 * Arguments: @const char *p@ = pointer to name string
85 * Returns: The named cipher class, or null.
88 extern const gccipher *gcipher_byname(const char */*p*/);
90 /*----- That's all, folks -------------------------------------------------*/