3 * $Id: ofb.h,v 1.3 2000/06/17 11:48:24 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.3 2000/06/17 11:48:24 mdw
34 * Change buffer offset to be unsigned.
36 * Revision 1.2 1999/12/10 23:16:40 mdw
37 * Split mode macros into interface and implementation.
39 * Revision 1.1 1999/09/03 08:41:12 mdw
44 #ifndef CATACOMB_OFB_H
45 #define CATACOMB_OFB_H
51 /*----- Header files ------------------------------------------------------*/
55 #include <mLib/bits.h>
57 #ifndef CATACOMB_GCIPHER_H
61 #ifndef CATACOMB_GRAND_H
65 /*----- Macros ------------------------------------------------------------*/
67 /* --- @OFB_DECL@ --- *
69 * Arguments: @PRE@, @pre@ = prefixes for block cipher definitions
71 * Use: Makes declarations for output feedback mode.
74 #define OFB_DECL(PRE, pre) \
76 /* --- Output feedback context --- */ \
78 typedef struct pre##_ofbctx { \
79 pre##_ctx ctx; /* Underlying cipher context */ \
80 unsigned off; /* Current offset in buffer */ \
81 octet iv[PRE##_BLKSZ]; /* Output buffer and IV */ \
84 /* --- @pre_ofbgetiv@ --- * \
86 * Arguments: @const pre_ofbctx *ctx@ = pointer to OFB context block \
87 * @void *iv#@ = pointer to output data block \
91 * Use: Reads the currently set IV. Reading and setting an IV \
92 * is not transparent to the cipher. It will add a `step' \
93 * which must be matched by a similar operation during \
97 extern void pre##_ofbgetiv(const pre##_ofbctx */*ctx*/, \
100 /* --- @pre_ofbsetiv@ --- * \
102 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
103 * @cnost void *iv@ = pointer to IV to set \
107 * Use: Sets the IV to use for subsequent encryption. \
110 extern void pre##_ofbsetiv(pre##_ofbctx */*ctx*/, \
111 const void */*iv*/); \
113 /* --- @pre_ofbbdry@ --- * \
115 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
119 * Use: Inserts a boundary during encryption. Successful \
120 * decryption must place a similar boundary. \
123 extern void pre##_ofbbdry(pre##_ofbctx */*ctx*/); \
125 /* --- @pre_ofbsetkey@ --- * \
127 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
128 * @const pre_ctx *k@ = pointer to cipher context \
132 * Use: Sets the OFB context to use a different cipher key. \
135 extern void pre##_ofbsetkey(pre##_ofbctx */*ctx*/, \
136 const pre##_ctx */*k*/); \
138 /* --- @pre_ofbinit@ --- * \
140 * Arguments: @pre_ofbctx *ctx@ = pointer to cipher context \
141 * @const void *key@ = pointer to the key buffer \
142 * @size_t sz@ = size of the key \
143 * @const void *iv@ = pointer to initialization vector \
147 * Use: Initializes a OFB context ready for use. You should \
148 * ensure that the IV chosen is unique: reusing an IV will \
149 * compromise the security of the entire plaintext. This \
150 * is equivalent to calls to @pre_init@, @pre_ofbsetkey@ \
151 * and @pre_ofbsetiv@. \
154 extern void pre##_ofbinit(pre##_ofbctx */*ctx*/, \
155 const void */*key*/, size_t /*sz*/, \
156 const void */*iv*/); \
158 /* --- @pre_ofbencrypt@ --- * \
160 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
161 * @const void *src@ = pointer to source data \
162 * @void *dest@ = pointer to destination data \
163 * @size_t sz@ = size of block to be encrypted \
167 * Use: Encrypts or decrypts a block with a block cipher in OFB \
168 * mode: encryption and decryption are the same in OFB. \
169 * The destination may be null to just churn the feedback \
170 * round for a bit. The source may be null to use the \
171 * cipher as a random data generator. \
174 extern void pre##_ofbencrypt(pre##_ofbctx */*ctx*/, \
175 const void */*src*/, void */*dest*/, \
178 /* --- @pre_ofbrand@ --- * \
180 * Arguments: @const void *k@ = pointer to key material \
181 * @size_t sz@ = size of key material \
183 * Returns: Pointer to generic random number generator interface. \
185 * Use: Creates a random number interface wrapper around an \
186 * OFB-mode block cipher. \
189 extern grand *pre##_ofbrand(const void */*k*/, size_t /*sz*/); \
191 /* --- Generic cipher interface --- */ \
193 extern const gccipher pre##_ofb;
195 /*----- That's all, folks -------------------------------------------------*/