projects
/
quassel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
test: Add build system support and a main function for unit tests
[quassel.git]
/
src
/
core
/
cipher.cpp
diff --git
a/src/core/cipher.cpp
b/src/core/cipher.cpp
index
7cc75d0
..
c5a40c2
100644
(file)
--- a/
src/core/cipher.cpp
+++ b/
src/core/cipher.cpp
@@
-13,7
+13,7
@@
*/
#include "cipher.h"
*/
#include "cipher.h"
-#include "log
ger
.h"
+#include "log
message
.h"
Cipher::Cipher()
{
Cipher::Cipher()
{
@@
-30,9
+30,6
@@
Cipher::Cipher(QByteArray key, QString cipherType)
}
}
-Cipher::~Cipher()
-{}
-
bool Cipher::setKey(QByteArray key)
{
if (key.isEmpty()) {
bool Cipher::setKey(QByteArray key)
{
if (key.isEmpty()) {
@@
-56,7
+53,8
@@
bool Cipher::setKey(QByteArray key)
// if(Preferences::self()->encryptionType())
// m_cbc = true;
// else
// if(Preferences::self()->encryptionType())
// m_cbc = true;
// else
- m_cbc = false;
+// default to CBC
+ m_cbc = true;
m_key = key;
}
return true;
m_key = key;
}
return true;
@@
-117,7
+115,6
@@
QByteArray Cipher::decrypt(QByteArray cipherText)
// (if cbc and no error we parse cbc) || (if ecb and error we parse cbc)
if ((m_cbc && !error) || (!m_cbc && error))
{
// (if cbc and no error we parse cbc) || (if ecb and error we parse cbc)
if ((m_cbc && !error) || (!m_cbc && error))
{
- cipherText = cipherText;
temp = blowfishCBC(cipherText, false);
if (temp == cipherText)
temp = blowfishCBC(cipherText, false);
if (temp == cipherText)
@@
-364,6
+361,10
@@
QByteArray Cipher::blowfishECB(QByteArray cipherText, bool direction)
}
else
{
}
else
{
+ // ECB Blowfish encodes in blocks of 12 chars, so anything else is malformed input
+ if ((temp.length() % 12) != 0)
+ return cipherText;
+
temp = b64ToByte(temp);
while ((temp.length() % 8) != 0) temp.append('\0');
}
temp = b64ToByte(temp);
while ((temp.length() % 8) != 0) temp.append('\0');
}
@@
-376,8
+377,13
@@
QByteArray Cipher::blowfishECB(QByteArray cipherText, bool direction)
if (!cipher.ok())
return cipherText;
if (!cipher.ok())
return cipherText;
- if (direction)
+ if (direction) {
+ // Sanity check
+ if ((temp2.length() % 8) != 0)
+ return cipherText;
+
temp2 = byteToB64(temp2);
temp2 = byteToB64(temp2);
+ }
return temp2;
}
return temp2;
}
@@
-420,13
+426,13
@@
QByteArray Cipher::byteToB64(QByteArray text)
right += v;
for (int i = 0; i < 6; i++) {
right += v;
for (int i = 0; i < 6; i++) {
- encoded.append(base64.at(right & 0x3F).to
Ascii
());
+ encoded.append(base64.at(right & 0x3F).to
Latin1
());
right = right >> 6;
}
right = right >> 6;
}
- //TODO make sure the .to
ascii
doesn't break anything
+ //TODO make sure the .to
Latin1
doesn't break anything
for (int i = 0; i < 6; i++) {
for (int i = 0; i < 6; i++) {
- encoded.append(base64.at(left & 0x3F).to
Ascii
());
+ encoded.append(base64.at(left & 0x3F).to
Latin1
());
left = left >> 6;
}
}
left = left >> 6;
}
}