ccRTP 2.1.2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
twofish.h
Go to the documentation of this file.
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 
40 typedef unsigned char Twofish_Byte;
41 
49 typedef unsigned int Twofish_UInt32;
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 
64 #define SUCCESS 1
65 #define ERR_UINT32 -2
66 #define ERR_BYTE -3
67 #define ERR_GET32 -4
68 #define ERR_PUT32 -5
69 #define ERR_ROLR -6
70 #define ERR_BSWAP -7
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
77 #define ERR_INIT -14
78 #define ERR_KEY_LEN -15
79 #define ERR_ILL_ARG -16
80 
81 
95 typedef
96  struct
97  {
98  Twofish_UInt32 s[4][256]; /* pre-computed S-boxes */
99  Twofish_UInt32 K[40]; /* Round key words */
100  }
101  Twofish_key;
102 
103 
117 extern int Twofish_initialise();
118 
119 
159 extern int Twofish_prepare_key(
160  Twofish_Byte key[],
161  int key_len,
162  Twofish_key * xkey
163  );
164 
165 
182 extern void Twofish_encrypt(
183  Twofish_key * xkey,
184  Twofish_Byte p[16],
185  Twofish_Byte c[16]
186  );
187 
188 
205 extern void Twofish_decrypt(
206  Twofish_key * xkey,
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.
Definition: twofish.h:95
unsigned char Twofish_Byte
A Twofish_Byte must be an unsigned 8-bit integer.
Definition: twofish.h:40
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.
Definition: twofish.h:49