3 * $Id: ofb.h,v 1.5 2004/04/08 01:36:15 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 #ifndef CATACOMB_OFB_H
31 #define CATACOMB_OFB_H
37 /*----- Header files ------------------------------------------------------*/
41 #include <mLib/bits.h>
43 #ifndef CATACOMB_GCIPHER_H
47 #ifndef CATACOMB_GRAND_H
51 /*----- Macros ------------------------------------------------------------*/
53 /* --- @OFB_DECL@ --- *
55 * Arguments: @PRE@, @pre@ = prefixes for block cipher definitions
57 * Use: Makes declarations for output feedback mode.
60 #define OFB_DECL(PRE, pre) \
62 /* --- Output feedback context --- */ \
64 typedef struct pre##_ofbctx { \
65 pre##_ctx ctx; /* Underlying cipher context */ \
66 unsigned off; /* Current offset in buffer */ \
67 octet iv[PRE##_BLKSZ]; /* Output buffer and IV */ \
70 /* --- @pre_ofbgetiv@ --- * \
72 * Arguments: @const pre_ofbctx *ctx@ = pointer to OFB context block \
73 * @void *iv@ = pointer to output data block \
77 * Use: Reads the currently set IV. Reading and setting an IV \
78 * is not transparent to the cipher. It will add a `step' \
79 * which must be matched by a similar operation during \
83 extern void pre##_ofbgetiv(const pre##_ofbctx */*ctx*/, \
86 /* --- @pre_ofbsetiv@ --- * \
88 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
89 * @cnost void *iv@ = pointer to IV to set \
93 * Use: Sets the IV to use for subsequent encryption. \
96 extern void pre##_ofbsetiv(pre##_ofbctx */*ctx*/, \
97 const void */*iv*/); \
99 /* --- @pre_ofbbdry@ --- * \
101 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
105 * Use: Inserts a boundary during encryption. Successful \
106 * decryption must place a similar boundary. \
109 extern void pre##_ofbbdry(pre##_ofbctx */*ctx*/); \
111 /* --- @pre_ofbsetkey@ --- * \
113 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
114 * @const pre_ctx *k@ = pointer to cipher context \
118 * Use: Sets the OFB context to use a different cipher key. \
121 extern void pre##_ofbsetkey(pre##_ofbctx */*ctx*/, \
122 const pre##_ctx */*k*/); \
124 /* --- @pre_ofbinit@ --- * \
126 * Arguments: @pre_ofbctx *ctx@ = pointer to cipher context \
127 * @const void *key@ = pointer to the key buffer \
128 * @size_t sz@ = size of the key \
129 * @const void *iv@ = pointer to initialization vector \
133 * Use: Initializes a OFB context ready for use. You should \
134 * ensure that the IV chosen is unique: reusing an IV will \
135 * compromise the security of the entire plaintext. This \
136 * is equivalent to calls to @pre_init@, @pre_ofbsetkey@ \
137 * and @pre_ofbsetiv@. \
140 extern void pre##_ofbinit(pre##_ofbctx */*ctx*/, \
141 const void */*key*/, size_t /*sz*/, \
142 const void */*iv*/); \
144 /* --- @pre_ofbencrypt@ --- * \
146 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
147 * @const void *src@ = pointer to source data \
148 * @void *dest@ = pointer to destination data \
149 * @size_t sz@ = size of block to be encrypted \
153 * Use: Encrypts or decrypts a block with a block cipher in OFB \
154 * mode: encryption and decryption are the same in OFB. \
155 * The destination may be null to just churn the feedback \
156 * round for a bit. The source may be null to use the \
157 * cipher as a random data generator. \
160 extern void pre##_ofbencrypt(pre##_ofbctx */*ctx*/, \
161 const void */*src*/, void */*dest*/, \
164 /* --- @pre_ofbrand@ --- * \
166 * Arguments: @const void *k@ = pointer to key material \
167 * @size_t sz@ = size of key material \
169 * Returns: Pointer to generic random number generator interface. \
171 * Use: Creates a random number interface wrapper around an \
172 * OFB-mode block cipher. \
175 extern grand *pre##_ofbrand(const void */*k*/, size_t /*sz*/); \
177 /* --- Generic cipher interface --- */ \
179 extern const gccipher pre##_ofb;
181 /*----- That's all, folks -------------------------------------------------*/