• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young (eay@cryptsoft.com)"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #ifndef OPENSSL_HEADER_BN_INTERNAL_H
58 #define OPENSSL_HEADER_BN_INTERNAL_H
59 
60 #include <openssl/base.h>
61 
62 #if defined(__cplusplus)
63 extern "C" {
64 #endif
65 
66 
67 static void ripemd160_block_data_order(uint32_t h[5], const uint8_t *data,
68                                        size_t num);
69 
70 #define DATA_ORDER_IS_LITTLE_ENDIAN
71 
72 #define HASH_LONG uint32_t
73 #define HASH_CTX RIPEMD160_CTX
74 #define HASH_CBLOCK RIPEMD160_CBLOCK
75 #define HASH_UPDATE RIPEMD160_Update
76 #define HASH_TRANSFORM RIPEMD160_Transform
77 #define HASH_FINAL RIPEMD160_Final
78 #define HASH_MAKE_STRING(c, s) \
79   do {                         \
80     unsigned long ll;          \
81     ll = (c)->h[0];            \
82     HOST_l2c(ll, (s));         \
83     ll = (c)->h[1];            \
84     HOST_l2c(ll, (s));         \
85     ll = (c)->h[2];            \
86     HOST_l2c(ll, (s));         \
87     ll = (c)->h[3];            \
88     HOST_l2c(ll, (s));         \
89     ll = (c)->h[4];            \
90     HOST_l2c(ll, (s));         \
91   } while (0)
92 #define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
93 
94 #include "../../crypto/fipsmodule/digest/md32_common.h"
95 
96 /* Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com> */
97 #define F1(x, y, z) ((x) ^ (y) ^ (z))
98 #define F2(x, y, z) ((((y) ^ (z)) & (x)) ^ (z))
99 #define F3(x, y, z) (((~(y)) | (x)) ^ (z))
100 #define F4(x, y, z) ((((x) ^ (y)) & (z)) ^ (y))
101 #define F5(x, y, z) (((~(z)) | (y)) ^ (x))
102 
103 #define RIPEMD160_A 0x67452301L
104 #define RIPEMD160_B 0xEFCDAB89L
105 #define RIPEMD160_C 0x98BADCFEL
106 #define RIPEMD160_D 0x10325476L
107 #define RIPEMD160_E 0xC3D2E1F0L
108 
109 #define ROTATE(a, n) (((a) << (n)) | (((a)&0xffffffff) >> (32 - (n))))
110 
111 #define RIP1(a, b, c, d, e, w, s) \
112   {                               \
113     a += F1(b, c, d) + X(w);      \
114     a = ROTATE(a, s) + e;         \
115     c = ROTATE(c, 10);            \
116   }
117 
118 #define RIP2(a, b, c, d, e, w, s, K) \
119   {                                  \
120     a += F2(b, c, d) + X(w) + K;     \
121     a = ROTATE(a, s) + e;            \
122     c = ROTATE(c, 10);               \
123   }
124 
125 #define RIP3(a, b, c, d, e, w, s, K) \
126   {                                  \
127     a += F3(b, c, d) + X(w) + K;     \
128     a = ROTATE(a, s) + e;            \
129     c = ROTATE(c, 10);               \
130   }
131 
132 #define RIP4(a, b, c, d, e, w, s, K) \
133   {                                  \
134     a += F4(b, c, d) + X(w) + K;     \
135     a = ROTATE(a, s) + e;            \
136     c = ROTATE(c, 10);               \
137   }
138 
139 #define RIP5(a, b, c, d, e, w, s, K) \
140   {                                  \
141     a += F5(b, c, d) + X(w) + K;     \
142     a = ROTATE(a, s) + e;            \
143     c = ROTATE(c, 10);               \
144   }
145 
146 #define KL0 0x00000000L
147 #define KL1 0x5A827999L
148 #define KL2 0x6ED9EBA1L
149 #define KL3 0x8F1BBCDCL
150 #define KL4 0xA953FD4EL
151 
152 #define KR0 0x50A28BE6L
153 #define KR1 0x5C4DD124L
154 #define KR2 0x6D703EF3L
155 #define KR3 0x7A6D76E9L
156 #define KR4 0x00000000L
157 
158 #define WL00  0
159 #define SL00 11
160 #define WL01  1
161 #define SL01 14
162 #define WL02  2
163 #define SL02 15
164 #define WL03  3
165 #define SL03 12
166 #define WL04  4
167 #define SL04  5
168 #define WL05  5
169 #define SL05  8
170 #define WL06  6
171 #define SL06  7
172 #define WL07  7
173 #define SL07  9
174 #define WL08  8
175 #define SL08 11
176 #define WL09  9
177 #define SL09 13
178 #define WL10 10
179 #define SL10 14
180 #define WL11 11
181 #define SL11 15
182 #define WL12 12
183 #define SL12  6
184 #define WL13 13
185 #define SL13  7
186 #define WL14 14
187 #define SL14  9
188 #define WL15 15
189 #define SL15  8
190 
191 #define WL16  7
192 #define SL16  7
193 #define WL17  4
194 #define SL17  6
195 #define WL18 13
196 #define SL18  8
197 #define WL19  1
198 #define SL19 13
199 #define WL20 10
200 #define SL20 11
201 #define WL21  6
202 #define SL21  9
203 #define WL22 15
204 #define SL22  7
205 #define WL23  3
206 #define SL23 15
207 #define WL24 12
208 #define SL24  7
209 #define WL25  0
210 #define SL25 12
211 #define WL26  9
212 #define SL26 15
213 #define WL27  5
214 #define SL27  9
215 #define WL28  2
216 #define SL28 11
217 #define WL29 14
218 #define SL29  7
219 #define WL30 11
220 #define SL30 13
221 #define WL31  8
222 #define SL31 12
223 
224 #define WL32  3
225 #define SL32 11
226 #define WL33 10
227 #define SL33 13
228 #define WL34 14
229 #define SL34  6
230 #define WL35  4
231 #define SL35  7
232 #define WL36  9
233 #define SL36 14
234 #define WL37 15
235 #define SL37  9
236 #define WL38  8
237 #define SL38 13
238 #define WL39  1
239 #define SL39 15
240 #define WL40  2
241 #define SL40 14
242 #define WL41  7
243 #define SL41  8
244 #define WL42  0
245 #define SL42 13
246 #define WL43  6
247 #define SL43  6
248 #define WL44 13
249 #define SL44  5
250 #define WL45 11
251 #define SL45 12
252 #define WL46  5
253 #define SL46  7
254 #define WL47 12
255 #define SL47  5
256 
257 #define WL48  1
258 #define SL48 11
259 #define WL49  9
260 #define SL49 12
261 #define WL50 11
262 #define SL50 14
263 #define WL51 10
264 #define SL51 15
265 #define WL52  0
266 #define SL52 14
267 #define WL53  8
268 #define SL53 15
269 #define WL54 12
270 #define SL54  9
271 #define WL55  4
272 #define SL55  8
273 #define WL56 13
274 #define SL56  9
275 #define WL57  3
276 #define SL57 14
277 #define WL58  7
278 #define SL58  5
279 #define WL59 15
280 #define SL59  6
281 #define WL60 14
282 #define SL60  8
283 #define WL61  5
284 #define SL61  6
285 #define WL62  6
286 #define SL62  5
287 #define WL63  2
288 #define SL63 12
289 
290 #define WL64  4
291 #define SL64  9
292 #define WL65  0
293 #define SL65 15
294 #define WL66  5
295 #define SL66  5
296 #define WL67  9
297 #define SL67 11
298 #define WL68  7
299 #define SL68  6
300 #define WL69 12
301 #define SL69  8
302 #define WL70  2
303 #define SL70 13
304 #define WL71 10
305 #define SL71 12
306 #define WL72 14
307 #define SL72  5
308 #define WL73  1
309 #define SL73 12
310 #define WL74  3
311 #define SL74 13
312 #define WL75  8
313 #define SL75 14
314 #define WL76 11
315 #define SL76 11
316 #define WL77  6
317 #define SL77  8
318 #define WL78 15
319 #define SL78  5
320 #define WL79 13
321 #define SL79  6
322 
323 #define WR00  5
324 #define SR00  8
325 #define WR01 14
326 #define SR01  9
327 #define WR02  7
328 #define SR02  9
329 #define WR03  0
330 #define SR03 11
331 #define WR04  9
332 #define SR04 13
333 #define WR05  2
334 #define SR05 15
335 #define WR06 11
336 #define SR06 15
337 #define WR07  4
338 #define SR07  5
339 #define WR08 13
340 #define SR08  7
341 #define WR09  6
342 #define SR09  7
343 #define WR10 15
344 #define SR10  8
345 #define WR11  8
346 #define SR11 11
347 #define WR12  1
348 #define SR12 14
349 #define WR13 10
350 #define SR13 14
351 #define WR14  3
352 #define SR14 12
353 #define WR15 12
354 #define SR15  6
355 
356 #define WR16  6
357 #define SR16  9
358 #define WR17 11
359 #define SR17 13
360 #define WR18  3
361 #define SR18 15
362 #define WR19  7
363 #define SR19  7
364 #define WR20  0
365 #define SR20 12
366 #define WR21 13
367 #define SR21  8
368 #define WR22  5
369 #define SR22  9
370 #define WR23 10
371 #define SR23 11
372 #define WR24 14
373 #define SR24  7
374 #define WR25 15
375 #define SR25  7
376 #define WR26  8
377 #define SR26 12
378 #define WR27 12
379 #define SR27  7
380 #define WR28  4
381 #define SR28  6
382 #define WR29  9
383 #define SR29 15
384 #define WR30  1
385 #define SR30 13
386 #define WR31  2
387 #define SR31 11
388 
389 #define WR32 15
390 #define SR32  9
391 #define WR33  5
392 #define SR33  7
393 #define WR34  1
394 #define SR34 15
395 #define WR35  3
396 #define SR35 11
397 #define WR36  7
398 #define SR36  8
399 #define WR37 14
400 #define SR37  6
401 #define WR38  6
402 #define SR38  6
403 #define WR39  9
404 #define SR39 14
405 #define WR40 11
406 #define SR40 12
407 #define WR41  8
408 #define SR41 13
409 #define WR42 12
410 #define SR42  5
411 #define WR43  2
412 #define SR43 14
413 #define WR44 10
414 #define SR44 13
415 #define WR45  0
416 #define SR45 13
417 #define WR46  4
418 #define SR46  7
419 #define WR47 13
420 #define SR47  5
421 
422 #define WR48  8
423 #define SR48 15
424 #define WR49  6
425 #define SR49  5
426 #define WR50  4
427 #define SR50  8
428 #define WR51  1
429 #define SR51 11
430 #define WR52  3
431 #define SR52 14
432 #define WR53 11
433 #define SR53 14
434 #define WR54 15
435 #define SR54  6
436 #define WR55  0
437 #define SR55 14
438 #define WR56  5
439 #define SR56  6
440 #define WR57 12
441 #define SR57  9
442 #define WR58  2
443 #define SR58 12
444 #define WR59 13
445 #define SR59  9
446 #define WR60  9
447 #define SR60 12
448 #define WR61  7
449 #define SR61  5
450 #define WR62 10
451 #define SR62 15
452 #define WR63 14
453 #define SR63  8
454 
455 #define WR64 12
456 #define SR64  8
457 #define WR65 15
458 #define SR65  5
459 #define WR66 10
460 #define SR66 12
461 #define WR67  4
462 #define SR67  9
463 #define WR68  1
464 #define SR68 12
465 #define WR69  5
466 #define SR69  5
467 #define WR70  8
468 #define SR70 14
469 #define WR71  7
470 #define SR71  6
471 #define WR72  6
472 #define SR72  8
473 #define WR73  2
474 #define SR73 13
475 #define WR74 13
476 #define SR74  6
477 #define WR75 14
478 #define SR75  5
479 #define WR76  0
480 #define SR76 15
481 #define WR77  3
482 #define SR77 13
483 #define WR78  9
484 #define SR78 11
485 #define WR79 11
486 #define SR79 11
487 
488 
489 #if defined(__cplusplus)
490 }  /* extern C */
491 #endif
492 
493 #endif  /* OPENSSL_HEADER_BN_INTERNAL_H */
494