Catcrypt tools: Roll out progress indicator stuff from hashsum.
[u/mdw/catacomb] / gcipher.h
CommitLineData
aa1082f2 1/* -*-c-*-
2 *
e2edda68 3 * $Id: gcipher.h,v 1.5 2004/04/21 00:37:32 mdw Exp $
aa1082f2 4 *
5 * Generic symmetric cipher interface
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
45c0fd36 10/*----- Licensing notice --------------------------------------------------*
aa1082f2 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.
45c0fd36 18 *
aa1082f2 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.
45c0fd36 23 *
aa1082f2 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
aa1082f2 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
b7e9df9c 41#include <mLib/bits.h>
aa1082f2 42
c61ee18c
MW
43#ifndef CATACOMB_KEYSZ_H
44# include "keysz.h"
45#endif
46
b7e9df9c 47/*----- Generic symmetric cipher interface --------------------------------*/
aa1082f2 48
49typedef struct gcipher {
50 const struct gcipher_ops *ops; /* Pointer to cipher operations */
51} gcipher;
52
53typedef struct gcipher_ops {
b7e9df9c 54 const struct gccipher *c; /* Pointer to cipher class */
aa1082f2 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
64typedef struct gccipher {
b7e9df9c 65 const char *name; /* Cipher name */
66 const octet *keysz; /* Preferred key size table */
67 size_t blksz; /* Block size or zero if none */
aa1082f2 68 gcipher *(*init)(const void */*k*/, size_t /*sz*/);
69} gccipher;
70
59919ae4 71#define GC_INIT(cc, k, sz) (cc)->init((k), (sz))
e2edda68 72#define GC_CLASS(cc) (cc)->ops->c
59919ae4 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
59919ae4 79/*----- Tables ------------------------------------------------------------*/
80
81extern 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
90extern const gccipher *gcipher_byname(const char */*p*/);
91
aa1082f2 92/*----- That's all, folks -------------------------------------------------*/
93
94#ifdef __cplusplus
95 }
96#endif
97
98#endif