replaced Q_UINT with quint

git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@80 b624d157-de02-0410-bad0-e51aec6abb33
master
tariq 19 years ago
parent 74c7b86a89
commit 580a8f357b
  1. 9
      changelog
  2. BIN
      share/keepass/icons/nuvola/32x32/actions/reload.png
  3. 31
      src/Database.h
  4. 149
      src/PwManager.cpp
  5. 19
      src/PwManager.h
  6. 8
      src/crypto/blowfish.h
  7. 388
      src/crypto/rijndael.cpp
  8. 22
      src/crypto/rijndael.h
  9. 26
      src/crypto/sha1.cpp
  10. 26
      src/crypto/sha1.h
  11. 56
      src/crypto/sha256.c
  12. 40
      src/crypto/twoclass.cpp
  13. 8
      src/crypto/twoclass.h
  14. 18
      src/crypto/twofish.cpp
  15. 1
      src/dialogs/EditEntryDlg.cpp
  16. 1
      src/dialogs/EditGroupDlg.cpp
  17. 2
      src/dialogs/SearchDlg.h
  18. 30
      src/dialogs/SelectIconDlg.cpp
  19. 3
      src/dialogs/SelectIconDlg.h
  20. 2
      src/import/Import_KWalletXml.cpp
  21. 8
      src/lib/AutoType.cpp
  22. 8
      src/lib/AutoType.h
  23. 37
      src/lib/EntryView.cpp
  24. 2
      src/lib/EntryView.h
  25. 3
      src/lib/IniReader.cpp
  26. 4
      src/lib/random.cpp
  27. 11
      src/main.cpp
  28. 1
      src/main.h
  29. 2
      src/mainwindow.h

@ -1,9 +1,14 @@
--------------- ---------------
0.2.1 0.2.1
--------------- ---------------
-Auto-Type -added AutoType feature
-Custom Icons Extension -added custom icons feature
-new command line option for manual language selection (-lang <LOCALE-CODE>)
-when saving an attachment the original filename is adopted by the file dialog -when saving an attachment the original filename is adopted by the file dialog
-fixed strange sorting behavior of entries (Bug #7083)
-sorting by dates now works as expected
-the 'Expires' column and the detailed entry view now also show the string 'never' for entries which don't expire
-entry view now gets updated after changing the column setup
--------------- ---------------
0.2.0 0.2.0
--------------- ---------------

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

@ -42,10 +42,10 @@ class CEntry{
public: public:
CEntry(); CEntry();
~CEntry(); ~CEntry();
Q_UINT8 ID[16]; quint8 ID[16];
Q_UINT32 sID; quint32 sID;
Q_UINT32 GroupID; quint32 GroupID;
Q_UINT32 ImageID; quint32 ImageID;
quint32 OldImgID; quint32 OldImgID;
QString Title; QString Title;
QString URL; QString URL;
@ -58,8 +58,8 @@ KpxDateTime LastMod;
KpxDateTime LastAccess; KpxDateTime LastAccess;
KpxDateTime Expire; KpxDateTime Expire;
QByteArray BinaryData; QByteArray BinaryData;
/*Q_UINT32 PasswordLength;*/ /*quint32 PasswordLength;*/
bool ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData); bool ReadEntryField(quint16 FieldType, quint32 FieldSize, quint8 *pData);
bool operator==(const CEntry&) const; bool operator==(const CEntry&) const;
}; };
@ -68,17 +68,17 @@ class CGroup{
public: public:
CGroup(); CGroup();
~CGroup(); ~CGroup();
Q_UINT32 ID; quint32 ID;
Q_UINT32 ImageID; quint32 ImageID;
quint32 OldImgID; quint32 OldImgID;
QString Name; QString Name;
QDateTime Creation; QDateTime Creation;
QDateTime LastMod; QDateTime LastMod;
QDateTime LastAccess; QDateTime LastAccess;
QDateTime Expire; QDateTime Expire;
Q_UINT16 Level; quint16 Level;
Q_UINT32 Flags; quint32 Flags;
bool ReadGroupField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData); bool ReadGroupField(quint16 FieldType, quint32 FieldSize, quint8 *pData);
bool operator==(const CGroup&) const; bool operator==(const CGroup&) const;
bool UI_ItemIsExpanded; bool UI_ItemIsExpanded;
@ -132,16 +132,17 @@ public:
virtual int numIcons()=0; virtual int numIcons()=0;
virtual void addIcon(const QPixmap& icon)=0; virtual void addIcon(const QPixmap& icon)=0;
virtual void removeIcon(int Id)=0; virtual void removeIcon(int Id)=0;
virtual void replaceIcon(int Id,const QPixmap& icon)=0;
Q_UINT32 CryptoAlgorithmus; quint32 CryptoAlgorithmus;
Q_UINT32 KeyEncRounds; quint32 KeyEncRounds;
QFile* file; QFile* file;
bool modflag; bool modflag;
int SearchGroupID; int SearchGroupID;
protected: protected:
Q_UINT8 MasterKey[32]; quint8 MasterKey[32];
Q_UINT8 TransformedMasterKey[32]; quint8 TransformedMasterKey[32];
}; };

