diff --git a/src/Database.cpp b/src/Database.cpp index cdc434f..7194036 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -20,8 +20,7 @@ -KpxUuid::KpxUuid(){ - Data.fill(0,16); +KpxUuid::KpxUuid() : Data(16,0){ } KpxUuid::KpxUuid(const void* src){ @@ -30,7 +29,7 @@ KpxUuid::KpxUuid(const void* src){ void KpxUuid::generate(){ char uuid[16]; - getRandomBytes(uuid,16); + randomize(uuid,16); quint32 Secs=QDateTime::currentDateTime().toTime_t(); quint16 mSecs=QTime::currentTime().msec(); mSecs=(mSecs & 0x3FF) | (*((quint16*)(uuid+4)) & 0xFC00); //msec has only 10 Bits, filling the rest with random data @@ -61,7 +60,7 @@ void KpxUuid::toRaw(void* dst)const{ } void KpxUuid::fromRaw(const void* src){ - Data=QByteArray((char*)src,16); + Data.replace(0,16,(char*)src); } bool KpxUuid::operator==(const KpxUuid& other)const{ diff --git a/src/crypto/arcfour.h b/src/crypto/arcfour.h index 84a3efe..e1c0416 100644 --- a/src/crypto/arcfour.h +++ b/src/crypto/arcfour.h @@ -22,7 +22,7 @@ #define _ARCFOUR_H_ #ifndef byte -#define byte unsigned char +#define byte quint8 #endif class CArcFour{ diff --git a/src/crypto/blowfish.h b/src/crypto/blowfish.h index 06bce4b..d9d1932 100644 --- a/src/crypto/blowfish.h +++ b/src/crypto/blowfish.h @@ -37,7 +37,9 @@ using std::string; #define uint8_t quint8 #define uint16_t quint16 #define uint32_t quint32 +#ifndef byte #define byte quint8 +#endif /** blowfish encryption algorithm. * Derived from libgcrypt-1.1.12 diff --git a/src/crypto/twofish.h b/src/crypto/twofish.h index 0d0d2f7..53e9624 100644 --- a/src/crypto/twofish.h +++ b/src/crypto/twofish.h @@ -180,4 +180,4 @@ extern void Twofish_decrypt( Twofish_Byte p[16] ); -#endif \ No newline at end of file +#endif diff --git a/src/crypto/yarrow.cpp b/src/crypto/yarrow.cpp index 92b60d6..3397435 100644 --- a/src/crypto/yarrow.cpp +++ b/src/crypto/yarrow.cpp @@ -400,12 +400,9 @@ void initYarrow(){ yarrow256_init(&WeakCtx,2,WeakSrc); yarrow256_init(&StrongCtx,2,StrongSrc); quint8 buffer[100]; - srand(time(0)); - for(int i=0;i<100;i++) - buffer[i]=rand()%256+1; + getRandomBytes(buffer,100); yarrow256_update(&WeakCtx,0,800,100,buffer); - for(int i=0;i<100;i++) - buffer[i]=rand()%256+1; + getRandomBytes(buffer,100); yarrow256_update(&WeakCtx,1,800,100,buffer); Q_ASSERT(yarrow256_is_seeded(&WeakCtx)); } @@ -429,8 +426,7 @@ void reseedStrongPool(quint8* buffer1,int l1,quint8* buffer2,int l2){ buffer1=buffer1+100; l1=l1-100; } - else - { + else{ yarrow256_update(&StrongCtx,1,100,25,buffer2); buffer2=buffer2+25; l2=l2-25; diff --git a/src/dialogs/PasswordDlg.h b/src/dialogs/PasswordDlg.h index 18abb91..d64a251 100644 --- a/src/dialogs/PasswordDlg.h +++ b/src/dialogs/PasswordDlg.h @@ -43,9 +43,9 @@ public: }; enum DlgExit { - Exit_Ok, - Exit_Cancel, - Exit_Quit + Exit_Ok=QDialog::Accepted, + Exit_Cancel=QDialog::Rejected, + Exit_Quit=3 }; typedef bool (KeyFileGenProc)(const QString& filename,QString* error); diff --git a/src/import/Import_PwManager.cpp b/src/import/Import_PwManager.cpp index 55dbd03..99801e5 100644 --- a/src/import/Import_PwManager.cpp +++ b/src/import/Import_PwManager.cpp @@ -31,7 +31,7 @@ bool Import_PwManager::importDatabase(QWidget* GuiParent, IDatabase* db){ char* buffer=NULL; int offset=0; int len=0; - if(len=file->size()){ + if((len=file->size())){ buffer=new char[len]; } else { diff --git a/src/keepassx.h b/src/keepassx.h index 4abd98e..10a87b0 100644 --- a/src/keepassx.h +++ b/src/keepassx.h @@ -34,60 +34,62 @@ #ifdef __cplusplus +#include #include + +#include #include #include -#include -#include -#include -#include -#include + +#include #include +#include #include -#include +#include +#include +#include #include -#include -#include +#include +#include #include +#include +#include +#include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include +#include #include +#include +#include +#include +#include #include -#include +#include #include +#include +#include "crypto/aescpp.h" +#include "crypto/arcfour.h" #include "crypto/blowfish.h" #include "crypto/sha1.h" -#include "crypto/twoclass.h" -#include "crypto/aescpp.h" #include "crypto/sha256.h" +#include "crypto/twoclass.h" #include "crypto/yarrow.h" -#include "crypto/arcfour.h" +#include "lib/bookmarks.h" +#include "lib/FileDialogs.h" #include "lib/random.h" #include "lib/SecString.h" #include "lib/tools.h" -#include "lib/FileDialogs.h" -#include "lib/bookmarks.h" #include "lib/UrlLabel.h" -#include "KpxConfig.h" #include "Database.h" +#include "KpxConfig.h" extern QString PluginLoadError; extern KpxConfig *config; @@ -99,4 +101,4 @@ extern QString DetailViewTemplate; extern QPixmap *EntryIcons; #endif //__cplusplus -#endif //KEEPASS_X_ \ No newline at end of file +#endif //KEEPASS_X_ diff --git a/src/lib/random.cpp b/src/lib/random.cpp index 755cfe6..6e08103 100644 --- a/src/lib/random.cpp +++ b/src/lib/random.cpp @@ -19,29 +19,44 @@ ***************************************************************************/ #include #include -#include -#include #include "random.h" -using namespace std; -void getRandomBytes(void* buffer,int NumBlocks,int BlockSize,bool Strong){ -FILE *dev_random; -if(Strong){ -dev_random = fopen("/dev/random","r");} -else{ -dev_random = fopen("/dev/urandom","r");} +#if defined(Q_WS_WIN) + #include +#include + #include +#endif + +using namespace std; -if (dev_random==NULL){ - srand(QTime(0,0,0).secsTo(QTime::currentTime())); - for(int i=0;i=QSysInfo::WV_XP){ + bool success=false; + HMODULE hLib=LoadLibraryA("ADVAPI32.DLL"); + if (hLib) { + BOOLEAN (APIENTRY *pfn)(void*, ULONG) = (BOOLEAN (APIENTRY *)(void*,ULONG))GetProcAddress(hLib,"SystemFunction036"); + if (pfn && pfn(buffer,NumBlocks)) { + success=true; + } + FreeLibrary(hLib); + } + if (success) + return; + } +#else + FILE* dev_random = fopen("/dev/random","r"); + if (dev_random){ + size_t bytesRead = fread(buffer,1,NumBlocks,dev_random); + fclose(dev_random); + if (bytesRead==NumBlocks) + return; + } +#endif + + srand(time(NULL)); + for(int i=0;i #include "main.h" -void initAppPaths(){ +void initAppPaths(int argc,char** argv){ AppDir = QApplication::applicationDirPath(); HomeDir = QString::fromLocal8Bit(qgetenv("APPDATA").constData());