key-data.[ch] (key_copydata): New function copies filtered key data.
[u/mdw/catacomb] / cfb.h
CommitLineData
d03ab969 1/* -*-c-*-
2 *
b817bfc6 3 * $Id: cfb.h,v 1.5 2004/04/08 01:36:15 mdw Exp $
d03ab969 4 *
5 * Ciphertext feedback for block ciphers
6 *
7 * (c) 1999 Straylight/Edgeware
8 */
9
45c0fd36 10/*----- Licensing notice --------------------------------------------------*
d03ab969 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.
45c0fd36 18 *
d03ab969 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.
45c0fd36 23 *
d03ab969 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
79ba130c 30#ifndef CATACOMB_CFB_H
31#define CATACOMB_CFB_H
d03ab969 32
33#ifdef __cplusplus
34 extern "C" {
35#endif
36
37/*----- Header files ------------------------------------------------------*/
38
79ba130c 39#include <stddef.h>
d03ab969 40
41#include <mLib/bits.h>
42
79ba130c 43#ifndef CATACOMB_GCIPHER_H
44# include "gcipher.h"
d03ab969 45#endif
46
47/*----- Data structures ---------------------------------------------------*/
48
49/* --- @CFB_DECL@ --- *
50 *
51 * Arguments: @PRE@, @pre@ = prefixes for the underlying block cipher
52 *
53 * Use: Creates declarations for CFB mode.
54 */
55
56#define CFB_DECL(PRE, pre) \
57 \
79ba130c 58/* --- Ciphertext feedback context --- */ \
d03ab969 59 \
79ba130c 60typedef struct pre##_cfbctx { \
61 pre##_ctx ctx; /* Underlying cipher context */ \
e97df21b 62 unsigned off; /* Offset into @iv@ buffer */ \
79ba130c 63 octet iv[PRE##_BLKSZ]; /* Previous ciphertext or IV */ \
64} pre##_cfbctx; \
d03ab969 65 \
66/* --- @pre_cfbgetiv@ --- * \
67 * \
68 * Arguments: @const pre_cfbctx *ctx@ = pointer to CFB context block \
4efe32ba 69 * @void *iv@ = pointer to output data block \
d03ab969 70 * \
71 * Returns: --- \
72 * \
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 \
76 * decryption. \
77 */ \
78 \
79ba130c 79extern void pre##_cfbgetiv(const pre##_cfbctx */*ctx*/, \
80 void */*iv*/); \
d03ab969 81 \
82/* --- @pre_cfbsetiv@ --- * \
83 * \
84 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
85 * @cnost void *iv@ = pointer to IV to set \
86 * \
87 * Returns: --- \
88 * \
89 * Use: Sets the IV to use for subsequent encryption. \
90 */ \
91 \
79ba130c 92extern void pre##_cfbsetiv(pre##_cfbctx */*ctx*/, \
93 const void */*iv*/); \
d03ab969 94 \
95/* --- @pre_cfbbdry@ --- * \
96 * \
97 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
98 * \
99 * Returns: --- \
100 * \
101 * Use: Inserts a boundary during encryption. Successful \
102 * decryption must place a similar boundary. \
103 */ \
104 \
79ba130c 105extern void pre##_cfbbdry(pre##_cfbctx */*ctx*/); \
d03ab969 106 \
107/* --- @pre_cfbsetkey@ --- * \
108 * \
109 * Arguments: @pre_cfbctx *ctx@ = pointer to CFB context block \
110 * @const pre_ctx *k@ = pointer to cipher context \
111 * \
112 * Returns: --- \
113 * \
114 * Use: Sets the CFB context to use a different cipher key. \
115 */ \
116 \
79ba130c 117extern void pre##_cfbsetkey(pre##_cfbctx */*ctx*/, \
118 const pre##_ctx */*k*/); \
d03ab969 119 \
120/* --- @pre_cfbinit@ --- * \
121 * \
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 \
126 * \
127 * Returns: --- \
128 * \
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@. \
134 */ \
135 \
79ba130c 136extern void pre##_cfbinit(pre##_cfbctx */*ctx*/, \
137 const void */*key*/, size_t /*sz*/, \
138 const void */*iv*/); \
d03ab969 139 \
140/* --- @pre_cfbencrypt@ --- * \
141 * \
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 \
146 * \
147 * Returns: --- \
148 * \
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. \
152 */ \
153 \
79ba130c 154extern void pre##_cfbencrypt(pre##_cfbctx */*ctx*/, \
155 const void */*src*/, void */*dest*/, \
156 size_t /*sz*/); \
d03ab969 157 \
79ba130c 158/* --- @pre_cfbencrypt@ --- * \
d03ab969 159 * \
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 \
164 * \
165 * Returns: --- \
166 * \
79ba130c 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. \
d03ab969 170 */ \
171 \
79ba130c 172extern void pre##_cfbdecrypt(pre##_cfbctx */*ctx*/, \
173 const void */*src*/, void */*dest*/, \
174 size_t /*sz*/); \
d03ab969 175 \
79ba130c 176/* --- Generic cipher interface --- */ \
d03ab969 177 \
79ba130c 178extern const gccipher pre##_cfb;
d03ab969 179
180/*----- That's all, folks -------------------------------------------------*/
181
182#ifdef __cplusplus
183 }
184#endif
185
186#endif