chiark / gitweb /
configure.ac: Replace with a new version.
[catacomb] / twofish.h
1 /* -*-c-*-
2  *
3  * $Id: twofish.h,v 1.5 2004/04/08 01:36:15 mdw Exp $
4  *
5  * The Twofish block cipher
6  *
7  * (c) 2000 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------*
11  *
12  * This file is part of Catacomb.
13  *
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.
18  *
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.
23  *
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,
27  * MA 02111-1307, USA.
28  */
29
30 /*----- Notes on the Twofish block cipher ---------------------------------*
31  *
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.
35  *
36  * Twofish is a complex cipher offering various space and time tradeoffs.
37  * This implementation has a heavy key schedule and fast bulk encryption.
38  */
39
40 #ifndef CATACOMB_TWOFISH_H
41 #define CATACOMB_TWOFISH_H
42
43 #ifdef __cplusplus
44   extern "C" {
45 #endif
46
47 /*----- Header files ------------------------------------------------------*/
48
49 #include <stddef.h>
50
51 #include <mLib/bits.h>
52
53 /*----- Magical numbers ---------------------------------------------------*/
54
55 #define TWOFISH_BLKSZ 16
56 #define TWOFISH_KEYSZ 32
57 #define TWOFISH_CLASS (N, L, 128)
58
59 extern const octet twofish_keysz[];
60
61 /*----- Data structures ---------------------------------------------------*/
62
63 typedef struct twofish_ctx {
64   uint32 k[40];
65   uint32 g[4][256];
66 } twofish_ctx;
67
68 typedef struct twofish_fk {
69   uint32 t0[8], t23[8], t4[2];
70   octet t1[32];
71 } twofish_fk;
72
73 /*----- Functions provided ------------------------------------------------*/
74
75 /* --- @twofish_initfk@ --- *
76  *
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
81  *
82  * Returns:     ---
83  *
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.
87  */
88
89 extern void twofish_initfk(twofish_ctx */*k*/, const void */*buf*/,
90                            size_t /*sz*/, const twofish_fk */*fk*/);
91
92 /* --- @twofish_init@ --- *
93  *
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  *
98  * Returns:     ---
99  *
100  * Use:         Initializes a Twofish key buffer.  Twofish accepts keys of up
101  *              to 256 bits in length.
102  */
103
104 extern void twofish_init(twofish_ctx */*k*/,
105                          const void */*buf*/, size_t /*sz*/);
106
107 /* --- @twofish_fkinit@ --- *
108  *
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
112  *
113  * Returns:     ---
114  *
115  * Use:         Initializes a family-key buffer.  This implementation allows
116  *              family keys of any size acceptable to the Twofish algorithm.
117  */
118
119 extern void twofish_fkinit(twofish_fk */*fk*/,
120                            const void */*buf*/, size_t /*sz*/);
121
122 /* --- @twofish_eblk@, @twofish_dblk@ --- *
123  *
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
127  *
128  * Returns:     ---
129  *
130  * Use:         Low-level block encryption and decryption.
131  */
132
133 extern void twofish_eblk(const twofish_ctx */*k*/,
134                          const uint32 */*s*/, uint32 */*d*/);
135
136 extern void twofish_dblk(const twofish_ctx */*k*/,
137                          const uint32 */*s*/, uint32 */*d*/);
138
139 /*----- That's all, folks -------------------------------------------------*/
140
141 #ifdef __cplusplus
142   }
143 #endif
144
145 #endif