]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/rcracki_mt/rcrackiThread.cpp
remove old deprecated rcracki
[freerainbowtables] / Client Applications / rcracki_mt / rcrackiThread.cpp
index 9dc1f14f535015c6ca0cf8b5a3da778555c9b90d..8123ba5d11d632a531c44fa94beefe31fd117315 100644 (file)
-#ifdef _WIN32
-       #pragma warning(disable : 4786 4267 4018)
-#endif
-
-#include "rcrackiThread.h"
-
-// create job for pre-calculation
-rcrackiThread::rcrackiThread(unsigned char* TargetHash, int thread_id, int nRainbowChainLen, int thread_count, uint64* pStartPosIndexE)
-{
-       t_TargetHash = TargetHash;
-       t_nRainbowChainLen = nRainbowChainLen;
-       t_ID = thread_id;
-       t_count = thread_count;
-       t_pStartPosIndexE = pStartPosIndexE;
-       t_nChainWalkStep = 0;
-       falseAlarmChecker = false;
-       falseAlarmCheckerO = false;
-}
-
-// create job for false alarm checking
-rcrackiThread::rcrackiThread(unsigned char* pHash)
-{
-       falseAlarmChecker = true;
-       falseAlarmCheckerO = false;
-       t_pChainsFound.clear();
-       t_nGuessedPoss.clear();
-       t_pHash = pHash;
-       t_nChainWalkStepDueToFalseAlarm = 0;
-       t_nFalseAlarm = 0;
-       foundHash = false;
-}
-
-// create job for false alarm checking OLD format
-rcrackiThread::rcrackiThread(unsigned char* pHash, bool oldFormat)
-{
-       falseAlarmChecker = true;
-       falseAlarmCheckerO = true;
-       t_pChainsFoundO.clear();
-       t_nGuessedPoss.clear();
-       t_pHash = pHash;
-       t_nChainWalkStepDueToFalseAlarm = 0;
-       t_nFalseAlarm = 0;
-       foundHash = false;
-}
-
-
-void rcrackiThread::AddAlarmCheck(RainbowChain* pChain, int nGuessedPos)
-{
-       t_pChainsFound.push_back(pChain);
-       t_nGuessedPoss.push_back(nGuessedPos);
-}
-
-void rcrackiThread::AddAlarmCheckO(RainbowChainO* pChain, int nGuessedPos)
-{
-       t_pChainsFoundO.push_back(pChain);
-       t_nGuessedPoss.push_back(nGuessedPos);
-}
-
-// Windows (beginthreadex) way of threads
-//unsigned __stdcall rcrackiThread::rcrackiThreadStaticEntryPoint(void * pThis)
-//{
-//     rcrackiThread* pTT = (rcrackiThread*)pThis;
-//     pTT->rcrackiThreadEntryPoint();
-//     _endthreadex( 2 );
-//     return 2;
-//}
-
-// entry point for the posix thread
-void * rcrackiThread::rcrackiThreadStaticEntryPointPthread(void * pThis)
-{
-       rcrackiThread* pTT = (rcrackiThread*)pThis;
-       pTT->rcrackiThreadEntryPoint();
-       pthread_exit(NULL);
-       return NULL;
-}
-
-// start processing of jobs
-void rcrackiThread::rcrackiThreadEntryPoint()
-{
-       if (falseAlarmChecker) {
-               if (falseAlarmCheckerO) {
-                       CheckAlarmO();
-               }
-               else {
-                       CheckAlarm();
-               }
-       }
-       else {
-               PreCalculate();
-       }
-}
-
-uint64 rcrackiThread::GetIndex(int nPos)
-{
-       uint64 t_index = t_vStartPosIndexE[nPos - t_ID];
-       return t_index;
-}
-
-int rcrackiThread::GetChainWalkStep()
-{
-       return t_nChainWalkStep;
-}
-
-int rcrackiThread::GetIndexCount()
-{
-       return t_vStartPosIndexE.size();
-}
-
-rcrackiThread::~rcrackiThread(void)
-{
-}
-
-void rcrackiThread::PreCalculate()
-{
-       for (t_nPos = t_nRainbowChainLen - 2 - t_ID; t_nPos >= 0; t_nPos -= t_count)
-       {
-               t_cwc.SetHash(t_TargetHash);
-               t_cwc.HashToIndex(t_nPos);
-               int i;
-               for (i = t_nPos + 1; i <= t_nRainbowChainLen - 2; i++)
-               //for (i = t_nPos + 1; i <= 10; i++)
-               {
-                       t_cwc.IndexToPlain();
-                       t_cwc.PlainToHash();
-                       t_cwc.HashToIndex(i);
-               }
-               t_pStartPosIndexE[t_nPos] = t_cwc.GetIndex();
-               t_nChainWalkStep += t_nRainbowChainLen - 2 - t_nPos;
-       }
-}
-
-void rcrackiThread::CheckAlarm()
-{
-       int i;
-       for (i = 0; i < t_pChainsFound.size(); i++)
-       {
-               RainbowChain* t_pChain = t_pChainsFound[i];
-               int t_nGuessedPos = t_nGuessedPoss[i];          
-               
-               CChainWalkContext cwc;
-               //uint64 nIndexS = t_pChain->nIndexS & 0x0000FFFFFFFFFFFF; // for first 6 bytes
-               //uint64 nIndexS = t_pChain->nIndexS >> 16;
-               uint64 nIndexS = t_pChain->nIndexS & 0x0000FFFFFFFFFFFFULL; // for first 6 bytes
-               cwc.SetIndex(nIndexS);
-               //cwc.SetIndex(t_pChain->nIndexS);      
-               int nPos;
-               for (nPos = 0; nPos < t_nGuessedPos; nPos++)
-               {
-                       cwc.IndexToPlain();
-                       cwc.PlainToHash();
-                       cwc.HashToIndex(nPos);
-               }
-               cwc.IndexToPlain();
-               cwc.PlainToHash();
-               if (cwc.CheckHash(t_pHash))
-               {
-                       t_Hash = cwc.GetHash();
-                       t_Plain = cwc.GetPlain();
-                       t_Binary = cwc.GetBinary();
-
-                       foundHash = true;
-                       break;
-               }
-               else {
-                       foundHash = false;
-                       t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1;
-                       t_nFalseAlarm++;
-               }
-       }
-}
-
-void rcrackiThread::CheckAlarmO()
-{
-       int i;
-       for (i = 0; i < t_pChainsFoundO.size(); i++)
-       {
-               RainbowChainO* t_pChain = t_pChainsFoundO[i];
-               int t_nGuessedPos = t_nGuessedPoss[i];          
-               
-               CChainWalkContext cwc;
-
-               uint64 nIndexS = t_pChain->nIndexS;
-               cwc.SetIndex(nIndexS);
-
-               int nPos;
-               for (nPos = 0; nPos < t_nGuessedPos; nPos++)
-               {
-                       cwc.IndexToPlain();
-                       cwc.PlainToHash();
-                       cwc.HashToIndex(nPos);
-               }
-               cwc.IndexToPlain();
-               cwc.PlainToHash();
-               if (cwc.CheckHash(t_pHash))
-               {
-                       t_Hash = cwc.GetHash();
-                       t_Plain = cwc.GetPlain();
-                       t_Binary = cwc.GetBinary();
-
-                       foundHash = true;
-                       break;
-               }
-               else {
-                       foundHash = false;
-                       t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1;
-                       t_nFalseAlarm++;
-               }
-       }
-}
-
-bool rcrackiThread::FoundHash()
-{
-       return foundHash;
-}
-
-int rcrackiThread::GetChainWalkStepDueToFalseAlarm()
-{
-       return t_nChainWalkStepDueToFalseAlarm;
-}
-
-int rcrackiThread::GetnFalseAlarm()
-{
-       return t_nFalseAlarm;
-}
-
-string rcrackiThread::GetHash()
-{
-       return t_Hash;
-}
-
-string rcrackiThread::GetPlain()
-{
-       return t_Plain;
-}
-
-string rcrackiThread::GetBinary()
-{
-       return t_Binary;
-}
+/*\r
+ * rcracki_mt is a multithreaded implementation and fork of the original \r
+ * RainbowCrack\r
+ *\r
+ * Copyright 2009, 2010 DaniĆ«l Niggebrugge <niggebrugge@fox-it.com>\r
+ * Copyright 2009, 2010 James Nobis <frt@quelrod.net>\r
+ *\r
+ * This file is part of racrcki_mt.\r
+ *\r
+ * rcracki_mt is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * rcracki_mt is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with rcracki_mt.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+\r
+#ifdef _WIN32\r
+       #pragma warning(disable : 4786 4267 4018)\r
+#endif\r
+\r
+#include "rcrackiThread.h"\r
+\r
+// create job for pre-calculation\r
+rcrackiThread::rcrackiThread(unsigned char* TargetHash, int thread_id, int nRainbowChainLen, int thread_count, uint64* pStartPosIndexE)\r
+{\r
+       t_TargetHash = TargetHash;\r
+       t_nRainbowChainLen = nRainbowChainLen;\r
+       t_ID = thread_id;\r
+       t_count = thread_count;\r
+       t_pStartPosIndexE = pStartPosIndexE;\r
+       t_nChainWalkStep = 0;\r
+       falseAlarmChecker = false;\r
+       falseAlarmCheckerO = false;\r
+}\r
+\r
+// create job for false alarm checking\r
+rcrackiThread::rcrackiThread(unsigned char* pHash, bool oldFormat)\r
+{\r
+       falseAlarmChecker = true;\r
+       falseAlarmCheckerO = oldFormat;\r
+       t_pChainsFound.clear();\r
+       t_nGuessedPoss.clear();\r
+       t_pHash = pHash;\r
+       t_nChainWalkStepDueToFalseAlarm = 0;\r
+       t_nFalseAlarm = 0;\r
+       foundHash = false;\r
+}\r
+\r
+void rcrackiThread::AddAlarmCheck(RainbowChain* pChain, int nGuessedPos)\r
+{\r
+       t_pChainsFound.push_back(pChain);\r
+       t_nGuessedPoss.push_back(nGuessedPos);\r
+}\r
+\r
+void rcrackiThread::AddAlarmCheckO(RainbowChainO* pChain, int nGuessedPos)\r
+{\r
+       t_pChainsFoundO.push_back(pChain);\r
+       t_nGuessedPoss.push_back(nGuessedPos);\r
+}\r
+\r
+// Windows (beginthreadex) way of threads\r
+//unsigned __stdcall rcrackiThread::rcrackiThreadStaticEntryPoint(void * pThis)\r
+//{\r
+//     rcrackiThread* pTT = (rcrackiThread*)pThis;\r
+//     pTT->rcrackiThreadEntryPoint();\r
+//     _endthreadex( 2 );\r
+//     return 2;\r
+//}\r
+\r
+// entry point for the posix thread\r
+void * rcrackiThread::rcrackiThreadStaticEntryPointPthread(void * pThis)\r
+{\r
+       rcrackiThread* pTT = (rcrackiThread*)pThis;\r
+       pTT->rcrackiThreadEntryPoint();\r
+       pthread_exit(NULL);\r
+       return NULL;\r
+}\r
+\r
+// start processing of jobs\r
+void rcrackiThread::rcrackiThreadEntryPoint()\r
+{\r
+       if (falseAlarmChecker) {\r
+               if (falseAlarmCheckerO) {\r
+                       CheckAlarmO();\r
+               }\r
+               else {\r
+                       CheckAlarm();\r
+               }\r
+       }\r
+       else {\r
+               PreCalculate();\r
+       }\r
+}\r
+\r
+uint64 rcrackiThread::GetIndex(int nPos)\r
+{\r
+       uint64 t_index = t_vStartPosIndexE[nPos - t_ID];\r
+       return t_index;\r
+}\r
+\r
+int rcrackiThread::GetChainWalkStep()\r
+{\r
+       return t_nChainWalkStep;\r
+}\r
+\r
+int rcrackiThread::GetIndexCount()\r
+{\r
+       return t_vStartPosIndexE.size();\r
+}\r
+\r
+rcrackiThread::~rcrackiThread(void)\r
+{\r
+}\r
+\r
+void rcrackiThread::PreCalculate()\r
+{\r
+       for (t_nPos = t_nRainbowChainLen - 2 - t_ID; t_nPos >= 0; t_nPos -= t_count)\r
+       {\r
+               t_cwc.SetHash(t_TargetHash);\r
+               t_cwc.HashToIndex(t_nPos);\r
+               int i;\r
+               for (i = t_nPos + 1; i <= t_nRainbowChainLen - 2; i++)\r
+               {\r
+                       t_cwc.IndexToPlain();\r
+                       t_cwc.PlainToHash();\r
+                       t_cwc.HashToIndex(i);\r
+               }\r
+               t_pStartPosIndexE[t_nPos] = t_cwc.GetIndex();\r
+               t_nChainWalkStep += t_nRainbowChainLen - 2 - t_nPos;\r
+       }\r
+}\r
+\r
+void rcrackiThread::CheckAlarm()\r
+{\r
+       UINT4 i;\r
+       for (i = 0; i < t_pChainsFound.size(); i++)\r
+       {\r
+               RainbowChain* t_pChain = t_pChainsFound[i];\r
+               int t_nGuessedPos = t_nGuessedPoss[i];          \r
+               \r
+               CChainWalkContext cwc;\r
+               //uint64 nIndexS = t_pChain->nIndexS & 0x0000FFFFFFFFFFFF; // for first 6 bytes\r
+               //uint64 nIndexS = t_pChain->nIndexS >> 16;\r
+               uint64 nIndexS = t_pChain->nIndexS & 0x0000FFFFFFFFFFFFULL; // for first 6 bytes\r
+               cwc.SetIndex(nIndexS);\r
+               //cwc.SetIndex(t_pChain->nIndexS);      \r
+               int nPos;\r
+               for (nPos = 0; nPos < t_nGuessedPos; nPos++)\r
+               {\r
+                       cwc.IndexToPlain();\r
+                       cwc.PlainToHash();\r
+                       cwc.HashToIndex(nPos);\r
+               }\r
+               cwc.IndexToPlain();\r
+               cwc.PlainToHash();\r
+               if (cwc.CheckHash(t_pHash))\r
+               {\r
+                       t_Hash = cwc.GetHash();\r
+                       t_Plain = cwc.GetPlain();\r
+                       t_Binary = cwc.GetBinary();\r
+\r
+                       foundHash = true;\r
+                       break;\r
+               }\r
+               else {\r
+                       foundHash = false;\r
+                       t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1;\r
+                       t_nFalseAlarm++;\r
+               }\r
+       }\r
+}\r
+\r
+void rcrackiThread::CheckAlarmO()\r
+{\r
+       UINT4 i;\r
+       for (i = 0; i < t_pChainsFoundO.size(); i++)\r
+       {\r
+               RainbowChainO* t_pChain = t_pChainsFoundO[i];\r
+               int t_nGuessedPos = t_nGuessedPoss[i];          \r
+               \r
+               CChainWalkContext cwc;\r
+\r
+               uint64 nIndexS = t_pChain->nIndexS;\r
+               cwc.SetIndex(nIndexS);\r
+\r
+               int nPos;\r
+               for (nPos = 0; nPos < t_nGuessedPos; nPos++)\r
+               {\r
+                       cwc.IndexToPlain();\r
+                       cwc.PlainToHash();\r
+                       cwc.HashToIndex(nPos);\r
+               }\r
+               cwc.IndexToPlain();\r
+               cwc.PlainToHash();\r
+               if (cwc.CheckHash(t_pHash))\r
+               {\r
+                       t_Hash = cwc.GetHash();\r
+                       t_Plain = cwc.GetPlain();\r
+                       t_Binary = cwc.GetBinary();\r
+\r
+                       foundHash = true;\r
+                       break;\r
+               }\r
+               else {\r
+                       foundHash = false;\r
+                       t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1;\r
+                       t_nFalseAlarm++;\r
+               }\r
+       }\r
+}\r
+\r
+bool rcrackiThread::FoundHash()\r
+{\r
+       return foundHash;\r
+}\r
+\r
+int rcrackiThread::GetChainWalkStepDueToFalseAlarm()\r
+{\r
+       return t_nChainWalkStepDueToFalseAlarm;\r
+}\r
+\r
+int rcrackiThread::GetnFalseAlarm()\r
+{\r
+       return t_nFalseAlarm;\r
+}\r
+\r
+string rcrackiThread::GetHash()\r
+{\r
+       return t_Hash;\r
+}\r
+\r
+string rcrackiThread::GetPlain()\r
+{\r
+       return t_Plain;\r
+}\r
+\r
+string rcrackiThread::GetBinary()\r
+{\r
+       return t_Binary;\r
+}\r