2 * rcracki_mt is a multithreaded implementation and fork of the original
5 * Copyright 2009, 2010 Daniƫl Niggebrugge <niggebrugge@fox-it.com>
6 * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
8 * This file is part of rcracki_mt.
10 * rcracki_mt is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
15 * rcracki_mt is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with rcracki_mt. If not, see <http://www.gnu.org/licenses/>.
24 #if defined(_WIN32) && !defined(__GNUC__)
25 #pragma warning(disable : 4786 4267 4018)
28 #include "rcrackiThread.h"
30 // create job for pre-calculation
31 rcrackiThread::rcrackiThread(unsigned char* TargetHash, int thread_id, int nRainbowChainLen, int thread_count, uint64* pStartPosIndexE)
33 t_TargetHash = TargetHash;
34 t_nRainbowChainLen = nRainbowChainLen;
36 t_count = thread_count;
37 t_pStartPosIndexE = pStartPosIndexE;
39 falseAlarmChecker = false;
40 falseAlarmCheckerO = false;
43 // create job for false alarm checking
44 rcrackiThread::rcrackiThread(unsigned char* pHash, bool oldFormat)
46 falseAlarmChecker = true;
47 falseAlarmCheckerO = oldFormat;
48 t_pChainsFound.clear();
49 t_nGuessedPoss.clear();
51 t_nChainWalkStepDueToFalseAlarm = 0;
56 void rcrackiThread::AddAlarmCheck(RainbowChain* pChain, int nGuessedPos)
58 t_pChainsFound.push_back(pChain);
59 t_nGuessedPoss.push_back(nGuessedPos);
62 void rcrackiThread::AddAlarmCheckO(RainbowChainO* pChain, int nGuessedPos)
64 t_pChainsFoundO.push_back(pChain);
65 t_nGuessedPoss.push_back(nGuessedPos);
68 // Windows (beginthreadex) way of threads
69 //unsigned __stdcall rcrackiThread::rcrackiThreadStaticEntryPoint(void * pThis)
71 // rcrackiThread* pTT = (rcrackiThread*)pThis;
72 // pTT->rcrackiThreadEntryPoint();
77 // entry point for the posix thread
78 void * rcrackiThread::rcrackiThreadStaticEntryPointPthread(void * pThis)
80 rcrackiThread* pTT = (rcrackiThread*)pThis;
81 pTT->rcrackiThreadEntryPoint();
86 // start processing of jobs
87 void rcrackiThread::rcrackiThreadEntryPoint()
89 if (falseAlarmChecker) {
90 if (falseAlarmCheckerO) {
102 uint64 rcrackiThread::GetIndex(int nPos)
104 uint64 t_index = t_vStartPosIndexE[nPos - t_ID];
108 int rcrackiThread::GetChainWalkStep()
110 return t_nChainWalkStep;
113 int rcrackiThread::GetIndexCount()
115 return t_vStartPosIndexE.size();
118 rcrackiThread::~rcrackiThread(void)
122 void rcrackiThread::PreCalculate()
124 for (t_nPos = t_nRainbowChainLen - 2 - t_ID; t_nPos >= 0; t_nPos -= t_count)
126 t_cwc.SetHash(t_TargetHash);
127 t_cwc.HashToIndex(t_nPos);
129 for (i = t_nPos + 1; i <= t_nRainbowChainLen - 2; i++)
131 t_cwc.IndexToPlain();
133 t_cwc.HashToIndex(i);
135 t_pStartPosIndexE[t_nPos] = t_cwc.GetIndex();
136 t_nChainWalkStep += t_nRainbowChainLen - 2 - t_nPos;
140 void rcrackiThread::CheckAlarm()
143 for (i = 0; i < t_pChainsFound.size(); i++)
145 RainbowChain* t_pChain = t_pChainsFound[i];
146 int t_nGuessedPos = t_nGuessedPoss[i];
148 CChainWalkContext cwc;
149 //uint64 nIndexS = t_pChain->nIndexS & 0x0000FFFFFFFFFFFF; // for first 6 bytes
150 //uint64 nIndexS = t_pChain->nIndexS >> 16;
151 uint64 nIndexS = t_pChain->nIndexS & 0x0000FFFFFFFFFFFFULL; // for first 6 bytes
152 cwc.SetIndex(nIndexS);
153 //cwc.SetIndex(t_pChain->nIndexS);
155 for (nPos = 0; nPos < t_nGuessedPos; nPos++)
159 cwc.HashToIndex(nPos);
163 if (cwc.CheckHash(t_pHash))
165 t_Hash = cwc.GetHash();
166 t_Plain = cwc.GetPlain();
167 t_Binary = cwc.GetBinary();
174 t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1;
180 void rcrackiThread::CheckAlarmO()
183 for (i = 0; i < t_pChainsFoundO.size(); i++)
185 RainbowChainO* t_pChain = t_pChainsFoundO[i];
186 int t_nGuessedPos = t_nGuessedPoss[i];
188 CChainWalkContext cwc;
190 uint64 nIndexS = t_pChain->nIndexS;
191 cwc.SetIndex(nIndexS);
194 for (nPos = 0; nPos < t_nGuessedPos; nPos++)
198 cwc.HashToIndex(nPos);
202 if (cwc.CheckHash(t_pHash))
204 t_Hash = cwc.GetHash();
205 t_Plain = cwc.GetPlain();
206 t_Binary = cwc.GetBinary();
213 t_nChainWalkStepDueToFalseAlarm += t_nGuessedPos + 1;
219 bool rcrackiThread::FoundHash()
224 int rcrackiThread::GetChainWalkStepDueToFalseAlarm()
226 return t_nChainWalkStepDueToFalseAlarm;
229 int rcrackiThread::GetnFalseAlarm()
231 return t_nFalseAlarm;
234 string rcrackiThread::GetHash()
239 string rcrackiThread::GetPlain()
244 string rcrackiThread::GetBinary()