]> git.sesse.net Git - freerainbowtables/blob - BOINC software/BOINC client apps/distrrtgen_flash/distrrtgen.cpp
updated distrrtgen_flash
[freerainbowtables] / BOINC software / BOINC client apps / distrrtgen_flash / distrrtgen.cpp
1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17
18 // This program serves as both
19 // - An example BOINC application, illustrating the use of the BOINC API
20 // - A program for testing various features of BOINC
21 //
22 // NOTE: this file exists as both
23 // boinc/apps/upper_case.C
24 // and
25 // boinc_samples/example_app/uc2.C
26 // If you update one, please update the other!
27
28 // The program converts a mixed-case file to upper case:
29 // read "in", convert to upper case, write to "out"
30 //
31 // command line options
32 // -run_slow: sleep 1 second after each character
33 // -cpu_time N: use about N CPU seconds after copying files
34 // -early_exit: exit(10) after 30 chars
35 // -early_crash: crash after 30 chars
36 //
37
38 #ifdef _WIN32
39
40 #else
41 #include <cstdio>
42 #include <cctype>
43 #include <ctime>
44 #include <cstring>
45 #include <cstdlib>
46 #include <csignal>
47 #include <unistd.h>
48 #endif
49
50 #include <string>
51 #include <fstream>
52 #include <iostream>
53 #include <time.h>
54 #include "Public.h"
55 // Rainbowcrack code
56 #include "ChainWalkContext.h"
57 typedef unsigned int uint32;
58 //typedef unsigned __int64 uint64;
59
60
61 using std::string;
62
63 /*
64 bool early_exit = false;
65 bool early_crash = false;
66 bool early_sleep = false;
67 double cpu_time = 20, comp_result;
68 */
69 int main(int argc, char **argv) {    
70     int retval;
71     double fd;
72         
73
74         if(argc < 10)
75         {
76                 fprintf(stderr, "Not enough parameters");
77                 return -1;
78         }
79         string sHashRoutineName, sCharsetName, sSalt, sCheckPoints;
80         uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen;
81         uint64 nChainStart;
82         sHashRoutineName = argv[1];
83         sCharsetName = argv[2];
84         nPlainLenMin = atoi(argv[3]);
85         nPlainLenMax = atoi(argv[4]);
86         nRainbowTableIndex = atoi(argv[5]);
87         nRainbowChainLen = atoi(argv[6]);
88         nRainbowChainCount = atoi(argv[7]);
89 #ifdef _WIN32
90
91         nChainStart = _atoi64(argv[8]);
92
93 #else
94         nChainStart = atoll(argv[8]);
95 #endif
96         sCheckPoints = argv[9];
97         vector<int> vCPPositions;
98         char *cp = strtok((char *)sCheckPoints.c_str(), ",");
99         while(cp != NULL)
100         {
101                 vCPPositions.push_back(atoi(cp));
102                 cp = strtok(NULL, ",");
103         }
104         if(argc == 11)
105         {
106                 sSalt = argv[10];
107         }
108         //std::cout << "Starting ChainGenerator" << std::endl;
109         // Setup CChainWalkContext
110         //std::cout << "ChainGenerator started." << std::endl;
111
112         if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
113         {
114                 fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str());
115                 return 1;
116         }
117         //std::cout << "Hash routine validated" << std::endl;
118
119         if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
120         {       
121                 std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
122                 return 2;
123         }
124         //std::cout << "Plain charset validated" << std::endl;
125
126         if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
127         {
128                 std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
129                 return 3;
130         }
131         //std::cout << "Rainbowtable index validated" << std::endl;
132
133         if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall")
134         {
135                 // Convert username to unicode
136                 const char *szSalt = sSalt.c_str();
137                 int salt_length = strlen(szSalt);
138                 unsigned char cur_salt[256];
139                 for (int i=0; i<salt_length; i++)
140                 {
141                         cur_salt[i*2] = szSalt[i];
142                         cur_salt[i*2+1] = 0x00;
143                 }
144                 CChainWalkContext::SetSalt(cur_salt, salt_length*2);
145         }
146         else if(sHashRoutineName == "halflmchall")
147         { // The salt is hardcoded into the hash routine
148         //      CChainWalkContext::SetSalt((unsigned char*)&salt, 8);
149         }
150         else if(sHashRoutineName == "oracle")
151         {
152                 CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length());
153         }
154         //std::cout << "Opening chain file" << std::endl;
155
156         
157         
158         // Check existing chains
159         size_t nReturn;
160         CChainWalkContext cwc;
161         uint64 nIndex[2];
162         time_t tStart = time(NULL);
163 //      std::cout << "Starting to generate chains" << std::endl;
164         for(int nCurrentCalculatedChains = 0; nCurrentCalculatedChains < nRainbowChainCount; nCurrentCalculatedChains++)
165         {               
166                 int cpcheck = 0;
167                 unsigned short checkpoint = 0;
168                 fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount;
169                 cwc.SetIndex(nChainStart++); // use a given index now!
170                 nIndex[0] = cwc.GetIndex();
171                 
172                 for (int nPos = 0; nPos < nRainbowChainLen - 1; nPos++)
173                 {
174                 //      std::cout << "IndexToPlain()" << std::endl;
175                         cwc.IndexToPlain();
176                 //      std::cout << "PlainToHash()" << std::endl;
177                         cwc.PlainToHash();
178                 //      std::cout << "HashToIndex()" << std::endl;
179                         cwc.HashToIndex(nPos);
180                         if(cpcheck < vCPPositions.size() && nPos == vCPPositions[cpcheck])
181                         {
182                                 
183                                 checkpoint |= (1 << cpcheck) & (unsigned short)cwc.GetIndex() << cpcheck;
184                                 cpcheck++;
185                         }
186                 }
187                 //std::cout << "GetIndex()" << std::endl;
188
189                 nIndex[1] = cwc.GetIndex();
190                 // Write chain to disk
191         }
192         //std::cout << "Generation completed" << std::endl;
193
194     
195         // main loop - read characters, convert to UC, write
196     //
197
198 }
199