chiark / gitweb /
configure.ac: Replace with a new version.
[catacomb] / gcipher.h
1 /* -*-c-*-
2  *
3  * $Id: gcipher.h,v 1.5 2004/04/21 00:37:32 mdw Exp $
4  *
5  * Generic symmetric cipher interface
6  *
7  * (c) 1999 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_GCIPHER_H
31 #define CATACOMB_GCIPHER_H
32
33 #ifdef __cplusplus
34   extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #include <stddef.h>
40
41 #include <mLib/bits.h>
42
43 #ifndef CATACOMB_KEYSZ_H
44 #  include "keysz.h"
45 #endif
46
47 /*----- Generic symmetric cipher interface --------------------------------*/
48
49 typedef struct gcipher {
50   const struct gcipher_ops *ops;        /* Pointer to cipher operations */
51 } gcipher;
52
53 typedef struct gcipher_ops {
54   const struct gccipher *c;             /* Pointer to cipher class */
55   void (*encrypt)(gcipher */*c*/, const void */*s*/,
56                   void */*t*/, size_t /*sz*/);
57   void (*decrypt)(gcipher */*c*/, const void */*s*/,
58                   void */*t*/, size_t /*sz*/);
59   void (*destroy)(gcipher */*c*/);
60   void (*setiv)(gcipher */*c*/, const void */*iv*/);
61   void (*bdry)(gcipher */*c*/);
62 } gcipher_ops;
63
64 typedef struct gccipher {
65   const char *name;                     /* Cipher name */
66   const octet *keysz;                   /* Preferred key size table */
67   size_t blksz;                         /* Block size or zero if none */
68   gcipher *(*init)(const void */*k*/, size_t /*sz*/);
69 } gccipher;
70
71 #define GC_INIT(cc, k, sz)      (cc)->init((k), (sz))
72 #define GC_CLASS(cc)            (cc)->ops->c
73 #define GC_ENCRYPT(c, s, t, sz) (c)->ops->encrypt((c), (s), (t), (sz))
74 #define GC_DECRYPT(c, s, t, sz) (c)->ops->decrypt((c), (s), (t), (sz))
75 #define GC_DESTROY(c)           (c)->ops->destroy((c))
76 #define GC_SETIV(c, iv)         (c)->ops->setiv((c), (iv))
77 #define GC_BDRY(c)              (c)->ops->bdry((c))
78
79 /*----- Tables ------------------------------------------------------------*/
80
81 extern const gccipher *const gciphertab[];
82
83 /* --- @gcipher_byname@ --- *
84  *
85  * Arguments:   @const char *p@ = pointer to name string
86  *
87  * Returns:     The named cipher class, or null.
88  */
89
90 extern const gccipher *gcipher_byname(const char */*p*/);
91
92 /*----- That's all, folks -------------------------------------------------*/
93
94 #ifdef __cplusplus
95   }
96 #endif
97
98 #endif