1 //============================================================================
2 // Name : rcuda_ext.cpp
5 // Description : A code to access internals of the CChainWalkContext
6 // for the CUDA generator of FreeRainbowTables
7 //============================================================================
16 CudaCWCExtender::CudaCWCExtender(CChainWalkContext *cwc) {
18 hash = rcuda::RHASH_UNDEF;
21 void CudaCWCExtender::Init(void) {
28 hashName = CChainWalkContext::m_sHashRoutineName;
29 std::transform(hashName.begin(), hashName.end(), hashName.begin(), ::tolower);
30 if(hashName.compare("lm") == 0)
31 hash = rcuda::RHASH_LM;
32 else if(hashName.compare("md4") == 0)
33 hash = rcuda::RHASH_MD4;
34 else if(hashName.compare("md5") == 0)
35 hash = rcuda::RHASH_MD5;
36 else if(hashName.compare("sha1") == 0)
37 hash = rcuda::RHASH_SHA1;
38 else if(hashName.compare("ntlm") == 0)
39 hash = rcuda::RHASH_NTLM;
41 hash = rcuda::RHASH_UNDEF;
43 for(ii = 0; ii < (int)CChainWalkContext::m_vCharset.size(); ii++) {
44 stCharset &chs = CChainWalkContext::m_vCharset[ii];
45 int chSetOffset = plainCharSet.size();
46 plainCharSet.append((char*)chs.m_PlainCharset, chs.m_nPlainCharsetLen);
47 for(jj = 0; jj < chs.m_nPlainLenMax; jj++) {
48 plainDimVec.push_back((unsigned int)chs.m_nPlainCharsetLen);
49 plainDimVec.push_back((unsigned int)-1/(unsigned int)chs.m_nPlainCharsetLen);
50 plainDimVec.push_back((unsigned int)chSetOffset);
55 int CudaCWCExtender::IndexToStartPlain(const uint64 nIndex, std::vector<unsigned char>& stPlain) {
56 int nPlainLen, nCharsetLen;
60 stPlain.reserve(0x20);
62 for(ii = CChainWalkContext::m_nPlainLenMaxTotal - 1; ii >= CChainWalkContext::m_nPlainLenMinTotal - 1; ii--) {
63 if(nIndex >= CChainWalkContext::m_nPlainSpaceUpToX[ii]) {
69 nPlainLen = CChainWalkContext::m_nPlainLenMinTotal;
70 uint64 nIndexOfX = nIndex - CChainWalkContext::m_nPlainSpaceUpToX[nPlainLen - 1];
72 // Slow version, but never mind
73 for(ii = nPlainLen - 1; ii >= 0; ii--) {
75 for(jj = 0; jj < (int)CChainWalkContext::m_vCharset.size(); jj++) {
76 stCharset &chs = CChainWalkContext::m_vCharset[jj];
77 nCharsetLen += chs.m_nPlainLenMax;
78 if(ii < nCharsetLen) { // We found the correct charset
79 stPlain.push_back(nIndexOfX % chs.m_nPlainCharsetLen + 1);
80 nIndexOfX /= chs.m_nPlainCharsetLen;
84 return stPlain.size();