3 * $Id: cfb.h,v 1.2 1999/12/10 23:16:39 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.2 1999/12/10 23:16:39 mdw
34 * Split mode macros into interface and implementation.
36 * Revision 1.1 1999/09/03 08:41:11 mdw
41 #ifndef CATACOMB_CFB_H
42 #define CATACOMB_CFB_H
48 /*----- Header files ------------------------------------------------------*/
52 #include <mLib/bits.h>
54 #ifndef CATACOMB_GCIPHER_H
58 /*----- Data structures ---------------------------------------------------*/
60 /* --- @CFB_DECL@ --- *
62 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
64 * Use: Creates declarations for CFB mode.
67 #define CFB_DECL(PRE, pre) \
69 /* --- Ciphertext feedback context --- */ \
71 typedef struct pre##_cfbctx { \
72 pre##_ctx ctx; /* Underlying cipher context */ \
73 int off; /* Offset into @iv@ buffer */ \
74 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
77 /* --- @pre_cfbgetiv@ --- * \
79 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
80 * @void *iv#@ = pointer to output data block \
84 * Use: Reads the currently set IV. Reading and setting an IV \
85 * is not transparent to the cipher. It will add a `step' \
86 * which must be matched by a similar operation during \
90 extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
93 /* --- @pre_cfbsetiv@ --- * \
95 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
96 * @cnost void *iv@ = pointer to IV to set \
100 * Use: Sets the IV to use for subsequent encryption. \
103 extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
104 const void */*iv*/); \
106 /* --- @pre_cfbbdry@ --- * \
108 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
112 * Use: Inserts a boundary during encryption. Successful \
113 * decryption must place a similar boundary. \
116 extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
118 /* --- @pre_cfbsetkey@ --- * \
120 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
121 * @const pre_ctx *k@ = pointer to cipher context \
125 * Use: Sets the CFB context to use a different cipher key. \
128 extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
129 const pre##_ctx */*k*/); \
131 /* --- @pre_cfbinit@ --- * \
133 * Arguments: @pre_cfbctx *ctx@ = pointer to cipher context \
134 * @const void *key@ = pointer to the key buffer \
135 * @size_t sz@ = size of the key \
136 * @const void *iv@ = pointer to initialization vector \
140 * Use: Initializes a CFB context ready for use. You should \
141 * ensure that the IV chosen is unique: reusing an IV will \
142 * compromise the security of at least the first block \
143 * encrypted. This is equivalent to calls to @pre_init@, \
144 * @pre_cfbsetkey@ and @pre_cfbsetiv@. \
147 extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
148 const void */*key*/, size_t /*sz*/, \
149 const void */*iv*/); \
151 /* --- @pre_cfbencrypt@ --- * \
153 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
154 * @const void *src@ = pointer to source data \
155 * @void *dest@ = pointer to destination data \
156 * @size_t sz@ = size of block to be encrypted \
160 * Use: Encrypts a block with a block cipher in CFB mode. The \
161 * input block may be arbitrary in size. CFB mode is not \
162 * sensitive to block boundaries. \
165 extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
166 const void */*src*/, void */*dest*/, \
169 /* --- @pre_cfbencrypt@ --- * \
171 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
172 * @const void *src@ = pointer to source data \
173 * @void *dest@ = pointer to destination data \
174 * @size_t sz@ = size of block to be encrypted \
178 * Use: Decrypts a block with a block cipher in CFB mode. The \
179 * input block may be arbitrary in size. CFB mode is not \
180 * sensitive to block boundaries. \
183 extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
184 const void */*src*/, void */*dest*/, \
187 /* --- Generic cipher interface --- */ \
189 extern const gccipher pre##_cfb;
191 /*----- That's all, folks -------------------------------------------------*/