3 * Ciphertext 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_CFB_H
29 #define CATACOMB_CFB_H
35 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/bits.h>
41 #ifndef CATACOMB_GCIPHER_H
45 /*----- Data structures ---------------------------------------------------*/
47 /* --- @CFB_DECL@ --- *
49 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
51 * Use: Creates declarations for CFB mode.
54 #define CFB_DECL(PRE, pre) \
56 /* --- Ciphertext feedback context --- */ \
58 typedef struct pre##_cfbctx { \
59 pre##_ctx ctx; /* Underlying cipher context */ \
60 unsigned off; /* Offset into @iv@ buffer */ \
61 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
64 /* --- @pre_cfbgetiv@ --- * \
66 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
67 * @void *iv@ = pointer to output data block \
71 * Use: Reads the currently set IV. Reading and setting an IV \
72 * is not transparent to the cipher. It will add a `step' \
73 * which must be matched by a similar operation during \
77 extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
80 /* --- @pre_cfbsetiv@ --- * \
82 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
83 * @cnost void *iv@ = pointer to IV to set \
87 * Use: Sets the IV to use for subsequent encryption. \
90 extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
91 const void */*iv*/); \
93 /* --- @pre_cfbbdry@ --- * \
95 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
99 * Use: Inserts a boundary during encryption. Successful \
100 * decryption must place a similar boundary. \
103 extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
105 /* --- @pre_cfbsetkey@ --- * \
107 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
108 * @const pre_ctx *k@ = pointer to cipher context \
112 * Use: Sets the CFB context to use a different cipher key. \
115 extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
116 const pre##_ctx */*k*/); \
118 /* --- @pre_cfbinit@ --- * \
120 * Arguments: @pre_cfbctx *ctx@ = pointer to cipher context \
121 * @const void *key@ = pointer to the key buffer \
122 * @size_t sz@ = size of the key \
123 * @const void *iv@ = pointer to initialization vector \
127 * Use: Initializes a CFB context ready for use. You should \
128 * ensure that the IV chosen is unique: reusing an IV will \
129 * compromise the security of at least the first block \
130 * encrypted. This is equivalent to calls to @pre_init@, \
131 * @pre_cfbsetkey@ and @pre_cfbsetiv@. \
134 extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
135 const void */*key*/, size_t /*sz*/, \
136 const void */*iv*/); \
138 /* --- @pre_cfbencrypt@ --- * \
140 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
141 * @const void *src@ = pointer to source data \
142 * @void *dest@ = pointer to destination data \
143 * @size_t sz@ = size of block to be encrypted \
147 * Use: Encrypts a block with a block cipher in CFB mode. The \
148 * input block may be arbitrary in size. CFB mode is not \
149 * sensitive to block boundaries. \
152 extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
153 const void */*src*/, void */*dest*/, \
156 /* --- @pre_cfbencrypt@ --- * \
158 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
159 * @const void *src@ = pointer to source data \
160 * @void *dest@ = pointer to destination data \
161 * @size_t sz@ = size of block to be encrypted \
165 * Use: Decrypts a block with a block cipher in CFB mode. The \
166 * input block may be arbitrary in size. CFB mode is not \
167 * sensitive to block boundaries. \
170 extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
171 const void */*src*/, void */*dest*/, \
174 /* --- Generic cipher interface --- */ \
176 extern const gccipher pre##_cfb;
178 /*----- That's all, folks -------------------------------------------------*/