3 * $Id: twofish.h,v 1.5 2004/04/08 01:36:15 mdw Exp $
5 * The Twofish block cipher
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 Twofish block cipher ---------------------------------*
32 * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David
33 * Wagner, Chris Hall and Niels Ferguson. The algorithm is unpatented and
34 * free for anyone to use. It was one of the five AES finalist algorithms.
36 * Twofish is a complex cipher offering various space and time tradeoffs.
37 * This implementation has a heavy key schedule and fast bulk encryption.
40 #ifndef CATACOMB_TWOFISH_H
41 #define CATACOMB_TWOFISH_H
47 /*----- Header files ------------------------------------------------------*/
51 #include <mLib/bits.h>
53 /*----- Magical numbers ---------------------------------------------------*/
55 #define TWOFISH_BLKSZ 16
56 #define TWOFISH_KEYSZ 32
57 #define TWOFISH_CLASS (N, L, 128)
59 extern const octet twofish_keysz[];
61 /*----- Data structures ---------------------------------------------------*/
63 typedef struct twofish_ctx {
68 typedef struct twofish_fk {
69 uint32 t0[8], t23[8], t4[2];
73 /*----- Functions provided ------------------------------------------------*/
75 /* --- @twofish_initfk@ --- *
77 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
78 * @const void *buf@ = pointer to buffer of key material
79 * @size_t sz@ = size of key material
80 * @const twofish_fk *fk@ = family-key information
84 * Use: Does the underlying Twofish key initialization with family
85 * key. Pass in a family-key structure initialized to
86 * all-bits-zero for a standard key schedule.
89 extern void twofish_initfk(twofish_ctx */*k*/, const void */*buf*/,
90 size_t /*sz*/, const twofish_fk */*fk*/);
92 /* --- @twofish_init@ --- *
94 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
95 * @const void *buf@ = pointer to buffer of key material
96 * @size_t sz@ = size of key material
100 * Use: Initializes a Twofish key buffer. Twofish accepts keys of up
101 * to 256 bits in length.
104 extern void twofish_init(twofish_ctx */*k*/,
105 const void */*buf*/, size_t /*sz*/);
107 /* --- @twofish_fkinit@ --- *
109 * Arguments: @twofish_fk *fk@ = pointer to family key block
110 * @const void *buf@ = pointer to buffer of key material
111 * @size_t sz@ = size of key material
115 * Use: Initializes a family-key buffer. This implementation allows
116 * family keys of any size acceptable to the Twofish algorithm.
119 extern void twofish_fkinit(twofish_fk */*fk*/,
120 const void */*buf*/, size_t /*sz*/);
122 /* --- @twofish_eblk@, @twofish_dblk@ --- *
124 * Arguments: @const twofish_ctx *k@ = pointer to key block
125 * @const uint32 s[4]@ = pointer to source block
126 * @uint32 d[4]@ = pointer to destination block
130 * Use: Low-level block encryption and decryption.
133 extern void twofish_eblk(const twofish_ctx */*k*/,
134 const uint32 */*s*/, uint32 */*d*/);
136 extern void twofish_dblk(const twofish_ctx */*k*/,
137 const uint32 */*s*/, uint32 */*d*/);
139 /*----- That's all, folks -------------------------------------------------*/