summaryrefslogtreecommitdiff
path: root/extra/yassl/taocrypt/src/blowfish.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'extra/yassl/taocrypt/src/blowfish.cpp')
-rw-r--r--extra/yassl/taocrypt/src/blowfish.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/extra/yassl/taocrypt/src/blowfish.cpp b/extra/yassl/taocrypt/src/blowfish.cpp
index 8ee2f3fe569..64e8f0a84aa 100644
--- a/extra/yassl/taocrypt/src/blowfish.cpp
+++ b/extra/yassl/taocrypt/src/blowfish.cpp
@@ -86,7 +86,10 @@ void Blowfish::Process(byte* out, const byte* in, word32 sz)
void Blowfish::SetKey(const byte* key_string, word32 keylength, CipherDir dir)
{
- assert(keylength >= 4 && keylength <= 56);
+ if (keylength < 4)
+ keylength = 4;
+ else if (keylength > 56)
+ keylength = 56;
unsigned i, j=0, k;
word32 data, dspace[2] = {0, 0};
@@ -165,16 +168,21 @@ void Blowfish::crypt_block(const word32 in[2], word32 out[2]) const
word32 left = in[0];
word32 right = in[1];
+ const word32 *const s = sbox_;
const word32* p = pbox_;
- word32 tmp;
left ^= p[0];
- BF_ROUNDS
+ // roll back up and use s and p index instead of just p
+ for (unsigned i = 0; i < ROUNDS / 2; i++) {
+ right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)])
+ ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)])
+ ^ p[2*i+1];
-#if ROUNDS == 20
- BF_EXTRA_ROUNDS
-#endif
+ left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)])
+ ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)])
+ ^ p[2*i+2];
+ }
right ^= p[ROUNDS + 1];
@@ -188,17 +196,23 @@ typedef BlockGetAndPut<word32, BigEndian> gpBlock;
void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out)
const
{
- word32 tmp, left, right;
+ word32 left, right;
+ const word32 *const s = sbox_;
const word32* p = pbox_;
gpBlock::Get(in)(left)(right);
left ^= p[0];
- BF_ROUNDS
+ // roll back up and use s and p index instead of just p
+ for (unsigned i = 0; i < ROUNDS / 2; i++) {
+ right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)])
+ ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)])
+ ^ p[2*i+1];
-#if ROUNDS == 20
- BF_EXTRA_ROUNDS
-#endif
+ left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)])
+ ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)])
+ ^ p[2*i+2];
+ }
right ^= p[ROUNDS + 1];