Sunday, 22 October 2017
arrow Previous Versions arrow JDiceLock 6.0.0.1 arrow Hash arrow BaseRipemd128X.java (1)
BaseRipemd128X.java (1st part) (base Ripemd 128 & 256 hash digest algorithm Java 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
 
//
// Creator:    http://www.dicelocksecurity.com
// Version:    vers.6.0.0.1
//
// Copyright (C) 2011-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.
//
// Environment:
// java version "1.6.0_29"
// Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
// Java HotSpot(TM) Server VM (build 20.4-b02, mixed mode)
//
 
package com.dicelocksecurity.jdicelock.Hash;
 
/**
 * Ripemd128X base class for Ripemd128 and Ripemd256 hash algorithms
 *
 * @author      Angel Ferré @ DiceLock Security
 * @version     6.0.0.1
 * @since       2011-10-03
 */
public abstract class BaseRipemd128X extends BaseRipemd {
 
    /**
     * Special F function object
     */
    protected static final BaseRipemd_Function_F functionF = new BaseRipemd_Function_F();
 
    /**
     * Special G function object
     */
    protected static final BaseRipemd_Function_G functionG = new BaseRipemd_Function_G();
 
    /**
     * Special H function object
     */
    protected static final BaseRipemd_Function_H functionH = new BaseRipemd_Function_H();
 
    /**
     * Special I function object
     */
    protected static final BaseRipemd_Function_I functionI = new BaseRipemd_Function_I();
 
    /**
     * Ripemd128X transform function
     *
     * @param   function    special function
     * @param   a           int parameter by reference to be operated upon
     * @param   b           int parameter by reference to operate with
     * @param   c           int parameter by reference to operate with
     * @param   d           int parameter by reference to operate with
     * @param   x           int parameter to operate with
     * @param   s           int parameter of rotation to operate with
     * @param   k           int parameter CONSTANT to operate with
     */
    protected void Ripemd_Transform128X(BaseRipemd_BaseFunctions function, BaseHash_Int a, BaseHash_Int b,
                                        BaseHash_Int c, BaseHash_Int d, int x, int s, int k) {
 
        a.setValue(a.getValue() + function.Execute(b.getValue(), c.getValue(), d.getValue()) + x + k);
        a.setValue(function.Ripemd_RotateLeft(a.getValue(), s));
    }
 
    /**
     * First transform set
     *
     * @param   a1           int parameter by reference to be operated upon
     * @param   b1           int parameter by reference to be operated upon
     * @param   c1           int parameter by reference to be operated upon
     * @param   d1           int parameter by reference to be operated upon
     * @param   X            stream being hashed
     */
    protected void Transform_F0(BaseHash_Int a1, BaseHash_Int b1, BaseHash_Int c1, BaseHash_Int d1, int[] X) {
 
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, a1, b1, c1, d1, X[0], BaseRipemd.RL_0_15[0],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, d1, a1, b1, c1, X[1], BaseRipemd.RL_0_15[1],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, c1, d1, a1, b1, X[2], BaseRipemd.RL_0_15[2],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, b1, c1, d1, a1, X[3], BaseRipemd.RL_0_15[3],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, a1, b1, c1, d1, X[4], BaseRipemd.RL_0_15[4],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, d1, a1, b1, c1, X[5], BaseRipemd.RL_0_15[5],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, c1, d1, a1, b1, X[6], BaseRipemd.RL_0_15[6],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, b1, c1, d1, a1, X[7], BaseRipemd.RL_0_15[7],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, a1, b1, c1, d1, X[8], BaseRipemd.RL_0_15[8],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, d1, a1, b1, c1, X[9], BaseRipemd.RL_0_15[9],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, c1, d1, a1, b1, X[10], BaseRipemd.RL_0_15[10],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, b1, c1, d1, a1, X[11], BaseRipemd.RL_0_15[11],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, a1, b1, c1, d1, X[12], BaseRipemd.RL_0_15[12],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, d1, a1, b1, c1, X[13], BaseRipemd.RL_0_15[13],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, c1, d1, a1, b1, X[14], BaseRipemd.RL_0_15[14],
                                  BaseRipemd.CONSTANT0);
        this.Ripemd_Transform128X(BaseRipemd128X.functionF, b1, c1, d1, a1, X[15], BaseRipemd.RL_0_15[15],
                                  BaseRipemd.CONSTANT0);
    }
 
    /**
     * Second transform set
     *
     * @param   a1           int parameter by reference to be operated upon
     * @param   b1           int parameter by reference to be operated upon
     * @param   c1           int parameter by reference to be operated upon
     * @param   d1           int parameter by reference to be operated upon
     * @param   X            stream being hashed
     */
    protected void Transform_G1(BaseHash_Int a1, BaseHash_Int b1, BaseHash_Int c1, BaseHash_Int d1, int[] X) {
 
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, a1, b1, c1, d1, X[7], BaseRipemd.RL_16_31[0],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, d1, a1, b1, c1, X[4], BaseRipemd.RL_16_31[1],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, c1, d1, a1, b1, X[13], BaseRipemd.RL_16_31[2],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, b1, c1, d1, a1, X[1], BaseRipemd.RL_16_31[3],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, a1, b1, c1, d1, X[10], BaseRipemd.RL_16_31[4],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, d1, a1, b1, c1, X[6], BaseRipemd.RL_16_31[5],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, c1, d1, a1, b1, X[15], BaseRipemd.RL_16_31[6],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, b1, c1, d1, a1, X[3], BaseRipemd.RL_16_31[7],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, a1, b1, c1, d1, X[12], BaseRipemd.RL_16_31[8],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, d1, a1, b1, c1, X[0], BaseRipemd.RL_16_31[9],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, c1, d1, a1, b1, X[9], BaseRipemd.RL_16_31[10],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, b1, c1, d1, a1, X[5], BaseRipemd.RL_16_31[11],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, a1, b1, c1, d1, X[2], BaseRipemd.RL_16_31[12],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, d1, a1, b1, c1, X[14], BaseRipemd.RL_16_31[13],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, c1, d1, a1, b1, X[11], BaseRipemd.RL_16_31[14],
                                  BaseRipemd.CONSTANT1);
        this.Ripemd_Transform128X(BaseRipemd128X.functionG, b1, c1, d1, a1, X[8], BaseRipemd.RL_16_31[15],
                                  BaseRipemd.CONSTANT1);
    }
 
    /**
     * Third transform set
     *
     * @param   a1           int parameter by reference to be operated upon
     * @param   b1           int parameter by reference to be operated upon
     * @param   c1           int parameter by reference to be operated upon
     * @param   d1           int parameter by reference to be operated upon
     * @param   X            stream being hashed
     */
    protected void Transform_H2(BaseHash_Int a1, BaseHash_Int b1, BaseHash_Int c1, BaseHash_Int d1, int[] X) {
 
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, a1, b1, c1, d1, X[3], BaseRipemd.RL_32_47[0],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, d1, a1, b1, c1, X[10], BaseRipemd.RL_32_47[1],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, c1, d1, a1, b1, X[14], BaseRipemd.RL_32_47[2],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, b1, c1, d1, a1, X[4], BaseRipemd.RL_32_47[3],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, a1, b1, c1, d1, X[9], BaseRipemd.RL_32_47[4],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, d1, a1, b1, c1, X[15], BaseRipemd.RL_32_47[5],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, c1, d1, a1, b1, X[8], BaseRipemd.RL_32_47[6],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, b1, c1, d1, a1, X[1], BaseRipemd.RL_32_47[7],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, a1, b1, c1, d1, X[2], BaseRipemd.RL_32_47[8],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, d1, a1, b1, c1, X[7], BaseRipemd.RL_32_47[9],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, c1, d1, a1, b1, X[0], BaseRipemd.RL_32_47[10],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, b1, c1, d1, a1, X[6], BaseRipemd.RL_32_47[11],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, a1, b1, c1, d1, X[13], BaseRipemd.RL_32_47[12],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, d1, a1, b1, c1, X[11], BaseRipemd.RL_32_47[13],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, c1, d1, a1, b1, X[5], BaseRipemd.RL_32_47[14],
                                  BaseRipemd.CONSTANT2);
        this.Ripemd_Transform128X(BaseRipemd128X.functionH, b1, c1, d1, a1, X[12], BaseRipemd.RL_32_47[15],
                                  BaseRipemd.CONSTANT2);
    }
 
    /**
     * Fourth transform set
     *
     * @param   a1           int parameter by reference to be operated upon
     * @param   b1           int parameter by reference to be operated upon
     * @param   c1           int parameter by reference to be operated upon
     * @param   d1           int parameter by reference to be operated upon
     * @param   X            stream being hashed
     */
    protected void Transform_I3(BaseHash_Int a1, BaseHash_Int b1, BaseHash_Int c1, BaseHash_Int d1, int[] X) {
 
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a1, b1, c1, d1, X[1], BaseRipemd.RL_48_63[0],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d1, a1, b1, c1, X[9], BaseRipemd.RL_48_63[1],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c1, d1, a1, b1, X[11], BaseRipemd.RL_48_63[2],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b1, c1, d1, a1, X[10], BaseRipemd.RL_48_63[3],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a1, b1, c1, d1, X[0], BaseRipemd.RL_48_63[4],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d1, a1, b1, c1, X[8], BaseRipemd.RL_48_63[5],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c1, d1, a1, b1, X[12], BaseRipemd.RL_48_63[6],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b1, c1, d1, a1, X[4], BaseRipemd.RL_48_63[7],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a1, b1, c1, d1, X[13], BaseRipemd.RL_48_63[8],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d1, a1, b1, c1, X[3], BaseRipemd.RL_48_63[9],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c1, d1, a1, b1, X[7], BaseRipemd.RL_48_63[10],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b1, c1, d1, a1, X[15], BaseRipemd.RL_48_63[11],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a1, b1, c1, d1, X[14], BaseRipemd.RL_48_63[12],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d1, a1, b1, c1, X[5], BaseRipemd.RL_48_63[13],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c1, d1, a1, b1, X[6], BaseRipemd.RL_48_63[14],
                                  BaseRipemd.CONSTANT3);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b1, c1, d1, a1, X[2], BaseRipemd.RL_48_63[15],
                                  BaseRipemd.CONSTANT3);
    }
 
    /**
     * Fifth transform set
     *
     * @param   a2           int parameter by reference to be operated upon
     * @param   b2           int parameter by reference to be operated upon
     * @param   c2           int parameter by reference to be operated upon
     * @param   d2           int parameter by reference to be operated upon
     * @param   X            stream being hashed
     */
    protected void Transform_I5(BaseHash_Int a2, BaseHash_Int b2, BaseHash_Int c2, BaseHash_Int d2, int[] X) {
 
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a2, b2, c2, d2, X[5], BaseRipemd.PRIME_RL_0_15[0],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d2, a2, b2, c2, X[14], BaseRipemd.PRIME_RL_0_15[1],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c2, d2, a2, b2, X[7], BaseRipemd.PRIME_RL_0_15[2],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b2, c2, d2, a2, X[0], BaseRipemd.PRIME_RL_0_15[3],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a2, b2, c2, d2, X[9], BaseRipemd.PRIME_RL_0_15[4],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d2, a2, b2, c2, X[2], BaseRipemd.PRIME_RL_0_15[5],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c2, d2, a2, b2, X[11], BaseRipemd.PRIME_RL_0_15[6],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b2, c2, d2, a2, X[4], BaseRipemd.PRIME_RL_0_15[7],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a2, b2, c2, d2, X[13], BaseRipemd.PRIME_RL_0_15[8],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d2, a2, b2, c2, X[6], BaseRipemd.PRIME_RL_0_15[9],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c2, d2, a2, b2, X[15], BaseRipemd.PRIME_RL_0_15[10],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b2, c2, d2, a2, X[8], BaseRipemd.PRIME_RL_0_15[11],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, a2, b2, c2, d2, X[1], BaseRipemd.PRIME_RL_0_15[12],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, d2, a2, b2, c2, X[10], BaseRipemd.PRIME_RL_0_15[13],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, c2, d2, a2, b2, X[3], BaseRipemd.PRIME_RL_0_15[14],
                                  BaseRipemd.CONSTANT5);
        this.Ripemd_Transform128X(BaseRipemd128X.functionI, b2, c2, d2, a2, X[12], BaseRipemd.PRIME_RL_0_15[15],
                                  BaseRipemd.CONSTANT5);
    }