3 * $Id: cfb.h,v 1.3 2000/06/17 10:50:55 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.3 2000/06/17 10:50:55 mdw
34 * Change buffer offset to be unsigned.
36 * Revision 1.2 1999/12/10 23:16:39 mdw
37 * Split mode macros into interface and implementation.
39 * Revision 1.1 1999/09/03 08:41:11 mdw
44 #ifndef CATACOMB_CFB_H
45 #define CATACOMB_CFB_H
51 /*----- Header files ------------------------------------------------------*/
55 #include <mLib/bits.h>
57 #ifndef CATACOMB_GCIPHER_H
61 /*----- Data structures ---------------------------------------------------*/
63 /* --- @CFB_DECL@ --- *
65 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
67 * Use: Creates declarations for CFB mode.
70 #define CFB_DECL(PRE, pre) \
72 /* --- Ciphertext feedback context --- */ \
74 typedef struct pre##_cfbctx { \
75 pre##_ctx ctx; /* Underlying cipher context */ \
76 unsigned off; /* Offset into @iv@ buffer */ \
77 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
80 /* --- @pre_cfbgetiv@ --- * \
82 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
83 * @void *iv#@ = pointer to output data block \
87 * Use: Reads the currently set IV. Reading and setting an IV \
88 * is not transparent to the cipher. It will add a `step' \
89 * which must be matched by a similar operation during \
93 extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
96 /* --- @pre_cfbsetiv@ --- * \
98 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
99 * @cnost void *iv@ = pointer to IV to set \
103 * Use: Sets the IV to use for subsequent encryption. \
106 extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
107 const void */*iv*/); \
109 /* --- @pre_cfbbdry@ --- * \
111 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
115 * Use: Inserts a boundary during encryption. Successful \
116 * decryption must place a similar boundary. \
119 extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
121 /* --- @pre_cfbsetkey@ --- * \
123 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
124 * @const pre_ctx *k@ = pointer to cipher context \
128 * Use: Sets the CFB context to use a different cipher key. \
131 extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
132 const pre##_ctx */*k*/); \
134 /* --- @pre_cfbinit@ --- * \
136 * Arguments: @pre_cfbctx *ctx@ = pointer to cipher context \
137 * @const void *key@ = pointer to the key buffer \
138 * @size_t sz@ = size of the key \
139 * @const void *iv@ = pointer to initialization vector \
143 * Use: Initializes a CFB context ready for use. You should \
144 * ensure that the IV chosen is unique: reusing an IV will \
145 * compromise the security of at least the first block \
146 * encrypted. This is equivalent to calls to @pre_init@, \
147 * @pre_cfbsetkey@ and @pre_cfbsetiv@. \
150 extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
151 const void */*key*/, size_t /*sz*/, \
152 const void */*iv*/); \
154 /* --- @pre_cfbencrypt@ --- * \
156 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
157 * @const void *src@ = pointer to source data \
158 * @void *dest@ = pointer to destination data \
159 * @size_t sz@ = size of block to be encrypted \
163 * Use: Encrypts a block with a block cipher in CFB mode. The \
164 * input block may be arbitrary in size. CFB mode is not \
165 * sensitive to block boundaries. \
168 extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
169 const void */*src*/, void */*dest*/, \
172 /* --- @pre_cfbencrypt@ --- * \
174 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
175 * @const void *src@ = pointer to source data \
176 * @void *dest@ = pointer to destination data \
177 * @size_t sz@ = size of block to be encrypted \
181 * Use: Decrypts a block with a block cipher in CFB mode. The \
182 * input block may be arbitrary in size. CFB mode is not \
183 * sensitive to block boundaries. \
186 extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
187 const void */*src*/, void */*dest*/, \
190 /* --- Generic cipher interface --- */ \
192 extern const gccipher pre##_cfb;
194 /*----- That's all, folks -------------------------------------------------*/