More changes. Still embryonic.
[u/mdw/catacomb] / cfb.h
1 /* -*-c-*-
2 *
3 * $Id: cfb.h,v 1.2 1999/12/10 23:16:39 mdw Exp $
4 *
5 * Ciphertext feedback for block ciphers
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 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: cfb.h,v $
33 * Revision 1.2 1999/12/10 23:16:39 mdw
34 * Split mode macros into interface and implementation.
35 *
36 * Revision 1.1 1999/09/03 08:41:11 mdw
37 * Initial import.
38 *
39 */
40
41 #ifndef CATACOMB_CFB_H
42 #define CATACOMB_CFB_H
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /*----- Header files ------------------------------------------------------*/
49
50 #include <stddef.h>
51
52 #include <mLib/bits.h>
53
54 #ifndef CATACOMB_GCIPHER_H
55 # include "gcipher.h"
56 #endif
57
58 /*----- Data structures ---------------------------------------------------*/
59
60 /* --- @CFB_DECL@ --- *
61 *
62 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
63 *
64 * Use: Creates declarations for CFB mode.
65 */
66
67 #define CFB_DECL(PRE, pre) \
68 \
69 /* --- Ciphertext feedback context --- */ \
70 \
71 typedef struct pre##_cfbctx { \
72 pre##_ctx ctx; /* Underlying cipher context */ \
73 int off; /* Offset into @iv@ buffer */ \
74 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
75 } pre##_cfbctx; \
76 \
77 /* --- @pre_cfbgetiv@ --- * \
78 * \
79 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
80 * @void *iv#@ = pointer to output data block \
81 * \
82 * Returns: --- \
83 * \
84 * Use: Reads the currently set IV. Reading and setting an IV \
85 * is not transparent to the cipher. It will add a `step' \
86 * which must be matched by a similar operation during \
87 * decryption. \
88 */ \
89 \
90 extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
91 void */*iv*/); \
92 \
93 /* --- @pre_cfbsetiv@ --- * \
94 * \
95 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
96 * @cnost void *iv@ = pointer to IV to set \
97 * \
98 * Returns: --- \
99 * \
100 * Use: Sets the IV to use for subsequent encryption. \
101 */ \
102 \
103 extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
104 const void */*iv*/); \
105 \
106 /* --- @pre_cfbbdry@ --- * \
107 * \
108 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
109 * \
110 * Returns: --- \
111 * \
112 * Use: Inserts a boundary during encryption. Successful \
113 * decryption must place a similar boundary. \
114 */ \
115 \
116 extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
117 \
118 /* --- @pre_cfbsetkey@ --- * \
119 * \
120 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
121 * @const pre_ctx *k@ = pointer to cipher context \
122 * \
123 * Returns: --- \
124 * \
125 * Use: Sets the CFB context to use a different cipher key. \
126 */ \
127 \
128 extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
129 const pre##_ctx */*k*/); \
130 \
131 /* --- @pre_cfbinit@ --- * \
132 * \
133 * Arguments: @pre_cfbctx *ctx@ = pointer to cipher context \
134 * @const void *key@ = pointer to the key buffer \
135 * @size_t sz@ = size of the key \
136 * @const void *iv@ = pointer to initialization vector \
137 * \
138 * Returns: --- \
139 * \
140 * Use: Initializes a CFB context ready for use. You should \
141 * ensure that the IV chosen is unique: reusing an IV will \
142 * compromise the security of at least the first block \
143 * encrypted. This is equivalent to calls to @pre_init@, \
144 * @pre_cfbsetkey@ and @pre_cfbsetiv@. \
145 */ \
146 \
147 extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
148 const void */*key*/, size_t /*sz*/, \
149 const void */*iv*/); \
150 \
151 /* --- @pre_cfbencrypt@ --- * \
152 * \
153 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
154 * @const void *src@ = pointer to source data \
155 * @void *dest@ = pointer to destination data \
156 * @size_t sz@ = size of block to be encrypted \
157 * \
158 * Returns: --- \
159 * \
160 * Use: Encrypts a block with a block cipher in CFB mode. The \
161 * input block may be arbitrary in size. CFB mode is not \
162 * sensitive to block boundaries. \
163 */ \
164 \
165 extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
166 const void */*src*/, void */*dest*/, \
167 size_t /*sz*/); \
168 \
169 /* --- @pre_cfbencrypt@ --- * \
170 * \
171 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
172 * @const void *src@ = pointer to source data \
173 * @void *dest@ = pointer to destination data \
174 * @size_t sz@ = size of block to be encrypted \
175 * \
176 * Returns: --- \
177 * \
178 * Use: Decrypts a block with a block cipher in CFB mode. The \
179 * input block may be arbitrary in size. CFB mode is not \
180 * sensitive to block boundaries. \
181 */ \
182 \
183 extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
184 const void */*src*/, void */*dest*/, \
185 size_t /*sz*/); \
186 \
187 /* --- Generic cipher interface --- */ \
188 \
189 extern const gccipher pre##_cfb;
190
191 /*----- That's all, folks -------------------------------------------------*/
192
193 #ifdef __cplusplus
194 }
195 #endif
196
197 #endif