diff options
Diffstat (limited to '')
-rw-r--r-- | src/experimental/blowfish.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/experimental/blowfish.cpp b/src/experimental/blowfish.cpp index 401291c..3dda87a 100644 --- a/src/experimental/blowfish.cpp +++ b/src/experimental/blowfish.cpp | |||
@@ -18,11 +18,13 @@ Bu::Blowfish::~Blowfish() | |||
18 | reset(); | 18 | reset(); |
19 | } | 19 | } |
20 | 20 | ||
21 | #define revBytes( x ) x = (((x&0xff)<<24)|((x&0xff00)<<8)|((x&0xff0000)>>8)|((x&0xff000000)>>24)) | ||
22 | |||
21 | void Bu::Blowfish::setPassword( const Bu::String &sPass ) | 23 | void Bu::Blowfish::setPassword( const Bu::String &sPass ) |
22 | { | 24 | { |
23 | reset(); | 25 | reset(); |
24 | 26 | ||
25 | unsigned int i,j,len=sPass.getSize(); | 27 | uint32_t i,j,len=sPass.getSize(); |
26 | Word Work,null0,null1; | 28 | Word Work,null0,null1; |
27 | 29 | ||
28 | if (len > 0) | 30 | if (len > 0) |
@@ -70,7 +72,7 @@ Bu::size Bu::Blowfish::stop() | |||
70 | 72 | ||
71 | Bu::size Bu::Blowfish::read( void *pBuf, Bu::size iBytes ) | 73 | Bu::size Bu::Blowfish::read( void *pBuf, Bu::size iBytes ) |
72 | { | 74 | { |
73 | unsigned int i; | 75 | uint32_t i; |
74 | DWord dwWork; | 76 | DWord dwWork; |
75 | 77 | ||
76 | if (iBytes%8) | 78 | if (iBytes%8) |
@@ -83,8 +85,11 @@ Bu::size Bu::Blowfish::read( void *pBuf, Bu::size iBytes ) | |||
83 | for (i=0;i<iBytes;i++) | 85 | for (i=0;i<iBytes;i++) |
84 | { | 86 | { |
85 | int iRead = rNext.read( &dwWork, 8 ); | 87 | int iRead = rNext.read( &dwWork, 8 ); |
86 | sio << "Read: " << iRead << sio.nl; | 88 | revBytes( dwWork.word0.word ); |
89 | revBytes( dwWork.word1.word ); | ||
87 | BF_De(&dwWork.word0,&dwWork.word1); | 90 | BF_De(&dwWork.word0,&dwWork.word1); |
91 | dwWork.word0.word = htobe32( dwWork.word0.word ); | ||
92 | dwWork.word1.word = htobe32( dwWork.word1.word ); | ||
88 | memcpy( ((char *)pBuf)+(i*8), &dwWork, 8 ); | 93 | memcpy( ((char *)pBuf)+(i*8), &dwWork, 8 ); |
89 | } | 94 | } |
90 | 95 | ||
@@ -94,7 +99,7 @@ Bu::size Bu::Blowfish::read( void *pBuf, Bu::size iBytes ) | |||
94 | 99 | ||
95 | Bu::size Bu::Blowfish::write( const void *pBuf, Bu::size iBytes ) | 100 | Bu::size Bu::Blowfish::write( const void *pBuf, Bu::size iBytes ) |
96 | { | 101 | { |
97 | unsigned int i; | 102 | uint32_t i; |
98 | DWord dwWork; | 103 | DWord dwWork; |
99 | 104 | ||
100 | if (iBytes%8) | 105 | if (iBytes%8) |
@@ -107,7 +112,11 @@ Bu::size Bu::Blowfish::write( const void *pBuf, Bu::size iBytes ) | |||
107 | for (i=0;i<iBytes;i++) | 112 | for (i=0;i<iBytes;i++) |
108 | { | 113 | { |
109 | memcpy( &dwWork, ((const char *)pBuf)+(i*8), 8 ); | 114 | memcpy( &dwWork, ((const char *)pBuf)+(i*8), 8 ); |
115 | dwWork.word0.word = be32toh( dwWork.word0.word ); | ||
116 | dwWork.word1.word = be32toh( dwWork.word1.word ); | ||
110 | BF_En(&dwWork.word0,&dwWork.word1); | 117 | BF_En(&dwWork.word0,&dwWork.word1); |
118 | revBytes( dwWork.word0.word ); | ||
119 | revBytes( dwWork.word1.word ); | ||
111 | rNext.write( &dwWork, 8 ); | 120 | rNext.write( &dwWork, 8 ); |
112 | } | 121 | } |
113 | 122 | ||
@@ -117,9 +126,9 @@ Bu::size Bu::Blowfish::write( const void *pBuf, Bu::size iBytes ) | |||
117 | 126 | ||
118 | void Bu::Blowfish::reset() | 127 | void Bu::Blowfish::reset() |
119 | { | 128 | { |
120 | unsigned int i,j; | 129 | uint32_t i,j; |
121 | 130 | ||
122 | static unsigned int PA_Init[NUM_SUBKEYS] = | 131 | static uint32_t PA_Init[NUM_SUBKEYS] = |
123 | { | 132 | { |
124 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, | 133 | 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, |
125 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, | 134 | 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, |
@@ -128,7 +137,7 @@ void Bu::Blowfish::reset() | |||
128 | 0x9216d5d9, 0x8979fb1b | 137 | 0x9216d5d9, 0x8979fb1b |
129 | }; | 138 | }; |
130 | 139 | ||
131 | static unsigned int SB_Init[NUM_S_BOXES][NUM_ENTRIES] = { | 140 | static uint32_t SB_Init[NUM_S_BOXES][NUM_ENTRIES] = { |
132 | { | 141 | { |
133 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, | 142 | 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, |
134 | 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, | 143 | 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, |