Tuesday, 17 October 2017
arrow HashDigester-x 6.0.0.1 arrow hashSuite.cpp (2)
hashSuite.cpp (2) (Hash algorithm suite C++ source code second part 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
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
 
    // REMOVING HASH ALGORITHMS
 
    // Removes a pointed hash algorithm from the 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 the suite based in the 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 the suite
    void HashSuite::RemoveAll(void) {
      unsigned short 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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 the defined hash from the 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--;
      }
    }
 
    // PERFORMING HASH
 
    // Performs the hash algorithms of BaseCryptoRandomStream with all instantiated hash 
    void HashSuite::Hash(BaseCryptoRandomStream* stream) {
      unsigned short 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 the suite
    void HashSuite::Initialize(void) {
      unsigned short 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 the 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 the suite
    void HashSuite::Finalize(void) {
      unsigned short int i;
      
      for (i=this->GetFirstHash(); i<this->GetMaximumNumberOfHashes(); i++) {
        if (this->suite[i] != NULL) {
          this->suite[i]->Finalize();
        }
      }
    }
 
    // GETTING SUITE INFORMATION
 
    // Gets the number of hash algorithms that contains the suite
    unsigned long int HashSuite::GetInstantiatedHashes(void) {
 
      return this->instantiatedHashes;
    }
 
    // Indicates if a hash algorithm object exists in the suite
    bool HashSuite::Exist(Hashes hash) {
 
      return (this->suite[hash] != NULL);
    }
 
    // Gets the first hash algorithm in the HashSuite
    Hashes HashSuite::GetFirstHash(void) {
 
      return this->firstHash;
    }
 
    // Gets the number of hash algorithms that can be used in the HahsSuite
    Hashes HashSuite::GetMaximumNumberOfHashes(void) {
 
      return NumberOfHashes;
    }
  }
}