Renamed from `rsa-decrypt', since the name was no longer appropriate.
[u/mdw/catacomb] / seal.h
1 /* -*-c-*-
2 *
3 * $Id: seal.h,v 1.1 2000/06/17 12:08:34 mdw Exp $
4 *
5 * The SEAL pseudo-random function family
6 *
7 * (c) 2000 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: seal.h,v $
33 * Revision 1.1 2000/06/17 12:08:34 mdw
34 * New cipher.
35 *
36 */
37
38 /*----- Notes on the SEAL pseudo-random function family -------------------*
39 *
40 * SEAL is a slightly odd cryptographic primitive. It was designed by Phil
41 * Rogaway and Don Coppersmith at IBM, basically as an exercise in producing
42 * a really fast symmetric cipher of some kind. They succeeded: SEAL is
43 * faster than the much simpler RC4.
44 *
45 * For each key, it gives you %$2^{32}$% different output streams. This
46 * implementation imposes no length limits on the size of output streams and
47 * performs careful buffer handling to allow arbitrary amounts of data to be
48 * extracted. In practice, extracting more than about 64K is possibly dodgy
49 * from a security point of view.
50 *
51 * SEAL is patented.
52 */
53
54 #ifndef CATACOMB_SEAL_H
55 #define CATACOMB_SEAL_H
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 /*----- Header files ------------------------------------------------------*/
62
63 #ifndef CATACOMB_GCIPHER_H
64 # include "gcipher.h"
65 #endif
66
67 #ifndef CATACOMB_GRAND_H
68 # include "grand.h"
69 #endif
70
71 /*----- Data structures ---------------------------------------------------*/
72
73 #define SEAL_R 256
74
75 typedef struct seal_key {
76 octet k[20]; /* Copy of the 160-bit key */
77 uint32 t[512]; /* Substitution table */
78 uint32 s[256]; /* Magic for each iteration */
79 uint32 r[SEAL_R]; /* Magic for the first 64K */
80 } seal_key;
81
82 typedef struct seal_ctx {
83 seal_key *k; /* Pointer to the key block */
84 uint32 *r, ri; /* Pointer to current magic */
85 uint32 n, l; /* Various indices into things */
86 uint32 a, b, c, d; /* Current chaining variables */
87 uint32 n1, n2, n3, n4; /* Increments for the variables */
88 unsigned i; /* Index into current iteration */
89 octet q[16]; /* Output buffer */
90 unsigned qsz; /* Number of bytes in the buffer */
91 uint32 rbuf[SEAL_R]; /* Buffer for later magic */
92 } seal_ctx;
93
94 /*----- Functions provided ------------------------------------------------*/
95
96 /* --- @seal_initkey@ --- *
97 *
98 * Arguments: @seal_key *k@ = pointer to key block
99 * @const void *buf@ = pointer to key material
100 * @size_t sz@ = size of the key material
101 *
102 * Returns: ---
103 *
104 * Use: Initializes a SEAL key block. The key material may be any
105 * size, but if it's not 20 bytes long it's passed to SHA for
106 * hashing first.
107 */
108
109 extern void seal_initkey(seal_key */*k*/,
110 const void */*buf*/, size_t /*sz*/);
111
112 /* --- @seal_initctx@ --- *
113 *
114 * Arguments: @seal_ctx *c@ = pointer to a SEAL context
115 * @seal_key *k@ = pointer to a SEAL key
116 * @uint32 n@ = integer sequence number
117 *
118 * Returns: ---
119 *
120 * Use: Initializes a SEAL context which can be used for random
121 * number generation or whatever.
122 */
123
124 extern void seal_initctx(seal_ctx */*c*/, seal_key */*k*/, uint32 /*n*/);
125
126 /* --- @seal_encrypt@ --- *
127 *
128 * Arguments: @seal_ctx *c@ = pointer to a SEAL context
129 * @const void *src@ = pointer to source data
130 * @void *dest@ = pointer to destination data
131 * @size_t sz@ = size of the data
132 *
133 * Returns: ---
134 *
135 * Use: Encrypts a block of data using SEAL. If @src@ is zero,
136 * @dest@ is filled with SEAL output. If @dest@ is zero, the
137 * SEAL generator is just spun around for a bit. This shouldn't
138 * be necessary, because SEAL isn't RC4.
139 */
140
141 extern void seal_encrypt(seal_ctx */*c*/, const void */*src*/,
142 void */*dest*/, size_t /*sz*/);
143
144 /*----- Generic cipher interface ------------------------------------------*/
145
146 #define SEAL_KEYSZ 20
147 extern const octet seal_keysz[];
148
149 extern const gccipher seal;
150
151 /*----- Generic random number generator interface -------------------------*/
152
153 /* --- @seal_rand@ --- *
154 *
155 * Arguments: @const void *k@ = pointer to key material
156 * @size_t sz@ = size of key material
157 * @uint32 n@ = sequence number
158 *
159 * Returns: Pointer to generic random number generator interface.
160 *
161 * Use: Creates a random number interface wrapper around a SEAL
162 * pseudorandom function.
163 */
164
165 extern grand *seal_rand(const void */*k*/, size_t /*sz*/, uint32 /*n*/);
166
167 /*----- That's all, folks -------------------------------------------------*/
168
169 #ifdef __cplusplus
170 }
171 #endif
172
173 #endif