3 * $Id: gcipher.h,v 1.5 2004/04/21 00:37:32 mdw Exp $
5 * Generic symmetric cipher interface
7 * (c) 1999 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,
30 #ifndef CATACOMB_GCIPHER_H
31 #define CATACOMB_GCIPHER_H
37 /*----- Header files ------------------------------------------------------*/
41 #include <mLib/bits.h>
43 #ifndef CATACOMB_KEYSZ_H
47 /*----- Generic symmetric cipher interface --------------------------------*/
49 typedef struct gcipher
{
50 const struct gcipher_ops
*ops
; /* Pointer to cipher operations */
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*/
);
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*/);
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))
79 /*----- Tables ------------------------------------------------------------*/
81 extern const gccipher
*const gciphertab
[];
83 /* --- @gcipher_byname@ --- *
85 * Arguments: @const char *p@ = pointer to name string
87 * Returns: The named cipher class, or null.
90 extern const gccipher
*gcipher_byname(const char */
*p*/
);
92 /*----- That's all, folks -------------------------------------------------*/