3 * $Id: seal.h,v 1.2 2004/04/08 01:36:15 mdw Exp $
5 * The SEAL pseudo-random function family
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Notes on the SEAL pseudo-random function family -------------------*
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.
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.
46 #ifndef CATACOMB_SEAL_H
47 #define CATACOMB_SEAL_H
53 /*----- Header files ------------------------------------------------------*/
55 #ifndef CATACOMB_GCIPHER_H
59 #ifndef CATACOMB_GRAND_H
63 /*----- Data structures ---------------------------------------------------*/
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 */
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 */
86 /*----- Functions provided ------------------------------------------------*/
88 /* --- @seal_initkey@ --- *
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
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
101 extern void seal_initkey(seal_key */*k*/,
102 const void */*buf*/, size_t /*sz*/);
104 /* --- @seal_initctx@ --- *
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
112 * Use: Initializes a SEAL context which can be used for random
113 * number generation or whatever.
116 extern void seal_initctx(seal_ctx */*c*/, seal_key */*k*/, uint32 /*n*/);
118 /* --- @seal_encrypt@ --- *
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
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.
133 extern void seal_encrypt(seal_ctx */*c*/, const void */*src*/,
134 void */*dest*/, size_t /*sz*/);
136 /*----- Generic cipher interface ------------------------------------------*/
138 #define SEAL_KEYSZ 20
139 extern const octet seal_keysz[];
141 extern const gccipher seal;
143 /*----- Generic random number generator interface -------------------------*/
145 /* --- @seal_rand@ --- *
147 * Arguments: @const void *k@ = pointer to key material
148 * @size_t sz@ = size of key material
149 * @uint32 n@ = sequence number
151 * Returns: Pointer to generic random number generator interface.
153 * Use: Creates a random number interface wrapper around a SEAL
154 * pseudorandom function.
157 extern grand *seal_rand(const void */*k*/, size_t /*sz*/, uint32 /*n*/);
159 /*----- That's all, folks -------------------------------------------------*/