]> git.sesse.net Git - freerainbowtables/blob - Common/rt api/ChainWalkContext.h
de7e2fb430373b0fe9260cb226bd0400f9d641da
[freerainbowtables] / Common / rt api / ChainWalkContext.h
1 /*
2    RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
3
4    Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
5 */
6
7 #ifndef _CHAINWALKCONTEXT_H
8 #define _CHAINWALKCONTEXT_H
9
10 #include "HashRoutine.h"
11 #include "Public.h"
12
13 typedef struct 
14 {
15         unsigned char m_PlainCharset[255];
16         int m_nPlainCharsetLen;
17         int m_nPlainLenMin;
18         int m_nPlainLenMax;
19         string m_sPlainCharsetName;
20         string m_sPlainCharsetContent;
21 } stCharset;
22 class CChainWalkContext 
23 {
24 public:
25         CChainWalkContext();
26         virtual ~CChainWalkContext();
27
28 private:
29         static string m_sHashRoutineName;       
30         static HASHROUTINE m_pHashRoutine;                                                      // Configuration
31         static int m_nHashLen;                                                                          // Configuration
32
33 //      static unsigned char m_PlainCharset[256];                                       // Configuration
34 //      static unsigned char m_PlainCharset2[256];                                      // Configuration
35         static vector<stCharset> m_vCharset;
36         static int m_nPlainLenMinTotal, m_nPlainLenMaxTotal;
37         static uint64 m_nPlainSpaceUpToX[MAX_PLAIN_LEN + 1];            // Performance consideration
38         static uint64 m_nPlainSpaceTotal;                                                       // Performance consideration
39         static int m_nHybridCharset;
40         static int m_nRainbowTableIndex;                                                        // Configuration
41         static uint64 m_nReduceOffset;                                                          // Performance consideration
42
43         // Context
44         uint64 m_nIndex;
45         unsigned char m_Plain[MAX_PLAIN_LEN];
46         int m_nPlainLen;
47         unsigned char m_Hash[MAX_HASH_LEN];
48         static unsigned char m_Salt[MAX_SALT_LEN];
49         static int m_nSaltLen;
50 private:
51         static bool LoadCharset(string sCharset);
52
53 public:
54         static bool SetHashRoutine(string sHashRoutineName);                                                                                            // Configuration
55         static bool SetPlainCharset(string sCharsetName, int nPlainLenMin, int nPlainLenMax);                           // Configuration
56         static bool SetRainbowTableIndex(int nRainbowTableIndex);       
57         static bool SetSalt(unsigned char *Salt, int nSaltLength);// Configuration
58         static bool SetupWithPathName(string sPathName, int& nRainbowChainLen, int& nRainbowChainCount);        // Wrapper
59         static string GetHashRoutineName();
60         static int GetHashLen();
61         static string GetPlainCharsetName();
62         static string GetPlainCharsetContent();
63         static int GetPlainLenMin();
64         static int GetPlainLenMax();
65         static uint64 GetPlainSpaceTotal();
66         static int GetRainbowTableIndex();
67         static void Dump();
68
69 //      void GenerateRandomIndex();
70         void SetIndex(uint64 nIndex);
71         void SetHash(unsigned char* pHash);             // The length should be m_nHashLen
72
73         void IndexToPlain();
74         void PlainToHash();
75         void HashToIndex(int nPos);
76
77         uint64 GetIndex();
78         const uint64* GetIndexPtr();
79         string GetPlain();
80         string GetBinary();
81 //      string GetPlainBinary();
82         string GetHash();
83         bool CheckHash(unsigned char* pHash);   // The length should be m_nHashLen
84 };
85
86 #endif