Indentation fix.
[u/mdw/catacomb] / cfb.h
CommitLineData
d03ab969 1/* -*-c-*-
2 *
4efe32ba 3 * $Id: cfb.h,v 1.4 2001/06/17 00:10:51 mdw Exp $
d03ab969 4 *
5 * Ciphertext feedback for block ciphers
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: cfb.h,v $
4efe32ba 33 * Revision 1.4 2001/06/17 00:10:51 mdw
34 * Typesetting fixes
35 *
e97df21b 36 * Revision 1.3 2000/06/17 10:50:55 mdw
37 * Change buffer offset to be unsigned.
38 *
79ba130c 39 * Revision 1.2 1999/12/10 23:16:39 mdw
40 * Split mode macros into interface and implementation.
41 *
d03ab969 42 * Revision 1.1 1999/09/03 08:41:11 mdw
43 * Initial import.
44 *
45 */
46
79ba130c 47#ifndef CATACOMB_CFB_H
48#define CATACOMB_CFB_H
d03ab969 49
50#ifdef __cplusplus
51 extern "C" {
52#endif
53
54/*----- Header files ------------------------------------------------------*/
55
79ba130c 56#include <stddef.h>
d03ab969 57
58#include <mLib/bits.h>
59
79ba130c 60#ifndef CATACOMB_GCIPHER_H
61# include "gcipher.h"
d03ab969 62#endif
63
64/*----- Data structures ---------------------------------------------------*/
65
66/* --- @CFB_DECL@ --- *
67 *
68 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
69 *
70 * Use: Creates declarations for CFB mode.
71 */
72
73#define CFB_DECL(PRE, pre) \
74 \
79ba130c 75/* --- Ciphertext feedback context --- */ \
d03ab969 76 \
79ba130c 77typedef struct pre##_cfbctx { \
78 pre##_ctx ctx; /* Underlying cipher context */ \
e97df21b 79 unsigned off; /* Offset into @iv@ buffer */ \
79ba130c 80 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
81} pre##_cfbctx; \
d03ab969 82 \
83/* --- @pre_cfbgetiv@ --- * \
84 * \
85 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
4efe32ba 86 * @void *iv@ = pointer to output data block \
d03ab969 87 * \
88 * Returns: --- \
89 * \
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 \
93 * decryption. \
94 */ \
95 \
79ba130c 96extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
97 void */*iv*/); \
d03ab969 98 \
99/* --- @pre_cfbsetiv@ --- * \
100 * \
101 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
102 * @cnost void *iv@ = pointer to IV to set \
103 * \
104 * Returns: --- \
105 * \
106 * Use: Sets the IV to use for subsequent encryption. \
107 */ \
108 \
79ba130c 109extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
110 const void */*iv*/); \
d03ab969 111 \
112/* --- @pre_cfbbdry@ --- * \
113 * \
114 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
115 * \
116 * Returns: --- \
117 * \
118 * Use: Inserts a boundary during encryption. Successful \
119 * decryption must place a similar boundary. \
120 */ \
121 \
79ba130c 122extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
d03ab969 123 \
124/* --- @pre_cfbsetkey@ --- * \
125 * \
126 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
127 * @const pre_ctx *k@ = pointer to cipher context \
128 * \
129 * Returns: --- \
130 * \
131 * Use: Sets the CFB context to use a different cipher key. \
132 */ \
133 \
79ba130c 134extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
135 const pre##_ctx */*k*/); \
d03ab969 136 \
137/* --- @pre_cfbinit@ --- * \
138 * \
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 \
143 * \
144 * Returns: --- \
145 * \
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@. \
151 */ \
152 \
79ba130c 153extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
154 const void */*key*/, size_t /*sz*/, \
155 const void */*iv*/); \
d03ab969 156 \
157/* --- @pre_cfbencrypt@ --- * \
158 * \
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 \
163 * \
164 * Returns: --- \
165 * \
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. \
169 */ \
170 \
79ba130c 171extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
172 const void */*src*/, void */*dest*/, \
173 size_t /*sz*/); \
d03ab969 174 \
79ba130c 175/* --- @pre_cfbencrypt@ --- * \
d03ab969 176 * \
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 \
181 * \
182 * Returns: --- \
183 * \
79ba130c 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. \
d03ab969 187 */ \
188 \
79ba130c 189extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
190 const void */*src*/, void */*dest*/, \
191 size_t /*sz*/); \
d03ab969 192 \
79ba130c 193/* --- Generic cipher interface --- */ \
d03ab969 194 \
79ba130c 195extern const gccipher pre##_cfb;
d03ab969 196
197/*----- That's all, folks -------------------------------------------------*/
198
199#ifdef __cplusplus
200 }
201#endif
202
203#endif