3 * $Id: seal.h,v 1.1 2000/06/17 12:08:34 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2000/06/17 12:08:34 mdw
38 /*----- Notes on the SEAL pseudo-random function family -------------------*
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.
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.
54 #ifndef CATACOMB_SEAL_H
55 #define CATACOMB_SEAL_H
61 /*----- Header files ------------------------------------------------------*/
63 #ifndef CATACOMB_GCIPHER_H
67 #ifndef CATACOMB_GRAND_H
71 /*----- Data structures ---------------------------------------------------*/
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 */
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 */
94 /*----- Functions provided ------------------------------------------------*/
96 /* --- @seal_initkey@ --- *
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
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
109 extern void seal_initkey(seal_key */
*k*/
,
110 const void */
*buf*/
, size_t /*sz*/);
112 /* --- @seal_initctx@ --- *
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
120 * Use: Initializes a SEAL context which can be used for random
121 * number generation or whatever.
124 extern void seal_initctx(seal_ctx */
*c*/
, seal_key */
*k*/
, uint32
/*n*/);
126 /* --- @seal_encrypt@ --- *
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
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.
141 extern void seal_encrypt(seal_ctx */
*c*/
, const void */
*src*/
,
142 void */
*dest*/
, size_t /*sz*/);
144 /*----- Generic cipher interface ------------------------------------------*/
146 #define SEAL_KEYSZ 20
147 extern const octet seal_keysz
[];
149 extern const gccipher seal
;
151 /*----- Generic random number generator interface -------------------------*/
153 /* --- @seal_rand@ --- *
155 * Arguments: @const void *k@ = pointer to key material
156 * @size_t sz@ = size of key material
157 * @uint32 n@ = sequence number
159 * Returns: Pointer to generic random number generator interface.
161 * Use: Creates a random number interface wrapper around a SEAL
162 * pseudorandom function.
165 extern grand
*seal_rand(const void */
*k*/
, size_t /*sz*/, uint32
/*n*/);
167 /*----- That's all, folks -------------------------------------------------*/