3 * $Id: ofb.h,v 1.4 2001/06/17 00:10:51 mdw Exp $
5 * Output feedback for block ciphers
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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.4 2001/06/17 00:10:51 mdw
36 * Revision 1.3 2000/06/17 11:48:24 mdw
37 * Change buffer offset to be unsigned.
39 * Revision 1.2 1999/12/10 23:16:40 mdw
40 * Split mode macros into interface and implementation.
42 * Revision 1.1 1999/09/03 08:41:12 mdw
47 #ifndef CATACOMB_OFB_H
48 #define CATACOMB_OFB_H
54 /*----- Header files ------------------------------------------------------*/
58 #include <mLib/bits.h>
60 #ifndef CATACOMB_GCIPHER_H
64 #ifndef CATACOMB_GRAND_H
68 /*----- Macros ------------------------------------------------------------*/
70 /* --- @OFB_DECL@ --- *
72 * Arguments: @PRE@, @pre@ = prefixes for block cipher definitions
74 * Use: Makes declarations for output feedback mode.
77 #define OFB_DECL(PRE, pre) \
79 /* --- Output feedback context --- */ \
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 */ \
87 /* --- @pre_ofbgetiv@ --- * \
89 * Arguments: @const pre_ofbctx *ctx@ = pointer to OFB context block \
90 * @void *iv@ = pointer to output data block \
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 \
100 extern void pre##_ofbgetiv(const pre##_ofbctx */*ctx*/, \
103 /* --- @pre_ofbsetiv@ --- * \
105 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
106 * @cnost void *iv@ = pointer to IV to set \
110 * Use: Sets the IV to use for subsequent encryption. \
113 extern void pre##_ofbsetiv(pre##_ofbctx */*ctx*/, \
114 const void */*iv*/); \
116 /* --- @pre_ofbbdry@ --- * \
118 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
122 * Use: Inserts a boundary during encryption. Successful \
123 * decryption must place a similar boundary. \
126 extern void pre##_ofbbdry(pre##_ofbctx */*ctx*/); \
128 /* --- @pre_ofbsetkey@ --- * \
130 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
131 * @const pre_ctx *k@ = pointer to cipher context \
135 * Use: Sets the OFB context to use a different cipher key. \
138 extern void pre##_ofbsetkey(pre##_ofbctx */*ctx*/, \
139 const pre##_ctx */*k*/); \
141 /* --- @pre_ofbinit@ --- * \
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 \
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@. \
157 extern void pre##_ofbinit(pre##_ofbctx */*ctx*/, \
158 const void */*key*/, size_t /*sz*/, \
159 const void */*iv*/); \
161 /* --- @pre_ofbencrypt@ --- * \
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 \
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. \
177 extern void pre##_ofbencrypt(pre##_ofbctx */*ctx*/, \
178 const void */*src*/, void */*dest*/, \
181 /* --- @pre_ofbrand@ --- * \
183 * Arguments: @const void *k@ = pointer to key material \
184 * @size_t sz@ = size of key material \
186 * Returns: Pointer to generic random number generator interface. \
188 * Use: Creates a random number interface wrapper around an \
189 * OFB-mode block cipher. \
192 extern grand *pre##_ofbrand(const void */*k*/, size_t /*sz*/); \
194 /* --- Generic cipher interface --- */ \
196 extern const gccipher pre##_ofb;
198 /*----- That's all, folks -------------------------------------------------*/