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