-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.h
120 lines (106 loc) · 4.17 KB
/
functions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
SHA1BruteForce, brute-force attack to recover SHA-1 hashed password.
Copyright (C) 2017 Clément Février
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Contact informations:
Email
Post address
4 impasse de l'Abbaye
38100 Grenoble
FRANCE
*/
#ifndef _FUNCTIONS_H_
#define _FUNCTIONS_H_
#include <string> // std::string
#include <iostream> // std::cout, ostream (std::endl)
#include <boost/thread.hpp> // boost::thread_group, boost::bind
//#include <crypto++/sha.h>
//#include <crypto++/hex.h>
#include <tomcrypt.h> // sha1_desc, hash_state, sha1_init, sha1_process
/* Hashes a given input string using the SHA-1 algorithm
using libtomcrypt
Parameter:
* The input sequence pointer
Returns:
* A 20 bytes long new[]-allocated pointer
to the resulting data. */
unsigned char * hashSHA1(const auto & input)
{
// Initial
auto * hashResult = new unsigned char [sha1_desc.hashsize];
// Initialize a state variable for the hash
hash_state md;
sha1_init(&md);
// Process the text
sha1_process(&md, (const decltype(hashSHA1(input))) input.c_str(), input.size());
// Finish the hash calculation
sha1_done(&md, hashResult);
// Return the result
return hashResult;
}
/* Return the hash SHA-1 of a string (source)
using Crypto++ */
//std::string generateHash(const auto & source);
/* Seek for password, display the latter if found it
and exit the program.
Parameters:
* hash: The hash to crack.
* pass: Current state of the password to build and test.
* list: List of all allowed characters.
* COUNT: Length of list.
* L: Maximum length of the password to test.
* l: Current length of the password to test.
* N_THREAD: Number of threads to launch. */
void findPasswordThread(const unsigned char * hash, const std::string & pass, const std::string * list, const unsigned char & COUNT, const unsigned char & L, const unsigned char & l, const unsigned char & N_THREAD);
/* Seek for password, display the latter if found it
and exit the program.
This function launch the threads that will do the job.
Depending on the number of threads,
Each thread will test a different subset of possibilities.
As a consequence,
a greater or smaller number of threads can divide
the set of possibilities in a way that it will reach faster
or slower the actual password.
However, there is noway to make an assumption on this number
if there is no assumption on the password.
Thus, the number of thread should be tuned
to maximize device performances,
i.e. the greatest number of operations per second.
Parameters:
* hash: The hash to crack.
* list: List of all allowed characters.
* COUNT: Length of list.
* L: Maximum length of the password to test.
* N_THREAD: Number of threads to launch. */
void findPassword(const auto hash, const auto list, const auto & COUNT, const auto & L, const auto & N_THREAD)
{
// Create a group of threads
boost::thread_group t;
for(unsigned char i = 0; i < COUNT; ++i)
{
// Launch a thread
// Initiate the recursive function with the first letter
t.create_thread(boost::bind(findPasswordThread, hash, list[i], list, COUNT, L, 1, N_THREAD));
// Wait until N_THREAD finish before launching news ones
if((i % N_THREAD) == (N_THREAD - 1))
{
// Do not continue before all launched threads finish
t.join_all();
// Display a progress to standard output
std::cout<<"progress: "<<100 * i / (float)COUNT <<"%"<<std::endl;
}
}
// Wait for remaining threads to finish
t.join_all();
}
#endif