3 * The Twofish block cipher
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 Twofish block cipher ---------------------------------*
30 * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David
31 * Wagner, Chris Hall and Niels Ferguson. The algorithm is unpatented and
32 * free for anyone to use. It was one of the five AES finalist algorithms.
34 * Twofish is a complex cipher offering various space and time tradeoffs.
35 * This implementation has a heavy key schedule and fast bulk encryption.
38 #ifndef CATACOMB_TWOFISH_H
39 #define CATACOMB_TWOFISH_H
45 /*----- Header files ------------------------------------------------------*/
49 #include <mLib/bits.h>
51 /*----- Magical numbers ---------------------------------------------------*/
53 #define TWOFISH_BLKSZ 16
54 #define TWOFISH_KEYSZ 32
55 #define TWOFISH_CLASS (N, L, 128)
57 extern const octet twofish_keysz[];
59 /*----- Data structures ---------------------------------------------------*/
61 typedef struct twofish_ctx {
66 typedef struct twofish_fk {
67 uint32 t0[8], t23[8], t4[2];
71 /*----- Functions provided ------------------------------------------------*/
73 /* --- @twofish_initfk@ --- *
75 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
76 * @const void *buf@ = pointer to buffer of key material
77 * @size_t sz@ = size of key material
78 * @const twofish_fk *fk@ = family-key information
82 * Use: Does the underlying Twofish key initialization with family
83 * key. Pass in a family-key structure initialized to
84 * all-bits-zero for a standard key schedule.
87 extern void twofish_initfk(twofish_ctx */*k*/, const void */*buf*/,
88 size_t /*sz*/, const twofish_fk */*fk*/);
90 /* --- @twofish_init@ --- *
92 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
93 * @const void *buf@ = pointer to buffer of key material
94 * @size_t sz@ = size of key material
98 * Use: Initializes a Twofish key buffer. Twofish accepts keys of up
99 * to 256 bits in length.
102 extern void twofish_init(twofish_ctx */*k*/,
103 const void */*buf*/, size_t /*sz*/);
105 /* --- @twofish_fkinit@ --- *
107 * Arguments: @twofish_fk *fk@ = pointer to family key block
108 * @const void *buf@ = pointer to buffer of key material
109 * @size_t sz@ = size of key material
113 * Use: Initializes a family-key buffer. This implementation allows
114 * family keys of any size acceptable to the Twofish algorithm.
117 extern void twofish_fkinit(twofish_fk */*fk*/,
118 const void */*buf*/, size_t /*sz*/);
120 /* --- @twofish_eblk@, @twofish_dblk@ --- *
122 * Arguments: @const twofish_ctx *k@ = pointer to key block
123 * @const uint32 s[4]@ = pointer to source block
124 * @uint32 d[4]@ = pointer to destination block
128 * Use: Low-level block encryption and decryption.
131 extern void twofish_eblk(const twofish_ctx */*k*/,
132 const uint32 */*s*/, uint32 */*d*/);
134 extern void twofish_dblk(const twofish_ctx */*k*/,
135 const uint32 */*s*/, uint32 */*d*/);
137 /*----- That's all, folks -------------------------------------------------*/