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