3 * $Id: twofish.h,v 1.4 2002/01/13 13:37:59 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.4 2002/01/13 13:37:59 mdw
34 * Add support for Twofish family keys.
36 * Revision 1.3 2001/04/29 18:12:43 mdw
39 * Revision 1.2 2000/10/08 15:48:58 mdw
40 * Update comments now that AES has been chosen.
42 * Revision 1.1 2000/06/17 12:10:17 mdw
47 /*----- Notes on the Twofish block cipher ---------------------------------*
49 * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David
50 * Wagner, Chris Hall and Niels Ferguson. The algorithm is unpatented and
51 * free for anyone to use. It was one of the five AES finalist algorithms.
53 * Twofish is a complex cipher offering various space and time tradeoffs.
54 * This implementation has a heavy key schedule and fast bulk encryption.
57 #ifndef CATACOMB_TWOFISH_H
58 #define CATACOMB_TWOFISH_H
64 /*----- Header files ------------------------------------------------------*/
68 #include <mLib/bits.h>
70 /*----- Magical numbers ---------------------------------------------------*/
72 #define TWOFISH_BLKSZ 16
73 #define TWOFISH_KEYSZ 32
74 #define TWOFISH_CLASS (N, L, 128)
76 extern const octet twofish_keysz
[];
78 /*----- Data structures ---------------------------------------------------*/
80 typedef struct twofish_ctx
{
85 typedef struct twofish_fk
{
86 uint32 t0
[8], t23
[8], t4
[2];
90 /*----- Functions provided ------------------------------------------------*/
92 /* --- @twofish_initfk@ --- *
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
97 * @const twofish_fk *fk@ = family-key information
101 * Use: Does the underlying Twofish key initialization with family
102 * key. Pass in a family-key structure initialized to
103 * all-bits-zero for a standard key schedule.
106 extern void twofish_initfk(twofish_ctx */
*k*/
, const void */
*buf*/
,
107 size_t /*sz*/, const twofish_fk */
*fk*/
);
109 /* --- @twofish_init@ --- *
111 * Arguments: @twofish_ctx *k@ = pointer to key block to fill in
112 * @const void *buf@ = pointer to buffer of key material
113 * @size_t sz@ = size of key material
117 * Use: Initializes a Twofish key buffer. Twofish accepts keys of up
118 * to 256 bits in length.
121 extern void twofish_init(twofish_ctx */
*k*/
,
122 const void */
*buf*/
, size_t /*sz*/);
124 /* --- @twofish_fkinit@ --- *
126 * Arguments: @twofish_fk *fk@ = pointer to family key block
127 * @const void *buf@ = pointer to buffer of key material
128 * @size_t sz@ = size of key material
132 * Use: Initializes a family-key buffer. This implementation allows
133 * family keys of any size acceptable to the Twofish algorithm.
136 extern void twofish_fkinit(twofish_fk */
*fk*/
,
137 const void */
*buf*/
, size_t /*sz*/);
139 /* --- @twofish_eblk@, @twofish_dblk@ --- *
141 * Arguments: @const twofish_ctx *k@ = pointer to key block
142 * @const uint32 s[4]@ = pointer to source block
143 * @uint32 d[4]@ = pointer to destination block
147 * Use: Low-level block encryption and decryption.
150 extern void twofish_eblk(const twofish_ctx */
*k*/
,
151 const uint32 */
*s*/
, uint32 */
*d*/
);
153 extern void twofish_dblk(const twofish_ctx */
*k*/
,
154 const uint32 */
*s*/
, uint32 */
*d*/
);
156 /*----- That's all, folks -------------------------------------------------*/