aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/blowfish.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/experimental/blowfish.h73
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
13namespace 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