8dd8c294 |
1 | /* -*-c-*- |
2 | * |
574d8527 |
3 | * $Id: twofish.h,v 1.4 2002/01/13 13:37:59 mdw Exp $ |
8dd8c294 |
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 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: twofish.h,v $ |
574d8527 |
33 | * Revision 1.4 2002/01/13 13:37:59 mdw |
34 | * Add support for Twofish family keys. |
35 | * |
db9326f0 |
36 | * Revision 1.3 2001/04/29 18:12:43 mdw |
37 | * Fix formatting. |
38 | * |
fbac94e6 |
39 | * Revision 1.2 2000/10/08 15:48:58 mdw |
40 | * Update comments now that AES has been chosen. |
41 | * |
8dd8c294 |
42 | * Revision 1.1 2000/06/17 12:10:17 mdw |
43 | * New cipher. |
44 | * |
45 | */ |
46 | |
47 | /*----- Notes on the Twofish block cipher ---------------------------------* |
48 | * |
49 | * Twofish was designed by Bruce Schneier, John Kelsey, Doug Whiting, David |
50 | * Wagner, Chris Hall and Niels Ferguson. The algorithm is unpatented and |
fbac94e6 |
51 | * free for anyone to use. It was one of the five AES finalist algorithms. |
8dd8c294 |
52 | * |
53 | * Twofish is a complex cipher offering various space and time tradeoffs. |
54 | * This implementation has a heavy key schedule and fast bulk encryption. |
55 | */ |
56 | |
57 | #ifndef CATACOMB_TWOFISH_H |
58 | #define CATACOMB_TWOFISH_H |
59 | |
60 | #ifdef __cplusplus |
61 | extern "C" { |
62 | #endif |
63 | |
64 | /*----- Header files ------------------------------------------------------*/ |
65 | |
66 | #include <stddef.h> |
67 | |
68 | #include <mLib/bits.h> |
69 | |
70 | /*----- Magical numbers ---------------------------------------------------*/ |
71 | |
72 | #define TWOFISH_BLKSZ 16 |
73 | #define TWOFISH_KEYSZ 32 |
74 | #define TWOFISH_CLASS (N, L, 128) |
75 | |
76 | extern const octet twofish_keysz[]; |
77 | |
78 | /*----- Data structures ---------------------------------------------------*/ |
79 | |
80 | typedef struct twofish_ctx { |
81 | uint32 k[40]; |
82 | uint32 g[4][256]; |
83 | } twofish_ctx; |
84 | |
574d8527 |
85 | typedef struct twofish_fk { |
86 | uint32 t0[8], t23[8], t4[2]; |
87 | octet t1[32]; |
88 | } twofish_fk; |
89 | |
8dd8c294 |
90 | /*----- Functions provided ------------------------------------------------*/ |
91 | |
574d8527 |
92 | /* --- @twofish_initfk@ --- * |
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 | * @const twofish_fk *fk@ = family-key information |
98 | * |
99 | * Returns: --- |
100 | * |
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. |
104 | */ |
105 | |
106 | extern void twofish_initfk(twofish_ctx */*k*/, const void */*buf*/, |
107 | size_t /*sz*/, const twofish_fk */*fk*/); |
108 | |
8dd8c294 |
109 | /* --- @twofish_init@ --- * |
110 | * |
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 |
114 | * |
115 | * Returns: --- |
116 | * |
117 | * Use: Initializes a Twofish key buffer. Twofish accepts keys of up |
118 | * to 256 bits in length. |
119 | */ |
120 | |
121 | extern void twofish_init(twofish_ctx */*k*/, |
122 | const void */*buf*/, size_t /*sz*/); |
123 | |
574d8527 |
124 | /* --- @twofish_fkinit@ --- * |
125 | * |
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 |
129 | * |
130 | * Returns: --- |
131 | * |
132 | * Use: Initializes a family-key buffer. This implementation allows |
133 | * family keys of any size acceptable to the Twofish algorithm. |
134 | */ |
135 | |
136 | extern void twofish_fkinit(twofish_fk */*fk*/, |
137 | const void */*buf*/, size_t /*sz*/); |
138 | |
8dd8c294 |
139 | /* --- @twofish_eblk@, @twofish_dblk@ --- * |
140 | * |
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 |
144 | * |
145 | * Returns: --- |
146 | * |
147 | * Use: Low-level block encryption and decryption. |
148 | */ |
149 | |
150 | extern void twofish_eblk(const twofish_ctx */*k*/, |
151 | const uint32 */*s*/, uint32 */*d*/); |
152 | |
153 | extern void twofish_dblk(const twofish_ctx */*k*/, |
db9326f0 |
154 | const uint32 */*s*/, uint32 */*d*/); |
8dd8c294 |
155 | |
156 | /*----- That's all, folks -------------------------------------------------*/ |
157 | |
158 | #ifdef __cplusplus |
159 | } |
160 | #endif |
161 | |
162 | #endif |