3 * The SEAL pseudo-random function family
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Notes on the SEAL pseudo-random function family -------------------*
30 * SEAL is a slightly odd cryptographic primitive. It was designed by Phil
31 * Rogaway and Don Coppersmith at IBM, basically as an exercise in producing
32 * a really fast symmetric cipher of some kind. They succeeded: SEAL is
33 * faster than the much simpler RC4.
35 * For each key, it gives you %$2^{32}$% different output streams. This
36 * implementation imposes no length limits on the size of output streams and
37 * performs careful buffer handling to allow arbitrary amounts of data to be
38 * extracted. In practice, extracting more than about 64K is possibly dodgy
39 * from a security point of view.
44 #ifndef CATACOMB_SEAL_H
45 #define CATACOMB_SEAL_H
51 /*----- Header files ------------------------------------------------------*/
53 #ifndef CATACOMB_GCIPHER_H
57 #ifndef CATACOMB_GRAND_H
61 /*----- Data structures ---------------------------------------------------*/
65 typedef struct seal_key {
66 octet k[20]; /* Copy of the 160-bit key */
67 uint32 t[512]; /* Substitution table */
68 uint32 s[256]; /* Magic for each iteration */
69 uint32 r[SEAL_R]; /* Magic for the first 64K */
72 typedef struct seal_ctx {
73 seal_key *k; /* Pointer to the key block */
74 uint32 *r, ri; /* Pointer to current magic */
75 uint32 n, l; /* Various indices into things */
76 uint32 a, b, c, d; /* Current chaining variables */
77 uint32 n1, n2, n3, n4; /* Increments for the variables */
78 unsigned i; /* Index into current iteration */
79 octet q[16]; /* Output buffer */
80 unsigned qsz; /* Number of bytes in the buffer */
81 uint32 rbuf[SEAL_R]; /* Buffer for later magic */
84 /*----- Functions provided ------------------------------------------------*/
86 /* --- @seal_initkey@ --- *
88 * Arguments: @seal_key *k@ = pointer to key block
89 * @const void *buf@ = pointer to key material
90 * @size_t sz@ = size of the key material
94 * Use: Initializes a SEAL key block. The key material may be any
95 * size, but if it's not 20 bytes long it's passed to SHA for
99 extern void seal_initkey(seal_key */*k*/,
100 const void */*buf*/, size_t /*sz*/);
102 /* --- @seal_initctx@ --- *
104 * Arguments: @seal_ctx *c@ = pointer to a SEAL context
105 * @seal_key *k@ = pointer to a SEAL key
106 * @uint32 n@ = integer sequence number
110 * Use: Initializes a SEAL context which can be used for random
111 * number generation or whatever.
114 extern void seal_initctx(seal_ctx */*c*/, seal_key */*k*/, uint32 /*n*/);
116 /* --- @seal_encrypt@ --- *
118 * Arguments: @seal_ctx *c@ = pointer to a SEAL context
119 * @const void *src@ = pointer to source data
120 * @void *dest@ = pointer to destination data
121 * @size_t sz@ = size of the data
125 * Use: Encrypts a block of data using SEAL. If @src@ is zero,
126 * @dest@ is filled with SEAL output. If @dest@ is zero, the
127 * SEAL generator is just spun around for a bit. This shouldn't
128 * be necessary, because SEAL isn't RC4.
131 extern void seal_encrypt(seal_ctx */*c*/, const void */*src*/,
132 void */*dest*/, size_t /*sz*/);
134 /*----- Generic cipher interface ------------------------------------------*/
136 #define SEAL_KEYSZ 20
137 extern const octet seal_keysz[];
139 extern const gccipher seal;
141 /*----- Generic random number generator interface -------------------------*/
143 /* --- @seal_rand@ --- *
145 * Arguments: @const void *k@ = pointer to key material
146 * @size_t sz@ = size of key material
147 * @uint32 n@ = sequence number
149 * Returns: Pointer to generic random number generator interface.
151 * Use: Creates a random number interface wrapper around a SEAL
152 * pseudorandom function.
155 extern grand *seal_rand(const void */*k*/, size_t /*sz*/, uint32 /*n*/);
157 /*----- That's all, folks -------------------------------------------------*/