diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-04-07 18:01:20 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-04-07 18:01:20 +0000 |
commit | 2c6cbad869b0e60b37859c3c4f0c850721d057ce (patch) | |
tree | c7f80d5c8741a01425a056d5ba0139a69ac12cd6 /src/experimental/blowfish.h | |
parent | 6385780dc110bacf69a67332c8db8ddee9499eff (diff) | |
download | libbu++-2c6cbad869b0e60b37859c3c4f0c850721d057ce.tar.gz libbu++-2c6cbad869b0e60b37859c3c4f0c850721d057ce.tar.bz2 libbu++-2c6cbad869b0e60b37859c3c4f0c850721d057ce.tar.xz libbu++-2c6cbad869b0e60b37859c3c4f0c850721d057ce.zip |
Basic blowfish encryption filter. It needs to be silghtly more clever. I'm
going to steal the extra cleverness from the AesFilter in fishtrax.
Diffstat (limited to 'src/experimental/blowfish.h')
-rw-r--r-- | src/experimental/blowfish.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/experimental/blowfish.h b/src/experimental/blowfish.h new file mode 100644 index 0000000..fb46dfd --- /dev/null +++ b/src/experimental/blowfish.h | |||
@@ -0,0 +1,73 @@ | |||
1 | #ifndef BU_BLOWFISH_H | ||
2 | #define BU_BLOWFISH_H | ||
3 | |||
4 | #include "bu/filter.h" | ||
5 | |||
6 | #define NUM_SUBKEYS 18 | ||
7 | #define NUM_S_BOXES 4 | ||
8 | #define NUM_ENTRIES 256 | ||
9 | |||
10 | #define MAX_STRING 256 | ||
11 | #define MAX_PASSWD 56 // 448bits | ||
12 | |||
13 | namespace Bu | ||
14 | { | ||
15 | class Blowfish : public Bu::Filter | ||
16 | { | ||
17 | public: | ||
18 | Blowfish( Bu::Stream &rNext ); | ||
19 | virtual ~Blowfish(); | ||
20 | |||
21 | void setPassword( const Bu::String &sPass ); | ||
22 | |||
23 | virtual void start(); | ||
24 | virtual Bu::size stop(); | ||
25 | |||
26 | virtual Bu::size read( void *pBuf, Bu::size iBytes ); | ||
27 | virtual Bu::size write( const void *pBuf, Bu::size iBytes ); | ||
28 | using Bu::Stream::read; | ||
29 | using Bu::Stream::write; | ||
30 | |||
31 | private: | ||
32 | unsigned int PA[NUM_SUBKEYS]; | ||
33 | unsigned int SB[NUM_S_BOXES][NUM_ENTRIES]; | ||
34 | |||
35 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
36 | struct WordByte | ||
37 | { | ||
38 | unsigned int zero:8; | ||
39 | unsigned int one:8; | ||
40 | unsigned int two:8; | ||
41 | unsigned int three:8; | ||
42 | }; | ||
43 | #elif __BYTE_ORDER == __LITTLE_ENDIAN | ||
44 | struct WordByte | ||
45 | { | ||
46 | unsigned int three:8; | ||
47 | unsigned int two:8; | ||
48 | unsigned int one:8; | ||
49 | unsigned int zero:8; | ||
50 | }; | ||
51 | #else | ||
52 | #error No endianness defined | ||
53 | #endif | ||
54 | |||
55 | union Word | ||
56 | { | ||
57 | unsigned int word; | ||
58 | WordByte byte; | ||
59 | }; | ||
60 | |||
61 | struct DWord | ||
62 | { | ||
63 | Word word0; | ||
64 | Word word1; | ||
65 | }; | ||
66 | |||
67 | void reset(); | ||
68 | inline void BF_En( Word *, Word * ); | ||
69 | inline void BF_De( Word *, Word * ); | ||
70 | }; | ||
71 | }; | ||
72 | |||
73 | #endif | ||