3 * $Id: cfb.h,v 1.4 2001/06/17 00:10:51 mdw Exp $
5 * Ciphertext 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 10:50:55 mdw
37 * Change buffer offset to be unsigned.
39 * Revision 1.2 1999/12/10 23:16:39 mdw
40 * Split mode macros into interface and implementation.
42 * Revision 1.1 1999/09/03 08:41:11 mdw
47 #ifndef CATACOMB_CFB_H
48 #define CATACOMB_CFB_H
54 /*----- Header files ------------------------------------------------------*/
58 #include <mLib/bits.h>
60 #ifndef CATACOMB_GCIPHER_H
64 /*----- Data structures ---------------------------------------------------*/
66 /* --- @CFB_DECL@ --- *
68 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
70 * Use: Creates declarations for CFB mode.
73 #define CFB_DECL(PRE, pre) \
75 /* --- Ciphertext feedback context --- */ \
77 typedef struct pre##_cfbctx { \
78 pre##_ctx ctx; /* Underlying cipher context */ \
79 unsigned off; /* Offset into @iv@ buffer */ \
80 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
83 /* --- @pre_cfbgetiv@ --- * \
85 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
86 * @void *iv@ = pointer to output data block \
90 * Use: Reads the currently set IV. Reading and setting an IV \
91 * is not transparent to the cipher. It will add a `step' \
92 * which must be matched by a similar operation during \
96 extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
99 /* --- @pre_cfbsetiv@ --- * \
101 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
102 * @cnost void *iv@ = pointer to IV to set \
106 * Use: Sets the IV to use for subsequent encryption. \
109 extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
110 const void */*iv*/); \
112 /* --- @pre_cfbbdry@ --- * \
114 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
118 * Use: Inserts a boundary during encryption. Successful \
119 * decryption must place a similar boundary. \
122 extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
124 /* --- @pre_cfbsetkey@ --- * \
126 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
127 * @const pre_ctx *k@ = pointer to cipher context \
131 * Use: Sets the CFB context to use a different cipher key. \
134 extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
135 const pre##_ctx */*k*/); \
137 /* --- @pre_cfbinit@ --- * \
139 * Arguments: @pre_cfbctx *ctx@ = pointer to cipher context \
140 * @const void *key@ = pointer to the key buffer \
141 * @size_t sz@ = size of the key \
142 * @const void *iv@ = pointer to initialization vector \
146 * Use: Initializes a CFB context ready for use. You should \
147 * ensure that the IV chosen is unique: reusing an IV will \
148 * compromise the security of at least the first block \
149 * encrypted. This is equivalent to calls to @pre_init@, \
150 * @pre_cfbsetkey@ and @pre_cfbsetiv@. \
153 extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
154 const void */*key*/, size_t /*sz*/, \
155 const void */*iv*/); \
157 /* --- @pre_cfbencrypt@ --- * \
159 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
160 * @const void *src@ = pointer to source data \
161 * @void *dest@ = pointer to destination data \
162 * @size_t sz@ = size of block to be encrypted \
166 * Use: Encrypts a block with a block cipher in CFB mode. The \
167 * input block may be arbitrary in size. CFB mode is not \
168 * sensitive to block boundaries. \
171 extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
172 const void */*src*/, void */*dest*/, \
175 /* --- @pre_cfbencrypt@ --- * \
177 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
178 * @const void *src@ = pointer to source data \
179 * @void *dest@ = pointer to destination data \
180 * @size_t sz@ = size of block to be encrypted \
184 * Use: Decrypts a block with a block cipher in CFB mode. The \
185 * input block may be arbitrary in size. CFB mode is not \
186 * sensitive to block boundaries. \
189 extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
190 const void */*src*/, void */*dest*/, \
193 /* --- Generic cipher interface --- */ \
195 extern const gccipher pre##_cfb;
197 /*----- That's all, folks -------------------------------------------------*/