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