@ -70,11 +70,11 @@ return ids;
bool PwDatabase::openDatabase(QString filename, QString& err){ bool PwDatabase::openDatabase(QString filename, QString& err){
unsigned long total_size,crypto_size; unsigned long total_size,crypto_size;
Q_UINT32 Signature1,Signature2,Version,NumGroups,NumEntries,Flags; quint32 Signature1,Signature2,Version,NumGroups,NumEntries,Flags;
Q_UINT8 TrafoRandomSeed[32]; quint8 TrafoRandomSeed[32];
Q_UINT8 FinalRandomSeed[16]; quint8 FinalRandomSeed[16];
Q_UINT8 ContentsHash[32]; quint8 ContentsHash[32];
Q_UINT8 EncryptionIV[16]; quint8 EncryptionIV[16];
file=new QFile(filename); file=new QFile(filename);
if(!file->open(QIODevice::ReadWrite)){ if(!file->open(QIODevice::ReadWrite)){
@ -122,7 +122,7 @@ else {
} }
transformKey(MasterKey,TransformedMasterKey,TrafoRandomSeed,KeyEncRounds); transformKey(MasterKey,TransformedMasterKey,TrafoRandomSeed,KeyEncRounds);
Q_UINT8 FinalKey[32]; quint8 FinalKey[32];
sha256_context sha32; sha256_context sha32;
sha256_starts(&sha32); sha256_starts(&sha32);
sha256_update(&sha32,FinalRandomSeed, 16); sha256_update(&sha32,FinalRandomSeed, 16);
@ -138,15 +138,15 @@ if(CryptoAlgorithmus == ALGO_AES)
{err=tr("AES-Init Failed"); {err=tr("AES-Init Failed");
return false;} return false;}
// Decrypt! The first bytes aren't encrypted (that's the header) // Decrypt! The first bytes aren't encrypted (that's the header)
crypto_size = (unsigned long)aes.padDecrypt((Q_UINT8 *)buffer + DB_HEADER_SIZE, crypto_size = (unsigned long)aes.padDecrypt((quint8 *)buffer + DB_HEADER_SIZE,
total_size - DB_HEADER_SIZE, (Q_UINT8 *)buffer + DB_HEADER_SIZE); total_size - DB_HEADER_SIZE, (quint8 *)buffer + DB_HEADER_SIZE);
} }
else if(CryptoAlgorithmus == ALGO_TWOFISH) else if(CryptoAlgorithmus == ALGO_TWOFISH)
{ {
CTwofish twofish; CTwofish twofish;
if(twofish.init(FinalKey, 32, EncryptionIV) != true){return false;} if(twofish.init(FinalKey, 32, EncryptionIV) != true){return false;}
crypto_size = (unsigned long)twofish.padDecrypt((Q_UINT8 *)buffer + DB_HEADER_SIZE, crypto_size = (unsigned long)twofish.padDecrypt((quint8 *)buffer + DB_HEADER_SIZE,
total_size - DB_HEADER_SIZE, (Q_UINT8 *)buffer + DB_HEADER_SIZE); total_size - DB_HEADER_SIZE, (quint8 *)buffer + DB_HEADER_SIZE);
} }
if((crypto_size > 2147483446) || (!crypto_size && NumGroups)){err=tr("Decryption failed.\nThe key is wrong or the file is damaged."); return false;} if((crypto_size > 2147483446) || (!crypto_size && NumGroups)){err=tr("Decryption failed.\nThe key is wrong or the file is damaged."); return false;}
@ -163,8 +163,8 @@ return false;}
unsigned long tmp_id=0; unsigned long tmp_id=0;
unsigned long pos = DB_HEADER_SIZE; unsigned long pos = DB_HEADER_SIZE;
Q_UINT16 FieldType; quint16 FieldType;
Q_UINT32 FieldSize; quint32 FieldSize;
char* pField; char* pField;
bool bRet; bool bRet;
CGroup group; CGroup group;
@ -185,7 +185,7 @@ CGroup group;
err=tr("Unexpected error: Offset is out of range. [G2]"); err=tr("Unexpected error: Offset is out of range. [G2]");
return false;} return false;}
bRet = group.ReadGroupField(FieldType, FieldSize, (Q_UINT8 *)pField); bRet = group.ReadGroupField(FieldType, FieldSize, (quint8 *)pField);
if((FieldType == 0xFFFF) && (bRet == true)){ if((FieldType == 0xFFFF) && (bRet == true)){
Groups << group; Groups << group;
CurGroup++;} // Now and ONLY now the counter gets increased CurGroup++;} // Now and ONLY now the counter gets increased
@ -215,7 +215,7 @@ CEntry entry;
err=tr("Unexpected error: Offset is out of range. [E2]"); err=tr("Unexpected error: Offset is out of range. [E2]");
return false; } return false; }
bRet = entry.ReadEntryField(FieldType,FieldSize,(Q_UINT8*)pField); bRet = entry.ReadEntryField(FieldType,FieldSize,(quint8*)pField);
if((FieldType == 0xFFFF) && (bRet == true)){ if((FieldType == 0xFFFF) && (bRet == true)){
entry.sID=tmp_id++; entry.sID=tmp_id++;
@ -252,7 +252,7 @@ return false; //unknown MetaStreams
} }
bool PwDatabase::parseCustomIconsMetaStream(const QByteArray& dta){ bool PwDatabase::parseCustomIconsMetaStream(const QByteArray& dta){
Q_UINT32 NumIcons,NumEntries,NumGroups,offset; quint32 NumIcons,NumEntries,NumGroups,offset;
memcpyFromLEnd32(&NumIcons,dta.data()); memcpyFromLEnd32(&NumIcons,dta.data());
memcpyFromLEnd32(&NumEntries,dta.data()+4); memcpyFromLEnd32(&NumEntries,dta.data()+4);
memcpyFromLEnd32(&NumGroups,dta.data()+8); memcpyFromLEnd32(&NumGroups,dta.data()+8);
@ -260,7 +260,7 @@ offset=12;
CustomIcons.clear(); CustomIcons.clear();
for(int i=0;i<NumIcons;i++){ for(int i=0;i<NumIcons;i++){
CustomIcons << QPixmap(); CustomIcons << QPixmap();
Q_UINT32 Size; quint32 Size;
memcpyFromLEnd32(&Size,dta.data()+offset); memcpyFromLEnd32(&Size,dta.data()+offset);
if(offset+Size > dta.size()){ if(offset+Size > dta.size()){
CustomIcons.clear(); CustomIcons.clear();
@ -275,7 +275,7 @@ for(int i=0;i<NumIcons;i++){
return false;} return false;}
} }
for(int i=0;i<NumEntries;i++){ for(int i=0;i<NumEntries;i++){
Q_UINT32 Entry,Icon; quint32 Entry,Icon;
memcpyFromLEnd32(&Entry,dta.data()+offset); memcpyFromLEnd32(&Entry,dta.data()+offset);
offset+=4; offset+=4;
memcpyFromLEnd32(&Icon,dta.data()+offset); memcpyFromLEnd32(&Icon,dta.data()+offset);
@ -284,7 +284,7 @@ for(int i=0;i<NumEntries;i++){
Entries[Entry].ImageID=Icon; Entries[Entry].ImageID=Icon;
} }
for(int i=0;i<NumGroups;i++){ for(int i=0;i<NumGroups;i++){
Q_UINT32 Group,Icon; quint32 Group,Icon;
memcpyFromLEnd32(&Group,dta.data()+offset); memcpyFromLEnd32(&Group,dta.data()+offset);
offset+=4; offset+=4;
memcpyFromLEnd32(&Icon,dta.data()+offset); memcpyFromLEnd32(&Icon,dta.data()+offset);
@ -303,19 +303,19 @@ e->Additional="KPX_CUSTOM_ICONS";
e->URL="$"; e->URL="$";
e->ImageID=0; e->ImageID=0;
int Size=12; int Size=12;
Q_UINT32 NumEntries=Entries.size(); quint32 NumEntries=Entries.size();
Q_UINT32 NumGroups=Groups.size(); quint32 NumGroups=Groups.size();
Size+=8*(NumEntries+NumGroups); Size+=8*(NumEntries+NumGroups);
Size+=CustomIcons.size()*1000; // 1KB Size+=CustomIcons.size()*1000; // 1KB
e->BinaryData.reserve(Size); e->BinaryData.reserve(Size);
e->BinaryData.resize(12); e->BinaryData.resize(12);
Q_UINT32 NumIcons=CustomIcons.size(); quint32 NumIcons=CustomIcons.size();
memcpyToLEnd32(e->BinaryData.data(),&NumIcons); memcpyToLEnd32(e->BinaryData.data(),&NumIcons);
memcpyToLEnd32(e->BinaryData.data()+4,&NumEntries); memcpyToLEnd32(e->BinaryData.data()+4,&NumEntries);
memcpyToLEnd32(e->BinaryData.data()+8,&NumGroups); memcpyToLEnd32(e->BinaryData.data()+8,&NumGroups);
for(int i=0;i<CustomIcons.size();i++){ for(int i=0;i<CustomIcons.size();i++){
Q_UINT32 ImgSize; quint32 ImgSize;
char ImgSizeBin[4]; char ImgSizeBin[4];
QByteArray png; QByteArray png;
png.reserve(1000); png.reserve(1000);
@ -326,17 +326,17 @@ for(int i=0;i<CustomIcons.size();i++){
e->BinaryData.append(QByteArray::fromRawData(ImgSizeBin,4)); e->BinaryData.append(QByteArray::fromRawData(ImgSizeBin,4));
e->BinaryData.append(png); e->BinaryData.append(png);
} }
for(Q_UINT32 i=0;i<Entries.size();i++){ for(quint32 i=0;i<Entries.size();i++){
char Bin[8]; char Bin[8];
memcpyToLEnd32(Bin,&i); memcpyToLEnd32(Bin,&i);
Q_UINT32 id=Entries[i].ImageID; quint32 id=Entries[i].ImageID;
memcpyToLEnd32(Bin+4,&id); memcpyToLEnd32(Bin+4,&id);
e->BinaryData.append(QByteArray::fromRawData(Bin,8)); e->BinaryData.append(QByteArray::fromRawData(Bin,8));
} }
for(Q_UINT32 i=0;i<Groups.size();i++){ for(quint32 i=0;i<Groups.size();i++){
char Bin[8]; char Bin[8];
memcpyToLEnd32(Bin,&i); memcpyToLEnd32(Bin,&i);
Q_UINT32 id=Groups[i].ImageID; quint32 id=Groups[i].ImageID;
memcpyToLEnd32(Bin+4,&id); memcpyToLEnd32(Bin+4,&id);
e->BinaryData.append(QByteArray::fromRawData(Bin,8)); e->BinaryData.append(QByteArray::fromRawData(Bin,8));
} }
@ -367,30 +367,37 @@ if(id >= CustomIcons.size()) return;
CustomIcons.removeAt(id); // .isNull()==true CustomIcons.removeAt(id); // .isNull()==true
for(int i=0;i<Entries.size();i++){ for(int i=0;i<Entries.size();i++){
if(Entries[i].ImageID == id+BUILTIN_ICONS) if(Entries[i].ImageID == id+BUILTIN_ICONS)
Entries[i].ImageID=0; Entries[i].ImageID=Entries[i].OldImgID;
if(Entries[i].ImageID>id+BUILTIN_ICONS) if(Entries[i].ImageID>id+BUILTIN_ICONS)
Entries[i].ImageID--; Entries[i].ImageID--;
} }
for(int i=0;i<Groups.size();i++){ for(int i=0;i<Groups.size();i++){
if(Groups[i].ImageID == id+BUILTIN_ICONS) if(Groups[i].ImageID == id+BUILTIN_ICONS)
Groups[i].ImageID=0; Groups[i].ImageID=Groups[i].OldImgID;
if(Groups[i].ImageID>id+BUILTIN_ICONS) if(Groups[i].ImageID>id+BUILTIN_ICONS)
Groups[i].ImageID--; Groups[i].ImageID--;
} }
emit modified();
}
void PwDatabase::replaceIcon(int id,const QPixmap& icon){
if(id<BUILTIN_ICONS)return;
CustomIcons[id-BUILTIN_ICONS]=icon;
emit modified();
} }
void PwDatabase::transformKey(Q_UINT8* src,Q_UINT8* dst,Q_UINT8* KeySeed,int rounds){ void PwDatabase::transformKey(quint8* src,quint8* dst,quint8* KeySeed,int rounds){
Q_UINT8* tmp=new Q_UINT8[32]; quint8* tmp=new quint8[32];
Rijndael rijndael; Rijndael rijndael;
sha256_context sha2; sha256_context sha2;
if(rijndael.init(Rijndael::ECB, Rijndael::Encrypt, (const Q_UINT8 *)KeySeed, if(rijndael.init(Rijndael::ECB, Rijndael::Encrypt, (const quint8 *)KeySeed,
Rijndael::Key32Bytes, 0) != RIJNDAEL_SUCCESS){ Rijndael::Key32Bytes, 0) != RIJNDAEL_SUCCESS){
_ERROR _ERROR
exit(1);} exit(1);}
memcpy(tmp,src,32); memcpy(tmp,src,32);
for(int i=0;i<rounds;i++){ for(int i=0;i<rounds;i++){
rijndael.blockEncrypt((const Q_UINT8 *)tmp, 256, (Q_UINT8 *)tmp); rijndael.blockEncrypt((const quint8 *)tmp, 256, (quint8 *)tmp);
} }
sha256_starts(&sha2); sha256_starts(&sha2);
@ -518,10 +525,10 @@ return &Entries.back();
bool PwDatabase::CalcMasterKeyByFileAndPw(QString filename, QString& Password){ bool PwDatabase::CalcMasterKeyByFileAndPw(QString filename, QString& Password){
Q_UINT8* FileKey; quint8* FileKey;
Q_UINT8* PasswordKey; quint8* PasswordKey;
PasswordKey=new Q_UINT8[32]; PasswordKey=new quint8[32];
FileKey=new Q_UINT8[32]; FileKey=new quint8[32];
sha256_context sha32; sha256_context sha32;
///////////////////////// /////////////////////////
QFile file(filename); QFile file(filename);
@ -605,8 +612,8 @@ entry->GroupID=dst->ID;
CEntry* PwDatabase::cloneEntry(CEntry* entry){ CEntry* PwDatabase::cloneEntry(CEntry* entry){
CEntry *Dolly=addEntry(); CEntry *Dolly=addEntry();
Q_UINT8 ID[16]; quint8 ID[16];
Q_UINT32 sid=Dolly->sID; quint32 sid=Dolly->sID;
memcpy(ID,Dolly->ID,16); memcpy(ID,Dolly->ID,16);
*Dolly=*entry; *Dolly=*entry;
Dolly->sID=sid; Dolly->sID=sid;
@ -615,7 +622,7 @@ return Dolly;
} }
bool CGroup::ReadGroupField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData) bool CGroup::ReadGroupField(quint16 FieldType, quint32 FieldSize, quint8 *pData)
{ {
switch(FieldType) switch(FieldType)
@ -668,7 +675,7 @@ void PwDatabase::newDatabase(){
file=new QFile(); file=new QFile();
} }
bool CEntry::ReadEntryField(Q_UINT16 FieldType, Q_UINT32 FieldSize, Q_UINT8 *pData){ bool CEntry::ReadEntryField(quint16 FieldType, quint32 FieldSize, quint8 *pData){
switch(FieldType) switch(FieldType)
@ -743,11 +750,11 @@ return true;
bool PwDatabase::saveDatabase(){ bool PwDatabase::saveDatabase(){
CGroup SearchGroup; CGroup SearchGroup;
Q_UINT32 NumGroups,NumEntries,Signature1,Signature2,Flags,Version; quint32 NumGroups,NumEntries,Signature1,Signature2,Flags,Version;
Q_UINT8 TrafoRandomSeed[32]; quint8 TrafoRandomSeed[32];
Q_UINT8 FinalRandomSeed[16]; quint8 FinalRandomSeed[16];
Q_UINT8 ContentsHash[32]; quint8 ContentsHash[32];
Q_UINT8 EncryptionIV[16]; quint8 EncryptionIV[16];
Q_ASSERT(file); Q_ASSERT(file);
if(!(file->openMode() & QIODevice::WriteOnly)){ if(!(file->openMode() & QIODevice::WriteOnly)){
@ -812,8 +819,8 @@ getRandomBytes(FinalRandomSeed,1,16,false);
getRandomBytes(TrafoRandomSeed,1,32,false); getRandomBytes(TrafoRandomSeed,1,32,false);
getRandomBytes(EncryptionIV,1,16,false); getRandomBytes(EncryptionIV,1,16,false);
Q_UINT16 FieldType; quint16 FieldType;
Q_UINT32 FieldSize; quint32 FieldSize;
int pos=DB_HEADER_SIZE; // Skip the header, it will be written later int pos=DB_HEADER_SIZE; // Skip the header, it will be written later
for(int i=0; i < Groups.size(); i++){ for(int i=0; i < Groups.size(); i++){
@ -1059,7 +1066,7 @@ memcpy(buffer+56,ContentsHash,32);
memcpy(buffer+88,TrafoRandomSeed,32); memcpy(buffer+88,TrafoRandomSeed,32);
memcpyToLEnd32(buffer+120,&KeyEncRounds); memcpyToLEnd32(buffer+120,&KeyEncRounds);
transformKey(MasterKey,TransformedMasterKey,TrafoRandomSeed,KeyEncRounds); transformKey(MasterKey,TransformedMasterKey,TrafoRandomSeed,KeyEncRounds);
Q_UINT8 FinalKey[32]; quint8 FinalKey[32];
sha256_starts(&context); sha256_starts(&context);
sha256_update(&context,FinalRandomSeed, 16); sha256_update(&context,FinalRandomSeed, 16);
sha256_update(&context,TransformedMasterKey, 32); sha256_update(&context,TransformedMasterKey, 32);
@ -1074,18 +1081,18 @@ Rijndael aes;
_ERROR _ERROR
delete [] buffer; delete [] buffer;
return false;} return false;}
EncryptedPartSize = (unsigned long)aes.padEncrypt((Q_UINT8*)buffer+DB_HEADER_SIZE, EncryptedPartSize = (unsigned long)aes.padEncrypt((quint8*)buffer+DB_HEADER_SIZE,
pos - DB_HEADER_SIZE, pos - DB_HEADER_SIZE,
(Q_UINT8*)buffer+DB_HEADER_SIZE); (quint8*)buffer+DB_HEADER_SIZE);
}else if(CryptoAlgorithmus == ALGO_TWOFISH){ }else if(CryptoAlgorithmus == ALGO_TWOFISH){
CTwofish twofish; CTwofish twofish;
if(twofish.init(FinalKey, 32, EncryptionIV) == false){ if(twofish.init(FinalKey, 32, EncryptionIV) == false){
_ERROR _ERROR
delete [] buffer; delete [] buffer;
return false;} return false;}
EncryptedPartSize = (unsigned long)twofish.padEncrypt((Q_UINT8*)buffer+DB_HEADER_SIZE, EncryptedPartSize = (unsigned long)twofish.padEncrypt((quint8*)buffer+DB_HEADER_SIZE,
pos - DB_HEADER_SIZE, pos - DB_HEADER_SIZE,
(Q_UINT8*)buffer+DB_HEADER_SIZE); (quint8*)buffer+DB_HEADER_SIZE);
} }
if((EncryptedPartSize > 2147483446) || (!EncryptedPartSize && Groups.size())){ if((EncryptedPartSize > 2147483446) || (!EncryptedPartSize && Groups.size())){
_ERROR _ERROR
@ -1186,14 +1193,14 @@ for(int i=0;i<db->numGroups();i++){
} }
} }
bool PwDatabase::isGroupIdInUse(Q_UINT32 id){ bool PwDatabase::isGroupIdInUse(quint32 id){
for(int i=0;i<Groups.size();i++) for(int i=0;i<Groups.size();i++)
if(Groups[i].ID==id)return true; if(Groups[i].ID==id)return true;
return false; return false;
} }
bool PwDatabase::isEntrySidInUse(Q_UINT32 sid){ bool PwDatabase::isEntrySidInUse(quint32 sid){
for(int i=0;i<Entries.size();i++) for(int i=0;i<Entries.size();i++)
if(Entries[i].sID==sid)return true; if(Entries[i].sID==sid)return true;
@ -1214,8 +1221,8 @@ return true;
} }
Q_UINT32 PwDatabase::getNewGroupId(){ quint32 PwDatabase::getNewGroupId(){
Q_UINT32 id; quint32 id;
bool used; bool used;
while(1){ while(1){
used=false; used=false;
@ -1227,8 +1234,8 @@ if(used==false)break;}
return id; return id;
} }
Q_UINT32 PwDatabase::getNewEntrySid(){ quint32 PwDatabase::getNewEntrySid(){
Q_UINT32 sid; quint32 sid;
while(1){ while(1){
getRandomBytes(&sid,4,1,false); getRandomBytes(&sid,4,1,false);
if(!sid)continue; if(!sid)continue;
@ -1241,7 +1248,7 @@ bool PwDatabase::convHexToBinaryKey(char* HexKey, char* dst){
QString hex=QString::fromAscii(HexKey,64); QString hex=QString::fromAscii(HexKey,64);
for(int i=0; i<64; i+=2){ for(int i=0; i<64; i+=2){
bool err; bool err;
Q_UINT8 bin; quint8 bin;
bin=hex.mid(i,2).toUInt(&err,16); bin=hex.mid(i,2).toUInt(&err,16);
if(!err){ if(!err){
qWarning("Invalid Hex Key\n"); qWarning("Invalid Hex Key\n");
@ -1370,7 +1377,7 @@ void PwDatabase::setEntry(unsigned long index,CEntry& entry){
int PwDatabase::numEntries(){ int PwDatabase::numEntries(){
return Entries.size();} return Entries.size();}
void memcpyFromLEnd32(Q_UINT32* dst,const char* src){ void memcpyFromLEnd32(quint32* dst,const char* src){
if(QSysInfo::ByteOrder==QSysInfo::BigEndian){ if(QSysInfo::ByteOrder==QSysInfo::BigEndian){
memcpy(((char*)dst)+3,src+0,1); memcpy(((char*)dst)+3,src+0,1);
@ -1382,7 +1389,7 @@ else
memcpy(dst,src,4); memcpy(dst,src,4);
} }
void memcpyFromLEnd16(Q_UINT16* dst,const char* src){ void memcpyFromLEnd16(quint16* dst,const char* src){
if(QSysInfo::ByteOrder==QSysInfo::BigEndian){ if(QSysInfo::ByteOrder==QSysInfo::BigEndian){
memcpy(((char*)dst)+1,src+0,1); memcpy(((char*)dst)+1,src+0,1);
@ -1392,7 +1399,7 @@ else
memcpy(dst,src,2); memcpy(dst,src,2);
} }
void memcpyToLEnd32(char* dst,const Q_UINT32* src){ void memcpyToLEnd32(char* dst,const quint32* src){
if(QSysInfo::ByteOrder==QSysInfo::BigEndian){ if(QSysInfo::ByteOrder==QSysInfo::BigEndian){
memcpy(dst+0,((char*)src)+3,1); memcpy(dst+0,((char*)src)+3,1);
@ -1404,7 +1411,7 @@ else
memcpy(dst,src,4); memcpy(dst,src,4);
} }
void memcpyToLEnd16(char* dst,const Q_UINT16* src){ void memcpyToLEnd16(char* dst,const quint16* src){
if(QSysInfo::ByteOrder==QSysInfo::BigEndian){ if(QSysInfo::ByteOrder==QSysInfo::BigEndian){
memcpy(dst+0,((char*)src)+1,1); memcpy(dst+0,((char*)src)+1,1);
@ -1417,9 +1424,9 @@ else
const QDateTime Date_Never(QDate(2999,12,28),QTime(23,59,59)); const QDateTime Date_Never(QDate(2999,12,28),QTime(23,59,59));
QDateTime dateFromPackedStruct5(const unsigned char* pBytes){ QDateTime dateFromPackedStruct5(const unsigned char* pBytes){
Q_UINT32 dw1, dw2, dw3, dw4, dw5; quint32 dw1, dw2, dw3, dw4, dw5;
dw1 = (Q_UINT32)pBytes[0]; dw2 = (Q_UINT32)pBytes[1]; dw3 = (Q_UINT32)pBytes[2]; dw1 = (quint32)pBytes[0]; dw2 = (quint32)pBytes[1]; dw3 = (quint32)pBytes[2];
dw4 = (Q_UINT32)pBytes[3]; dw5 = (Q_UINT32)pBytes[4]; dw4 = (quint32)pBytes[3]; dw5 = (quint32)pBytes[4];
int y = (dw1 << 6) | (dw2 >> 2); int y = (dw1 << 6) | (dw2 >> 2);
int mon = ((dw2 & 0x00000003) << 2) | (dw3 >> 6); int mon = ((dw2 & 0x00000003) << 2) | (dw3 >> 6);
int d = (dw3 >> 1) & 0x0000001F; int d = (dw3 >> 1) & 0x0000001F;
@ -1431,11 +1438,11 @@ return QDateTime(QDate(y,mon,d),QTime(h,min,s));
void dateToPackedStruct5(const QDateTime& d,unsigned char* pBytes){ void dateToPackedStruct5(const QDateTime& d,unsigned char* pBytes){
pBytes[0] = (Q_UINT8)(((Q_UINT32)d.date().year() >> 6) & 0x0000003F); pBytes[0] = (quint8)(((quint32)d.date().year() >> 6) & 0x0000003F);
pBytes[1] = (Q_UINT8)((((Q_UINT32)d.date().year() & 0x0000003F) << 2) | (((Q_UINT32)d.date().month() >> 2) & 0x00000003)); pBytes[1] = (quint8)((((quint32)d.date().year() & 0x0000003F) << 2) | (((quint32)d.date().month() >> 2) & 0x00000003));
pBytes[2] = (Q_UINT8)((((Q_UINT32)d.date().month() & 0x00000003) << 6) | (((Q_UINT32)d.date().day() & 0x0000001F) << 1) | (((Q_UINT32)d.time().hour() >> 4) & 0x00000001)); pBytes[2] = (quint8)((((quint32)d.date().month() & 0x00000003) << 6) | (((quint32)d.date().day() & 0x0000001F) << 1) | (((quint32)d.time().hour() >> 4) & 0x00000001));
pBytes[3] = (Q_UINT8)((((Q_UINT32)d.time().hour() & 0x0000000F) << 4) | (((Q_UINT32)d.time().minute() >> 2) & 0x0000000F)); pBytes[3] = (quint8)((((quint32)d.time().hour() & 0x0000000F) << 4) | (((quint32)d.time().minute() >> 2) & 0x0000000F));
pBytes[4] = (Q_UINT8)((((Q_UINT32)d.time().minute() & 0x00000003) << 6) | ((Q_UINT32)d.time().second() & 0x0000003F)); pBytes[4] = (quint8)((((quint32)d.time().minute() & 0x00000003) << 6) | ((quint32)d.time().second() & 0x0000003F));
} }

@ -84,6 +84,7 @@ public:
int numIcons(); int numIcons();
void addIcon(const QPixmap& icon); void addIcon(const QPixmap& icon);
void removeIcon(int Id); void removeIcon(int Id);
void replaceIcon(int Id,const QPixmap& icon);
QList<CGroup>Groups; QList<CGroup>Groups;
QList<CEntry>Entries; QList<CEntry>Entries;
@ -92,12 +93,12 @@ private:
bool parseMetaStream(const CEntry& Entry); bool parseMetaStream(const CEntry& Entry);
bool parseCustomIconsMetaStream(const QByteArray& data); bool parseCustomIconsMetaStream(const QByteArray& data);
void createCustomIconsMetaStream(CEntry* dst); void createCustomIconsMetaStream(CEntry* dst);
void transformKey(Q_UINT8* src,Q_UINT8* dst,Q_UINT8* seed,int rounds); void transformKey(quint8* src,quint8* dst,quint8* seed,int rounds);
bool readHeader(char* raw); bool readHeader(char* raw);
bool isGroupIdInUse(Q_UINT32 GroupID); bool isGroupIdInUse(quint32 GroupID);
bool isEntrySidInUse(Q_UINT32 sID); bool isEntrySidInUse(quint32 sID);
Q_UINT32 getNewGroupId(); quint32 getNewGroupId();
Q_UINT32 getNewEntrySid(); quint32 getNewEntrySid();
bool convHexToBinaryKey(char* HexKey, char* dst); bool convHexToBinaryKey(char* HexKey, char* dst);
QStringList Errors; QStringList Errors;
QList<QPixmap> CustomIcons; QList<QPixmap> CustomIcons;
@ -110,10 +111,10 @@ void modified();
void memcpyFromLEnd32(Q_UINT32* dst,const char* src); void memcpyFromLEnd32(quint32* dst,const char* src);
void memcpyFromLEnd16(Q_UINT16* dst,const char* src); void memcpyFromLEnd16(quint16* dst,const char* src);
void memcpyToLEnd32(char* src,const Q_UINT32* dst); void memcpyToLEnd32(char* src,const quint32* dst);
void memcpyToLEnd16(char* src,const Q_UINT16* dst); void memcpyToLEnd16(char* src,const quint16* dst);
QDateTime dateFromPackedStruct5(const unsigned char* pBytes); QDateTime dateFromPackedStruct5(const unsigned char* pBytes);
void dateToPackedStruct5(const QDateTime& datetime, unsigned char* dst); void dateToPackedStruct5(const QDateTime& datetime, unsigned char* dst);

@ -25,10 +25,10 @@ using std::string;
#define BLOWFISH_ROUNDS 16 #define BLOWFISH_ROUNDS 16
#define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */ #define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */
#define uint8_t Q_UINT8 #define uint8_t quint8
#define uint16_t Q_UINT16 #define uint16_t quint16
#define uint32_t Q_UINT32 #define uint32_t quint32
#define byte Q_UINT8 #define byte quint8
/** blowfish encryption algorithm. /** blowfish encryption algorithm.
* Derived from libgcrypt-1.1.12 * Derived from libgcrypt-1.1.12

@ -40,7 +40,7 @@
#include "rijndael.h" #include "rijndael.h"
static Q_UINT8 S[256]= static quint8 S[256]=
{ {
99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118,
202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192,
@ -61,7 +61,7 @@ static Q_UINT8 S[256]=
}; };
static Q_UINT8 T1[256][4]= static quint8 T1[256][4]=
{ {
0xc6,0x63,0x63,0xa5, 0xf8,0x7c,0x7c,0x84, 0xee,0x77,0x77,0x99, 0xf6,0x7b,0x7b,0x8d, 0xc6,0x63,0x63,0xa5, 0xf8,0x7c,0x7c,0x84, 0xee,0x77,0x77,0x99, 0xf6,0x7b,0x7b,0x8d,
0xff,0xf2,0xf2,0x0d, 0xd6,0x6b,0x6b,0xbd, 0xde,0x6f,0x6f,0xb1, 0x91,0xc5,0xc5,0x54, 0xff,0xf2,0xf2,0x0d, 0xd6,0x6b,0x6b,0xbd, 0xde,0x6f,0x6f,0xb1, 0x91,0xc5,0xc5,0x54,
@ -129,7 +129,7 @@ static Q_UINT8 T1[256][4]=
0x7b,0xb0,0xb0,0xcb, 0xa8,0x54,0x54,0xfc, 0x6d,0xbb,0xbb,0xd6, 0x2c,0x16,0x16,0x3a 0x7b,0xb0,0xb0,0xcb, 0xa8,0x54,0x54,0xfc, 0x6d,0xbb,0xbb,0xd6, 0x2c,0x16,0x16,0x3a
}; };
static Q_UINT8 T2[256][4]= static quint8 T2[256][4]=
{ {
0xa5,0xc6,0x63,0x63, 0x84,0xf8,0x7c,0x7c, 0x99,0xee,0x77,0x77, 0x8d,0xf6,0x7b,0x7b, 0xa5,0xc6,0x63,0x63, 0x84,0xf8,0x7c,0x7c, 0x99,0xee,0x77,0x77, 0x8d,0xf6,0x7b,0x7b,
0x0d,0xff,0xf2,0xf2, 0xbd,0xd6,0x6b,0x6b, 0xb1,0xde,0x6f,0x6f, 0x54,0x91,0xc5,0xc5, 0x0d,0xff,0xf2,0xf2, 0xbd,0xd6,0x6b,0x6b, 0xb1,0xde,0x6f,0x6f, 0x54,0x91,0xc5,0xc5,
@ -197,7 +197,7 @@ static Q_UINT8 T2[256][4]=
0xcb,0x7b,0xb0,0xb0, 0xfc,0xa8,0x54,0x54, 0xd6,0x6d,0xbb,0xbb, 0x3a,0x2c,0x16,0x16 0xcb,0x7b,0xb0,0xb0, 0xfc,0xa8,0x54,0x54, 0xd6,0x6d,0xbb,0xbb, 0x3a,0x2c,0x16,0x16
}; };
static Q_UINT8 T3[256][4]= static quint8 T3[256][4]=
{ {
0x63,0xa5,0xc6,0x63, 0x7c,0x84,0xf8,0x7c, 0x77,0x99,0xee,0x77, 0x7b,0x8d,0xf6,0x7b, 0x63,0xa5,0xc6,0x63, 0x7c,0x84,0xf8,0x7c, 0x77,0x99,0xee,0x77, 0x7b,0x8d,0xf6,0x7b,
0xf2,0x0d,0xff,0xf2, 0x6b,0xbd,0xd6,0x6b, 0x6f,0xb1,0xde,0x6f, 0xc5,0x54,0x91,0xc5, 0xf2,0x0d,0xff,0xf2, 0x6b,0xbd,0xd6,0x6b, 0x6f,0xb1,0xde,0x6f, 0xc5,0x54,0x91,0xc5,
@ -265,7 +265,7 @@ static Q_UINT8 T3[256][4]=
0xb0,0xcb,0x7b,0xb0, 0x54,0xfc,0xa8,0x54, 0xbb,0xd6,0x6d,0xbb, 0x16,0x3a,0x2c,0x16 0xb0,0xcb,0x7b,0xb0, 0x54,0xfc,0xa8,0x54, 0xbb,0xd6,0x6d,0xbb, 0x16,0x3a,0x2c,0x16
}; };
static Q_UINT8 T4[256][4]= static quint8 T4[256][4]=
{ {
0x63,0x63,0xa5,0xc6, 0x7c,0x7c,0x84,0xf8, 0x77,0x77,0x99,0xee, 0x7b,0x7b,0x8d,0xf6, 0x63,0x63,0xa5,0xc6, 0x7c,0x7c,0x84,0xf8, 0x77,0x77,0x99,0xee, 0x7b,0x7b,0x8d,0xf6,
0xf2,0xf2,0x0d,0xff, 0x6b,0x6b,0xbd,0xd6, 0x6f,0x6f,0xb1,0xde, 0xc5,0xc5,0x54,0x91, 0xf2,0xf2,0x0d,0xff, 0x6b,0x6b,0xbd,0xd6, 0x6f,0x6f,0xb1,0xde, 0xc5,0xc5,0x54,0x91,
@ -333,7 +333,7 @@ static Q_UINT8 T4[256][4]=
0xb0,0xb0,0xcb,0x7b, 0x54,0x54,0xfc,0xa8, 0xbb,0xbb,0xd6,0x6d, 0x16,0x16,0x3a,0x2c 0xb0,0xb0,0xcb,0x7b, 0x54,0x54,0xfc,0xa8, 0xbb,0xbb,0xd6,0x6d, 0x16,0x16,0x3a,0x2c
}; };
static Q_UINT8 T5[256][4]= static quint8 T5[256][4]=
{ {
0x51,0xf4,0xa7,0x50, 0x7e,0x41,0x65,0x53, 0x1a,0x17,0xa4,0xc3, 0x3a,0x27,0x5e,0x96, 0x51,0xf4,0xa7,0x50, 0x7e,0x41,0x65,0x53, 0x1a,0x17,0xa4,0xc3, 0x3a,0x27,0x5e,0x96,
0x3b,0xab,0x6b,0xcb, 0x1f,0x9d,0x45,0xf1, 0xac,0xfa,0x58,0xab, 0x4b,0xe3,0x03,0x93, 0x3b,0xab,0x6b,0xcb, 0x1f,0x9d,0x45,0xf1, 0xac,0xfa,0x58,0xab, 0x4b,0xe3,0x03,0x93,
@ -401,7 +401,7 @@ static Q_UINT8 T5[256][4]=
0x7b,0xcb,0x84,0x61, 0xd5,0x32,0xb6,0x70, 0x48,0x6c,0x5c,0x74, 0xd0,0xb8,0x57,0x42 0x7b,0xcb,0x84,0x61, 0xd5,0x32,0xb6,0x70, 0x48,0x6c,0x5c,0x74, 0xd0,0xb8,0x57,0x42
}; };
static Q_UINT8 T6[256][4]= static quint8 T6[256][4]=
{ {
0x50,0x51,0xf4,0xa7, 0x53,0x7e,0x41,0x65, 0xc3,0x1a,0x17,0xa4, 0x96,0x3a,0x27,0x5e, 0x50,0x51,0xf4,0xa7, 0x53,0x7e,0x41,0x65, 0xc3,0x1a,0x17,0xa4, 0x96,0x3a,0x27,0x5e,
0xcb,0x3b,0xab,0x6b, 0xf1,0x1f,0x9d,0x45, 0xab,0xac,0xfa,0x58, 0x93,0x4b,0xe3,0x03, 0xcb,0x3b,0xab,0x6b, 0xf1,0x1f,0x9d,0x45, 0xab,0xac,0xfa,0x58, 0x93,0x4b,0xe3,0x03,
@ -469,7 +469,7 @@ static Q_UINT8 T6[256][4]=
0x61,0x7b,0xcb,0x84, 0x70,0xd5,0x32,0xb6, 0x74,0x48,0x6c,0x5c, 0x42,0xd0,0xb8,0x57 0x61,0x7b,0xcb,0x84, 0x70,0xd5,0x32,0xb6, 0x74,0x48,0x6c,0x5c, 0x42,0xd0,0xb8,0x57
}; };
static Q_UINT8 T7[256][4]= static quint8 T7[256][4]=
{ {
0xa7,0x50,0x51,0xf4, 0x65,0x53,0x7e,0x41, 0xa4,0xc3,0x1a,0x17, 0x5e,0x96,0x3a,0x27, 0xa7,0x50,0x51,0xf4, 0x65,0x53,0x7e,0x41, 0xa4,0xc3,0x1a,0x17, 0x5e,0x96,0x3a,0x27,
0x6b,0xcb,0x3b,0xab, 0x45,0xf1,0x1f,0x9d, 0x58,0xab,0xac,0xfa, 0x03,0x93,0x4b,0xe3, 0x6b,0xcb,0x3b,0xab, 0x45,0xf1,0x1f,0x9d, 0x58,0xab,0xac,0xfa, 0x03,0x93,0x4b,0xe3,
@ -537,7 +537,7 @@ static Q_UINT8 T7[256][4]=
0x84,0x61,0x7b,0xcb, 0xb6,0x70,0xd5,0x32, 0x5c,0x74,0x48,0x6c, 0x57,0x42,0xd0,0xb8 0x84,0x61,0x7b,0xcb, 0xb6,0x70,0xd5,0x32, 0x5c,0x74,0x48,0x6c, 0x57,0x42,0xd0,0xb8
}; };
static Q_UINT8 T8[256][4]= static quint8 T8[256][4]=
{ {
0xf4,0xa7,0x50,0x51, 0x41,0x65,0x53,0x7e, 0x17,0xa4,0xc3,0x1a, 0x27,0x5e,0x96,0x3a, 0xf4,0xa7,0x50,0x51, 0x41,0x65,0x53,0x7e, 0x17,0xa4,0xc3,0x1a, 0x27,0x5e,0x96,0x3a,
0xab,0x6b,0xcb,0x3b, 0x9d,0x45,0xf1,0x1f, 0xfa,0x58,0xab,0xac, 0xe3,0x03,0x93,0x4b, 0xab,0x6b,0xcb,0x3b, 0x9d,0x45,0xf1,0x1f, 0xfa,0x58,0xab,0xac, 0xe3,0x03,0x93,0x4b,
@ -605,7 +605,7 @@ static Q_UINT8 T8[256][4]=
0xcb,0x84,0x61,0x7b, 0x32,0xb6,0x70,0xd5, 0x6c,0x5c,0x74,0x48, 0xb8,0x57,0x42,0xd0 0xcb,0x84,0x61,0x7b, 0x32,0xb6,0x70,0xd5, 0x6c,0x5c,0x74,0x48, 0xb8,0x57,0x42,0xd0
}; };
static Q_UINT8 S5[256]= static quint8 S5[256]=
{ {
0x52,0x09,0x6a,0xd5, 0x52,0x09,0x6a,0xd5,
0x30,0x36,0xa5,0x38, 0x30,0x36,0xa5,0x38,
@ -673,7 +673,7 @@ static Q_UINT8 S5[256]=
0x55,0x21,0x0c,0x7d 0x55,0x21,0x0c,0x7d
}; };
static Q_UINT8 U1[256][4]= static quint8 U1[256][4]=
{ {
0x00,0x00,0x00,0x00, 0x0e,0x09,0x0d,0x0b, 0x1c,0x12,0x1a,0x16, 0x12,0x1b,0x17,0x1d, 0x00,0x00,0x00,0x00, 0x0e,0x09,0x0d,0x0b, 0x1c,0x12,0x1a,0x16, 0x12,0x1b,0x17,0x1d,
0x38,0x24,0x34,0x2c, 0x36,0x2d,0x39,0x27, 0x24,0x36,0x2e,0x3a, 0x2a,0x3f,0x23,0x31, 0x38,0x24,0x34,0x2c, 0x36,0x2d,0x39,0x27, 0x24,0x36,0x2e,0x3a, 0x2a,0x3f,0x23,0x31,
@ -741,7 +741,7 @@ static Q_UINT8 U1[256][4]=
0x9f,0x5d,0x80,0xbe, 0x91,0x54,0x8d,0xb5, 0x83,0x4f,0x9a,0xa8, 0x8d,0x46,0x97,0xa3 0x9f,0x5d,0x80,0xbe, 0x91,0x54,0x8d,0xb5, 0x83,0x4f,0x9a,0xa8, 0x8d,0x46,0x97,0xa3
}; };
static Q_UINT8 U2[256][4]= static quint8 U2[256][4]=
{ {
0x00,0x00,0x00,0x00, 0x0b,0x0e,0x09,0x0d, 0x16,0x1c,0x12,0x1a, 0x1d,0x12,0x1b,0x17, 0x00,0x00,0x00,0x00, 0x0b,0x0e,0x09,0x0d, 0x16,0x1c,0x12,0x1a, 0x1d,0x12,0x1b,0x17,
0x2c,0x38,0x24,0x34, 0x27,0x36,0x2d,0x39, 0x3a,0x24,0x36,0x2e, 0x31,0x2a,0x3f,0x23, 0x2c,0x38,0x24,0x34, 0x27,0x36,0x2d,0x39, 0x3a,0x24,0x36,0x2e, 0x31,0x2a,0x3f,0x23,
@ -809,7 +809,7 @@ static Q_UINT8 U2[256][4]=
0xbe,0x9f,0x5d,0x80, 0xb5,0x91,0x54,0x8d, 0xa8,0x83,0x4f,0x9a, 0xa3,0x8d,0x46,0x97 0xbe,0x9f,0x5d,0x80, 0xb5,0x91,0x54,0x8d, 0xa8,0x83,0x4f,0x9a, 0xa3,0x8d,0x46,0x97
}; };
static Q_UINT8 U3[256][4]= static quint8 U3[256][4]=
{ {
0x00,0x00,0x00,0x00, 0x0d,0x0b,0x0e,0x09, 0x1a,0x16,0x1c,0x12, 0x17,0x1d,0x12,0x1b, 0x00,0x00,0x00,0x00, 0x0d,0x0b,0x0e,0x09, 0x1a,0x16,0x1c,0x12, 0x17,0x1d,0x12,0x1b,
0x34,0x2c,0x38,0x24, 0x39,0x27,0x36,0x2d, 0x2e,0x3a,0x24,0x36, 0x23,0x31,0x2a,0x3f, 0x34,0x2c,0x38,0x24, 0x39,0x27,0x36,0x2d, 0x2e,0x3a,0x24,0x36, 0x23,0x31,0x2a,0x3f,
@ -877,7 +877,7 @@ static Q_UINT8 U3[256][4]=
0x80,0xbe,0x9f,0x5d, 0x8d,0xb5,0x91,0x54, 0x9a,0xa8,0x83,0x4f, 0x97,0xa3,0x8d,0x46 0x80,0xbe,0x9f,0x5d, 0x8d,0xb5,0x91,0x54, 0x9a,0xa8,0x83,0x4f, 0x97,0xa3,0x8d,0x46
}; };
static Q_UINT8 U4[256][4]= static quint8 U4[256][4]=
{ {
0x00,0x00,0x00,0x00, 0x09,0x0d,0x0b,0x0e, 0x12,0x1a,0x16,0x1c, 0x1b,0x17,0x1d,0x12, 0x00,0x00,0x00,0x00, 0x09,0x0d,0x0b,0x0e, 0x12,0x1a,0x16,0x1c, 0x1b,0x17,0x1d,0x12,
0x24,0x34,0x2c,0x38, 0x2d,0x39,0x27,0x36, 0x36,0x2e,0x3a,0x24, 0x3f,0x23,0x31,0x2a, 0x24,0x34,0x2c,0x38, 0x2d,0x39,0x27,0x36, 0x36,0x2e,0x3a,0x24, 0x3f,0x23,0x31,0x2a,
@ -945,7 +945,7 @@ static Q_UINT8 U4[256][4]=
0x5d,0x80,0xbe,0x9f, 0x54,0x8d,0xb5,0x91, 0x4f,0x9a,0xa8,0x83, 0x46,0x97,0xa3,0x8d 0x5d,0x80,0xbe,0x9f, 0x54,0x8d,0xb5,0x91, 0x4f,0x9a,0xa8,0x83, 0x46,0x97,0xa3,0x8d
}; };
static Q_UINT32 rcon[30]= static quint32 rcon[30]=
{ {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8,
@ -970,7 +970,7 @@ Rijndael::~Rijndael()
// nothing here // nothing here
} }
int Rijndael::init(Mode mode,Direction dir,const Q_UINT8 * key,KeyLength keyLen,Q_UINT8 * initVector) int Rijndael::init(Mode mode,Direction dir,const quint8 * key,KeyLength keyLen,quint8 * initVector)
{ {
// Not initialized yet // Not initialized yet
m_state = Invalid; m_state = Invalid;
@ -999,7 +999,7 @@ int Rijndael::init(Mode mode,Direction dir,const Q_UINT8 * key,KeyLength keyLen,
} }
} }
Q_UINT32 uKeyLenInBytes; quint32 uKeyLenInBytes;
// And check the key length // And check the key length
switch(keyLen) switch(keyLen)
@ -1025,9 +1025,9 @@ int Rijndael::init(Mode mode,Direction dir,const Q_UINT8 * key,KeyLength keyLen,
if(!key) return RIJNDAEL_BAD_KEY; if(!key) return RIJNDAEL_BAD_KEY;
Q_UINT8 keyMatrix[_MAX_KEY_COLUMNS][4]; quint8 keyMatrix[_MAX_KEY_COLUMNS][4];
for(Q_UINT32 i = 0;i < uKeyLenInBytes;i++)keyMatrix[i >> 2][i & 3] = key[i]; for(quint32 i = 0;i < uKeyLenInBytes;i++)keyMatrix[i >> 2][i & 3] = key[i];
keySched(keyMatrix); keySched(keyMatrix);
@ -1038,10 +1038,10 @@ int Rijndael::init(Mode mode,Direction dir,const Q_UINT8 * key,KeyLength keyLen,
return RIJNDAEL_SUCCESS; return RIJNDAEL_SUCCESS;
} }
int Rijndael::blockEncrypt(const Q_UINT8 *input,int inputLen,Q_UINT8 *outBuffer) int Rijndael::blockEncrypt(const quint8 *input,int inputLen,quint8 *outBuffer)
{ {
int i, k, numBlocks; int i, k, numBlocks;
Q_UINT8 block[16], iv[4][4]; quint8 block[16], iv[4][4];
if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED; if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED;
if(m_direction != Encrypt) return RIJNDAEL_BAD_DIRECTION; if(m_direction != Encrypt) return RIJNDAEL_BAD_DIRECTION;
@ -1060,18 +1060,18 @@ int Rijndael::blockEncrypt(const Q_UINT8 *input,int inputLen,Q_UINT8 *outBuffer)
} }
break; break;
case CBC: case CBC:
((Q_UINT32*)block)[0] = ((Q_UINT32*)m_initVector)[0] ^ ((Q_UINT32*)input)[0]; ((quint32*)block)[0] = ((quint32*)m_initVector)[0] ^ ((quint32*)input)[0];
((Q_UINT32*)block)[1] = ((Q_UINT32*)m_initVector)[1] ^ ((Q_UINT32*)input)[1]; ((quint32*)block)[1] = ((quint32*)m_initVector)[1] ^ ((quint32*)input)[1];
((Q_UINT32*)block)[2] = ((Q_UINT32*)m_initVector)[2] ^ ((Q_UINT32*)input)[2]; ((quint32*)block)[2] = ((quint32*)m_initVector)[2] ^ ((quint32*)input)[2];
((Q_UINT32*)block)[3] = ((Q_UINT32*)m_initVector)[3] ^ ((Q_UINT32*)input)[3]; ((quint32*)block)[3] = ((quint32*)m_initVector)[3] ^ ((quint32*)input)[3];
encrypt(block,outBuffer); encrypt(block,outBuffer);
input += 16; input += 16;
for(i = numBlocks - 1;i > 0;i--) for(i = numBlocks - 1;i > 0;i--)
{ {
((Q_UINT32*)block)[0] = ((Q_UINT32*)outBuffer)[0] ^ ((Q_UINT32*)input)[0]; ((quint32*)block)[0] = ((quint32*)outBuffer)[0] ^ ((quint32*)input)[0];
((Q_UINT32*)block)[1] = ((Q_UINT32*)outBuffer)[1] ^ ((Q_UINT32*)input)[1]; ((quint32*)block)[1] = ((quint32*)outBuffer)[1] ^ ((quint32*)input)[1];
((Q_UINT32*)block)[2] = ((Q_UINT32*)outBuffer)[2] ^ ((Q_UINT32*)input)[2]; ((quint32*)block)[2] = ((quint32*)outBuffer)[2] ^ ((quint32*)input)[2];
((Q_UINT32*)block)[3] = ((Q_UINT32*)outBuffer)[3] ^ ((Q_UINT32*)input)[3]; ((quint32*)block)[3] = ((quint32*)outBuffer)[3] ^ ((quint32*)input)[3];
outBuffer += 16; outBuffer += 16;
encrypt(block,outBuffer); encrypt(block,outBuffer);
input += 16; input += 16;
@ -1081,19 +1081,19 @@ int Rijndael::blockEncrypt(const Q_UINT8 *input,int inputLen,Q_UINT8 *outBuffer)
#if STRICT_ALIGN #if STRICT_ALIGN
memcpy(iv,m_initVector,16); memcpy(iv,m_initVector,16);
#else /* !STRICT_ALIGN */ #else /* !STRICT_ALIGN */
*((Q_UINT32*)iv[0]) = *((Q_UINT32*)(m_initVector )); *((quint32*)iv[0]) = *((quint32*)(m_initVector ));
*((Q_UINT32*)iv[1]) = *((Q_UINT32*)(m_initVector + 4)); *((quint32*)iv[1]) = *((quint32*)(m_initVector + 4));
*((Q_UINT32*)iv[2]) = *((Q_UINT32*)(m_initVector + 8)); *((quint32*)iv[2]) = *((quint32*)(m_initVector + 8));
*((Q_UINT32*)iv[3]) = *((Q_UINT32*)(m_initVector +12)); *((quint32*)iv[3]) = *((quint32*)(m_initVector +12));
#endif /* ?STRICT_ALIGN */ #endif /* ?STRICT_ALIGN */
for(i = numBlocks; i > 0; i--) for(i = numBlocks; i > 0; i--)
{ {
for(k = 0; k < 128; k++) for(k = 0; k < 128; k++)
{ {
*((Q_UINT32*) block ) = *((Q_UINT32*)iv[0]); *((quint32*) block ) = *((quint32*)iv[0]);
*((Q_UINT32*)(block+ 4)) = *((Q_UINT32*)iv[1]); *((quint32*)(block+ 4)) = *((quint32*)iv[1]);
*((Q_UINT32*)(block+ 8)) = *((Q_UINT32*)iv[2]); *((quint32*)(block+ 8)) = *((quint32*)iv[2]);
*((Q_UINT32*)(block+12)) = *((Q_UINT32*)iv[3]); *((quint32*)(block+12)) = *((quint32*)iv[3]);
encrypt(block,block); encrypt(block,block);
outBuffer[k/8] ^= (block[0] & 0x80) >> (k & 7); outBuffer[k/8] ^= (block[0] & 0x80) >> (k & 7);
iv[0][0] = (iv[0][0] << 1) | (iv[0][1] >> 7); iv[0][0] = (iv[0][0] << 1) | (iv[0][1] >> 7);
@ -1123,10 +1123,10 @@ int Rijndael::blockEncrypt(const Q_UINT8 *input,int inputLen,Q_UINT8 *outBuffer)
return 128 * numBlocks; return 128 * numBlocks;
} }
int Rijndael::padEncrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuffer) int Rijndael::padEncrypt(const quint8 *input, int inputOctets, quint8 *outBuffer)
{ {
int i, numBlocks, padLen; int i, numBlocks, padLen;
Q_UINT8 block[16], *iv; quint8 block[16], *iv;
if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED; if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED;
if(m_direction != Encrypt) return RIJNDAEL_NOT_INITIALIZED; if(m_direction != Encrypt) return RIJNDAEL_NOT_INITIALIZED;
@ -1154,10 +1154,10 @@ int Rijndael::padEncrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuff
iv = m_initVector; iv = m_initVector;
for(i = numBlocks; i > 0; i--) for(i = numBlocks; i > 0; i--)
{ {
((Q_UINT32*)block)[0] = ((Q_UINT32*)input)[0] ^ ((Q_UINT32*)iv)[0]; ((quint32*)block)[0] = ((quint32*)input)[0] ^ ((quint32*)iv)[0];
((Q_UINT32*)block)[1] = ((Q_UINT32*)input)[1] ^ ((Q_UINT32*)iv)[1]; ((quint32*)block)[1] = ((quint32*)input)[1] ^ ((quint32*)iv)[1];
((Q_UINT32*)block)[2] = ((Q_UINT32*)input)[2] ^ ((Q_UINT32*)iv)[2]; ((quint32*)block)[2] = ((quint32*)input)[2] ^ ((quint32*)iv)[2];
((Q_UINT32*)block)[3] = ((Q_UINT32*)input)[3] ^ ((Q_UINT32*)iv)[3]; ((quint32*)block)[3] = ((quint32*)input)[3] ^ ((quint32*)iv)[3];
encrypt(block, outBuffer); encrypt(block, outBuffer);
iv = outBuffer; iv = outBuffer;
input += 16; input += 16;
@ -1169,7 +1169,7 @@ int Rijndael::padEncrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuff
block[i] = input[i] ^ iv[i]; block[i] = input[i] ^ iv[i];
} }
for (i = 16 - padLen; i < 16; i++) { for (i = 16 - padLen; i < 16; i++) {
block[i] = (Q_UINT8)padLen ^ iv[i]; block[i] = (quint8)padLen ^ iv[i];
} }
encrypt(block,outBuffer); encrypt(block,outBuffer);
break; break;
@ -1181,10 +1181,10 @@ int Rijndael::padEncrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuff
return 16*(numBlocks + 1); return 16*(numBlocks + 1);
} }
int Rijndael::blockDecrypt(const Q_UINT8 *input, int inputLen, Q_UINT8 *outBuffer) int Rijndael::blockDecrypt(const quint8 *input, int inputLen, quint8 *outBuffer)
{ {
int i, k, numBlocks; int i, k, numBlocks;
Q_UINT8 block[16], iv[4][4]; quint8 block[16], iv[4][4];
if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED; if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED;
if((m_mode != CFB1) && (m_direction == Encrypt)) return RIJNDAEL_BAD_DIRECTION; if((m_mode != CFB1) && (m_direction == Encrypt)) return RIJNDAEL_BAD_DIRECTION;
@ -1207,26 +1207,26 @@ int Rijndael::blockDecrypt(const Q_UINT8 *input, int inputLen, Q_UINT8 *outBuffe
#if STRICT_ALIGN #if STRICT_ALIGN
memcpy(iv,m_initVector,16); memcpy(iv,m_initVector,16);
#else #else
*((Q_UINT32*)iv[0]) = *((Q_UINT32*)(m_initVector )); *((quint32*)iv[0]) = *((quint32*)(m_initVector ));
*((Q_UINT32*)iv[1]) = *((Q_UINT32*)(m_initVector+ 4)); *((quint32*)iv[1]) = *((quint32*)(m_initVector+ 4));
*((Q_UINT32*)iv[2]) = *((Q_UINT32*)(m_initVector+ 8)); *((quint32*)iv[2]) = *((quint32*)(m_initVector+ 8));
*((Q_UINT32*)iv[3]) = *((Q_UINT32*)(m_initVector+12)); *((quint32*)iv[3]) = *((quint32*)(m_initVector+12));
#endif #endif
for (i = numBlocks; i > 0; i--) for (i = numBlocks; i > 0; i--)
{ {
decrypt(input, block); decrypt(input, block);
((Q_UINT32*)block)[0] ^= *((Q_UINT32*)iv[0]); ((quint32*)block)[0] ^= *((quint32*)iv[0]);
((Q_UINT32*)block)[1] ^= *((Q_UINT32*)iv[1]); ((quint32*)block)[1] ^= *((quint32*)iv[1]);
((Q_UINT32*)block)[2] ^= *((Q_UINT32*)iv[2]); ((quint32*)block)[2] ^= *((quint32*)iv[2]);
((Q_UINT32*)block)[3] ^= *((Q_UINT32*)iv[3]); ((quint32*)block)[3] ^= *((quint32*)iv[3]);
#if STRICT_ALIGN #if STRICT_ALIGN
memcpy(iv, input, 16); memcpy(iv, input, 16);
memcpy(outBuf, block, 16); memcpy(outBuf, block, 16);
#else #else
*((Q_UINT32*)iv[0]) = ((Q_UINT32*)input)[0]; ((Q_UINT32*)outBuffer)[0] = ((Q_UINT32*)block)[0]; *((quint32*)iv[0]) = ((quint32*)input)[0]; ((quint32*)outBuffer)[0] = ((quint32*)block)[0];
*((Q_UINT32*)iv[1]) = ((Q_UINT32*)input)[1]; ((Q_UINT32*)outBuffer)[1] = ((Q_UINT32*)block)[1]; *((quint32*)iv[1]) = ((quint32*)input)[1]; ((quint32*)outBuffer)[1] = ((quint32*)block)[1];
*((Q_UINT32*)iv[2]) = ((Q_UINT32*)input)[2]; ((Q_UINT32*)outBuffer)[2] = ((Q_UINT32*)block)[2]; *((quint32*)iv[2]) = ((quint32*)input)[2]; ((quint32*)outBuffer)[2] = ((quint32*)block)[2];
*((Q_UINT32*)iv[3]) = ((Q_UINT32*)input)[3]; ((Q_UINT32*)outBuffer)[3] = ((Q_UINT32*)block)[3]; *((quint32*)iv[3]) = ((quint32*)input)[3]; ((quint32*)outBuffer)[3] = ((quint32*)block)[3];
#endif #endif
input += 16; input += 16;
outBuffer += 16; outBuffer += 16;
@ -1236,19 +1236,19 @@ int Rijndael::blockDecrypt(const Q_UINT8 *input, int inputLen, Q_UINT8 *outBuffe
#if STRICT_ALIGN #if STRICT_ALIGN
memcpy(iv, m_initVector, 16); memcpy(iv, m_initVector, 16);
#else #else
*((Q_UINT32*)iv[0]) = *((Q_UINT32*)(m_initVector)); *((quint32*)iv[0]) = *((quint32*)(m_initVector));
*((Q_UINT32*)iv[1]) = *((Q_UINT32*)(m_initVector+ 4)); *((quint32*)iv[1]) = *((quint32*)(m_initVector+ 4));
*((Q_UINT32*)iv[2]) = *((Q_UINT32*)(m_initVector+ 8)); *((quint32*)iv[2]) = *((quint32*)(m_initVector+ 8));
*((Q_UINT32*)iv[3]) = *((Q_UINT32*)(m_initVector+12)); *((quint32*)iv[3]) = *((quint32*)(m_initVector+12));
#endif #endif
for(i = numBlocks; i > 0; i--) for(i = numBlocks; i > 0; i--)
{ {
for(k = 0; k < 128; k++) for(k = 0; k < 128; k++)
{ {
*((Q_UINT32*) block ) = *((Q_UINT32*)iv[0]); *((quint32*) block ) = *((quint32*)iv[0]);
*((Q_UINT32*)(block+ 4)) = *((Q_UINT32*)iv[1]); *((quint32*)(block+ 4)) = *((quint32*)iv[1]);
*((Q_UINT32*)(block+ 8)) = *((Q_UINT32*)iv[2]); *((quint32*)(block+ 8)) = *((quint32*)iv[2]);
*((Q_UINT32*)(block+12)) = *((Q_UINT32*)iv[3]); *((quint32*)(block+12)) = *((quint32*)iv[3]);
encrypt(block, block); encrypt(block, block);
iv[0][0] = (iv[0][0] << 1) | (iv[0][1] >> 7); iv[0][0] = (iv[0][0] << 1) | (iv[0][1] >> 7);
iv[0][1] = (iv[0][1] << 1) | (iv[0][2] >> 7); iv[0][1] = (iv[0][1] << 1) | (iv[0][2] >> 7);
@ -1278,11 +1278,11 @@ int Rijndael::blockDecrypt(const Q_UINT8 *input, int inputLen, Q_UINT8 *outBuffe
return 128*numBlocks; return 128*numBlocks;
} }
int Rijndael::padDecrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuffer) int Rijndael::padDecrypt(const quint8 *input, int inputOctets, quint8 *outBuffer)
{ {
int i, numBlocks, padLen; int i, numBlocks, padLen;
Q_UINT8 block[16]; quint8 block[16];
Q_UINT32 iv[4]; quint32 iv[4];
if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED; if(m_state != Valid) return RIJNDAEL_NOT_INITIALIZED;
if(m_direction != Decrypt) return RIJNDAEL_BAD_DIRECTION; if(m_direction != Decrypt) return RIJNDAEL_BAD_DIRECTION;
@ -1317,10 +1317,10 @@ int Rijndael::padDecrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuff
for (i = numBlocks - 1; i > 0; i--) for (i = numBlocks - 1; i > 0; i--)
{ {
decrypt(input, block); decrypt(input, block);
((Q_UINT32*)block)[0] ^= iv[0]; ((quint32*)block)[0] ^= iv[0];
((Q_UINT32*)block)[1] ^= iv[1]; ((quint32*)block)[1] ^= iv[1];
((Q_UINT32*)block)[2] ^= iv[2]; ((quint32*)block)[2] ^= iv[2];
((Q_UINT32*)block)[3] ^= iv[3]; ((quint32*)block)[3] ^= iv[3];
memcpy(iv, input, 16); memcpy(iv, input, 16);
memcpy(outBuffer, block, 16); memcpy(outBuffer, block, 16);
input += 16; input += 16;
@ -1328,10 +1328,10 @@ int Rijndael::padDecrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuff
} }
/* last block */ /* last block */
decrypt(input, block); decrypt(input, block);
((Q_UINT32*)block)[0] ^= iv[0]; ((quint32*)block)[0] ^= iv[0];
((Q_UINT32*)block)[1] ^= iv[1]; ((quint32*)block)[1] ^= iv[1];
((Q_UINT32*)block)[2] ^= iv[2]; ((quint32*)block)[2] ^= iv[2];
((Q_UINT32*)block)[3] ^= iv[3]; ((quint32*)block)[3] ^= iv[3];
padLen = block[15]; padLen = block[15];
if((padLen <= 0) || (padLen > 16)) return RIJNDAEL_CORRUPTED_DATA; if((padLen <= 0) || (padLen > 16)) return RIJNDAEL_CORRUPTED_DATA;
for(i = 16 - padLen; i < 16; i++) for(i = 16 - padLen; i < 16; i++)
@ -1354,7 +1354,7 @@ int Rijndael::padDecrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuff
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Rijndael::keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4]) void Rijndael::keySched(quint8 key[_MAX_KEY_COLUMNS][4])
{ {
int j,rconpointer = 0; int j,rconpointer = 0;
@ -1362,13 +1362,13 @@ void Rijndael::keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4])
// The number of calculations depends on keyBits and blockBits // The number of calculations depends on keyBits and blockBits
int uKeyColumns = m_uRounds - 6; int uKeyColumns = m_uRounds - 6;
Q_UINT8 tempKey[_MAX_KEY_COLUMNS][4]; quint8 tempKey[_MAX_KEY_COLUMNS][4];
// Copy the input key to the temporary key matrix // Copy the input key to the temporary key matrix
for(j = 0;j < uKeyColumns;j++) for(j = 0;j < uKeyColumns;j++)
{ {
*((Q_UINT32*)(tempKey[j])) = *((Q_UINT32*)(key[j])); *((quint32*)(tempKey[j])) = *((quint32*)(key[j]));
} }
int r = 0; int r = 0;
@ -1379,7 +1379,7 @@ void Rijndael::keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4])
{ {
for(;(j < uKeyColumns) && (t < 4); j++, t++) for(;(j < uKeyColumns) && (t < 4); j++, t++)
{ {
*((Q_UINT32*)m_expandedKey[r][t]) = *((Q_UINT32*)tempKey[j]); *((quint32*)m_expandedKey[r][t]) = *((quint32*)tempKey[j]);
} }
@ -1402,12 +1402,12 @@ void Rijndael::keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4])
{ {
for(j = 1; j < uKeyColumns; j++) for(j = 1; j < uKeyColumns; j++)
{ {
*((Q_UINT32*)tempKey[j]) ^= *((Q_UINT32*)tempKey[j-1]); *((quint32*)tempKey[j]) ^= *((quint32*)tempKey[j-1]);
} }
} else { } else {
for(j = 1; j < uKeyColumns/2; j++) for(j = 1; j < uKeyColumns/2; j++)
{ {
*((Q_UINT32*)tempKey[j]) ^= *((Q_UINT32*)tempKey[j-1]); *((quint32*)tempKey[j]) ^= *((quint32*)tempKey[j-1]);
} }
tempKey[uKeyColumns/2][0] ^= S[tempKey[uKeyColumns/2 - 1][0]]; tempKey[uKeyColumns/2][0] ^= S[tempKey[uKeyColumns/2 - 1][0]];
tempKey[uKeyColumns/2][1] ^= S[tempKey[uKeyColumns/2 - 1][1]]; tempKey[uKeyColumns/2][1] ^= S[tempKey[uKeyColumns/2 - 1][1]];
@ -1415,14 +1415,14 @@ void Rijndael::keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4])
tempKey[uKeyColumns/2][3] ^= S[tempKey[uKeyColumns/2 - 1][3]]; tempKey[uKeyColumns/2][3] ^= S[tempKey[uKeyColumns/2 - 1][3]];
for(j = uKeyColumns/2 + 1; j < uKeyColumns; j++) for(j = uKeyColumns/2 + 1; j < uKeyColumns; j++)
{ {
*((Q_UINT32*)tempKey[j]) ^= *((Q_UINT32*)tempKey[j-1]); *((quint32*)tempKey[j]) ^= *((quint32*)tempKey[j-1]);
} }
} }
for(j = 0; (j < uKeyColumns) && (r <= (int)m_uRounds); ) for(j = 0; (j < uKeyColumns) && (r <= (int)m_uRounds); )
{ {
for(; (j < uKeyColumns) && (t < 4); j++, t++) for(; (j < uKeyColumns) && (t < 4); j++, t++)
{ {
*((Q_UINT32*)m_expandedKey[r][t]) = *((Q_UINT32*)tempKey[j]); *((quint32*)m_expandedKey[r][t]) = *((quint32*)tempKey[j]);
} }
if(t == 4) if(t == 4)
{ {
@ -1436,74 +1436,74 @@ void Rijndael::keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4])
void Rijndael::keyEncToDec() void Rijndael::keyEncToDec()
{ {
int r; int r;
Q_UINT8 *w; quint8 *w;
for(r = 1; r < (int)m_uRounds; r++) for(r = 1; r < (int)m_uRounds; r++)
{ {
w = m_expandedKey[r][0]; w = m_expandedKey[r][0];
*((Q_UINT32*)w) = *((Q_UINT32*)U1[w[0]]) ^ *((Q_UINT32*)U2[w[1]]) ^ *((Q_UINT32*)U3[w[2]]) ^ *((Q_UINT32*)U4[w[3]]); *((quint32*)w) = *((quint32*)U1[w[0]]) ^ *((quint32*)U2[w[1]]) ^ *((quint32*)U3[w[2]]) ^ *((quint32*)U4[w[3]]);
w = m_expandedKey[r][1]; w = m_expandedKey[r][1];
*((Q_UINT32*)w) = *((Q_UINT32*)U1[w[0]]) ^ *((Q_UINT32*)U2[w[1]]) ^ *((Q_UINT32*)U3[w[2]]) ^ *((Q_UINT32*)U4[w[3]]); *((quint32*)w) = *((quint32*)U1[w[0]]) ^ *((quint32*)U2[w[1]]) ^ *((quint32*)U3[w[2]]) ^ *((quint32*)U4[w[3]]);
w = m_expandedKey[r][2]; w = m_expandedKey[r][2];
*((Q_UINT32*)w) = *((Q_UINT32*)U1[w[0]]) ^ *((Q_UINT32*)U2[w[1]]) ^ *((Q_UINT32*)U3[w[2]]) ^ *((Q_UINT32*)U4[w[3]]); *((quint32*)w) = *((quint32*)U1[w[0]]) ^ *((quint32*)U2[w[1]]) ^ *((quint32*)U3[w[2]]) ^ *((quint32*)U4[w[3]]);
w = m_expandedKey[r][3]; w = m_expandedKey[r][3];
*((Q_UINT32*)w) = *((Q_UINT32*)U1[w[0]]) ^ *((Q_UINT32*)U2[w[1]]) ^ *((Q_UINT32*)U3[w[2]]) ^ *((Q_UINT32*)U4[w[3]]); *((quint32*)w) = *((quint32*)U1[w[0]]) ^ *((quint32*)U2[w[1]]) ^ *((quint32*)U3[w[2]]) ^ *((quint32*)U4[w[3]]);
} }
} }
void Rijndael::encrypt(const Q_UINT8 a[16], Q_UINT8 b[16]) void Rijndael::encrypt(const quint8 a[16], quint8 b[16])
{ {
int r; int r;
Q_UINT8 temp[4][4]; quint8 temp[4][4];
*((Q_UINT32*)temp[0]) = *((Q_UINT32*)(a )) ^ *((Q_UINT32*)m_expandedKey[0][0]); *((quint32*)temp[0]) = *((quint32*)(a )) ^ *((quint32*)m_expandedKey[0][0]);
*((Q_UINT32*)temp[1]) = *((Q_UINT32*)(a+ 4)) ^ *((Q_UINT32*)m_expandedKey[0][1]); *((quint32*)temp[1]) = *((quint32*)(a+ 4)) ^ *((quint32*)m_expandedKey[0][1]);
*((Q_UINT32*)temp[2]) = *((Q_UINT32*)(a+ 8)) ^ *((Q_UINT32*)m_expandedKey[0][2]); *((quint32*)temp[2]) = *((quint32*)(a+ 8)) ^ *((quint32*)m_expandedKey[0][2]);
*((Q_UINT32*)temp[3]) = *((Q_UINT32*)(a+12)) ^ *((Q_UINT32*)m_expandedKey[0][3]); *((quint32*)temp[3]) = *((quint32*)(a+12)) ^ *((quint32*)m_expandedKey[0][3]);
*((Q_UINT32*)(b )) = *((Q_UINT32*)T1[temp[0][0]]) *((quint32*)(b )) = *((quint32*)T1[temp[0][0]])
^ *((Q_UINT32*)T2[temp[1][1]]) ^ *((quint32*)T2[temp[1][1]])
^ *((Q_UINT32*)T3[temp[2][2]]) ^ *((quint32*)T3[temp[2][2]])
^ *((Q_UINT32*)T4[temp[3][3]]); ^ *((quint32*)T4[temp[3][3]]);
*((Q_UINT32*)(b + 4)) = *((Q_UINT32*)T1[temp[1][0]]) *((quint32*)(b + 4)) = *((quint32*)T1[temp[1][0]])
^ *((Q_UINT32*)T2[temp[2][1]]) ^ *((quint32*)T2[temp[2][1]])
^ *((Q_UINT32*)T3[temp[3][2]]) ^ *((quint32*)T3[temp[3][2]])
^ *((Q_UINT32*)T4[temp[0][3]]); ^ *((quint32*)T4[temp[0][3]]);
*((Q_UINT32*)(b + 8)) = *((Q_UINT32*)T1[temp[2][0]]) *((quint32*)(b + 8)) = *((quint32*)T1[temp[2][0]])
^ *((Q_UINT32*)T2[temp[3][1]]) ^ *((quint32*)T2[temp[3][1]])
^ *((Q_UINT32*)T3[temp[0][2]]) ^ *((quint32*)T3[temp[0][2]])
^ *((Q_UINT32*)T4[temp[1][3]]); ^ *((quint32*)T4[temp[1][3]]);
*((Q_UINT32*)(b +12)) = *((Q_UINT32*)T1[temp[3][0]]) *((quint32*)(b +12)) = *((quint32*)T1[temp[3][0]])
^ *((Q_UINT32*)T2[temp[0][1]]) ^ *((quint32*)T2[temp[0][1]])
^ *((Q_UINT32*)T3[temp[1][2]]) ^ *((quint32*)T3[temp[1][2]])
^ *((Q_UINT32*)T4[temp[2][3]]); ^ *((quint32*)T4[temp[2][3]]);
for(r = 1; r < (int)m_uRounds-1; r++) for(r = 1; r < (int)m_uRounds-1; r++)
{ {
*((Q_UINT32*)temp[0]) = *((Q_UINT32*)(b )) ^ *((Q_UINT32*)m_expandedKey[r][0]); *((quint32*)temp[0]) = *((quint32*)(b )) ^ *((quint32*)m_expandedKey[r][0]);
*((Q_UINT32*)temp[1]) = *((Q_UINT32*)(b+ 4)) ^ *((Q_UINT32*)m_expandedKey[r][1]); *((quint32*)temp[1]) = *((quint32*)(b+ 4)) ^ *((quint32*)m_expandedKey[r][1]);
*((Q_UINT32*)temp[2]) = *((Q_UINT32*)(b+ 8)) ^ *((Q_UINT32*)m_expandedKey[r][2]); *((quint32*)temp[2]) = *((quint32*)(b+ 8)) ^ *((quint32*)m_expandedKey[r][2]);
*((Q_UINT32*)temp[3]) = *((Q_UINT32*)(b+12)) ^ *((Q_UINT32*)m_expandedKey[r][3]); *((quint32*)temp[3]) = *((quint32*)(b+12)) ^ *((quint32*)m_expandedKey[r][3]);
*((Q_UINT32*)(b )) = *((Q_UINT32*)T1[temp[0][0]]) *((quint32*)(b )) = *((quint32*)T1[temp[0][0]])
^ *((Q_UINT32*)T2[temp[1][1]]) ^ *((quint32*)T2[temp[1][1]])
^ *((Q_UINT32*)T3[temp[2][2]]) ^ *((quint32*)T3[temp[2][2]])
^ *((Q_UINT32*)T4[temp[3][3]]); ^ *((quint32*)T4[temp[3][3]]);
*((Q_UINT32*)(b + 4)) = *((Q_UINT32*)T1[temp[1][0]]) *((quint32*)(b + 4)) = *((quint32*)T1[temp[1][0]])
^ *((Q_UINT32*)T2[temp[2][1]]) ^ *((quint32*)T2[temp[2][1]])
^ *((Q_UINT32*)T3[temp[3][2]]) ^ *((quint32*)T3[temp[3][2]])
^ *((Q_UINT32*)T4[temp[0][3]]); ^ *((quint32*)T4[temp[0][3]]);
*((Q_UINT32*)(b + 8)) = *((Q_UINT32*)T1[temp[2][0]]) *((quint32*)(b + 8)) = *((quint32*)T1[temp[2][0]])
^ *((Q_UINT32*)T2[temp[3][1]]) ^ *((quint32*)T2[temp[3][1]])
^ *((Q_UINT32*)T3[temp[0][2]]) ^ *((quint32*)T3[temp[0][2]])
^ *((Q_UINT32*)T4[temp[1][3]]); ^ *((quint32*)T4[temp[1][3]]);
*((Q_UINT32*)(b +12)) = *((Q_UINT32*)T1[temp[3][0]]) *((quint32*)(b +12)) = *((quint32*)T1[temp[3][0]])
^ *((Q_UINT32*)T2[temp[0][1]]) ^ *((quint32*)T2[temp[0][1]])
^ *((Q_UINT32*)T3[temp[1][2]]) ^ *((quint32*)T3[temp[1][2]])
^ *((Q_UINT32*)T4[temp[2][3]]); ^ *((quint32*)T4[temp[2][3]]);
} }
*((Q_UINT32*)temp[0]) = *((Q_UINT32*)(b )) ^ *((Q_UINT32*)m_expandedKey[m_uRounds-1][0]); *((quint32*)temp[0]) = *((quint32*)(b )) ^ *((quint32*)m_expandedKey[m_uRounds-1][0]);
*((Q_UINT32*)temp[1]) = *((Q_UINT32*)(b+ 4)) ^ *((Q_UINT32*)m_expandedKey[m_uRounds-1][1]); *((quint32*)temp[1]) = *((quint32*)(b+ 4)) ^ *((quint32*)m_expandedKey[m_uRounds-1][1]);
*((Q_UINT32*)temp[2]) = *((Q_UINT32*)(b+ 8)) ^ *((Q_UINT32*)m_expandedKey[m_uRounds-1][2]); *((quint32*)temp[2]) = *((quint32*)(b+ 8)) ^ *((quint32*)m_expandedKey[m_uRounds-1][2]);
*((Q_UINT32*)temp[3]) = *((Q_UINT32*)(b+12)) ^ *((Q_UINT32*)m_expandedKey[m_uRounds-1][3]); *((quint32*)temp[3]) = *((quint32*)(b+12)) ^ *((quint32*)m_expandedKey[m_uRounds-1][3]);
b[ 0] = T1[temp[0][0]][1]; b[ 0] = T1[temp[0][0]][1];
b[ 1] = T1[temp[1][1]][1]; b[ 1] = T1[temp[1][1]][1];
b[ 2] = T1[temp[2][2]][1]; b[ 2] = T1[temp[2][2]][1];
@ -1520,66 +1520,66 @@ void Rijndael::encrypt(const Q_UINT8 a[16], Q_UINT8 b[16])
b[13] = T1[temp[0][1]][1]; b[13] = T1[temp[0][1]][1];
b[14] = T1[temp[1][2]][1]; b[14] = T1[temp[1][2]][1];
b[15] = T1[temp[2][3]][1]; b[15] = T1[temp[2][3]][1];
*((Q_UINT32*)(b )) ^= *((Q_UINT32*)m_expandedKey[m_uRounds][0]); *((quint32*)(b )) ^= *((quint32*)m_expandedKey[m_uRounds][0]);
*((Q_UINT32*)(b+ 4)) ^= *((Q_UINT32*)m_expandedKey[m_uRounds][1]); *((quint32*)(b+ 4)) ^= *((quint32*)m_expandedKey[m_uRounds][1]);
*((Q_UINT32*)(b+ 8)) ^= *((Q_UINT32*)m_expandedKey[m_uRounds][2]); *((quint32*)(b+ 8)) ^= *((quint32*)m_expandedKey[m_uRounds][2]);
*((Q_UINT32*)(b+12)) ^= *((Q_UINT32*)m_expandedKey[m_uRounds][3]); *((quint32*)(b+12)) ^= *((quint32*)m_expandedKey[m_uRounds][3]);
} }
void Rijndael::decrypt(const Q_UINT8 a[16], Q_UINT8 b[16]) void Rijndael::decrypt(const quint8 a[16], quint8 b[16])
{ {
int r; int r;
Q_UINT8 temp[4][4]; quint8 temp[4][4];
*((Q_UINT32*)temp[0]) = *((Q_UINT32*)(a )) ^ *((Q_UINT32*)m_expandedKey[m_uRounds][0]); *((quint32*)temp[0]) = *((quint32*)(a )) ^ *((quint32*)m_expandedKey[m_uRounds][0]);
*((Q_UINT32*)temp[1]) = *((Q_UINT32*)(a+ 4)) ^ *((Q_UINT32*)m_expandedKey[m_uRounds][1]); *((quint32*)temp[1]) = *((quint32*)(a+ 4)) ^ *((quint32*)m_expandedKey[m_uRounds][1]);
*((Q_UINT32*)temp[2]) = *((Q_UINT32*)(a+ 8)) ^ *((Q_UINT32*)m_expandedKey[m_uRounds][2]); *((quint32*)temp[2]) = *((quint32*)(a+ 8)) ^ *((quint32*)m_expandedKey[m_uRounds][2]);
*((Q_UINT32*)temp[3]) = *((Q_UINT32*)(a+12)) ^ *((Q_UINT32*)m_expandedKey[m_uRounds][3]); *((quint32*)temp[3]) = *((quint32*)(a+12)) ^ *((quint32*)m_expandedKey[m_uRounds][3]);
*((Q_UINT32*)(b )) = *((Q_UINT32*)T5[temp[0][0]]) *((quint32*)(b )) = *((quint32*)T5[temp[0][0]])
^ *((Q_UINT32*)T6[temp[3][1]]) ^ *((quint32*)T6[temp[3][1]])
^ *((Q_UINT32*)T7[temp[2][2]]) ^ *((quint32*)T7[temp[2][2]])
^ *((Q_UINT32*)T8[temp[1][3]]); ^ *((quint32*)T8[temp[1][3]]);
*((Q_UINT32*)(b+ 4)) = *((Q_UINT32*)T5[temp[1][0]]) *((quint32*)(b+ 4)) = *((quint32*)T5[temp[1][0]])
^ *((Q_UINT32*)T6[temp[0][1]]) ^ *((quint32*)T6[temp[0][1]])
^ *((Q_UINT32*)T7[temp[3][2]]) ^ *((quint32*)T7[temp[3][2]])
^ *((Q_UINT32*)T8[temp[2][3]]); ^ *((quint32*)T8[temp[2][3]]);
*((Q_UINT32*)(b+ 8)) = *((Q_UINT32*)T5[temp[2][0]]) *((quint32*)(b+ 8)) = *((quint32*)T5[temp[2][0]])
^ *((Q_UINT32*)T6[temp[1][1]]) ^ *((quint32*)T6[temp[1][1]])
^ *((Q_UINT32*)T7[temp[0][2]]) ^ *((quint32*)T7[temp[0][2]])
^ *((Q_UINT32*)T8[temp[3][3]]); ^ *((quint32*)T8[temp[3][3]]);
*((Q_UINT32*)(b+12)) = *((Q_UINT32*)T5[temp[3][0]]) *((quint32*)(b+12)) = *((quint32*)T5[temp[3][0]])
^ *((Q_UINT32*)T6[temp[2][1]]) ^ *((quint32*)T6[temp[2][1]])
^ *((Q_UINT32*)T7[temp[1][2]]) ^ *((quint32*)T7[temp[1][2]])
^ *((Q_UINT32*)T8[temp[0][3]]); ^ *((quint32*)T8[temp[0][3]]);
for(r = m_uRounds-1; r > 1; r--) for(r = m_uRounds-1; r > 1; r--)
{ {
*((Q_UINT32*)temp[0]) = *((Q_UINT32*)(b )) ^ *((Q_UINT32*)m_expandedKey[r][0]); *((quint32*)temp[0]) = *((quint32*)(b )) ^ *((quint32*)m_expandedKey[r][0]);
*((Q_UINT32*)temp[1]) = *((Q_UINT32*)(b+ 4)) ^ *((Q_UINT32*)m_expandedKey[r][1]); *((quint32*)temp[1]) = *((quint32*)(b+ 4)) ^ *((quint32*)m_expandedKey[r][1]);
*((Q_UINT32*)temp[2]) = *((Q_UINT32*)(b+ 8)) ^ *((Q_UINT32*)m_expandedKey[r][2]); *((quint32*)temp[2]) = *((quint32*)(b+ 8)) ^ *((quint32*)m_expandedKey[r][2]);
*((Q_UINT32*)temp[3]) = *((Q_UINT32*)(b+12)) ^ *((Q_UINT32*)m_expandedKey[r][3]); *((quint32*)temp[3]) = *((quint32*)(b+12)) ^ *((quint32*)m_expandedKey[r][3]);
*((Q_UINT32*)(b )) = *((Q_UINT32*)T5[temp[0][0]]) *((quint32*)(b )) = *((quint32*)T5[temp[0][0]])
^ *((Q_UINT32*)T6[temp[3][1]]) ^ *((quint32*)T6[temp[3][1]])
^ *((Q_UINT32*)T7[temp[2][2]]) ^ *((quint32*)T7[temp[2][2]])
^ *((Q_UINT32*)T8[temp[1][3]]); ^ *((quint32*)T8[temp[1][3]]);
*((Q_UINT32*)(b+ 4)) = *((Q_UINT32*)T5[temp[1][0]]) *((quint32*)(b+ 4)) = *((quint32*)T5[temp[1][0]])
^ *((Q_UINT32*)T6[temp[0][1]]) ^ *((quint32*)T6[temp[0][1]])
^ *((Q_UINT32*)T7[temp[3][2]]) ^ *((quint32*)T7[temp[3][2]])
^ *((Q_UINT32*)T8[temp[2][3]]); ^ *((quint32*)T8[temp[2][3]]);
*((Q_UINT32*)(b+ 8)) = *((Q_UINT32*)T5[temp[2][0]]) *((quint32*)(b+ 8)) = *((quint32*)T5[temp[2][0]])
^ *((Q_UINT32*)T6[temp[1][1]]) ^ *((quint32*)T6[temp[1][1]])
^ *((Q_UINT32*)T7[temp[0][2]]) ^ *((quint32*)T7[temp[0][2]])
^ *((Q_UINT32*)T8[temp[3][3]]); ^ *((quint32*)T8[temp[3][3]]);
*((Q_UINT32*)(b+12)) = *((Q_UINT32*)T5[temp[3][0]]) *((quint32*)(b+12)) = *((quint32*)T5[temp[3][0]])
^ *((Q_UINT32*)T6[temp[2][1]]) ^ *((quint32*)T6[temp[2][1]])
^ *((Q_UINT32*)T7[temp[1][2]]) ^ *((quint32*)T7[temp[1][2]])
^ *((Q_UINT32*)T8[temp[0][3]]); ^ *((quint32*)T8[temp[0][3]]);
} }
*((Q_UINT32*)temp[0]) = *((Q_UINT32*)(b )) ^ *((Q_UINT32*)m_expandedKey[1][0]); *((quint32*)temp[0]) = *((quint32*)(b )) ^ *((quint32*)m_expandedKey[1][0]);
*((Q_UINT32*)temp[1]) = *((Q_UINT32*)(b+ 4)) ^ *((Q_UINT32*)m_expandedKey[1][1]); *((quint32*)temp[1]) = *((quint32*)(b+ 4)) ^ *((quint32*)m_expandedKey[1][1]);
*((Q_UINT32*)temp[2]) = *((Q_UINT32*)(b+ 8)) ^ *((Q_UINT32*)m_expandedKey[1][2]); *((quint32*)temp[2]) = *((quint32*)(b+ 8)) ^ *((quint32*)m_expandedKey[1][2]);
*((Q_UINT32*)temp[3]) = *((Q_UINT32*)(b+12)) ^ *((Q_UINT32*)m_expandedKey[1][3]); *((quint32*)temp[3]) = *((quint32*)(b+12)) ^ *((quint32*)m_expandedKey[1][3]);
b[ 0] = S5[temp[0][0]]; b[ 0] = S5[temp[0][0]];
b[ 1] = S5[temp[3][1]]; b[ 1] = S5[temp[3][1]];
b[ 2] = S5[temp[2][2]]; b[ 2] = S5[temp[2][2]];
@ -1596,10 +1596,10 @@ void Rijndael::decrypt(const Q_UINT8 a[16], Q_UINT8 b[16])
b[13] = S5[temp[2][1]]; b[13] = S5[temp[2][1]];
b[14] = S5[temp[1][2]]; b[14] = S5[temp[1][2]];
b[15] = S5[temp[0][3]]; b[15] = S5[temp[0][3]];
*((Q_UINT32*)(b )) ^= *((Q_UINT32*)m_expandedKey[0][0]); *((quint32*)(b )) ^= *((quint32*)m_expandedKey[0][0]);
*((Q_UINT32*)(b+ 4)) ^= *((Q_UINT32*)m_expandedKey[0][1]); *((quint32*)(b+ 4)) ^= *((quint32*)m_expandedKey[0][1]);
*((Q_UINT32*)(b+ 8)) ^= *((Q_UINT32*)m_expandedKey[0][2]); *((quint32*)(b+ 8)) ^= *((quint32*)m_expandedKey[0][2]);
*((Q_UINT32*)(b+12)) ^= *((Q_UINT32*)m_expandedKey[0][3]); *((quint32*)(b+12)) ^= *((quint32*)m_expandedKey[0][3]);
} }

@ -101,9 +101,9 @@ protected:
State m_state; State m_state;
Mode m_mode; Mode m_mode;
Direction m_direction; Direction m_direction;
Q_UINT8 m_initVector[MAX_IV_SIZE]; quint8 m_initVector[MAX_IV_SIZE];
Q_UINT32 m_uRounds; quint32 m_uRounds;
Q_UINT8 m_expandedKey[_MAX_ROUNDS+1][4][4]; quint8 m_expandedKey[_MAX_ROUNDS+1][4][4];
public: public:
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// API // API
@ -123,7 +123,7 @@ public:
// this CAN be binary data (it is not expected to be null terminated) // this CAN be binary data (it is not expected to be null terminated)
// keyLen : Rijndael::Key16Bytes , Rijndael::Key24Bytes or Rijndael::Key32Bytes // keyLen : Rijndael::Key16Bytes , Rijndael::Key24Bytes or Rijndael::Key32Bytes
// initVector: initialization vector, you will usually use 0 here // initVector: initialization vector, you will usually use 0 here
int init(Mode mode,Direction dir,const Q_UINT8 *key,KeyLength keyLen,Q_UINT8 * initVector = 0); int init(Mode mode,Direction dir,const quint8 *key,KeyLength keyLen,quint8 * initVector = 0);
// Encrypts the input array (can be binary data) // Encrypts the input array (can be binary data)
// The input array length must be a multiple of 16 bytes, the remaining part // The input array length must be a multiple of 16 bytes, the remaining part
// is DISCARDED. // is DISCARDED.
@ -131,28 +131,28 @@ public:
// Input len is in BITS! // Input len is in BITS!
// outBuffer must be at least inputLen / 8 bytes long. // outBuffer must be at least inputLen / 8 bytes long.
// Returns the encrypted buffer length in BITS or an error code < 0 in case of error // Returns the encrypted buffer length in BITS or an error code < 0 in case of error
int blockEncrypt(const Q_UINT8 *input, int inputLen, Q_UINT8 *outBuffer); int blockEncrypt(const quint8 *input, int inputLen, quint8 *outBuffer);
// Encrypts the input array (can be binary data) // Encrypts the input array (can be binary data)
// The input array can be any length , it is automatically padded on a 16 byte boundary. // The input array can be any length , it is automatically padded on a 16 byte boundary.
// Input len is in BYTES! // Input len is in BYTES!
// outBuffer must be at least (inputLen + 16) bytes long // outBuffer must be at least (inputLen + 16) bytes long
// Returns the encrypted buffer length in BYTES or an error code < 0 in case of error // Returns the encrypted buffer length in BYTES or an error code < 0 in case of error
int padEncrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuffer); int padEncrypt(const quint8 *input, int inputOctets, quint8 *outBuffer);
// Decrypts the input vector // Decrypts the input vector
// Input len is in BITS! // Input len is in BITS!
// outBuffer must be at least inputLen / 8 bytes long // outBuffer must be at least inputLen / 8 bytes long
// Returns the decrypted buffer length in BITS and an error code < 0 in case of error // Returns the decrypted buffer length in BITS and an error code < 0 in case of error
int blockDecrypt(const Q_UINT8 *input, int inputLen, Q_UINT8 *outBuffer); int blockDecrypt(const quint8 *input, int inputLen, quint8 *outBuffer);
// Decrypts the input vector // Decrypts the input vector
// Input len is in BYTES! // Input len is in BYTES!
// outBuffer must be at least inputLen bytes long // outBuffer must be at least inputLen bytes long
// Returns the decrypted buffer length in BYTES and an error code < 0 in case of error // Returns the decrypted buffer length in BYTES and an error code < 0 in case of error
int padDecrypt(const Q_UINT8 *input, int inputOctets, Q_UINT8 *outBuffer); int padDecrypt(const quint8 *input, int inputOctets, quint8 *outBuffer);
protected: protected:
void keySched(Q_UINT8 key[_MAX_KEY_COLUMNS][4]); void keySched(quint8 key[_MAX_KEY_COLUMNS][4]);
void keyEncToDec(); void keyEncToDec();
void encrypt(const Q_UINT8 a[16], Q_UINT8 b[16]); void encrypt(const quint8 a[16], quint8 b[16]);
void decrypt(const Q_UINT8 a[16], Q_UINT8 b[16]); void decrypt(const quint8 a[16], quint8 b[16]);
}; };
#endif // _RIJNDAEL_H_ #endif // _RIJNDAEL_H_

@ -72,7 +72,7 @@ void CSHA1::Reset()
} }
void CSHA1::Update(unsigned char* data, int len){ void CSHA1::Update(unsigned char* data, int len){
Q_UINT_32 i, j; quint_32 i, j;
j = (m_count[0] >> 3) & 63; j = (m_count[0] >> 3) & 63;
@ -98,10 +98,10 @@ void CSHA1::Update(unsigned char* data, int len){
} }
void CSHA1::Transform(Q_UINT_32 *state, Q_UINT_8 *buffer) void CSHA1::Transform(quint_32 *state, quint_8 *buffer)
{ {
// Copy state[] to working vars // Copy state[] to working vars
Q_UINT_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; quint_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
memcpy(m_block, buffer, 64); memcpy(m_block, buffer, 64);
@ -146,7 +146,7 @@ bool CSHA1::HashFile(char *szFileName)
{ {
unsigned long ulFileSize, ulRest, ulBlocks; unsigned long ulFileSize, ulRest, ulBlocks;
unsigned long i; unsigned long i;
Q_UINT_8 uData[SHA1_MAX_FILE_BUFFER]; quint_8 uData[SHA1_MAX_FILE_BUFFER];
FILE *fIn; FILE *fIn;
if(szFileName == NULL) return false; if(szFileName == NULL) return false;
@ -172,13 +172,13 @@ bool CSHA1::HashFile(char *szFileName)
for(i = 0; i < ulBlocks; i++) for(i = 0; i < ulBlocks; i++)
{ {
fread(uData, 1, SHA1_MAX_FILE_BUFFER, fIn); fread(uData, 1, SHA1_MAX_FILE_BUFFER, fIn);
Update((Q_UINT_8 *)uData, SHA1_MAX_FILE_BUFFER); Update((quint_8 *)uData, SHA1_MAX_FILE_BUFFER);
} }
if(ulRest != 0) if(ulRest != 0)
{ {
fread(uData, 1, ulRest, fIn); fread(uData, 1, ulRest, fIn);
Update((Q_UINT_8 *)uData, ulRest); Update((quint_8 *)uData, ulRest);
} }
fclose(fIn); fIn = NULL; fclose(fIn); fIn = NULL;
@ -187,23 +187,23 @@ bool CSHA1::HashFile(char *szFileName)
void CSHA1::Final() void CSHA1::Final()
{ {
Q_UINT_32 i; quint_32 i;
Q_UINT_8 finalcount[8]; quint_8 finalcount[8];
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
finalcount[i] = (Q_UINT_8)((m_count[((i >= 4) ? 0 : 1)] finalcount[i] = (quint_8)((m_count[((i >= 4) ? 0 : 1)]
>> ((3 - (i & 3)) * 8) ) & 255); // Endian independent >> ((3 - (i & 3)) * 8) ) & 255); // Endian independent
Update((Q_UINT_8 *)"\200", 1); Update((quint_8 *)"\200", 1);
while ((m_count[0] & 504) != 448) while ((m_count[0] & 504) != 448)
Update((Q_UINT_8 *)"\0", 1); Update((quint_8 *)"\0", 1);
Update(finalcount, 8); // Cause a SHA1Transform() Update(finalcount, 8); // Cause a SHA1Transform()
for(i = 0; i < 20; i++) for(i = 0; i < 20; i++)
{ {
m_digest[i] = (Q_UINT_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255); m_digest[i] = (quint_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255);
} }
// Wipe variables for security reasons // Wipe variables for security reasons
@ -251,7 +251,7 @@ void CSHA1::ReportHash(char *szReport, unsigned char uReportType)
} }
// Get the raw message digest // Get the raw message digest
void CSHA1::GetHash(Q_UINT_8 *puDest) void CSHA1::GetHash(quint_8 *puDest)
{ {
memcpy(puDest, m_digest, 20); memcpy(puDest, m_digest, 20);
} }

@ -38,12 +38,12 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Define 8- and 32-bit variables // Define 8- and 32-bit variables
#ifndef Q_UINT_32 #ifndef quint_32
#define Q_UINT_8 unsigned char #define quint_8 unsigned char
#if (ULONG_MAX == 0xFFFFFFFF) #if (ULONG_MAX == 0xFFFFFFFF)
#define Q_UINT_32 unsigned long #define quint_32 unsigned long
#else #else
#define Q_UINT_32 unsigned int #define quint_32 unsigned int
#endif #endif
#endif #endif
@ -53,8 +53,8 @@
typedef union typedef union
{ {
Q_UINT_8 c[64]; quint_8 c[64];
Q_UINT_32 l[16]; quint_32 l[16];
} SHA1_WORKSPACE_BLOCK; } SHA1_WORKSPACE_BLOCK;
class CSHA1 class CSHA1
@ -71,10 +71,10 @@ public:
CSHA1(); CSHA1();
~CSHA1(); ~CSHA1();
Q_UINT_32 m_state[5]; quint_32 m_state[5];
Q_UINT_32 m_count[2]; quint_32 m_count[2];
Q_UINT_8 m_buffer[64]; quint_8 m_buffer[64];
Q_UINT_8 m_digest[20]; quint_8 m_digest[20];
void Reset(); void Reset();
@ -85,14 +85,14 @@ public:
// Finalize hash and report // Finalize hash and report
void Final(); void Final();
void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX); void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
void GetHash(Q_UINT_8 *puDest); void GetHash(quint_8 *puDest);
private: private:
// Private SHA-1 transformation // Private SHA-1 transformation
void Transform(Q_UINT_32 *state, Q_UINT_8 *buffer); void Transform(quint_32 *state, quint_8 *buffer);
// Member variables // Member variables
Q_UINT_8 m_workspace[64]; quint_8 m_workspace[64];
SHA1_WORKSPACE_BLOCK *m_block; // SHA1 pointer to the byte array above SHA1_WORKSPACE_BLOCK *m_block; // SHA1 pointer to the byte array above
}; };

@ -22,7 +22,7 @@
#include "sha256.h" #include "sha256.h"
#define GET_Q_UINT32(n,b,i) \ #define GET_quint32(n,b,i) \
{ \ { \
(n) = ( (uint32) (b)[(i) ] << 24 ) \ (n) = ( (uint32) (b)[(i) ] << 24 ) \
| ( (uint32) (b)[(i) + 1] << 16 ) \ | ( (uint32) (b)[(i) + 1] << 16 ) \
@ -30,7 +30,7 @@
| ( (uint32) (b)[(i) + 3] ); \ | ( (uint32) (b)[(i) + 3] ); \
} }
#define PUT_Q_UINT32(n,b,i) \ #define PUT_quint32(n,b,i) \
{ \ { \
(b)[(i) ] = (uint8) ( (n) >> 24 ); \ (b)[(i) ] = (uint8) ( (n) >> 24 ); \
(b)[(i) + 1] = (uint8) ( (n) >> 16 ); \ (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \
@ -58,22 +58,22 @@ void sha256_process( sha256_context *ctx, uint8 data[64] )
uint32 temp1, temp2, W[64]; uint32 temp1, temp2, W[64];
uint32 A, B, C, D, E, F, G, H; uint32 A, B, C, D, E, F, G, H;
GET_Q_UINT32( W[0], data, 0 ); GET_quint32( W[0], data, 0 );
GET_Q_UINT32( W[1], data, 4 ); GET_quint32( W[1], data, 4 );
GET_Q_UINT32( W[2], data, 8 ); GET_quint32( W[2], data, 8 );
GET_Q_UINT32( W[3], data, 12 ); GET_quint32( W[3], data, 12 );
GET_Q_UINT32( W[4], data, 16 ); GET_quint32( W[4], data, 16 );
GET_Q_UINT32( W[5], data, 20 ); GET_quint32( W[5], data, 20 );
GET_Q_UINT32( W[6], data, 24 ); GET_quint32( W[6], data, 24 );
GET_Q_UINT32( W[7], data, 28 ); GET_quint32( W[7], data, 28 );
GET_Q_UINT32( W[8], data, 32 ); GET_quint32( W[8], data, 32 );
GET_Q_UINT32( W[9], data, 36 ); GET_quint32( W[9], data, 36 );
GET_Q_UINT32( W[10], data, 40 ); GET_quint32( W[10], data, 40 );
GET_Q_UINT32( W[11], data, 44 ); GET_quint32( W[11], data, 44 );
GET_Q_UINT32( W[12], data, 48 ); GET_quint32( W[12], data, 48 );
GET_Q_UINT32( W[13], data, 52 ); GET_quint32( W[13], data, 52 );
GET_Q_UINT32( W[14], data, 56 ); GET_quint32( W[14], data, 56 );
GET_Q_UINT32( W[15], data, 60 ); GET_quint32( W[15], data, 60 );
#define SHR(x,n) ((x & 0xFFFFFFFF) >> n) #define SHR(x,n) ((x & 0xFFFFFFFF) >> n)
#define ROTR(x,n) (SHR(x,n) | (x << (32 - n))) #define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
@ -241,8 +241,8 @@ void sha256_finish( sha256_context *ctx, uint8 digest[32] )
| ( ctx->total[1] << 3 ); | ( ctx->total[1] << 3 );
low = ( ctx->total[0] << 3 ); low = ( ctx->total[0] << 3 );
PUT_Q_UINT32( high, msglen, 0 ); PUT_quint32( high, msglen, 0 );
PUT_Q_UINT32( low, msglen, 4 ); PUT_quint32( low, msglen, 4 );
last = ctx->total[0] & 0x3F; last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
@ -250,14 +250,14 @@ void sha256_finish( sha256_context *ctx, uint8 digest[32] )
sha256_update( ctx, sha256_padding, padn ); sha256_update( ctx, sha256_padding, padn );
sha256_update( ctx, msglen, 8 ); sha256_update( ctx, msglen, 8 );
PUT_Q_UINT32( ctx->state[0], digest, 0 ); PUT_quint32( ctx->state[0], digest, 0 );
PUT_Q_UINT32( ctx->state[1], digest, 4 ); PUT_quint32( ctx->state[1], digest, 4 );
PUT_Q_UINT32( ctx->state[2], digest, 8 ); PUT_quint32( ctx->state[2], digest, 8 );
PUT_Q_UINT32( ctx->state[3], digest, 12 ); PUT_quint32( ctx->state[3], digest, 12 );
PUT_Q_UINT32( ctx->state[4], digest, 16 ); PUT_quint32( ctx->state[4], digest, 16 );
PUT_Q_UINT32( ctx->state[5], digest, 20 ); PUT_quint32( ctx->state[5], digest, 20 );
PUT_Q_UINT32( ctx->state[6], digest, 24 ); PUT_quint32( ctx->state[6], digest, 24 );
PUT_Q_UINT32( ctx->state[7], digest, 28 ); PUT_quint32( ctx->state[7], digest, 28 );
} }
#ifdef TEST #ifdef TEST

@ -40,7 +40,7 @@ CTwofish::~CTwofish()
{ {
} }
bool CTwofish::init(Q_UINT8 *pKey, unsigned long uKeyLen, Q_UINT8 *initVector) bool CTwofish::init(quint8 *pKey, unsigned long uKeyLen, quint8 *initVector)
{ {
//ASSERT(pKey != NULL); //ASSERT(pKey != NULL);
if(pKey == NULL) return false; if(pKey == NULL) return false;
@ -61,10 +61,10 @@ bool CTwofish::init(Q_UINT8 *pKey, unsigned long uKeyLen, Q_UINT8 *initVector)
return true; return true;
} }
int CTwofish::padEncrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer) int CTwofish::padEncrypt(quint8 *pInput, int nInputOctets, quint8 *pOutBuffer)
{ {
int i, numBlocks, padLen; int i, numBlocks, padLen;
Q_UINT8 block[16], *iv; quint8 block[16], *iv;
//ASSERT((pInput != NULL) && (nInputOctets != NULL) && (pOutBuffer != NULL)); //ASSERT((pInput != NULL) && (nInputOctets != NULL) && (pOutBuffer != NULL));
if((pInput == NULL) || (nInputOctets <= 0) || (pOutBuffer == NULL)) return 0; if((pInput == NULL) || (nInputOctets <= 0) || (pOutBuffer == NULL)) return 0;
@ -74,10 +74,10 @@ int CTwofish::padEncrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer)
iv = m_pInitVector; iv = m_pInitVector;
for(i = numBlocks; i > 0; i--) for(i = numBlocks; i > 0; i--)
{ {
((Q_UINT32*)block)[0] = ((Q_UINT32*)pInput)[0] ^ ((Q_UINT32*)iv)[0]; ((quint32*)block)[0] = ((quint32*)pInput)[0] ^ ((quint32*)iv)[0];
((Q_UINT32*)block)[1] = ((Q_UINT32*)pInput)[1] ^ ((Q_UINT32*)iv)[1]; ((quint32*)block)[1] = ((quint32*)pInput)[1] ^ ((quint32*)iv)[1];
((Q_UINT32*)block)[2] = ((Q_UINT32*)pInput)[2] ^ ((Q_UINT32*)iv)[2]; ((quint32*)block)[2] = ((quint32*)pInput)[2] ^ ((quint32*)iv)[2];
((Q_UINT32*)block)[3] = ((Q_UINT32*)pInput)[3] ^ ((Q_UINT32*)iv)[3]; ((quint32*)block)[3] = ((quint32*)pInput)[3] ^ ((quint32*)iv)[3];
Twofish_encrypt(&m_key, (Twofish_Byte *)block, (Twofish_Byte *)pOutBuffer); Twofish_encrypt(&m_key, (Twofish_Byte *)block, (Twofish_Byte *)pOutBuffer);
@ -90,12 +90,12 @@ int CTwofish::padEncrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer)
for (i = 0; i < 16 - padLen; i++) for (i = 0; i < 16 - padLen; i++)
{ {
block[i] = (Q_UINT8)(pInput[i] ^ iv[i]); block[i] = (quint8)(pInput[i] ^ iv[i]);
} }
for (i = 16 - padLen; i < 16; i++) for (i = 16 - padLen; i < 16; i++)
{ {
block[i] = (Q_UINT8)((Q_UINT8)padLen ^ iv[i]); block[i] = (quint8)((quint8)padLen ^ iv[i]);
} }
Twofish_encrypt(&m_key, (Twofish_Byte *)block, (Twofish_Byte *)pOutBuffer); Twofish_encrypt(&m_key, (Twofish_Byte *)block, (Twofish_Byte *)pOutBuffer);
@ -103,11 +103,11 @@ int CTwofish::padEncrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer)
return 16 * (numBlocks + 1); return 16 * (numBlocks + 1);
} }
int CTwofish::padDecrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer) int CTwofish::padDecrypt(quint8 *pInput, int nInputOctets, quint8 *pOutBuffer)
{ {
int i, numBlocks, padLen; int i, numBlocks, padLen;
Q_UINT8 block[16]; quint8 block[16];
Q_UINT32 iv[4]; quint32 iv[4];
//ASSERT((pInput != NULL) && (nInputOctets != NULL) && (pOutBuffer != NULL)); //ASSERT((pInput != NULL) && (nInputOctets != NULL) && (pOutBuffer != NULL));
if((pInput == NULL) || (nInputOctets <= 0) || (pOutBuffer == NULL)) return 0; if((pInput == NULL) || (nInputOctets <= 0) || (pOutBuffer == NULL)) return 0;
@ -121,10 +121,10 @@ int CTwofish::padDecrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer)
for(i = numBlocks - 1; i > 0; i--) for(i = numBlocks - 1; i > 0; i--)
{ {
Twofish_decrypt(&m_key, (Twofish_Byte *)pInput, (Twofish_Byte *)block); Twofish_decrypt(&m_key, (Twofish_Byte *)pInput, (Twofish_Byte *)block);
((Q_UINT32*)block)[0] ^= iv[0]; ((quint32*)block)[0] ^= iv[0];
((Q_UINT32*)block)[1] ^= iv[1]; ((quint32*)block)[1] ^= iv[1];
((Q_UINT32*)block)[2] ^= iv[2]; ((quint32*)block)[2] ^= iv[2];
((Q_UINT32*)block)[3] ^= iv[3]; ((quint32*)block)[3] ^= iv[3];
memcpy(iv, pInput, 16); memcpy(iv, pInput, 16);
memcpy(pOutBuffer, block, 16); memcpy(pOutBuffer, block, 16);
pInput += 16; pInput += 16;
@ -132,10 +132,10 @@ int CTwofish::padDecrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer)
} }
Twofish_decrypt(&m_key, (Twofish_Byte *)pInput, (Twofish_Byte *)block); Twofish_decrypt(&m_key, (Twofish_Byte *)pInput, (Twofish_Byte *)block);
((Q_UINT32*)block)[0] ^= iv[0]; ((quint32*)block)[0] ^= iv[0];
((Q_UINT32*)block)[1] ^= iv[1]; ((quint32*)block)[1] ^= iv[1];
((Q_UINT32*)block)[2] ^= iv[2]; ((quint32*)block)[2] ^= iv[2];
((Q_UINT32*)block)[3] ^= iv[3]; ((quint32*)block)[3] ^= iv[3];
padLen = block[15]; padLen = block[15];
if(padLen <= 0 || padLen > 16) return -1; if(padLen <= 0 || padLen > 16) return -1;
for(i = 16 - padLen; i < 16; i++) for(i = 16 - padLen; i < 16; i++)

@ -39,14 +39,14 @@ public:
CTwofish(); CTwofish();
virtual ~CTwofish(); virtual ~CTwofish();
bool init(Q_UINT8 *pKey, unsigned long uKeyLen, Q_UINT8 *initVector = NULL); bool init(quint8 *pKey, unsigned long uKeyLen, quint8 *initVector = NULL);
int padEncrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer); int padEncrypt(quint8 *pInput, int nInputOctets, quint8 *pOutBuffer);
int padDecrypt(Q_UINT8 *pInput, int nInputOctets, Q_UINT8 *pOutBuffer); int padDecrypt(quint8 *pInput, int nInputOctets, quint8 *pOutBuffer);
private: private:
Twofish_key m_key; Twofish_key m_key;
Q_UINT8 m_pInitVector[16]; quint8 m_pInitVector[16];
}; };
#endif #endif

@ -245,7 +245,7 @@
* *
* Unfortunately there is no portable way of writing the constant * Unfortunately there is no portable way of writing the constant
* 0xffffffff. You don't know which suffix to use (U, or UL?) * 0xffffffff. You don't know which suffix to use (U, or UL?)
* The Q_UINT32_MASK definition uses a bit of trickery. Shift-left * The quint32_MASK definition uses a bit of trickery. Shift-left
* is only defined if the shift amount is strictly less than the size * is only defined if the shift amount is strictly less than the size
* of the UInt32, so we can't use (1<<32). The answer it to take the value * of the UInt32, so we can't use (1<<32). The answer it to take the value
* 2, cast it to a UInt32, shift it left 31 positions, and subtract one. * 2, cast it to a UInt32, shift it left 31 positions, and subtract one.
@ -263,11 +263,11 @@
* For example, MS compilers have the __rotl and __rotr functions * For example, MS compilers have the __rotl and __rotr functions
* that generate x86 rotation instructions. * that generate x86 rotation instructions.
*/ */
#define Q_UINT32_MASK ( (((Twofish_UInt32)2)<<31) - 1 ) #define quint32_MASK ( (((Twofish_UInt32)2)<<31) - 1 )
#ifndef _MSC_VER #ifndef _MSC_VER
#define ROL32(x,n) ( (x)<<(n) | ((x) & Q_UINT32_MASK) >> (32-(n)) ) #define ROL32(x,n) ( (x)<<(n) | ((x) & quint32_MASK) >> (32-(n)) )
#define ROR32(x,n) ( (x)>>(n) | ((x) & Q_UINT32_MASK) << (32-(n)) ) #define ROR32(x,n) ( (x)>>(n) | ((x) & quint32_MASK) << (32-(n)) )
#else #else
#define ROL32(x,n) (_lrotl((x), (n))) #define ROL32(x,n) (_lrotl((x), (n)))
#define ROR32(x,n) (_lrotr((x), (n))) #define ROR32(x,n) (_lrotr((x), (n)))
@ -306,7 +306,7 @@
* This macro does not affect the conversion of the inputs and outputs * This macro does not affect the conversion of the inputs and outputs
* of the cipher. See the CONVERT_USING_CASTS macro for that. * of the cipher. See the CONVERT_USING_CASTS macro for that.
*/ */
#define SELECT_BYTE_FROM_Q_UINT32_IN_MEMORY 0 /* default = 0 */ #define SELECT_BYTE_FROM_quint32_IN_MEMORY 0 /* default = 0 */
/* /*
@ -331,7 +331,7 @@
* This option does not work unless a UInt32 is exactly 32 bits. * This option does not work unless a UInt32 is exactly 32 bits.
* *
* This macro only changes the reading/writing of the plaintext/ciphertext. * This macro only changes the reading/writing of the plaintext/ciphertext.
* See the SELECT_BYTE_FROM_Q_UINT32_IN_MEMORY to affect the way in which * See the SELECT_BYTE_FROM_quint32_IN_MEMORY to affect the way in which
* a UInt32 is split into 4 bytes for the S-box selection. * a UInt32 is split into 4 bytes for the S-box selection.
*/ */
#define CONVERT_USING_CASTS 0 /* default = 0 */ #define CONVERT_USING_CASTS 0 /* default = 0 */
@ -339,7 +339,7 @@
/* /*
* Endianness switch. * Endianness switch.
* Only relevant if SELECT_BYTE_FROM_Q_UINT32_IN_MEMORY or * Only relevant if SELECT_BYTE_FROM_quint32_IN_MEMORY or
* CONVERT_USING_CASTS is set. * CONVERT_USING_CASTS is set.
* *
* Set to 1 on a big-endian machine, and to 0 on a little-endian machine. * Set to 1 on a big-endian machine, and to 0 on a little-endian machine.
@ -407,7 +407,7 @@
/* /*
* Compute byte offset within a UInt32 stored in memory. * Compute byte offset within a UInt32 stored in memory.
* *
* This is only used when SELECT_BYTE_FROM_Q_UINT32_IN_MEMORY is set. * This is only used when SELECT_BYTE_FROM_quint32_IN_MEMORY is set.
* *
* The input is the byte number 0..3, 0 for least significant. * The input is the byte number 0..3, 0 for least significant.
* Note the use of sizeof() to support UInt32 types that are larger * Note the use of sizeof() to support UInt32 types that are larger
@ -424,7 +424,7 @@
* Macro to get Byte no. b from UInt32 value X. * Macro to get Byte no. b from UInt32 value X.
* We use two different definition, depending on the settings. * We use two different definition, depending on the settings.
*/ */
#if SELECT_BYTE_FROM_Q_UINT32_IN_MEMORY #if SELECT_BYTE_FROM_quint32_IN_MEMORY
/* Pick the byte from the memory in which X is stored. */ /* Pick the byte from the memory in which X is stored. */
#define SELECT_BYTE( X, b ) (((Twofish_Byte *)(&(X)))[BYTE_OFFSET(b)]) #define SELECT_BYTE( X, b ) (((Twofish_Byte *)(&(X)))[BYTE_OFFSET(b)])
#else #else

@ -365,7 +365,6 @@ else
void CEditEntryDlg::OnCustomIcons(){ void CEditEntryDlg::OnCustomIcons(){
CSelectIconDlg dlg(db,Combo_IconPicker->currentItem(),this); CSelectIconDlg dlg(db,Combo_IconPicker->currentItem(),this);
int r=dlg.exec(); int r=dlg.exec();
if(dlg.ModFlag)ModFlag=true;
if(r!=-1){ if(r!=-1){
Combo_IconPicker->clear(); Combo_IconPicker->clear();
for(int i=0;i<db->numIcons();i++) for(int i=0;i<db->numIcons();i++)

@ -69,7 +69,6 @@ done(0);
void CEditGroupDialog::OnIconDlg(){ void CEditGroupDialog::OnIconDlg(){
CSelectIconDlg dlg(db,IconID,this); CSelectIconDlg dlg(db,IconID,this);
int r=dlg.exec(); int r=dlg.exec();
if(dlg.ModFlag)ModFlag=true;
if(r!=-1){ if(r!=-1){
ComboIconPicker->clear(); ComboIconPicker->clear();
for(int i=0;i<db->numIcons();i++) for(int i=0;i<db->numIcons();i++)

@ -30,7 +30,7 @@ public:
CSearchDlg(Database* _db, CGroup* pGroup=NULL,QWidget* parent = 0, const char* name = 0, CSearchDlg(Database* _db, CGroup* pGroup=NULL,QWidget* parent = 0, const char* name = 0,
bool modal = FALSE, Qt::WFlags fl = 0 ); bool modal = FALSE, Qt::WFlags fl = 0 );
~CSearchDlg(); ~CSearchDlg();
QList<Q_UINT32> Hits; QList<quint32> Hits;
public slots: public slots:
virtual void OnButtonClose(); virtual void OnButtonClose();

@ -32,15 +32,16 @@ CSelectIconDlg::CSelectIconDlg(Database* database,int CurrentID,QWidget* parent,
setupUi(this); setupUi(this);
db=database; db=database;
CtxMenu=new QMenu(this); CtxMenu=new QMenu(this);
ReplaceAction=CtxMenu->addAction(*Icon_Swap,tr("Replace..."));
DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete")); DeleteAction=CtxMenu->addAction(*Icon_EditDelete,tr("Delete"));
connect(Button_AddIcon, SIGNAL(clicked()), this, SLOT(OnAddIcon())); connect(Button_AddIcon, SIGNAL(clicked()), this, SLOT(OnAddIcon()));
connect(Button_PickIcon, SIGNAL(clicked()), this, SLOT(OnPickIcon())); connect(Button_PickIcon, SIGNAL(clicked()), this, SLOT(OnPickIcon()));
connect(Button_Cancel, SIGNAL(clicked()), this, SLOT(OnCancel())); connect(Button_Cancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
connect(DeleteAction,SIGNAL(triggered()),this,SLOT(OnDelete())); connect(DeleteAction,SIGNAL(triggered()),this,SLOT(OnDelete()));
connect(ReplaceAction,SIGNAL(triggered()),this,SLOT(OnReplace()));
connect(List,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this,SLOT(OnSelectionChanged(QListWidgetItem*,QListWidgetItem*))); connect(List,SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),this,SLOT(OnSelectionChanged(QListWidgetItem*,QListWidgetItem*)));
updateView(); updateView();
List->setCurrentItem(List->item(CurrentID)); List->setCurrentItem(List->item(CurrentID));
ModFlag=false;
} }
void CSelectIconDlg::updateView(){ void CSelectIconDlg::updateView(){
@ -60,7 +61,7 @@ for(int i=0; i<db->numIcons(); i++){
void CSelectIconDlg::OnAddIcon(){ void CSelectIconDlg::OnAddIcon(){
QStringList filenames=QFileDialog::getOpenFileNames(this,tr("Add Icons..."),QDir::homePath(),tr("Images (%1)") QStringList filenames=QFileDialog::getOpenFileNames(this,tr("Add Icons..."),QDir::homePath(),tr("Images (%1)")
.arg("*.png *.jpeg *.jpg *.bmp *.gif *.bpm *.pgm *.ppm *.xbm *xpm")); .arg("*.png *.jpeg *.jpg *.bmp *.gif *.bpm *.pgm *.ppm *.xbm *xpm"));
QStringList errors; QString errors;
for(int i=0;i<filenames.size();i++){ for(int i=0;i<filenames.size();i++){
QPixmap icon; QPixmap icon;
if(!icon.load(filenames[i])){ if(!icon.load(filenames[i])){
@ -69,8 +70,7 @@ for(int i=0;i<filenames.size();i++){
db->addIcon(icon.scaled(16,16,Qt::KeepAspectRatio,Qt::SmoothTransformation)); db->addIcon(icon.scaled(16,16,Qt::KeepAspectRatio,Qt::SmoothTransformation));
} }
if(errors.size()) if(errors.size())
QMessageBox::warning(this,tr("Error"),tr("An error occured while loading the icon(s):\n")); QMessageBox::warning(this,tr("Error"),tr("An error occured while loading the icon(s):\n%1").arg(errors));
ModFlag=true;
updateView(); updateView();
List->setCurrentItem(List->item(List->count()-1)); List->setCurrentItem(List->item(List->count()-1));
} }
@ -80,21 +80,35 @@ void CSelectIconDlg::contextMenuEvent(QContextMenuEvent *event){
QListWidgetItem* item=List->itemAt(List->mapFromParent(event->pos())); QListWidgetItem* item=List->itemAt(List->mapFromParent(event->pos()));
if(!item)return; if(!item)return;
if(item->data(32).toInt()<BUILTIN_ICONS) if(item->data(32).toInt()<BUILTIN_ICONS){
DeleteAction->setDisabled(true); DeleteAction->setDisabled(true);
else ReplaceAction->setDisabled(true);}
else{
DeleteAction->setDisabled(false); DeleteAction->setDisabled(false);
ReplaceAction->setDisabled(false);}
event->accept(); event->accept();
CtxMenu->popup(event->globalPos()); CtxMenu->popup(event->globalPos());
} }
void CSelectIconDlg::OnDelete(){ void CSelectIconDlg::OnDelete(){
ModFlag=true;
db->removeIcon(List->currentItem()->data(32).toInt()); db->removeIcon(List->currentItem()->data(32).toInt());
updateView(); updateView();
List->setCurrentItem(List->item(0)); List->setCurrentItem(List->item(0));
} }
void CSelectIconDlg::OnReplace(){
QString filename=QFileDialog::getOpenFileName(this,tr("Add Icons..."),QDir::homePath(),tr("Images (%1)")
.arg("*.png *.jpeg *.jpg *.bmp *.gif *.bpm *.pgm *.ppm *.xbm *xpm"));
if(filename==QString())return;
QPixmap icon;
if(!icon.load(filename)){
QMessageBox::warning(this,tr("Error"),tr("An error occured while loading the icon."));
return;
}
db->replaceIcon(List->currentItem()->data(32).toInt(),icon.scaled(16,16,Qt::KeepAspectRatio,Qt::SmoothTransformation));
}
void CSelectIconDlg::OnPickIcon(){ void CSelectIconDlg::OnPickIcon(){
done(List->currentItem()->data(32).toInt()); done(List->currentItem()->data(32).toInt());
} }
@ -107,6 +121,4 @@ done(-1);
void CSelectIconDlg::OnSelectionChanged(QListWidgetItem* cur,QListWidgetItem* prev){ void CSelectIconDlg::OnSelectionChanged(QListWidgetItem* cur,QListWidgetItem* prev){
Button_PickIcon->setEnabled(cur); Button_PickIcon->setEnabled(cur);
} }

@ -32,13 +32,13 @@ class CSelectIconDlg:public QDialog, public Ui_SelectIconDlg{
Q_OBJECT Q_OBJECT
public: public:
CSelectIconDlg(Database* db,int,QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WFlags fl = 0); CSelectIconDlg(Database* db,int,QWidget* parent = 0, const char* name = 0, bool modal = false, Qt::WFlags fl = 0);
bool ModFlag;
public slots: public slots:
void OnAddIcon(); void OnAddIcon();
void OnPickIcon(); void OnPickIcon();
void OnCancel(); void OnCancel();
void OnDelete(); void OnDelete();
void OnReplace();
void OnSelectionChanged(QListWidgetItem*,QListWidgetItem*); void OnSelectionChanged(QListWidgetItem*,QListWidgetItem*);
private: private:
@ -46,6 +46,7 @@ private:
void updateView(); void updateView();
QMenu* CtxMenu; QMenu* CtxMenu;
QAction* DeleteAction; QAction* DeleteAction;
QAction* ReplaceAction;
protected: protected:
virtual void contextMenuEvent(QContextMenuEvent *event); virtual void contextMenuEvent(QContextMenuEvent *event);

@ -37,7 +37,7 @@ int len=file.size();
if(len==0){ if(len==0){
err+=QObject::tr("File is empty."); err+=QObject::tr("File is empty.");
return false;} return false;}
Q_UINT8* buffer=new Q_UINT8[len]; quint8* buffer=new quint8[len];
file.readBlock((char*)buffer,len); file.readBlock((char*)buffer,len);
file.close(); file.close();
QDomDocument doc; QDomDocument doc;

@ -79,7 +79,7 @@ if(c==1){
else else
str="{USERNAME}{TAB}{PASSWORD}{ENTER}"; str="{USERNAME}{TAB}{PASSWORD}{ENTER}";
QList<Q_UINT16> Keys; QList<quint16> Keys;
for(int i=0;i<str.size();i++){ for(int i=0;i<str.size();i++){
if(str[i]=='{'){ if(str[i]=='{'){
int start=i; int start=i;
@ -1131,9 +1131,9 @@ tKeysymMap AutoType::KeysymMap[] =
{ 0x20ac, 0x20ac }, /* EuroSign € EURO SIGN */ { 0x20ac, 0x20ac }, /* EuroSign € EURO SIGN */
}; };
Q_UINT16 AutoType::getKeysym(const QChar& c){ quint16 AutoType::getKeysym(const QChar& c){
int MapSize=sizeof(KeysymMap); int MapSize=sizeof(KeysymMap);
Q_UINT16 unicode=c.unicode(); quint16 unicode=c.unicode();
/* first check for Latin-1 characters (1:1 mapping) */ /* first check for Latin-1 characters (1:1 mapping) */
if ((unicode >= 0x0020 && unicode <= 0x007e) || if ((unicode >= 0x0020 && unicode <= 0x007e) ||
(unicode >= 0x00a0 && unicode <= 0x00ff)) (unicode >= 0x00a0 && unicode <= 0x00ff))
@ -1148,4 +1148,4 @@ for(int i=0; i<MapSize;i++){
} }
//Q_ASSERT(false); //Q_ASSERT(false);
return 0; return 0;
} }

@ -35,8 +35,8 @@
#include "Database.h" #include "Database.h"
typedef struct tKeysymMap{ typedef struct tKeysymMap{
Q_UINT16 keysym; quint16 keysym;
Q_UINT16 unicode; quint16 unicode;
}; };
class AutoType:public QObject{ class AutoType:public QObject{
@ -45,7 +45,7 @@ public:
static void perform(CEntry* entry,QString& errors); static void perform(CEntry* entry,QString& errors);
private: private:
static tKeysymMap KeysymMap[]; static tKeysymMap KeysymMap[];
static Q_UINT16 getKeysym(const QChar& unicode); static quint16 getKeysym(const QChar& unicode);
static int getModifiers(Display*,KeySym,int); static int getModifiers(Display*,KeySym,int);
static void pressModifiers(Display*,int,bool Press=true); static void pressModifiers(Display*,int,bool Press=true);
static void releaseModifiers(Display*,int); static void releaseModifiers(Display*,int);
@ -58,4 +58,4 @@ private:
}; };
#endif #endif

@ -19,7 +19,6 @@
***************************************************************************/ ***************************************************************************/
#include <math.h>
#include <QDragEnterEvent> #include <QDragEnterEvent>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QDragLeaveEvent> #include <QDragLeaveEvent>
@ -58,7 +57,7 @@ setAlternatingRowColors(config.AlternatingRowColors);
KeepassEntryView::~KeepassEntryView(){ KeepassEntryView::~KeepassEntryView(){
for(int i=0;i<ColumnSizes.size();i++){ for(int i=0;i<ColumnSizes.size();i++){
config.ColumnSizes[i]=round(ColumnSizes[i]*10000.0f); config.ColumnSizes[i]=(int)(ColumnSizes[i]*10000.0f);
} }
} }
@ -122,7 +121,7 @@ if(SelectionIDs.size())
} }
} }
void KeepassEntryView::showSearchResults(QList<Q_UINT32>& results){ void KeepassEntryView::showSearchResults(QList<quint32>& results){
IsSearchGroup=true; IsSearchGroup=true;
clear(); clear();
Items.clear(); Items.clear();
@ -260,7 +259,7 @@ int wx=0; int j=0;
for(int i=0;i<NUM_COLUMNS;i++){ for(int i=0;i<NUM_COLUMNS;i++){
if(!config.Columns[i])continue; if(!config.Columns[i])continue;
int NewWidth=round(ColumnSizes[i]*(float)w); int NewWidth=(int)(ColumnSizes[i]*(float)w);
wx+=NewWidth; wx+=NewWidth;
header()->resizeSection(j++,NewWidth); header()->resizeSection(j++,NewWidth);
//add rounding difference (w-wx) to the last column //add rounding difference (w-wx) to the last column
@ -392,8 +391,30 @@ EntryViewItem::EntryViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding
bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{ bool EntryViewItem::operator<(const QTreeWidgetItem& other)const{
if(QString::localeAwareCompare( text(treeWidget()->sortColumn()),other.text(treeWidget()->sortColumn())) < 0) int SortCol=treeWidget()->sortColumn();
return true; if(SortCol < 5 || SortCol==9){ //columns with string values (Title, Username, Password, URL, Comment)
else if(QString::localeAwareCompare(text(SortCol),other.text(SortCol)) < 0)
return false; return true;
else
return false;
}
QDateTime *DateThis;
QDateTime *DateOther;
switch(SortCol){
case 5: DateThis=&pEntry->Expire;
DateOther=&((EntryViewItem&)other).pEntry->Expire;
break;
case 6: DateThis=&pEntry->Creation;
DateOther=&((EntryViewItem&)other).pEntry->Creation;
break;
case 7: DateThis=&pEntry->LastMod;
DateOther=&((EntryViewItem&)other).pEntry->LastMod;
break;
case 8: DateThis=&pEntry->LastAccess;
DateOther=&((EntryViewItem&)other).pEntry->LastAccess;
break;
default:Q_ASSERT(false);
}
return *DateThis < *DateOther;
} }

@ -40,7 +40,7 @@ public:
void updateItems(unsigned int group); void updateItems(unsigned int group);
void updateColumns(); void updateColumns();
void refreshItems(); void refreshItems();
void showSearchResults(QList<Q_UINT32>& results); void showSearchResults(QList<quint32>& results);
Database* db; Database* db;
vector<EntryViewItem*>Items; vector<EntryViewItem*>Items;
QMenu *ContextMenu; QMenu *ContextMenu;

@ -24,8 +24,9 @@
// Local Includes // Local Includes
#include "IniReader.h" #include "IniReader.h"
#include <qglobal.h>
#if defined(WIN32) #if defined(Q_WS_WIN)
#define iniEOL endl #define iniEOL endl
#else #else
#define iniEOL '\r' << endl #define iniEOL '\r' << endl

@ -34,8 +34,8 @@ dev_random = fopen("/dev/urandom","r");}
if (dev_random==NULL){ if (dev_random==NULL){
srand(QTime(0,0,0).secsTo(QTime::currentTime())); srand(QTime(0,0,0).secsTo(QTime::currentTime()));
for(int i=0;i<NumBlocks*BlockSize;i++){ for(int i=0;i<NumBlocks*BlockSize;i++){
Q_UINT8 rnd=rand()%256; quint8 rnd=rand()%256;
((Q_UINT8*)buffer)[i]=rnd; ((quint8*)buffer)[i]=rnd;
} }
return; return;
} }

@ -73,6 +73,7 @@ QIcon *Icon_EditSearch;
QIcon *Icon_Configure; QIcon *Icon_Configure;
QIcon *Icon_Help; QIcon *Icon_Help;
QIcon *Icon_AutoType; QIcon *Icon_AutoType;
QIcon *Icon_Swap;
inline void loadImages(); inline void loadImages();
inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang); inline void parseCmdLineArgs(int argc, char** argv,QString &ArgFile,QString& ArgCfg,QString& ArgLang);
@ -292,7 +293,7 @@ _loadIcon(Icon_EditSearch,"/actions/find.png");
_loadIcon(Icon_Configure,"/actions/configure.png"); _loadIcon(Icon_Configure,"/actions/configure.png");
_loadIcon(Icon_Help,"/actions/help.png"); _loadIcon(Icon_Help,"/actions/help.png");
_loadIcon(Icon_AutoType,"/apps/ktouch.png"); _loadIcon(Icon_AutoType,"/apps/ktouch.png");
_loadIcon(Icon_Swap,"/actions/reload.png");
} }
@ -303,12 +304,12 @@ int i=1;
ArgFile=QString::fromUtf8(argv[i]); ArgFile=QString::fromUtf8(argv[i]);
i++; } i++; }
for(i; i<argc;i++){ for(i; i<argc;i++){
if(QString(argv[i])=="-h"){ if(QString(argv[i])=="-help"){
cout << "KeePassX" << KEEPASS_VERSION << endl; cout << "KeePassX" << KEEPASS_VERSION << endl;
cout << "Usage: keepass [Filename] [Options]" << endl; cout << "Usage: keepass [Filename] [Options]" << endl;
cout << " -h This Help" << endl; cout << " -help This Help" << endl;
cout << " -cfg <ConfigFile> Use specified configuration." << endl; cout << " -cfg <CONFIG> Use specified file for loading/saving the configuration." << endl;
cout << " -lang <LOCALE> Use specified language instead of system default." << endl; cout << " -lang <LOCALE> Use specified language instead of systems default." << endl;
cout << " <LOCALE> is the ISO-639 language code with or without ISO-3166 country code" << endl; cout << " <LOCALE> is the ISO-639 language code with or without ISO-3166 country code" << endl;
cout << " Examples: de German" << endl; cout << " Examples: de German" << endl;
cout << " de_CH German(Switzerland)"<<endl; cout << " de_CH German(Switzerland)"<<endl;

@ -65,6 +65,7 @@ extern QIcon *Icon_EditSearch;
extern QIcon *Icon_Configure; extern QIcon *Icon_Configure;
extern QIcon *Icon_Help; extern QIcon *Icon_Help;
extern QIcon *Icon_AutoType; extern QIcon *Icon_AutoType;
extern QIcon *Icon_Swap;
#endif #endif

@ -106,7 +106,7 @@ private:
bool ModFlag; bool ModFlag;
QClipboard* Clipboard; QClipboard* Clipboard;
QTimer ClipboardTimer; QTimer ClipboardTimer;
QList<Q_UINT32> SearchResults; QList<quint32> SearchResults;
inline void setupToolbar(); inline void setupToolbar();
inline void setupIcons(); inline void setupIcons();
inline void setupConnections(); inline void setupConnections();