hashsum.c: Document `--progress' in the `--help' display.
[u/mdw/catacomb] / ofb.h
CommitLineData
d03ab969 1/* -*-c-*-
2 *
b817bfc6 3 * $Id: ofb.h,v 1.5 2004/04/08 01:36:15 mdw Exp $
d03ab969 4 *
5 * Output 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_OFB_H
31#define CATACOMB_OFB_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
79ba130c 47#ifndef CATACOMB_GRAND_H
48# include "grand.h"
d03ab969 49#endif
50
51/*----- Macros ------------------------------------------------------------*/
52
53/* --- @OFB_DECL@ --- *
54 *
55 * Arguments: @PRE@, @pre@ = prefixes for block cipher definitions
56 *
57 * Use: Makes declarations for output feedback mode.
58 */
59
60#define OFB_DECL(PRE, pre) \
61 \
79ba130c 62/* --- Output feedback context --- */ \
d03ab969 63 \
79ba130c 64typedef struct pre##_ofbctx { \
65 pre##_ctx ctx; /* Underlying cipher context */ \
75b1b624 66 unsigned off; /* Current offset in buffer */ \
79ba130c 67 octet iv[PRE##_BLKSZ]; /* Output buffer and IV */ \
68} pre##_ofbctx; \
d03ab969 69 \
70/* --- @pre_ofbgetiv@ --- * \
71 * \
72 * Arguments: @const pre_ofbctx *ctx@ = pointer to OFB context block \
4efe32ba 73 * @void *iv@ = pointer to output data block \
d03ab969 74 * \
75 * Returns: --- \
76 * \
77 * Use: Reads the currently set IV. Reading and setting an IV \
78 * is not transparent to the cipher. It will add a `step' \
79 * which must be matched by a similar operation during \
80 * decryption. \
81 */ \
82 \
79ba130c 83extern void pre##_ofbgetiv(const pre##_ofbctx */*ctx*/, \
84 void */*iv*/); \
d03ab969 85 \
86/* --- @pre_ofbsetiv@ --- * \
87 * \
88 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
89 * @cnost void *iv@ = pointer to IV to set \
90 * \
91 * Returns: --- \
92 * \
93 * Use: Sets the IV to use for subsequent encryption. \
94 */ \
95 \
79ba130c 96extern void pre##_ofbsetiv(pre##_ofbctx */*ctx*/, \
97 const void */*iv*/); \
d03ab969 98 \
99/* --- @pre_ofbbdry@ --- * \
100 * \
101 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
102 * \
103 * Returns: --- \
104 * \
105 * Use: Inserts a boundary during encryption. Successful \
106 * decryption must place a similar boundary. \
107 */ \
108 \
79ba130c 109extern void pre##_ofbbdry(pre##_ofbctx */*ctx*/); \
d03ab969 110 \
111/* --- @pre_ofbsetkey@ --- * \
112 * \
113 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
114 * @const pre_ctx *k@ = pointer to cipher context \
115 * \
116 * Returns: --- \
117 * \
118 * Use: Sets the OFB context to use a different cipher key. \
119 */ \
120 \
79ba130c 121extern void pre##_ofbsetkey(pre##_ofbctx */*ctx*/, \
122 const pre##_ctx */*k*/); \
d03ab969 123 \
124/* --- @pre_ofbinit@ --- * \
125 * \
126 * Arguments: @pre_ofbctx *ctx@ = pointer to cipher context \
127 * @const void *key@ = pointer to the key buffer \
128 * @size_t sz@ = size of the key \
129 * @const void *iv@ = pointer to initialization vector \
130 * \
131 * Returns: --- \
132 * \
133 * Use: Initializes a OFB context ready for use. You should \
134 * ensure that the IV chosen is unique: reusing an IV will \
135 * compromise the security of the entire plaintext. This \
136 * is equivalent to calls to @pre_init@, @pre_ofbsetkey@ \
137 * and @pre_ofbsetiv@. \
138 */ \
139 \
79ba130c 140extern void pre##_ofbinit(pre##_ofbctx */*ctx*/, \
141 const void */*key*/, size_t /*sz*/, \
142 const void */*iv*/); \
d03ab969 143 \
144/* --- @pre_ofbencrypt@ --- * \
145 * \
146 * Arguments: @pre_ofbctx *ctx@ = pointer to OFB context block \
147 * @const void *src@ = pointer to source data \
148 * @void *dest@ = pointer to destination data \
149 * @size_t sz@ = size of block to be encrypted \
150 * \
151 * Returns: --- \
152 * \
153 * Use: Encrypts or decrypts a block with a block cipher in OFB \
154 * mode: encryption and decryption are the same in OFB. \
155 * The destination may be null to just churn the feedback \
156 * round for a bit. The source may be null to use the \
157 * cipher as a random data generator. \
158 */ \
159 \
79ba130c 160extern void pre##_ofbencrypt(pre##_ofbctx */*ctx*/, \
161 const void */*src*/, void */*dest*/, \
162 size_t /*sz*/); \
d03ab969 163 \
79ba130c 164/* --- @pre_ofbrand@ --- * \
165 * \
166 * Arguments: @const void *k@ = pointer to key material \
167 * @size_t sz@ = size of key material \
168 * \
169 * Returns: Pointer to generic random number generator interface. \
170 * \
171 * Use: Creates a random number interface wrapper around an \
172 * OFB-mode block cipher. \
173 */ \
d03ab969 174 \
79ba130c 175extern grand *pre##_ofbrand(const void */*k*/, size_t /*sz*/); \
d03ab969 176 \
79ba130c 177/* --- Generic cipher interface --- */ \
d03ab969 178 \
79ba130c 179extern const gccipher pre##_ofb;
d03ab969 180
181/*----- That's all, folks -------------------------------------------------*/
182
183#ifdef __cplusplus
184 }
185#endif
186
187#endif