Commit 1f760e41 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) Fixed thread safety problem. JM-1035

2) Small twiks to improve performance.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8062 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8166986e
...@@ -14,13 +14,14 @@ ...@@ -14,13 +14,14 @@
package org.jivesoftware.util; package org.jivesoftware.util;
import java.util.*; import java.security.MessageDigest;
import java.security.*; import java.util.Random;
/** /**
* A class that provides easy Blowfish encryption.<p> * A class that provides easy Blowfish encryption.<p>
* *
* @author Markus Hahn <markus_hahn@gmx.net> * @author Markus Hahn <markus_hahn@gmx.net>
* @author Gaston Dombiak
*/ */
public class Blowfish { public class Blowfish {
...@@ -95,11 +96,13 @@ public class Blowfish { ...@@ -95,11 +96,13 @@ public class Blowfish {
buf[nPos++] = bPadVal; buf[nPos++] = bPadVal;
} }
synchronized (m_bfish) {
// create the encryptor // create the encryptor
m_bfish.setCBCIV(lNewCBCIV); m_bfish.setCBCIV(lNewCBCIV);
// encrypt the buffer // encrypt the buffer
m_bfish.encrypt(buf); m_bfish.encrypt(buf);
}
// return the binhex string // return the binhex string
byte[] newCBCIV = new byte[BlowfishCBC.BLOCKSIZE]; byte[] newCBCIV = new byte[BlowfishCBC.BLOCKSIZE];
...@@ -136,9 +139,6 @@ public class Blowfish { ...@@ -136,9 +139,6 @@ public class Blowfish {
if (nNumOfBytes < BlowfishCBC.BLOCKSIZE) if (nNumOfBytes < BlowfishCBC.BLOCKSIZE)
return null; return null;
// (got it)
m_bfish.setCBCIV(cbciv);
// something left to decrypt? // something left to decrypt?
nLen -= BlowfishCBC.BLOCKSIZE; nLen -= BlowfishCBC.BLOCKSIZE;
if (nLen == 0) if (nLen == 0)
...@@ -162,8 +162,13 @@ public class Blowfish { ...@@ -162,8 +162,13 @@ public class Blowfish {
return null; return null;
} }
synchronized (m_bfish) {
// (got it)
m_bfish.setCBCIV(cbciv);
// decrypt the buffer // decrypt the buffer
m_bfish.decrypt(buf); m_bfish.decrypt(buf);
}
// get the last padding byte // get the last padding byte
int nPadByte = (int)buf[buf.length - 1] & 0x0ff; int nPadByte = (int)buf[buf.length - 1] & 0x0ff;
...@@ -1344,7 +1349,7 @@ public class Blowfish { ...@@ -1344,7 +1349,7 @@ public class Blowfish {
int nStartPos, int nStartPos,
int nNumOfBytes) int nNumOfBytes)
{ {
StringBuffer sbuf = new StringBuffer(); StringBuilder sbuf = new StringBuilder();
sbuf.setLength(nNumOfBytes << 1); sbuf.setLength(nNumOfBytes << 1);
int nPos = 0; int nPos = 0;
...@@ -1446,7 +1451,7 @@ public class Blowfish { ...@@ -1446,7 +1451,7 @@ public class Blowfish {
nNumOfBytes = nAvailCapacity; nNumOfBytes = nAvailCapacity;
} }
StringBuffer sbuf = new StringBuffer(); StringBuilder sbuf = new StringBuilder();
sbuf.setLength(nNumOfBytes >> 1); sbuf.setLength(nNumOfBytes >> 1);
int nSBufPos = 0; int nSBufPos = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment