Sunday, 22 October 2017
HashSuite.java (2nd part) (Hash algorithm suite Java 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

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
 
    // REMOVING HASH ALGORITHMS
 
    /**
     * Removes the pointed hash from the suite
     *
     * @param    hashObject    hash object to be removed from the suite
     */
    public void Remove(BaseHash hashObject) {
        Hashes hash;
 
        hash = hashObject.GetType();
        if ((this.suite[hash.ordinal()] != null) && (this.suite[hash.ordinal()] == hashObject)) {
            if (this.selfCreatedHash[hash.ordinal()]) {
                this.suite[hash.ordinal()] = null;
            }
            this.suite[hash.ordinal()] = null;
            this.selfCreatedHash[hash.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes a hash from the suite based in the enumerated hash algorithms
     *
     * @param    hash    hash algorithm as enumerated parameter to be removed from the suite
     */
    public void Remove(Hashes hash) {
 
        if (this.suite[hash.ordinal()] != null) {
            if (this.selfCreatedHash[hash.ordinal()]) {
                this.suite[hash.ordinal()] = null;
            }
            this.suite[hash.ordinal()] = null;
            this.selfCreatedHash[hash.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes all hash algorithms from the suite
     */
    public void RemoveAll() {
        int i;
 
        for (i = this.GetFirstHash().ordinal(); i < this.GetMaximumNumberOfHashes().ordinal(); i++) {
            if (this.suite[i] != null) {
                if (this.selfCreatedHash[i]) {
                    this.suite[i] = null;
                }
                this.suite[i] = null;
                this.selfCreatedHash[i] = false;
            }
        }
        this.instantiatedHashes = 0;
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveSha1() {
 
        if (this.suite[Hashes.SHA_1.ordinal()] != null) {
            this.suite[Hashes.SHA_1.ordinal()] = null;
            this.selfCreatedHash[Hashes.SHA_1.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveSha224() {
 
        if (this.suite[Hashes.SHA_224.ordinal()] != null) {
            this.suite[Hashes.SHA_224.ordinal()] = null;
            this.selfCreatedHash[Hashes.SHA_224.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveSha256() {
 
        if (this.suite[Hashes.SHA_256.ordinal()] != null) {
            this.suite[Hashes.SHA_256.ordinal()] = null;
            this.selfCreatedHash[Hashes.SHA_256.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveSha384() {
 
        if (this.suite[Hashes.SHA_384.ordinal()] != null) {
            this.suite[Hashes.SHA_384.ordinal()] = null;
            this.selfCreatedHash[Hashes.SHA_384.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveSha512() {
 
        if (this.suite[Hashes.SHA_512.ordinal()] != null) {
            this.suite[Hashes.SHA_512.ordinal()] = null;
            this.selfCreatedHash[Hashes.SHA_512.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveRipemd128() {
 
        if (this.suite[Hashes.RIPEMD_128.ordinal()] != null) {
            this.suite[Hashes.RIPEMD_128.ordinal()] = null;
            this.selfCreatedHash[Hashes.RIPEMD_128.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveRipemd160() {
 
        if (this.suite[Hashes.RIPEMD_160.ordinal()] != null) {
            this.suite[Hashes.RIPEMD_160.ordinal()] = null;
            this.selfCreatedHash[Hashes.RIPEMD_160.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveRipemd256() {
 
        if (this.suite[Hashes.RIPEMD_256.ordinal()] != null) {
            this.suite[Hashes.RIPEMD_256.ordinal()] = null;
            this.selfCreatedHash[Hashes.RIPEMD_256.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    /**
     * Removes defined hash from the suite
     */
    public void RemoveRipemd320() {
 
        if (this.suite[Hashes.RIPEMD_320.ordinal()] != null) {
            this.suite[Hashes.RIPEMD_320.ordinal()] = null;
            this.selfCreatedHash[Hashes.RIPEMD_320.ordinal()] = false;
            this.instantiatedHashes--;
        }
    }
 
    // PERFORMING HASH
 
    /**
     * Performs the hash algorithms of BaseCryptoRandomStream with all instantiated hash
     */
    public void Hash(BaseCryptoRandomStream stream) {
        int i;
 
        this.Initialize();
        for (i = this.GetFirstHash().ordinal(); i < this.GetMaximumNumberOfHashes().ordinal(); i++) {
            if (this.suite[i] != null) {
                this.suite[i].Add(stream);
                this.suite[i].Finalize();
            }
        }
    }
 
    // INITIALIZE SUITE
 
    /**
     * Initializes all hash algorithms in the suite
     */
    public void Initialize() {
        int i;
 
        for (i = this.GetFirstHash().ordinal(); i < this.GetMaximumNumberOfHashes().ordinal(); i++) {
            if (this.suite[i] != null) {
                this.suite[i].Initialize();
            }
        }
    }
 
    // ADDS STREAM TO THE SUITE
 
    /**
     * Adds BaseCryptoRandomStream stream to hash algorithms in the suite
     *
     * @param    stream    bit stream to be added to hash
     */
    public void Add(BaseCryptoRandomStream stream) {
        int i;
 
        for (i = this.GetFirstHash().ordinal(); i < this.GetMaximumNumberOfHashes().ordinal(); i++) {
            if (this.suite[i] != null) {
                this.suite[i].Add(stream);
            }
        }
    }
 
    // FINALIZE THE SUITE
 
    /**
     * Finalize hash algorithms in the suite
     */
    public void Finalize() {
        int i;
 
        for (i = this.GetFirstHash().ordinal(); i < this.GetMaximumNumberOfHashes().ordinal(); i++) {
            if (this.suite[i] != null) {
                this.suite[i].Finalize();
            }
        }
    }
 
    // GETTING SUITE INFORMATION
 
    /**
     * Gets the number of hash algorithms that contains the suite
     *
     * @return  short:    number of instantiated hash algorithm objects in the suite
     */
    public short GetInstantiatedHashes() {
 
        return this.instantiatedHashes;
    }
 
    /**
     * Indicates if a hash algorithm exists in the suite
     *
     * @param    hash    hash algorithm as enumerated parameter to check if the corresponding hash object has been instantiated in the suite
     * @return  boolean    return "true" if corresponding hash algorithm object is instantiated in the suite, "false" otherwise  
     */
    public boolean Exist(Hashes hash) {
 
        return (this.suite[hash.ordinal()] != null);
    }
 
    /**
     * Gets the first hash algorithm in the HashSuite
     *
     * @return  Hashes    returns first instantiated hash algorithm object as enumerated type
     */
    public Hashes GetFirstHash() {
 
        return HashSuite.firstHash;
    }
 
    /**
     * Gets the number of hash algorithms that can be used in the HahsSuite
     *
     * @return  Hashes    returns maximum number of hash algorithms allowed to be instantiated
     */
    public Hashes GetMaximumNumberOfHashes() {
 
        return Hashes.NumberOfHashes;
    }
 
}