Commit | Line | Data |
---|---|---|
aa1082f2 | 1 | /* -*-c-*- |
aa1082f2 | 2 | * |
3 | * Generic symmetric cipher interface | |
4 | * | |
5 | * (c) 1999 Straylight/Edgeware | |
6 | */ | |
7 | ||
45c0fd36 | 8 | /*----- Licensing notice --------------------------------------------------* |
aa1082f2 | 9 | * |
10 | * This file is part of Catacomb. | |
11 | * | |
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. | |
45c0fd36 | 16 | * |
aa1082f2 | 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. | |
45c0fd36 | 21 | * |
aa1082f2 | 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, | |
25 | * MA 02111-1307, USA. | |
26 | */ | |
27 | ||
aa1082f2 | 28 | #ifndef CATACOMB_GCIPHER_H |
29 | #define CATACOMB_GCIPHER_H | |
30 | ||
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
35 | /*----- Header files ------------------------------------------------------*/ | |
36 | ||
37 | #include <stddef.h> | |
38 | ||
b7e9df9c | 39 | #include <mLib/bits.h> |
aa1082f2 | 40 | |
c61ee18c MW |
41 | #ifndef CATACOMB_KEYSZ_H |
42 | # include "keysz.h" | |
43 | #endif | |
44 | ||
b7e9df9c | 45 | /*----- Generic symmetric cipher interface --------------------------------*/ |
aa1082f2 | 46 | |
47 | typedef struct gcipher { | |
48 | const struct gcipher_ops *ops; /* Pointer to cipher operations */ | |
49 | } gcipher; | |
50 | ||
51 | typedef struct gcipher_ops { | |
b7e9df9c | 52 | const struct gccipher *c; /* Pointer to cipher class */ |
aa1082f2 | 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*/); | |
60 | } gcipher_ops; | |
61 | ||
62 | typedef struct gccipher { | |
b7e9df9c | 63 | const char *name; /* Cipher name */ |
64 | const octet *keysz; /* Preferred key size table */ | |
65 | size_t blksz; /* Block size or zero if none */ | |
aa1082f2 | 66 | gcipher *(*init)(const void */*k*/, size_t /*sz*/); |
67 | } gccipher; | |
68 | ||
59919ae4 | 69 | #define GC_INIT(cc, k, sz) (cc)->init((k), (sz)) |
e2edda68 | 70 | #define GC_CLASS(cc) (cc)->ops->c |
59919ae4 | 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)) | |
76 | ||
59919ae4 | 77 | /*----- Tables ------------------------------------------------------------*/ |
78 | ||
79 | extern const gccipher *const gciphertab[]; | |
80 | ||
81 | /* --- @gcipher_byname@ --- * | |
82 | * | |
83 | * Arguments: @const char *p@ = pointer to name string | |
84 | * | |
85 | * Returns: The named cipher class, or null. | |
86 | */ | |
87 | ||
88 | extern const gccipher *gcipher_byname(const char */*p*/); | |
89 | ||
aa1082f2 | 90 | /*----- That's all, folks -------------------------------------------------*/ |
91 | ||
92 | #ifdef __cplusplus | |
93 | } | |
94 | #endif | |
95 | ||
96 | #endif |