Fix bug in daemon mode.
[u/mdw/catacomb] / ofb.h
1 /* -*-c-*-
2 *
3 * $Id: ofb.h,v 1.4 2001/06/17 00:10:51 mdw Exp $
4 *
5 * Output 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: ofb.h,v $
33 * Revision 1.4 2001/06/17 00:10:51 mdw
34 * Typesetting fixes
35 *
36 * Revision 1.3 2000/06/17 11:48:24 mdw
37 * Change buffer offset to be unsigned.
38 *
39 * Revision 1.2 1999/12/10 23:16:40 mdw
40 * Split mode macros into interface and implementation.
41 *
42 * Revision 1.1 1999/09/03 08:41:12 mdw
43 * Initial import.
44 *
45 */
46
47 #ifndef CATACOMB_OFB_H
48 #define CATACOMB_OFB_H
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 /*----- Header files ------------------------------------------------------*/
55
56 #include <stddef.h>
57
58 #include <mLib/bits.h>
59
60 #ifndef CATACOMB_GCIPHER_H
61 # include "gcipher.h"
62 #endif
63
64 #ifndef CATACOMB_GRAND_H
65 # include "grand.h"
66 #endif
67
68 /*----- Macros ------------------------------------------------------------*/
69
70 /* --- @OFB_DECL@ --- *
71 *
72 * Arguments: @PRE@, @pre@ = prefixes for block cipher definitions
73 *
74 * Use: Makes declarations for output feedback mode.
75 */
76
77 #define OFB_DECL(PRE, pre) \
78 \
79 /* --- Output feedback context --- */ \
80 \
81 typedef struct pre##_ofbctx { \
82 pre##_ctx ctx; /* Underlying cipher context */ \
83 unsigned off; /* Current offset in buffer */ \
84 octet iv[PRE##_BLKSZ]; /* Output buffer and IV */ \
85 } pre##_ofbctx; \
86 \
87 /* --- @pre_ofbgetiv@ --- * \
88 * \
89 * Arguments: @const pre_ofbctx *ctx@ = pointer to OFB context block \
90 * @void *iv@ = pointer to output data block \
91 * \
92 * Returns: --- \
93 * \
94 * Use: Reads the currently set IV. Reading and setting an IV \
95 * is not transparent to the cipher. It will add a `step' \
96 * which must be matched by a similar operation during \
97 * decryption. \
98 */ \
99 \
100 extern void pre##_ofbgetiv(const pre##_ofbctx */*ctx*/, \
101 void */*iv*/); \
102 \
103 /* --- @pre_ofbsetiv@ --- * \
104 * \
105 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
106 * @cnost void *iv@ = pointer to IV to set \
107 * \
108 * Returns: --- \
109 * \
110 * Use: Sets the IV to use for subsequent encryption. \
111 */ \
112 \
113 extern void pre##_ofbsetiv(pre##_ofbctx */*ctx*/, \
114 const void */*iv*/); \
115 \
116 /* --- @pre_ofbbdry@ --- * \
117 * \
118 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
119 * \
120 * Returns: --- \
121 * \
122 * Use: Inserts a boundary during encryption. Successful \
123 * decryption must place a similar boundary. \
124 */ \
125 \
126 extern void pre##_ofbbdry(pre##_ofbctx */*ctx*/); \
127 \
128 /* --- @pre_ofbsetkey@ --- * \
129 * \
130 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
131 * @const pre_ctx *k@ = pointer to cipher context \
132 * \
133 * Returns: --- \
134 * \
135 * Use: Sets the OFB context to use a different cipher key. \
136 */ \
137 \
138 extern void pre##_ofbsetkey(pre##_ofbctx */*ctx*/, \
139 const pre##_ctx */*k*/); \
140 \
141 /* --- @pre_ofbinit@ --- * \
142 * \
143 * Arguments: @pre_ofbctx *ctx@ = pointer to cipher context \
144 * @const void *key@ = pointer to the key buffer \
145 * @size_t sz@ = size of the key \
146 * @const void *iv@ = pointer to initialization vector \
147 * \
148 * Returns: --- \
149 * \
150 * Use: Initializes a OFB context ready for use. You should \
151 * ensure that the IV chosen is unique: reusing an IV will \
152 * compromise the security of the entire plaintext. This \
153 * is equivalent to calls to @pre_init@, @pre_ofbsetkey@ \
154 * and @pre_ofbsetiv@. \
155 */ \
156 \
157 extern void pre##_ofbinit(pre##_ofbctx */*ctx*/, \
158 const void */*key*/, size_t /*sz*/, \
159 const void */*iv*/); \
160 \
161 /* --- @pre_ofbencrypt@ --- * \
162 * \
163 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
164 * @const void *src@ = pointer to source data \
165 * @void *dest@ = pointer to destination data \
166 * @size_t sz@ = size of block to be encrypted \
167 * \
168 * Returns: --- \
169 * \
170 * Use: Encrypts or decrypts a block with a block cipher in OFB \
171 * mode: encryption and decryption are the same in OFB. \
172 * The destination may be null to just churn the feedback \
173 * round for a bit. The source may be null to use the \
174 * cipher as a random data generator. \
175 */ \
176 \
177 extern void pre##_ofbencrypt(pre##_ofbctx */*ctx*/, \
178 const void */*src*/, void */*dest*/, \
179 size_t /*sz*/); \
180 \
181 /* --- @pre_ofbrand@ --- * \
182 * \
183 * Arguments: @const void *k@ = pointer to key material \
184 * @size_t sz@ = size of key material \
185 * \
186 * Returns: Pointer to generic random number generator interface. \
187 * \
188 * Use: Creates a random number interface wrapper around an \
189 * OFB-mode block cipher. \
190 */ \
191 \
192 extern grand *pre##_ofbrand(const void */*k*/, size_t /*sz*/); \
193 \
194 /* --- Generic cipher interface --- */ \
195 \
196 extern const gccipher pre##_ofb;
197
198 /*----- That's all, folks -------------------------------------------------*/
199
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif