1 /*
2 * Fast, portable, and easy-to-use Twofish implementation,
3 * Version 0.3.
4 * Copyright (c) 2002 by Niels Ferguson.
5 *
6 * See the twofish.c file for the details of the how and why of this code.
7 *
8 * The author hereby grants a perpetual license to everybody to
9 * use this code for any purpose as long as the copyright message is included
10 * in the source code of this or any derived work.
11 */
12
13
14 /*
15 * PLATFORM FIXES
16 * ==============
17 *
18 * The following definitions have to be fixed for each particular platform
19 * you work on. If you have a multi-platform program, you no doubt have
20 * portable definitions that you can substitute here without changing
21 * the rest of the code.
22 *
23 * The defaults provided here should work on most PC compilers.
24 */
25 #ifndef _TWOFISH_H
26 #define _TWOFISH_H
27
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32
33
41
50
51
52 /*
53 * END OF PLATFORM FIXES
54 * =====================
55 *
56 * You should not have to touch the rest of this file, but the code
57 * in twofish.c has a few things you need to fix too.
58 */
59
71 #define ERR_SELECTB -8
72 #define ERR_TEST_ENC -9
73 #define ERR_TEST_DEC -10
74 #define ERR_SEQ_ENC -11
75 #define ERR_SEQ_DEC -12
76 #define ERR_ODD_KEY -13
78 #define ERR_KEY_LEN -15
79 #define ERR_ILL_ARG -16
80
81
96 struct
97 {
98 Twofish_UInt32 s[4][256];
/* pre-computed S-boxes */
99 Twofish_UInt32 K[40];
/* Round key words */
100 }
102
103
118
119
160 Twofish_Byte key[],
161 int key_len,
163 );
164
165
184 Twofish_Byte p[16],
185 Twofish_Byte c[16]
186 );
187
188
207 Twofish_Byte c[16],
208 Twofish_Byte p[16]
209 );
210
211 #ifdef __cplusplus
212 }
213 #endif
214 #endif
Structure that contains a prepared Twofish key.
unsigned char Twofish_Byte
A Twofish_Byte must be an unsigned 8-bit integer.
int Twofish_initialise()
Initialise and test the Twofish implementation.
void Twofish_decrypt(Twofish_key *xkey, Twofish_Byte c[16], Twofish_Byte p[16])
Decrypt a single block of data.
void Twofish_encrypt(Twofish_key *xkey, Twofish_Byte p[16], Twofish_Byte c[16])
Encrypt a single block of data.
int Twofish_prepare_key(Twofish_Byte key[], int key_len, Twofish_key *xkey)
Convert a cipher key to the internal form used for encryption and decryption.
unsigned int Twofish_UInt32
A Twofish_UInt32 must be an unsigned integer of at least 32 bits.