]> git.sesse.net Git - freerainbowtables/blob - BOINC software/BOINC client apps/distrrtgen_cuda/rcuda_ext.cpp
merge all the algorithms for distrrtgen_cuda
[freerainbowtables] / BOINC software / BOINC client apps / distrrtgen_cuda / rcuda_ext.cpp
1 //============================================================================
2 // Name        : rcuda_ext.cpp
3 // Author      : Jan Kyska
4 // Version     : 1.00
5 // Description : A code to access internals of the CChainWalkContext 
6 //               for the CUDA generator of FreeRainbowTables
7 //============================================================================ 
8
9 #include "rcuda_ext.h"
10 #include <algorithm>
11 #include <string>
12 #include <time.h>
13 #include <fstream>
14 #include <iostream>
15
16 CudaCWCExtender::CudaCWCExtender(CChainWalkContext *cwc) { 
17         this->cwc = cwc; 
18         hash = rcuda::RHASH_UNDEF;
19 }
20
21 void CudaCWCExtender::Init(void) { 
22         std::string hashName;
23         int ii, jj;
24
25         plainDimVec.clear();
26         plainCharSet.clear();
27
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;
40         else
41                 hash = rcuda::RHASH_UNDEF;
42
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);
51                 }
52         }
53 }
54
55 int CudaCWCExtender::IndexToStartPlain(const uint64 nIndex, std::vector<unsigned char>& stPlain) {
56         int nPlainLen, nCharsetLen;
57         int ii, jj;
58
59         stPlain.clear();
60         stPlain.reserve(0x20);
61         nPlainLen = 0;
62         for(ii = CChainWalkContext::m_nPlainLenMaxTotal - 1; ii >= CChainWalkContext::m_nPlainLenMinTotal - 1; ii--) {
63                 if(nIndex >= CChainWalkContext::m_nPlainSpaceUpToX[ii]) {
64                         nPlainLen = ii + 1;
65                         break;
66                 }
67         }
68         if(nPlainLen == 0)
69                 nPlainLen = CChainWalkContext::m_nPlainLenMinTotal;
70         uint64 nIndexOfX = nIndex - CChainWalkContext::m_nPlainSpaceUpToX[nPlainLen - 1];
71
72         // Slow version, but never mind
73         for(ii = nPlainLen - 1; ii >= 0; ii--) {
74                 nCharsetLen = 0;
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                                 //XXX from md5 only cuda stPlain.push_back(nIndexOfX % chs.m_nPlainCharsetLen + 1);
80                                 stPlain.push_back((unsigned char)(nIndexOfX % (uint64)chs.m_nPlainCharsetLen + 1));
81                                 nIndexOfX /= chs.m_nPlainCharsetLen;
82                         }
83                 }
84         }
85         return stPlain.size();
86 }