3 * $Id: cfb.h,v 1.5 2004/04/08 01:36:15 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 #ifndef CATACOMB_CFB_H
31 #define CATACOMB_CFB_H
37 /*----- Header files ------------------------------------------------------*/
41 #include <mLib/bits.h>
43 #ifndef CATACOMB_GCIPHER_H
47 /*----- Data structures ---------------------------------------------------*/
49 /* --- @CFB_DECL@ --- *
51 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
53 * Use: Creates declarations for CFB mode.
56 #define CFB_DECL(PRE, pre) \
58 /* --- Ciphertext feedback context --- */ \
60 typedef struct pre##_cfbctx { \
61 pre##_ctx ctx; /* Underlying cipher context */ \
62 unsigned off; /* Offset into @iv@ buffer */ \
63 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
66 /* --- @pre_cfbgetiv@ --- * \
68 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
69 * @void *iv@ = pointer to output data block \
73 * Use: Reads the currently set IV. Reading and setting an IV \
74 * is not transparent to the cipher. It will add a `step' \
75 * which must be matched by a similar operation during \
79 extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
82 /* --- @pre_cfbsetiv@ --- * \
84 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
85 * @cnost void *iv@ = pointer to IV to set \
89 * Use: Sets the IV to use for subsequent encryption. \
92 extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
93 const void */*iv*/); \
95 /* --- @pre_cfbbdry@ --- * \
97 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
101 * Use: Inserts a boundary during encryption. Successful \
102 * decryption must place a similar boundary. \
105 extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
107 /* --- @pre_cfbsetkey@ --- * \
109 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
110 * @const pre_ctx *k@ = pointer to cipher context \
114 * Use: Sets the CFB context to use a different cipher key. \
117 extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
118 const pre##_ctx */*k*/); \
120 /* --- @pre_cfbinit@ --- * \
122 * Arguments: @pre_cfbctx *ctx@ = pointer to cipher context \
123 * @const void *key@ = pointer to the key buffer \
124 * @size_t sz@ = size of the key \
125 * @const void *iv@ = pointer to initialization vector \
129 * Use: Initializes a CFB context ready for use. You should \
130 * ensure that the IV chosen is unique: reusing an IV will \
131 * compromise the security of at least the first block \
132 * encrypted. This is equivalent to calls to @pre_init@, \
133 * @pre_cfbsetkey@ and @pre_cfbsetiv@. \
136 extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
137 const void */*key*/, size_t /*sz*/, \
138 const void */*iv*/); \
140 /* --- @pre_cfbencrypt@ --- * \
142 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
143 * @const void *src@ = pointer to source data \
144 * @void *dest@ = pointer to destination data \
145 * @size_t sz@ = size of block to be encrypted \
149 * Use: Encrypts a block with a block cipher in CFB mode. The \
150 * input block may be arbitrary in size. CFB mode is not \
151 * sensitive to block boundaries. \
154 extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
155 const void */*src*/, void */*dest*/, \
158 /* --- @pre_cfbencrypt@ --- * \
160 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
161 * @const void *src@ = pointer to source data \
162 * @void *dest@ = pointer to destination data \
163 * @size_t sz@ = size of block to be encrypted \
167 * Use: Decrypts a block with a block cipher in CFB mode. The \
168 * input block may be arbitrary in size. CFB mode is not \
169 * sensitive to block boundaries. \
172 extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
173 const void */*src*/, void */*dest*/, \
176 /* --- Generic cipher interface --- */ \
178 extern const gccipher pre##_cfb;
180 /*----- That's all, folks -------------------------------------------------*/