Thursday, 19 October 2017

DiceLockSecurity Knowledge

DicelockSecurity (version 9.X)

Linux - Source Code

DiceLock-x 9.0.0.1
DiceChecker-x 6.0.0.1
HashDigester-x 6.0.0.1
Previous Versions
DiceLock-x 8.0.0.1
hashSuite.cpp (Hash algorithm suite C++ source code file) Print E-mail
Get C++ DiceLock cipher architecture source code packages of DiceLock for Microsoft Visual Studio 2013 and DiceLock-x for Linux with Test Driver Programs and Response Test Vector files to verify that both them work as expected.
DiceLock for Windows and Linux
DiceLock Security governing software licenses are Free/Libre Source Code License and Educational and Research License

DiceLock is protected by US patent 7508945 and European Patent 1182777 where applicable.

DiceLock and DiceLock logo are trademarks or registered trademarks in the EC, USA and others.

License information can be obtained at our corporate web site




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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
 
//
// Creator:    http://www.dicelocksecurity.com
// Version:    vers.8.0.0.1
//
// Copyright (C) 2009-2012 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 first hash in 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 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 suite based in 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;
        case MD_2:
          if (this->suite[MD_2] == NULL) {
            this->suite[MD_2] = new Md2();
            this->instantiatedHashes++;
          }
          break;
        case MD_4:
          if (this->suite[MD_4] == NULL) {
            this->suite[MD_4] = new Md4();
            this->instantiatedHashes++;
          }
          break;
        case MD_5:
          if (this->suite[MD_5] == NULL) {
            this->suite[MD_5] = new Md5();
            this->instantiatedHashes++;
          }
          break;
        default:
          break;
      }
      this->selfCreatedHash[hash] = true;
    }
 
    // Creates and adds all hash algorithms to 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();
      this->suite[MD_2] = new Md2();
      this->suite[MD_4] = new Md4();
      this->suite[MD_5] = new Md5();
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        this->selfCreatedHash[i] = true;
      }
      this->instantiatedHashes = NumberOfHashes;
 
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddSha1(void) {
 
      this->suite[SHA_1] = new Sha1();
      this->selfCreatedHash[SHA_1] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddSha224(void) {
 
      this->suite[SHA_224] = new Sha224();
      this->selfCreatedHash[SHA_224] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddSha256(void) {
 
      this->suite[SHA_256] = new Sha256();
      this->selfCreatedHash[SHA_256] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddSha384(void) {
 
      this->suite[SHA_384] = new Sha384();
      this->selfCreatedHash[SHA_384] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddSha512(void) {
 
      this->suite[SHA_512] = new Sha512();
      this->selfCreatedHash[SHA_512] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddRipemd128(void) {
 
      this->suite[RIPEMD_128] = new Ripemd128();
      this->selfCreatedHash[RIPEMD_128] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddRipemd160(void) {
 
      this->suite[RIPEMD_160] = new Ripemd160();
      this->selfCreatedHash[RIPEMD_160] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddRipemd256(void) {
 
      this->suite[RIPEMD_256] = new Ripemd256();
      this->selfCreatedHash[RIPEMD_256] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddRipemd320(void) {
 
      this->suite[RIPEMD_320] = new Ripemd320();
      this->selfCreatedHash[RIPEMD_320] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddMd2(void) {
 
      this->suite[MD_2] = new Md2();
      this->selfCreatedHash[MD_2] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddMd4(void) {
 
      this->suite[MD_4] = new Md4();
      this->selfCreatedHash[MD_4] = true;
      this->instantiatedHashes++;
    }
 
    // Creates and adds defined hash to suite
    void HashSuite::AddMd5(void) {
 
      this->suite[MD_5] = new Md5();
      this->selfCreatedHash[MD_5] = true;
      this->instantiatedHashes++;
    }
 
    // GETTING HASH OBJECT
      
    // Gets a hash algorithm from suite based in enumerated hash
    BaseHash* HashSuite::GetMessageDigest(Hashes hash) {
 
      return this->suite[hash];
    }
 
    // Gets defined hash from suite
    Sha1* HashSuite::GetSha1(void) {
 
      return (Sha1 *)this->suite[SHA_1];
    }
 
    // Gets defined hash from suite
    Sha224* HashSuite::GetSha224(void) {
 
      return (Sha224 *)this->suite[SHA_224];
    }
 
    // Gets defined hash from suite
    Sha256* HashSuite::GetSha256(void) {
 
      return (Sha256 *)this->suite[SHA_256];
    }
 
    // Gets defined hash from suite
    Sha384* HashSuite::GetSha384(void) {
 
      return (Sha384 *)this->suite[SHA_384];
    }
 
    // Gets defined hash from suite
    Sha512* HashSuite::GetSha512(void) {
 
      return (Sha512 *)this->suite[SHA_512];
    }
 
    // Gets defined hash from suite
    Ripemd128* HashSuite::GetRipemd128(void) {
 
      return (Ripemd128 *)this->suite[RIPEMD_128];
    }
 
    // Gets defined hash from suite
    Ripemd160* HashSuite::GetRipemd160(void) {
 
      return (Ripemd160 *)this->suite[RIPEMD_160];
    }
 
    // Gets defined hash from suite
    Ripemd256* HashSuite::GetRipemd256(void) {
 
      return (Ripemd256 *)this->suite[RIPEMD_256];
    }
 
    // Gets defined hash from suite
    Ripemd320* HashSuite::GetRipemd320(void) {
 
      return (Ripemd320 *)this->suite[RIPEMD_320];
    }
 
    // Gets defined hash from suite
    Md2* HashSuite::GetMd2(void) {
 
      return (Md2 *)this->suite[MD_2];
    }
 
    // Gets defined hash from suite
    Md4* HashSuite::GetMd4(void) {
 
      return (Md4 *)this->suite[MD_4];
    }
 
    // Gets defined hash from suite
    Md5* HashSuite::GetMd5(void) {
 
      return (Md5 *)this->suite[MD_5];
    }
 
    // REMOVING HASH ALGORITHMS
 
    // Removes a pointed hash algorithm from suite
    void HashSuite::Remove(BaseHash* hashObject) {
      Hashes hash;
 
      hash = hashObject->GetType();
      if ((this->suite[hash] != NULL) && (this->suite[hash] == hashObject)) {
        if (this->selfCreatedHash[hash]) {
          delete this->suite[hash];
        }
        this->suite[hash] = NULL;
        this->selfCreatedHash[hash] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes a hash algorithm from suite based in enumerated hash algorithm
    void HashSuite::Remove(Hashes hash) {
 
      if (this->suite[hash] != NULL) {
        if (this->selfCreatedHash[hash]) {
          delete this->suite[hash];
        }
        this->suite[hash] = NULL;
        this->selfCreatedHash[hash] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes all hash algorithms from suite
    void HashSuite::RemoveAll(void) {
      int i;
 
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        if (this->suite[i] != NULL) {
          if (this->selfCreatedHash[i]) {
            delete this->suite[i];
          }
          this->suite[i] = NULL;
            this->selfCreatedHash[i] = false;
        }
      }
      this->instantiatedHashes = 0;
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveSha1(void) {
 
      if (this->suite[SHA_1] != NULL) {
        if (this->selfCreatedHash[SHA_1]) {
          delete this->suite[SHA_1];
        }
        this->suite[SHA_1] = NULL;
          this->selfCreatedHash[SHA_1] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveSha224(void) {
 
      if (this->suite[SHA_224] != NULL) {
        if (this->selfCreatedHash[SHA_224]) {
          delete this->suite[SHA_224];
        }
        this->suite[SHA_224] = NULL;
          this->selfCreatedHash[SHA_224] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveSha256(void) {
 
      if (this->suite[SHA_256] != NULL) {
        if (this->selfCreatedHash[SHA_256]) {
          delete this->suite[SHA_256];
        }
        this->suite[SHA_256] = NULL;
          this->selfCreatedHash[SHA_256] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveSha384(void) {
 
      if (this->suite[SHA_384] != NULL) {
        if (this->selfCreatedHash[SHA_384]) {
          delete this->suite[SHA_384];
        }
        this->suite[SHA_384] = NULL;
          this->selfCreatedHash[SHA_384] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveSha512(void) {
 
      if (this->suite[SHA_512] != NULL) {
        if (this->selfCreatedHash[SHA_512]) {
          delete this->suite[SHA_512];
        }
        this->suite[SHA_512] = NULL;
          this->selfCreatedHash[SHA_512] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveRipemd128(void) {
 
      if (this->suite[RIPEMD_128] != NULL) {
        if (this->selfCreatedHash[RIPEMD_128]) {
          delete this->suite[RIPEMD_128];
        }
        this->suite[RIPEMD_128] = NULL;
          this->selfCreatedHash[RIPEMD_128] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveRipemd160(void) {
 
      if (this->suite[RIPEMD_160] != NULL) {
        if (this->selfCreatedHash[RIPEMD_160]) {
          delete this->suite[RIPEMD_160];
        }
        this->suite[RIPEMD_160] = NULL;
          this->selfCreatedHash[RIPEMD_160] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveRipemd256(void) {
 
      if (this->suite[RIPEMD_256] != NULL) {
        if (this->selfCreatedHash[RIPEMD_256]) {
          delete this->suite[RIPEMD_256];
        }
        this->suite[RIPEMD_256] = NULL;
          this->selfCreatedHash[RIPEMD_256] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveRipemd320(void) {
 
      if (this->suite[RIPEMD_320] != NULL) {
        if (this->selfCreatedHash[RIPEMD_320]) {
          delete this->suite[RIPEMD_320];
        }
        this->suite[RIPEMD_320] = NULL;
          this->selfCreatedHash[RIPEMD_320] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveMd2(void) {
 
      if (this->suite[MD_2] != NULL) {
        if (this->selfCreatedHash[MD_2]) {
          delete this->suite[MD_2];
        }
        this->suite[MD_2] = NULL;
          this->selfCreatedHash[MD_2] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveMd4(void) {
 
      if (this->suite[MD_4] != NULL) {
        if (this->selfCreatedHash[MD_4]) {
          delete this->suite[MD_4];
        }
        this->suite[MD_4] = NULL;
          this->selfCreatedHash[MD_4] = false;
        this->instantiatedHashes--;
      }
    }
 
    // Removes defined hash from suite
    void HashSuite::RemoveMd5(void) {
 
      if (this->suite[MD_5] != NULL) {
        if (this->selfCreatedHash[MD_5]) {
          delete this->suite[MD_5];
        }
        this->suite[MD_5] = NULL;
          this->selfCreatedHash[MD_5] = false;
        this->instantiatedHashes--;
      }
    }
 
    // PERFORMING HASH
 
    // Performs hash algorithms of BaseCryptoRandomStream with all instantiated hash 
    void HashSuite::Hash(BaseCryptoRandomStream* stream) {
      int i;
      
      this->Initialize();
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        if (this->suite[i] != NULL) {
          this->suite[i]->Add(stream); 
          this->suite[i]->Finalize(); 
        }
      }
    }
 
    // INITIALIZE SUITE
      
    // Initializes all hash algorithms in suite
    void HashSuite::Initialize(void) {
      int i;
      
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        if (this->suite[i] != NULL) {
          this->suite[i]->Initialize();
        }
      }
    }
 
    // ADDS STREAM TO THE SUITE
      
    // Adds BaseCryptoRandomStream stream to hash algorithms in suite
    void HashSuite::Add(BaseCryptoRandomStream* stream) {
      int i;
      
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        if (this->suite[i] != NULL) {
          this->suite[i]->Add(stream);
        }
      }
    }
 
    // FINALIZE THE SUITE
      
    // Finalize hash algorithms in suite
    void HashSuite::Finalize(void) {
      int i;
      
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        if (this->suite[i] != NULL) {
          this->suite[i]->Finalize();
        }
      }
    }
 
    // GETTING SUITE INFORMATION
 
    // Gets number of hash algorithms that contains suite
    unsigned long int HashSuite::GetInstantiatedHashes(void) {
 
      return this->instantiatedHashes;
    }
 
    // Indicates if a hash algorithm object exists in suite
    bool HashSuite::Exist(Hashes hash) {
 
      return (this->suite[hash] != NULL);
    }
 
    // Gets first hash algorithm in HashSuite
    Hashes HashSuite::GetFirstHash(void) {
 
      return this->firstHash;
    }
 
    // Gets number of hash algorithms that can be used in HahsSuite
    Hashes HashSuite::GetMaximumNumberOfHashes(void) {
 
      return NumberOfHashes;
    }
  }
}