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
|
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "rmd_locl.h"
#include <openssl/opensslv.h>
#ifdef RMD160_ASM
void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p, size_t num);
# define ripemd160_block ripemd160_block_x86
#else
void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p, size_t num);
#endif
int RIPEMD160_Init(RIPEMD160_CTX *c)
{
memset(c, 0, sizeof(*c));
c->A = RIPEMD160_A;
c->B = RIPEMD160_B;
c->C = RIPEMD160_C;
c->D = RIPEMD160_D;
c->E = RIPEMD160_E;
return 1;
}
#ifndef ripemd160_block_data_order
# ifdef X
# undef X
# endif
void ripemd160_block_data_order(RIPEMD160_CTX *ctx, const void *p, size_t num)
{
const unsigned char *data = p;
register unsigned MD32_REG_T A, B, C, D, E;
unsigned MD32_REG_T a, b, c, d, e, l;
# ifndef MD32_XARRAY
/* See comment in crypto/sha/sha_locl.h for details. */
unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
XX8, XX9, XX10, XX11, XX12, XX13, XX14, XX15;
# define X(i) XX##i
# else
RIPEMD160_LONG XX[16];
# define X(i) XX[i]
# endif
for (; num--;) {
A = ctx->A;
B = ctx->B;
C = ctx->C;
D = ctx->D;
E = ctx->E;
(void)HOST_c2l(data, l);
X(0) = l;
(void)HOST_c2l(data, l);
X(1) = l;
RIP1(A, B, C, D, E, WL00, SL00);
(void)HOST_c2l(data, l);
X(2) = l;
RIP1(E, A, B, C, D, WL01, SL01);
(void)HOST_c2l(data, l);
X(3) = l;
RIP1(D, E, A, B, C, WL02, SL02);
(void)HOST_c2l(data, l);
X(4) = l;
RIP1(C, D, E, A, B, WL03, SL03);
(void)HOST_c2l(data, l);
X(5) = l;
RIP1(B, C, D, E, A, WL04, SL04);
(void)HOST_c2l(data, l);
X(6) = l;
RIP1(A, B, C, D, E, WL05, SL05);
(void)HOST_c2l(data, l);
X(7) = l;
RIP1(E, A, B, C, D, WL06, SL06);
(void)HOST_c2l(data, l);
X(8) = l;
RIP1(D, E, A, B, C, WL07, SL07);
(void)HOST_c2l(data, l);
X(9) = l;
RIP1(C, D, E, A, B, WL08, SL08);
(void)HOST_c2l(data, l);
X(10) = l;
RIP1(B, C, D, E, A, WL09, SL09);
(void)HOST_c2l(data, l);
X(11) = l;
RIP1(A, B, C, D, E, WL10, SL10);
(void)HOST_c2l(data, l);
X(12) = l;
RIP1(E, A, B, C, D, WL11, SL11);
(void)HOST_c2l(data, l);
X(13) = l;
RIP1(D, E, A, B, C, WL12, SL12);
(void)HOST_c2l(data, l);
X(14) = l;
RIP1(C, D, E, A, B, WL13, SL13);
(void)HOST_c2l(data, l);
X(15) = l;
RIP1(B, C, D, E, A, WL14, SL14);
RIP1(A, B, C, D, E, WL15, SL15);
RIP2(E, A, B, C, D, WL16, SL16, KL1);
RIP2(D, E, A, B, C, WL17, SL17, KL1);
RIP2(C, D, E, A, B, WL18, SL18, KL1);
RIP2(B, C, D, E, A, WL19, SL19, KL1);
RIP2(A, B, C, D, E, WL20, SL20, KL1);
RIP2(E, A, B, C, D, WL21, SL21, KL1);
RIP2(D, E, A, B, C, WL22, SL22, KL1);
RIP2(C, D, E, A, B, WL23, SL23, KL1);
RIP2(B, C, D, E, A, WL24, SL24, KL1);
RIP2(A, B, C, D, E, WL25, SL25, KL1);
RIP2(E, A, B, C, D, WL26, SL26, KL1);
RIP2(D, E, A, B, C, WL27, SL27, KL1);
RIP2(C, D, E, A, B, WL28, SL28, KL1);
RIP2(B, C, D, E, A, WL29, SL29, KL1);
RIP2(A, B, C, D, E, WL30, SL30, KL1);
RIP2(E, A, B, C, D, WL31, SL31, KL1);
RIP3(D, E, A, B, C, WL32, SL32, KL2);
RIP3(C, D, E, A, B, WL33, SL33, KL2);
RIP3(B, C, D, E, A, WL34, SL34, KL2);
RIP3(A, B, C, D, E, WL35, SL35, KL2);
RIP3(E, A, B, C, D, WL36, SL36, KL2);
RIP3(D, E, A, B, C, WL37, SL37, KL2);
RIP3(C, D, E, A, B, WL38, SL38, KL2);
RIP3(B, C, D, E, A, WL39, SL39, KL2);
RIP3(A, B, C, D, E, WL40, SL40, KL2);
RIP3(E, A, B, C, D, WL41, SL41, KL2);
RIP3(D, E, A, B, C, WL42, SL42, KL2);
RIP3(C, D, E, A, B, WL43, SL43, KL2);
RIP3(
|