3 * Output feedback for block ciphers
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #ifndef CATACOMB_OFB_H
29 #define CATACOMB_OFB_H
35 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/bits.h>
41 #ifndef CATACOMB_GCIPHER_H
45 #ifndef CATACOMB_GRAND_H
49 /*----- Macros ------------------------------------------------------------*/
51 /* --- @OFB_DECL@ --- *
53 * Arguments: @PRE@, @pre@ = prefixes for block cipher definitions
55 * Use: Makes declarations for output feedback mode.
58 #define OFB_DECL(PRE, pre) \
60 /* --- Output feedback context --- */ \
62 typedef struct pre##_ofbctx { \
63 pre##_ctx ctx; /* Underlying cipher context */ \
64 unsigned off; /* Current offset in buffer */ \
65 octet b[PRE##_BLKSZ]; /* Output buffer and IV */ \
68 /* --- @pre_ofbgetiv@ --- * \
70 * Arguments: @const pre_ofbctx *ctx@ = pointer to OFB context block \
71 * @void *iv@ = pointer to output data block \
75 * Use: Reads the currently set IV. Reading and setting an IV \
76 * is not transparent to the cipher. It will add a `step' \
77 * which must be matched by a similar operation during \
81 extern void pre##_ofbgetiv(const pre##_ofbctx */*ctx*/, \
84 /* --- @pre_ofbsetiv@ --- * \
86 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
87 * @cnost void *iv@ = pointer to IV to set \
91 * Use: Sets the IV to use for subsequent encryption. \
94 extern void pre##_ofbsetiv(pre##_ofbctx */*ctx*/, \
95 const void */*iv*/); \
97 /* --- @pre_ofbbdry@ --- * \
99 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
103 * Use: Inserts a boundary during encryption. Successful \
104 * decryption must place a similar boundary. \
107 extern void pre##_ofbbdry(pre##_ofbctx */*ctx*/); \
109 /* --- @pre_ofbsetkey@ --- * \
111 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
112 * @const pre_ctx *k@ = pointer to cipher context \
116 * Use: Sets the OFB context to use a different cipher key. \
119 extern void pre##_ofbsetkey(pre##_ofbctx */*ctx*/, \
120 const pre##_ctx */*k*/); \
122 /* --- @pre_ofbinit@ --- * \
124 * Arguments: @pre_ofbctx *ctx@ = pointer to cipher context \
125 * @const void *key@ = pointer to the key buffer \
126 * @size_t sz@ = size of the key \
127 * @const void *iv@ = pointer to initialization vector \
131 * Use: Initializes a OFB context ready for use. You should \
132 * ensure that the IV chosen is unique: reusing an IV will \
133 * compromise the security of the entire plaintext. This \
134 * is equivalent to calls to @pre_init@, @pre_ofbsetkey@ \
135 * and @pre_ofbsetiv@. \
138 extern void pre##_ofbinit(pre##_ofbctx */*ctx*/, \
139 const void */*key*/, size_t /*sz*/, \
140 const void */*iv*/); \
142 /* --- @pre_ofbencrypt@ --- * \
144 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
145 * @const void *src@ = pointer to source data \
146 * @void *dest@ = pointer to destination data \
147 * @size_t sz@ = size of block to be encrypted \
151 * Use: Encrypts or decrypts a block with a block cipher in OFB \
152 * mode: encryption and decryption are the same in OFB. \
153 * The destination may be null to just churn the feedback \
154 * round for a bit. The source may be null to use the \
155 * cipher as a random data generator. \
158 extern void pre##_ofbencrypt(pre##_ofbctx */*ctx*/, \
159 const void */*src*/, void */*dest*/, \
162 /* --- @pre_ofbrand@ --- * \
164 * Arguments: @const void *k@ = pointer to key material \
165 * @size_t sz@ = size of key material \
167 * Returns: Pointer to generic random number generator interface. \
169 * Use: Creates a random number interface wrapper around an \
170 * OFB-mode block cipher. \
173 extern grand *pre##_ofbrand(const void */*k*/, size_t /*sz*/); \
175 /* --- Generic cipher interface --- */ \
177 extern const gccipher pre##_ofb;
179 /*----- That's all, folks -------------------------------------------------*/