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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
//
// Creator: http://www.dicelocksecurity.com
// Version: vers.5.0.0.1
//
// Copyright 2009-2011 DiceLock Security, LLC. All rights reserved.
//
// DISCLAIMER
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// DICELOCK IS A REGISTERED TRADEMARK OR TRADEMARK OF THE OWNERS.
//
#include <stdexcept>
#include <stdlib.h>
#include "hashSuite.h"
using namespace std;
namespace DiceLockSecurity {
namespace Hash {
// Points the first hash in the suite
const Hashes HashSuite::firstHash = SHA_1;
// Constructor, default, initializes suite
HashSuite::HashSuite() {
int i;
for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
this->suite[i] = NULL;
this->selfCreatedHash[i] = false;
}
this->instantiatedHashes = 0;
}
// Destructor
HashSuite::~HashSuite() {
int i;
for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
if (this->suite[i] != NULL) {
delete this->suite[i];
this->suite[i] = NULL;
this->selfCreatedHash[i] = false;
}
}
this->instantiatedHashes = 0;
}
// ADDING HASHES
// Adds a random test to the suite
void HashSuite::Add(BaseHash* hash) {
if (hash != NULL) {
this->suite[hash->GetType()] = hash;
this->selfCreatedHash[hash->GetType()] = false;
this->instantiatedHashes++;
}
}
// Creates and adds a random test to the suite based in the enumerated random tests
void HashSuite::Add(Hashes hash) {
switch (hash) {
case SHA_1:
if (this->suite[SHA_1] == NULL) {
this->suite[SHA_1] = new Sha1();
this->instantiatedHashes++;
}
break;
case SHA_224:
if (this->suite[SHA_224] == NULL) {
this->suite[SHA_224] = new Sha224();
this->instantiatedHashes++;
}
break;
case SHA_256:
if (this->suite[SHA_256] == NULL) {
this->suite[SHA_256] = new Sha256();
this->instantiatedHashes++;
}
break;
case SHA_384:
if (this->suite[SHA_384] == NULL) {
this->suite[SHA_384] = new Sha384();
this->instantiatedHashes++;
}
break;
case SHA_512:
if (this->suite[SHA_512] == NULL) {
this->suite[SHA_512] = new Sha512();
this->instantiatedHashes++;
}
break;
case RIPEMD_128:
if (this->suite[RIPEMD_128] == NULL) {
this->suite[RIPEMD_128] = new Ripemd128();
this->instantiatedHashes++;
}
break;
case RIPEMD_160:
if (this->suite[RIPEMD_160] == NULL) {
this->suite[RIPEMD_160] = new Ripemd160();
this->instantiatedHashes++;
}
break;
case RIPEMD_256:
if (this->suite[RIPEMD_256] == NULL) {
this->suite[RIPEMD_256] = new Ripemd256();
this->instantiatedHashes++;
}
break;
case RIPEMD_320:
if (this->suite[RIPEMD_320] == NULL) {
this->suite[RIPEMD_320] = new Ripemd320();
this->instantiatedHashes++;
}
break;
default:
break;
}
this->selfCreatedHash[hash] = true;
}
// Creates and adds all hash algorithms to the suite
void HashSuite::AddAll(void) {
int i;
this->suite[SHA_1] = new Sha1();
this->suite[SHA_224] = new Sha224();
this->suite[SHA_256] = new Sha256();
this->suite[SHA_384] = new Sha384();
this->suite[SHA_512] = new Sha512();
this->suite[RIPEMD_128] = new Ripemd128();
this->suite[RIPEMD_160] = new Ripemd160();
this->suite[RIPEMD_256] = new Ripemd256();
this->suite[RIPEMD_320] = new Ripemd320();
for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
this->selfCreatedHash[i] = true;
}
this->instantiatedHashes = NumberOfHashes;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddSha1(void) {
this->suite[SHA_1] = new Sha1();
this->selfCreatedHash[SHA_1] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddSha224(void) {
this->suite[SHA_224] = new Sha224();
this->selfCreatedHash[SHA_224] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddSha256(void) {
this->suite[SHA_256] = new Sha256();
this->selfCreatedHash[SHA_256] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddSha384(void) {
this->suite[SHA_384] = new Sha384();
this->selfCreatedHash[SHA_384] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddSha512(void) {
this->suite[SHA_512] = new Sha512();
this->selfCreatedHash[SHA_512] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddRipemd128(void) {
this->suite[RIPEMD_128] = new Ripemd128();
this->selfCreatedHash[RIPEMD_128] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddRipemd160(void) {
this->suite[RIPEMD_160] = new Ripemd160();
this->selfCreatedHash[RIPEMD_160] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddRipemd256(void) {
this->suite[RIPEMD_256] = new Ripemd256();
this->selfCreatedHash[RIPEMD_256] = true;
this->instantiatedHashes++;
}
// Creates and adds the defined hash to the suite
void HashSuite::AddRipemd320(void) {
this->suite[RIPEMD_320] = new Ripemd320();
this->selfCreatedHash[RIPEMD_320] = true;
this->instantiatedHashes++;
}
// GETTING HASH OBJECT
// Gets a hash algorithm from the suite based in the enumerated hash
BaseHash* HashSuite::GetMessageDigest(Hashes hash) {
return this->suite[hash];
}
// Gets the defined hash from the suite
Sha1* HashSuite::GetSha1(void) {
return (Sha1 *)this->suite[SHA_1];
}
// Gets the defined hash from the suite
Sha224* HashSuite::GetSha224(void) {
return (Sha224 *)this->suite[SHA_224];
}
// Gets the defined hash from the suite
Sha256* HashSuite::GetSha256(void) {
return (Sha256 *)this->suite[SHA_256];
}
// Gets the defined hash from the suite
Sha384* HashSuite::GetSha384(void) {
return (Sha384 *)this->suite[SHA_384];
}
// Gets the defined hash from the suite
Sha512* HashSuite::GetSha512(void) {
return (Sha512 *)this->suite[SHA_512];
}
// Gets the defined hash from the suite
Ripemd128* HashSuite::GetRipemd128(void) {
return (Ripemd128 *)this->suite[RIPEMD_128];
}
// Gets the defined hash from the suite
Ripemd160* HashSuite::GetRipemd160(void) {
return (Ripemd160 *)this->suite[RIPEMD_160];
}
// Gets the defined hash from the suite
Ripemd256* HashSuite::GetRipemd256(void) {
return (Ripemd256 *)this->suite[RIPEMD_256];
}
// Gets the defined hash from the suite
Ripemd320* HashSuite::GetRipemd320(void) {
return (Ripemd320 *)this->suite[RIPEMD_320];
}
|