blob: c043b12e46f22ef08f5028ba67b51aba1dafb888 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#ifndef BU_BLOWFISH_H
#define BU_BLOWFISH_H
#include "bu/cipher.h"
#define NUM_SUBKEYS 18
#define NUM_S_BOXES 4
#define NUM_ENTRIES 256
#define MAX_STRING 256
#define MAX_PASSWD 56 // 448bits
namespace Bu
{
class Blowfish : public Bu::Cipher<8>
{
public:
Blowfish( Bu::Stream &rNext );
virtual ~Blowfish();
void setPassword( const Bu::String &sPass );
private:
uint32_t PA[NUM_SUBKEYS];
uint32_t SB[NUM_S_BOXES][NUM_ENTRIES];
#if __BYTE_ORDER == __BIG_ENDIAN
struct WordByte
{
uint32_t zero:8;
uint32_t one:8;
uint32_t two:8;
uint32_t three:8;
};
#elif __BYTE_ORDER == __LITTLE_ENDIAN
struct WordByte
{
uint32_t three:8;
uint32_t two:8;
uint32_t one:8;
uint32_t zero:8;
};
#else
#error No endianness defined
#endif
union Word
{
uint32_t word;
WordByte byte;
};
struct DWord
{
Word word0;
Word word1;
};
void reset();
virtual void encipher( void *pData );
virtual void decipher( void *pData );
inline void keyEncipher( Word &w1, Word &w2 );
};
};
#endif
|