1 /*
2  * freerainbowtables is a project for generating, distributing, and using
3  * perfect rainbow tables
4  *
5  * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
6  * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
7  * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
8  * Copyright 2009, 2010, 2011, 2012 James Nobis <quel@quelrod.net>
9  * Copyright 2011 Logan Watt <logan.watt@gmail.com>
10  *
11  * This file is part of freerainbowtables.
12  *
13  * freerainbowtables is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, version 2 of the License.
16  *
17  * freerainbowtables is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with freerainbowtables.  If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #ifndef _PUBLIC_H
27 #define _PUBLIC_H
28 
29 #define __STDC_FORMAT_MACROS /* for PRI macros */
30 #define __STDC_LIMIT_MACROS /* for uint64_t, UINT64_MAX, etc. */
31 
32 #include "global.h"
33 
34 #include <stdio.h>
35 #include <stdint.h>
36 #if defined(_WIN32) && !defined(__GNUC__)
37 	#include "inttypes.h"
38 #else
39 	#include "/usr/include/inttypes.h"
40 #endif
41 #include <stdlib.h>
42 #include <string.h>
43 #include <math.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 
47 #include <string>
48 #include <vector>
49 #include <list>
50 #include <iterator>
51 #include <iostream>
52 #include <fstream>
53 #include <map>
54 #include <algorithm>
55 
56 #if defined(_WIN32) && !defined(__GNUC__)
57 	#include <io.h>
58 #endif
59 
60 struct RainbowChainO
61 {
62 	uint64_t nIndexS;
63 	uint64_t nIndexE;
64 };
65 
66 #if defined(_WIN32) && !defined(__GNUC__)
67 	#pragma warning(disable: 4201)
68 #endif
69 union RainbowChain
70 {
71 	uint64_t nIndexS;
72 	struct
73 	{
74 		unsigned short foo[3];
75 		unsigned short nIndexE;
76 	};
77 	//int nCheckPoint;
78 };
79 #if defined(_WIN32) && !defined(__GNUC__)
80 	#pragma warning(default : 4201)
81 #endif
82 
83 struct RainbowChainCP
84 {
85 	uint64_t startpt;
86 	uint64_t endpt;
87 	unsigned short checkpts;
88 };
89 
90 struct IndexChain
91 {
92 	uint64_t nPrefix;
93 	uint32_t nFirstChain;
94 	uint32_t nChainCount;
95 };
96 
97 /* rcracki_mt IndexChain
98 #pragma pack(1)
99 union IndexChain
100 {
101 	uint64_t nPrefix; //5
102 	struct
103 	{
104 		unsigned char foo[5];
105 		unsigned int nFirstChain; //4
106 		unsigned short nChainCount; //2
107 	};
108 	//unsigned short nChainCount; (maybe union with nPrefix, 1 byte spoiled, no pack(1) needed)
109 };
110 #pragma pack()
111 */
112 
113 struct IndexRow
114 {
115 	uint64_t prefix;
116 	unsigned int prefixstart, numchains;
117 };
118 
119 typedef struct
120 {
121 	std::string sName;
122 	int nPlainLenMin;
123 	int nPlainLenMax;
124 } tCharset;
125 
126 #define MAX_PLAIN_LEN 256
127 #define MIN_HASH_LEN  8
128 #define MAX_HASH_LEN  256
129 #define MAX_SALT_LEN  256
130 
131 typedef struct
132 {
133 	uint64_t m_nPlainSpaceUpToX[MAX_PLAIN_LEN];		// Performance consideration
134 	//unsigned char m_PlainCharset[255];
135 	unsigned char m_PlainCharset[MAX_PLAIN_LEN];
136 	uint64_t m_nPlainSpaceTotal;
137 	uint64_t m_nIndexX;
138 	unsigned int m_nPlainCharsetLen;
139 	int m_nPlainLenMin;
140 	int m_nPlainLenMax;
141 	std::string m_sPlainCharsetName;
142 	std::string m_sPlainCharsetContent;
143 } stCharset;
144 
145 // XXX nmap is GPL2, will check newer releases regarding license
146 // Code comes from nmap, used for the linux implementation of kbhit()
147 #ifndef _WIN32
148 #include <unistd.h>
149 #include <termios.h>
150 #include <fcntl.h>
151 
152 int tty_getchar();
153 void tty_done();
154 void tty_init();
155 void tty_flush(void);
156 // end nmap code
157 
158 #endif
159 
160 #if defined(_WIN32) && !defined(__GNUC__)
161 	int gettimeofday( struct timeval *tv, struct timezone *tz );
162 #else
163 	#include <sys/time.h>
164 #endif
165 
166 timeval sub_timeofday( timeval tv2, timeval tv );
167 
168 long GetFileLen(FILE* file);
169 long GetFileLen(char* file);
170 long GetFileLen( std::string file );
171 uint8_t getRTfileFormatId( std::string RTfileFormatName );
172 std::string TrimString( std::string s );
173 bool boinc_ReadLinesFromFile( std::string sPathName, std::vector<std::string>& vLine );
174 bool ReadLinesFromFile( std::string sPathName, std::vector<std::string>& vLine);
175 bool SeperateString( std::string s, std::string sSeperator, std::vector<std::string>& vPart);
176 std::string uint64tostr(uint64_t n);
177 std::string uint64tohexstr(uint64_t n);
178 std::string HexToBinary( const char* data, int len );
179 std::string HexToStr(const unsigned char* pData, int nLen);
180 unsigned long GetAvailPhysMemorySize();
181 std::string GetApplicationPath();
182 void ParseHash( std::string sHash, unsigned char* pHash, int& nHashLen );
183 bool GetHybridCharsets( std::string sCharset, std::vector<tCharset>& vCharset );
184 void Logo();
185 bool writeResultLineToFile( std::string sOutputFile, std::string sHash, std::string sPlain, std::string sBinary );
186 
187 #endif
188