/src/nettle/ripemd160-compress.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* ripemd160-compress.c |
2 | | |
3 | | RIPE-MD160 (Transform function) |
4 | | |
5 | | Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. |
6 | | |
7 | | This file is part of GNU Nettle. |
8 | | |
9 | | GNU Nettle is free software: you can redistribute it and/or |
10 | | modify it under the terms of either: |
11 | | |
12 | | * the GNU Lesser General Public License as published by the Free |
13 | | Software Foundation; either version 3 of the License, or (at your |
14 | | option) any later version. |
15 | | |
16 | | or |
17 | | |
18 | | * the GNU General Public License as published by the Free |
19 | | Software Foundation; either version 2 of the License, or (at your |
20 | | option) any later version. |
21 | | |
22 | | or both in parallel, as here. |
23 | | |
24 | | GNU Nettle is distributed in the hope that it will be useful, |
25 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 | | General Public License for more details. |
28 | | |
29 | | You should have received copies of the GNU General Public License and |
30 | | the GNU Lesser General Public License along with this program. If |
31 | | not, see http://www.gnu.org/licenses/. |
32 | | */ |
33 | | |
34 | | /* Ported from libgcrypt by Andres Mejia <mcitadel@gmail.com> */ |
35 | | |
36 | | #if HAVE_CONFIG_H |
37 | | # include "config.h" |
38 | | #endif |
39 | | |
40 | | #include <string.h> |
41 | | |
42 | | #include "ripemd160.h" |
43 | | #include "ripemd160-internal.h" |
44 | | |
45 | | #include "macros.h" |
46 | | |
47 | | |
48 | | /**************** |
49 | | * Transform the message X which consists of 16 32-bit-words |
50 | | */ |
51 | | void |
52 | | _nettle_ripemd160_compress(uint32_t *state, const uint8_t *data) |
53 | 0 | { |
54 | 0 | register uint32_t a,b,c,d,e; |
55 | 0 | uint32_t aa,bb,cc,dd,ee,t; |
56 | 0 | uint32_t x[16]; |
57 | |
|
58 | | #ifdef WORDS_BIGENDIAN |
59 | | { |
60 | | int i; |
61 | | for (i=0; i < 16; i++, data += 4 ) |
62 | | x[i] = LE_READ_UINT32(data); |
63 | | } |
64 | | #else |
65 | | /* memcpy seems a bit faster. Benchmarked on Intel SU4100, it makes |
66 | | the entire update function roughly 6% faster. */ |
67 | 0 | memcpy(x, data, sizeof(x)); |
68 | 0 | #endif |
69 | | |
70 | |
|
71 | 0 | #define K0 0x00000000 |
72 | 0 | #define K1 0x5A827999 |
73 | 0 | #define K2 0x6ED9EBA1 |
74 | 0 | #define K3 0x8F1BBCDC |
75 | 0 | #define K4 0xA953FD4E |
76 | 0 | #define KK0 0x50A28BE6 |
77 | 0 | #define KK1 0x5C4DD124 |
78 | 0 | #define KK2 0x6D703EF3 |
79 | 0 | #define KK3 0x7A6D76E9 |
80 | 0 | #define KK4 0x00000000 |
81 | 0 | #define F0(x,y,z) ( (x) ^ (y) ^ (z) ) |
82 | 0 | #define F1(x,y,z) ( ((x) & (y)) | (~(x) & (z)) ) |
83 | 0 | #define F2(x,y,z) ( ((x) | ~(y)) ^ (z) ) |
84 | 0 | #define F3(x,y,z) ( ((x) & (z)) | ((y) & ~(z)) ) |
85 | 0 | #define F4(x,y,z) ( (x) ^ ((y) | ~(z)) ) |
86 | 0 | #define R(a,b,c,d,e,f,k,r,s) do { t = a + f(b,c,d) + k + x[r]; \ |
87 | 0 | a = ROTL32(s,t) + e; \ |
88 | 0 | c = ROTL32(10,c); \ |
89 | 0 | } while(0) |
90 | | |
91 | | /* left lane */ |
92 | 0 | a = state[0]; |
93 | 0 | b = state[1]; |
94 | 0 | c = state[2]; |
95 | 0 | d = state[3]; |
96 | 0 | e = state[4]; |
97 | 0 | R( a, b, c, d, e, F0, K0, 0, 11 ); |
98 | 0 | R( e, a, b, c, d, F0, K0, 1, 14 ); |
99 | 0 | R( d, e, a, b, c, F0, K0, 2, 15 ); |
100 | 0 | R( c, d, e, a, b, F0, K0, 3, 12 ); |
101 | 0 | R( b, c, d, e, a, F0, K0, 4, 5 ); |
102 | 0 | R( a, b, c, d, e, F0, K0, 5, 8 ); |
103 | 0 | R( e, a, b, c, d, F0, K0, 6, 7 ); |
104 | 0 | R( d, e, a, b, c, F0, K0, 7, 9 ); |
105 | 0 | R( c, d, e, a, b, F0, K0, 8, 11 ); |
106 | 0 | R( b, c, d, e, a, F0, K0, 9, 13 ); |
107 | 0 | R( a, b, c, d, e, F0, K0, 10, 14 ); |
108 | 0 | R( e, a, b, c, d, F0, K0, 11, 15 ); |
109 | 0 | R( d, e, a, b, c, F0, K0, 12, 6 ); |
110 | 0 | R( c, d, e, a, b, F0, K0, 13, 7 ); |
111 | 0 | R( b, c, d, e, a, F0, K0, 14, 9 ); |
112 | 0 | R( a, b, c, d, e, F0, K0, 15, 8 ); |
113 | 0 | R( e, a, b, c, d, F1, K1, 7, 7 ); |
114 | 0 | R( d, e, a, b, c, F1, K1, 4, 6 ); |
115 | 0 | R( c, d, e, a, b, F1, K1, 13, 8 ); |
116 | 0 | R( b, c, d, e, a, F1, K1, 1, 13 ); |
117 | 0 | R( a, b, c, d, e, F1, K1, 10, 11 ); |
118 | 0 | R( e, a, b, c, d, F1, K1, 6, 9 ); |
119 | 0 | R( d, e, a, b, c, F1, K1, 15, 7 ); |
120 | 0 | R( c, d, e, a, b, F1, K1, 3, 15 ); |
121 | 0 | R( b, c, d, e, a, F1, K1, 12, 7 ); |
122 | 0 | R( a, b, c, d, e, F1, K1, 0, 12 ); |
123 | 0 | R( e, a, b, c, d, F1, K1, 9, 15 ); |
124 | 0 | R( d, e, a, b, c, F1, K1, 5, 9 ); |
125 | 0 | R( c, d, e, a, b, F1, K1, 2, 11 ); |
126 | 0 | R( b, c, d, e, a, F1, K1, 14, 7 ); |
127 | 0 | R( a, b, c, d, e, F1, K1, 11, 13 ); |
128 | 0 | R( e, a, b, c, d, F1, K1, 8, 12 ); |
129 | 0 | R( d, e, a, b, c, F2, K2, 3, 11 ); |
130 | 0 | R( c, d, e, a, b, F2, K2, 10, 13 ); |
131 | 0 | R( b, c, d, e, a, F2, K2, 14, 6 ); |
132 | 0 | R( a, b, c, d, e, F2, K2, 4, 7 ); |
133 | 0 | R( e, a, b, c, d, F2, K2, 9, 14 ); |
134 | 0 | R( d, e, a, b, c, F2, K2, 15, 9 ); |
135 | 0 | R( c, d, e, a, b, F2, K2, 8, 13 ); |
136 | 0 | R( b, c, d, e, a, F2, K2, 1, 15 ); |
137 | 0 | R( a, b, c, d, e, F2, K2, 2, 14 ); |
138 | 0 | R( e, a, b, c, d, F2, K2, 7, 8 ); |
139 | 0 | R( d, e, a, b, c, F2, K2, 0, 13 ); |
140 | 0 | R( c, d, e, a, b, F2, K2, 6, 6 ); |
141 | 0 | R( b, c, d, e, a, F2, K2, 13, 5 ); |
142 | 0 | R( a, b, c, d, e, F2, K2, 11, 12 ); |
143 | 0 | R( e, a, b, c, d, F2, K2, 5, 7 ); |
144 | 0 | R( d, e, a, b, c, F2, K2, 12, 5 ); |
145 | 0 | R( c, d, e, a, b, F3, K3, 1, 11 ); |
146 | 0 | R( b, c, d, e, a, F3, K3, 9, 12 ); |
147 | 0 | R( a, b, c, d, e, F3, K3, 11, 14 ); |
148 | 0 | R( e, a, b, c, d, F3, K3, 10, 15 ); |
149 | 0 | R( d, e, a, b, c, F3, K3, 0, 14 ); |
150 | 0 | R( c, d, e, a, b, F3, K3, 8, 15 ); |
151 | 0 | R( b, c, d, e, a, F3, K3, 12, 9 ); |
152 | 0 | R( a, b, c, d, e, F3, K3, 4, 8 ); |
153 | 0 | R( e, a, b, c, d, F3, K3, 13, 9 ); |
154 | 0 | R( d, e, a, b, c, F3, K3, 3, 14 ); |
155 | 0 | R( c, d, e, a, b, F3, K3, 7, 5 ); |
156 | 0 | R( b, c, d, e, a, F3, K3, 15, 6 ); |
157 | 0 | R( a, b, c, d, e, F3, K3, 14, 8 ); |
158 | 0 | R( e, a, b, c, d, F3, K3, 5, 6 ); |
159 | 0 | R( d, e, a, b, c, F3, K3, 6, 5 ); |
160 | 0 | R( c, d, e, a, b, F3, K3, 2, 12 ); |
161 | 0 | R( b, c, d, e, a, F4, K4, 4, 9 ); |
162 | 0 | R( a, b, c, d, e, F4, K4, 0, 15 ); |
163 | 0 | R( e, a, b, c, d, F4, K4, 5, 5 ); |
164 | 0 | R( d, e, a, b, c, F4, K4, 9, 11 ); |
165 | 0 | R( c, d, e, a, b, F4, K4, 7, 6 ); |
166 | 0 | R( b, c, d, e, a, F4, K4, 12, 8 ); |
167 | 0 | R( a, b, c, d, e, F4, K4, 2, 13 ); |
168 | 0 | R( e, a, b, c, d, F4, K4, 10, 12 ); |
169 | 0 | R( d, e, a, b, c, F4, K4, 14, 5 ); |
170 | 0 | R( c, d, e, a, b, F4, K4, 1, 12 ); |
171 | 0 | R( b, c, d, e, a, F4, K4, 3, 13 ); |
172 | 0 | R( a, b, c, d, e, F4, K4, 8, 14 ); |
173 | 0 | R( e, a, b, c, d, F4, K4, 11, 11 ); |
174 | 0 | R( d, e, a, b, c, F4, K4, 6, 8 ); |
175 | 0 | R( c, d, e, a, b, F4, K4, 15, 5 ); |
176 | 0 | R( b, c, d, e, a, F4, K4, 13, 6 ); |
177 | |
|
178 | 0 | aa = a; bb = b; cc = c; dd = d; ee = e; |
179 | | |
180 | | /* right lane */ |
181 | 0 | a = state[0]; |
182 | 0 | b = state[1]; |
183 | 0 | c = state[2]; |
184 | 0 | d = state[3]; |
185 | 0 | e = state[4]; |
186 | 0 | R( a, b, c, d, e, F4, KK0, 5, 8); |
187 | 0 | R( e, a, b, c, d, F4, KK0, 14, 9); |
188 | 0 | R( d, e, a, b, c, F4, KK0, 7, 9); |
189 | 0 | R( c, d, e, a, b, F4, KK0, 0, 11); |
190 | 0 | R( b, c, d, e, a, F4, KK0, 9, 13); |
191 | 0 | R( a, b, c, d, e, F4, KK0, 2, 15); |
192 | 0 | R( e, a, b, c, d, F4, KK0, 11, 15); |
193 | 0 | R( d, e, a, b, c, F4, KK0, 4, 5); |
194 | 0 | R( c, d, e, a, b, F4, KK0, 13, 7); |
195 | 0 | R( b, c, d, e, a, F4, KK0, 6, 7); |
196 | 0 | R( a, b, c, d, e, F4, KK0, 15, 8); |
197 | 0 | R( e, a, b, c, d, F4, KK0, 8, 11); |
198 | 0 | R( d, e, a, b, c, F4, KK0, 1, 14); |
199 | 0 | R( c, d, e, a, b, F4, KK0, 10, 14); |
200 | 0 | R( b, c, d, e, a, F4, KK0, 3, 12); |
201 | 0 | R( a, b, c, d, e, F4, KK0, 12, 6); |
202 | 0 | R( e, a, b, c, d, F3, KK1, 6, 9); |
203 | 0 | R( d, e, a, b, c, F3, KK1, 11, 13); |
204 | 0 | R( c, d, e, a, b, F3, KK1, 3, 15); |
205 | 0 | R( b, c, d, e, a, F3, KK1, 7, 7); |
206 | 0 | R( a, b, c, d, e, F3, KK1, 0, 12); |
207 | 0 | R( e, a, b, c, d, F3, KK1, 13, 8); |
208 | 0 | R( d, e, a, b, c, F3, KK1, 5, 9); |
209 | 0 | R( c, d, e, a, b, F3, KK1, 10, 11); |
210 | 0 | R( b, c, d, e, a, F3, KK1, 14, 7); |
211 | 0 | R( a, b, c, d, e, F3, KK1, 15, 7); |
212 | 0 | R( e, a, b, c, d, F3, KK1, 8, 12); |
213 | 0 | R( d, e, a, b, c, F3, KK1, 12, 7); |
214 | 0 | R( c, d, e, a, b, F3, KK1, 4, 6); |
215 | 0 | R( b, c, d, e, a, F3, KK1, 9, 15); |
216 | 0 | R( a, b, c, d, e, F3, KK1, 1, 13); |
217 | 0 | R( e, a, b, c, d, F3, KK1, 2, 11); |
218 | 0 | R( d, e, a, b, c, F2, KK2, 15, 9); |
219 | 0 | R( c, d, e, a, b, F2, KK2, 5, 7); |
220 | 0 | R( b, c, d, e, a, F2, KK2, 1, 15); |
221 | 0 | R( a, b, c, d, e, F2, KK2, 3, 11); |
222 | 0 | R( e, a, b, c, d, F2, KK2, 7, 8); |
223 | 0 | R( d, e, a, b, c, F2, KK2, 14, 6); |
224 | 0 | R( c, d, e, a, b, F2, KK2, 6, 6); |
225 | 0 | R( b, c, d, e, a, F2, KK2, 9, 14); |
226 | 0 | R( a, b, c, d, e, F2, KK2, 11, 12); |
227 | 0 | R( e, a, b, c, d, F2, KK2, 8, 13); |
228 | 0 | R( d, e, a, b, c, F2, KK2, 12, 5); |
229 | 0 | R( c, d, e, a, b, F2, KK2, 2, 14); |
230 | 0 | R( b, c, d, e, a, F2, KK2, 10, 13); |
231 | 0 | R( a, b, c, d, e, F2, KK2, 0, 13); |
232 | 0 | R( e, a, b, c, d, F2, KK2, 4, 7); |
233 | 0 | R( d, e, a, b, c, F2, KK2, 13, 5); |
234 | 0 | R( c, d, e, a, b, F1, KK3, 8, 15); |
235 | 0 | R( b, c, d, e, a, F1, KK3, 6, 5); |
236 | 0 | R( a, b, c, d, e, F1, KK3, 4, 8); |
237 | 0 | R( e, a, b, c, d, F1, KK3, 1, 11); |
238 | 0 | R( d, e, a, b, c, F1, KK3, 3, 14); |
239 | 0 | R( c, d, e, a, b, F1, KK3, 11, 14); |
240 | 0 | R( b, c, d, e, a, F1, KK3, 15, 6); |
241 | 0 | R( a, b, c, d, e, F1, KK3, 0, 14); |
242 | 0 | R( e, a, b, c, d, F1, KK3, 5, 6); |
243 | 0 | R( d, e, a, b, c, F1, KK3, 12, 9); |
244 | 0 | R( c, d, e, a, b, F1, KK3, 2, 12); |
245 | 0 | R( b, c, d, e, a, F1, KK3, 13, 9); |
246 | 0 | R( a, b, c, d, e, F1, KK3, 9, 12); |
247 | 0 | R( e, a, b, c, d, F1, KK3, 7, 5); |
248 | 0 | R( d, e, a, b, c, F1, KK3, 10, 15); |
249 | 0 | R( c, d, e, a, b, F1, KK3, 14, 8); |
250 | 0 | R( b, c, d, e, a, F0, KK4, 12, 8); |
251 | 0 | R( a, b, c, d, e, F0, KK4, 15, 5); |
252 | 0 | R( e, a, b, c, d, F0, KK4, 10, 12); |
253 | 0 | R( d, e, a, b, c, F0, KK4, 4, 9); |
254 | 0 | R( c, d, e, a, b, F0, KK4, 1, 12); |
255 | 0 | R( b, c, d, e, a, F0, KK4, 5, 5); |
256 | 0 | R( a, b, c, d, e, F0, KK4, 8, 14); |
257 | 0 | R( e, a, b, c, d, F0, KK4, 7, 6); |
258 | 0 | R( d, e, a, b, c, F0, KK4, 6, 8); |
259 | 0 | R( c, d, e, a, b, F0, KK4, 2, 13); |
260 | 0 | R( b, c, d, e, a, F0, KK4, 13, 6); |
261 | 0 | R( a, b, c, d, e, F0, KK4, 14, 5); |
262 | 0 | R( e, a, b, c, d, F0, KK4, 0, 15); |
263 | 0 | R( d, e, a, b, c, F0, KK4, 3, 13); |
264 | 0 | R( c, d, e, a, b, F0, KK4, 9, 11); |
265 | 0 | R( b, c, d, e, a, F0, KK4, 11, 11); |
266 | | |
267 | |
|
268 | 0 | t = state[1] + d + cc; |
269 | 0 | state[1] = state[2] + e + dd; |
270 | 0 | state[2] = state[3] + a + ee; |
271 | 0 | state[3] = state[4] + b + aa; |
272 | 0 | state[4] = state[0] + c + bb; |
273 | 0 | state[0] = t; |
274 | 0 | } |