summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ripemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ripemd')
-rw-r--r--src/lib/libcrypto/ripemd/asm/rmd-586.pl112
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h46
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c471
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h182
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c9
5 files changed, 362 insertions, 458 deletions
diff --git a/src/lib/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
index dc3f6c792e..0ab6f76bff 100644
--- a/src/lib/libcrypto/ripemd/asm/rmd-586.pl
+++ b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
@@ -1,9 +1,7 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3# Normal is the 3# Normal is the
4# ripemd160_block_x86(MD5_CTX *c, ULONG *X); 4# ripemd160_block_asm_host_order(RIPEMD160_CTX *c, ULONG *X,int blocks);
5# version, non-normal is the
6# ripemd160_block_x86(MD5_CTX *c, ULONG *X,int blocks);
7 5
8$normal=0; 6$normal=0;
9 7
@@ -12,13 +10,13 @@ require "x86asm.pl";
12 10
13&asm_init($ARGV[0],$0); 11&asm_init($ARGV[0],$0);
14 12
15$A="eax"; 13$A="ecx";
16$B="ebx"; 14$B="esi";
17$C="ecx"; 15$C="edi";
18$D="edx"; 16$D="ebx";
19$E="ebp"; 17$E="ebp";
20$tmp1="esi"; 18$tmp1="eax";
21$tmp2="edi"; 19$tmp2="edx";
22 20
23$KL1=0x5A827999; 21$KL1=0x5A827999;
24$KL2=0x6ED9EBA1; 22$KL2=0x6ED9EBA1;
@@ -58,13 +56,13 @@ $KR3=0x7A6D76E9;
58 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11, 56 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11,
59 ); 57 );
60 58
61&ripemd160_block("ripemd160_block_x86"); 59&ripemd160_block("ripemd160_block_asm_host_order");
62&asm_finish(); 60&asm_finish();
63 61
64sub Xv 62sub Xv
65 { 63 {
66 local($n)=@_; 64 local($n)=@_;
67 return(&swtmp($n+1)); 65 return(&swtmp($n));
68 # tmp on stack 66 # tmp on stack
69 } 67 }
70 68
@@ -82,7 +80,7 @@ sub RIP1
82 &comment($p++); 80 &comment($p++);
83 if ($p & 1) 81 if ($p & 1)
84 { 82 {
85 &mov($tmp1, $c) if $o == -1; 83 #&mov($tmp1, $c) if $o == -1;
86 &xor($tmp1, $d) if $o == -1; 84 &xor($tmp1, $d) if $o == -1;
87 &mov($tmp2, &Xv($pos)); 85 &mov($tmp2, &Xv($pos));
88 &xor($tmp1, $b); 86 &xor($tmp1, $b);
@@ -290,7 +288,7 @@ sub RIP5
290 &rotl($c, 10); 288 &rotl($c, 10);
291 &lea($a, &DWP($K,$a,$tmp1,1)); 289 &lea($a, &DWP($K,$a,$tmp1,1));
292 &sub($tmp2, &Np($d)) if $o <= 0; 290 &sub($tmp2, &Np($d)) if $o <= 0;
293 &mov(&swtmp(1+16), $A) if $o == 1; 291 &mov(&swtmp(16), $A) if $o == 1;
294 &mov($tmp1, &Np($d)) if $o == 2; 292 &mov($tmp1, &Np($d)) if $o == 2;
295 &rotl($a, $s); 293 &rotl($a, $s);
296 &add($a, $e); 294 &add($a, $e);
@@ -310,19 +308,25 @@ sub ripemd160_block
310 # D 12 308 # D 12
311 # E 16 309 # E 16
312 310
311 &mov($tmp2, &wparam(0));
312 &mov($tmp1, &wparam(1));
313 &push("esi"); 313 &push("esi");
314 &mov($C, &wparam(2)); 314 &mov($A, &DWP( 0,$tmp2,"",0));
315 &push("edi"); 315 &push("edi");
316 &mov($tmp1, &wparam(1)); # edi 316 &mov($B, &DWP( 4,$tmp2,"",0));
317 &push("ebp"); 317 &push("ebp");
318 &add($C, $tmp1); # offset we end at 318 &mov($C, &DWP( 8,$tmp2,"",0));
319 &push("ebx"); 319 &push("ebx");
320 &sub($C, 64); 320 &stack_push(16+5+6);
321 &stack_push(16+5+1); 321 # Special comment about the figure of 6.
322 # XXX 322 # Idea is to pad the current frame so
323 323 # that the top of the stack gets fairly
324 &mov(&swtmp(0), $C); 324 # aligned. Well, as you realize it would
325 &mov($tmp2, &wparam(0)); # Done at end of loop 325 # always depend on how the frame below is
326 # aligned. The good news are that gcc-2.95
327 # and later does keep first argument at
328 # least double-wise aligned.
329 # <appro@fy.chalmers.se>
326 330
327 &set_label("start") unless $normal; 331 &set_label("start") unless $normal;
328 &comment(""); 332 &comment("");
@@ -332,16 +336,12 @@ sub ripemd160_block
332 336
333 for ($z=0; $z<16; $z+=2) 337 for ($z=0; $z<16; $z+=2)
334 { 338 {
335 &mov($A, &DWP( $z*4,$tmp1,"",0)); 339 &mov($D, &DWP( $z*4,$tmp1,"",0));
336 &mov($B, &DWP( ($z+1)*4,$tmp1,"",0)); 340 &mov($E, &DWP( ($z+1)*4,$tmp1,"",0));
337 &mov(&swtmp(1+$z), $A); 341 &mov(&swtmp($z), $D);
338 &mov(&swtmp(1+$z+1), $B); 342 &mov(&swtmp($z+1), $E);
339 } 343 }
340 &add($tmp1, 64); 344 &mov($tmp1, $C);
341 &mov($A, &DWP( 0,$tmp2,"",0));
342 &mov(&wparam(1),$tmp1);
343 &mov($B, &DWP( 4,$tmp2,"",0));
344 &mov($C, &DWP( 8,$tmp2,"",0));
345 &mov($D, &DWP(12,$tmp2,"",0)); 345 &mov($D, &DWP(12,$tmp2,"",0));
346 &mov($E, &DWP(16,$tmp2,"",0)); 346 &mov($E, &DWP(16,$tmp2,"",0));
347 347
@@ -431,14 +431,14 @@ sub ripemd160_block
431 &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1); 431 &RIP5($B,$C,$D,$E,$A,$wl[79],$sl[79],$KL4,1);
432 432
433 # &mov($tmp2, &wparam(0)); # moved into last RIP5 433 # &mov($tmp2, &wparam(0)); # moved into last RIP5
434 # &mov(&swtmp(1+16), $A); 434 # &mov(&swtmp(16), $A);
435 &mov($A, &DWP( 0,$tmp2,"",0)); 435 &mov($A, &DWP( 0,$tmp2,"",0));
436 &mov(&swtmp(1+17), $B); 436 &mov(&swtmp(16+1), $B);
437 &mov(&swtmp(1+18), $C); 437 &mov(&swtmp(16+2), $C);
438 &mov($B, &DWP( 4,$tmp2,"",0)); 438 &mov($B, &DWP( 4,$tmp2,"",0));
439 &mov(&swtmp(1+19), $D); 439 &mov(&swtmp(16+3), $D);
440 &mov($C, &DWP( 8,$tmp2,"",0)); 440 &mov($C, &DWP( 8,$tmp2,"",0));
441 &mov(&swtmp(1+20), $E); 441 &mov(&swtmp(16+4), $E);
442 &mov($D, &DWP(12,$tmp2,"",0)); 442 &mov($D, &DWP(12,$tmp2,"",0));
443 &mov($E, &DWP(16,$tmp2,"",0)); 443 &mov($E, &DWP(16,$tmp2,"",0));
444 444
@@ -530,47 +530,55 @@ sub ripemd160_block
530 # &mov($tmp2, &wparam(0)); # Moved into last round 530 # &mov($tmp2, &wparam(0)); # Moved into last round
531 531
532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B 532 &mov($tmp1, &DWP( 4,$tmp2,"",0)); # ctx->B
533 &add($D, $tmp1); 533 &add($D, $tmp1);
534 &mov($tmp1, &swtmp(1+18)); # $c 534 &mov($tmp1, &swtmp(16+2)); # $c
535 &add($D, $tmp1); 535 &add($D, $tmp1);
536 536
537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C 537 &mov($tmp1, &DWP( 8,$tmp2,"",0)); # ctx->C
538 &add($E, $tmp1); 538 &add($E, $tmp1);
539 &mov($tmp1, &swtmp(1+19)); # $d 539 &mov($tmp1, &swtmp(16+3)); # $d
540 &add($E, $tmp1); 540 &add($E, $tmp1);
541 541
542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D 542 &mov($tmp1, &DWP(12,$tmp2,"",0)); # ctx->D
543 &add($A, $tmp1); 543 &add($A, $tmp1);
544 &mov($tmp1, &swtmp(1+20)); # $e 544 &mov($tmp1, &swtmp(16+4)); # $e
545 &add($A, $tmp1); 545 &add($A, $tmp1);
546 546
547 547
548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E 548 &mov($tmp1, &DWP(16,$tmp2,"",0)); # ctx->E
549 &add($B, $tmp1); 549 &add($B, $tmp1);
550 &mov($tmp1, &swtmp(1+16)); # $a 550 &mov($tmp1, &swtmp(16+0)); # $a
551 &add($B, $tmp1); 551 &add($B, $tmp1);
552 552
553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A 553 &mov($tmp1, &DWP( 0,$tmp2,"",0)); # ctx->A
554 &add($C, $tmp1); 554 &add($C, $tmp1);
555 &mov($tmp1, &swtmp(1+17)); # $b 555 &mov($tmp1, &swtmp(16+1)); # $b
556 &add($C, $tmp1); 556 &add($C, $tmp1);
557 557
558 &mov($tmp1, &wparam(2));
559
558 &mov(&DWP( 0,$tmp2,"",0), $D); 560 &mov(&DWP( 0,$tmp2,"",0), $D);
559 &mov(&DWP( 4,$tmp2,"",0), $E); 561 &mov(&DWP( 4,$tmp2,"",0), $E);
560 &mov(&DWP( 8,$tmp2,"",0), $A); 562 &mov(&DWP( 8,$tmp2,"",0), $A);
561 &mov(&DWP(12,$tmp2,"",0), $B); 563 &sub($tmp1,1);
562 &mov(&DWP(16,$tmp2,"",0), $C); 564 &mov(&DWP(12,$tmp2,"",0), $B);
565 &mov(&DWP(16,$tmp2,"",0), $C);
563 566
564 &mov($tmp2, &swtmp(0)); 567 &jle(&label("get_out"));
565 &mov($tmp1, &wparam(1)); 568
569 &mov(&wparam(2),$tmp1);
570 &mov($C, $A);
571 &mov($tmp1, &wparam(1));
572 &mov($A, $D);
573 &add($tmp1, 64);
574 &mov($B, $E);
575 &mov(&wparam(1),$tmp1);
566 576
567 &cmp($tmp2,$tmp1); 577 &jmp(&label("start"));
568 &mov($tmp2, &wparam(0));
569 578
570 # XXX 579 &set_label("get_out");
571 &jge(&label("start"));
572 580
573 &stack_pop(16+5+1); 581 &stack_pop(16+5+6);
574 582
575 &pop("ebx"); 583 &pop("ebx");
576 &pop("ebp"); 584 &pop("ebp");
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
index a3bc6e3ab2..78d5f36560 100644
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ b/src/lib/libcrypto/ripemd/ripemd.h
@@ -59,39 +59,43 @@
59#ifndef HEADER_RIPEMD_H 59#ifndef HEADER_RIPEMD_H
60#define HEADER_RIPEMD_H 60#define HEADER_RIPEMD_H
61 61
62#include <openssl/e_os2.h>
63
62#ifdef __cplusplus 64#ifdef __cplusplus
63extern "C" { 65extern "C" {
64#endif 66#endif
65 67
68#ifdef OPENSSL_NO_RIPEMD
69#error RIPEMD is disabled.
70#endif
71
72#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
73#define RIPEMD160_LONG unsigned long
74#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
75#define RIPEMD160_LONG unsigned long
76#define RIPEMD160_LONG_LOG2 3
77#else
78#define RIPEMD160_LONG unsigned int
79#endif
80
66#define RIPEMD160_CBLOCK 64 81#define RIPEMD160_CBLOCK 64
67#define RIPEMD160_LBLOCK 16 82#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK/4)
68#define RIPEMD160_BLOCK 16
69#define RIPEMD160_LAST_BLOCK 56
70#define RIPEMD160_LENGTH_BLOCK 8
71#define RIPEMD160_DIGEST_LENGTH 20 83#define RIPEMD160_DIGEST_LENGTH 20
72 84
73typedef struct RIPEMD160state_st 85typedef struct RIPEMD160state_st
74 { 86 {
75 unsigned long A,B,C,D,E; 87 RIPEMD160_LONG A,B,C,D,E;
76 unsigned long Nl,Nh; 88 RIPEMD160_LONG Nl,Nh;
77 unsigned long data[RIPEMD160_LBLOCK]; 89 RIPEMD160_LONG data[RIPEMD160_LBLOCK];
78 int num; 90 int num;
79 } RIPEMD160_CTX; 91 } RIPEMD160_CTX;
80 92
81#ifndef NOPROTO 93int RIPEMD160_Init(RIPEMD160_CTX *c);
82void RIPEMD160_Init(RIPEMD160_CTX *c); 94int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
83void RIPEMD160_Update(RIPEMD160_CTX *c, unsigned char *data, unsigned long len); 95int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
84void RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 96unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
85unsigned char *RIPEMD160(unsigned char *d, unsigned long n, unsigned char *md); 97 unsigned char *md);
86void RIPEMD160_Transform(RIPEMD160_CTX *c, unsigned char *b); 98void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
87#else
88void RIPEMD160_Init();
89void RIPEMD160_Update();
90void RIPEMD160_Final();
91unsigned char *RIPEMD160();
92void RIPEMD160_Transform();
93#endif
94
95#ifdef __cplusplus 99#ifdef __cplusplus
96} 100}
97#endif 101#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
index 210de1977d..a3170f7c8a 100644
--- a/src/lib/libcrypto/ripemd/rmd_dgst.c
+++ b/src/lib/libcrypto/ripemd/rmd_dgst.c
@@ -58,27 +58,18 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "rmd_locl.h" 60#include "rmd_locl.h"
61#include <openssl/opensslv.h>
61 62
62char *RMD160_version="RIPEMD160 part of SSLeay 0.9.0b 29-Jun-1998"; 63const char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
63 64
64#ifndef NOPROTO
65# ifdef RMD160_ASM 65# ifdef RMD160_ASM
66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num); 66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
67# define ripemd160_block ripemd160_block_x86 67# define ripemd160_block ripemd160_block_x86
68# else 68# else
69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num); 69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
70# endif 70# endif
71#else
72# ifdef RMD160_ASM
73 void ripemd160_block_x86();
74# define ripemd160_block ripemd160_block_x86
75# else
76 static void ripemd160_block();
77# endif
78#endif
79 71
80void RIPEMD160_Init(c) 72int RIPEMD160_Init(RIPEMD160_CTX *c)
81RIPEMD160_CTX *c;
82 { 73 {
83 c->A=RIPEMD160_A; 74 c->A=RIPEMD160_A;
84 c->B=RIPEMD160_B; 75 c->B=RIPEMD160_B;
@@ -88,189 +79,24 @@ RIPEMD160_CTX *c;
88 c->Nl=0; 79 c->Nl=0;
89 c->Nh=0; 80 c->Nh=0;
90 c->num=0; 81 c->num=0;
82 return 1;
91 } 83 }
92 84
93void RIPEMD160_Update(c, data, len) 85#ifndef ripemd160_block_host_order
94RIPEMD160_CTX *c; 86#ifdef X
95register unsigned char *data; 87#undef X
96unsigned long len;
97 {
98 register ULONG *p;
99 int sw,sc;
100 ULONG l;
101
102 if (len == 0) return;
103
104 l=(c->Nl+(len<<3))&0xffffffffL;
105 if (l < c->Nl) /* overflow */
106 c->Nh++;
107 c->Nh+=(len>>29);
108 c->Nl=l;
109
110 if (c->num != 0)
111 {
112 p=c->data;
113 sw=c->num>>2;
114 sc=c->num&0x03;
115
116 if ((c->num+len) >= RIPEMD160_CBLOCK)
117 {
118 l= p[sw];
119 p_c2l(data,l,sc);
120 p[sw++]=l;
121 for (; sw<RIPEMD160_LBLOCK; sw++)
122 {
123 c2l(data,l);
124 p[sw]=l;
125 }
126 len-=(RIPEMD160_CBLOCK-c->num);
127
128 ripemd160_block(c,p,64);
129 c->num=0;
130 /* drop through and do the rest */
131 }
132 else
133 {
134 int ew,ec;
135
136 c->num+=(int)len;
137 if ((sc+len) < 4) /* ugly, add char's to a word */
138 {
139 l= p[sw];
140 p_c2l_p(data,l,sc,len);
141 p[sw]=l;
142 }
143 else
144 {
145 ew=(c->num>>2);
146 ec=(c->num&0x03);
147 l= p[sw];
148 p_c2l(data,l,sc);
149 p[sw++]=l;
150 for (; sw < ew; sw++)
151 { c2l(data,l); p[sw]=l; }
152 if (ec)
153 {
154 c2l_p(data,l,ec);
155 p[sw]=l;
156 }
157 }
158 return;
159 }
160 }
161 /* we now can process the input data in blocks of RIPEMD160_CBLOCK
162 * chars and save the leftovers to c->data. */
163#ifdef L_ENDIAN
164 if ((((unsigned long)data)%sizeof(ULONG)) == 0)
165 {
166 sw=(int)len/RIPEMD160_CBLOCK;
167 if (sw > 0)
168 {
169 sw*=RIPEMD160_CBLOCK;
170 ripemd160_block(c,(ULONG *)data,sw);
171 data+=sw;
172 len-=sw;
173 }
174 }
175#endif 88#endif
176 p=c->data; 89#define X(i) XX[i]
177 while (len >= RIPEMD160_CBLOCK) 90void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num)
178 {
179#if defined(L_ENDIAN) || defined(B_ENDIAN)
180 if (p != (unsigned long *)data)
181 memcpy(p,data,RIPEMD160_CBLOCK);
182 data+=RIPEMD160_CBLOCK;
183#ifdef B_ENDIAN
184 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
185 {
186 Endian_Reverse32(p[0]);
187 Endian_Reverse32(p[1]);
188 Endian_Reverse32(p[2]);
189 Endian_Reverse32(p[3]);
190 p+=4;
191 }
192#endif
193#else
194 for (sw=(RIPEMD160_LBLOCK/4); sw; sw--)
195 {
196 c2l(data,l); *(p++)=l;
197 c2l(data,l); *(p++)=l;
198 c2l(data,l); *(p++)=l;
199 c2l(data,l); *(p++)=l;
200 }
201#endif
202 p=c->data;
203 ripemd160_block(c,p,64);
204 len-=RIPEMD160_CBLOCK;
205 }
206 sc=(int)len;
207 c->num=sc;
208 if (sc)
209 {
210 sw=sc>>2; /* words to copy */
211#ifdef L_ENDIAN
212 p[sw]=0;
213 memcpy(p,data,sc);
214#else
215 sc&=0x03;
216 for ( ; sw; sw--)
217 { c2l(data,l); *(p++)=l; }
218 c2l_p(data,l,sc);
219 *p=l;
220#endif
221 }
222 }
223
224void RIPEMD160_Transform(c,b)
225RIPEMD160_CTX *c;
226unsigned char *b;
227 { 91 {
228 ULONG p[16]; 92 const RIPEMD160_LONG *XX=p;
229#if !defined(L_ENDIAN) 93 register unsigned long A,B,C,D,E;
230 ULONG *q; 94 register unsigned long a,b,c,d,e;
231 int i;
232#endif
233 95
234#if defined(B_ENDIAN) || defined(L_ENDIAN) 96 for (;num--;XX+=HASH_LBLOCK)
235 memcpy(p,b,64);
236#ifdef B_ENDIAN
237 q=p;
238 for (i=(RIPEMD160_LBLOCK/4); i; i--)
239 {
240 Endian_Reverse32(q[0]);
241 Endian_Reverse32(q[1]);
242 Endian_Reverse32(q[2]);
243 Endian_Reverse32(q[3]);
244 q+=4;
245 }
246#endif
247#else
248 q=p;
249 for (i=(RIPEMD160_LBLOCK/4); i; i--)
250 { 97 {
251 ULONG l;
252 c2l(b,l); *(q++)=l;
253 c2l(b,l); *(q++)=l;
254 c2l(b,l); *(q++)=l;
255 c2l(b,l); *(q++)=l;
256 }
257#endif
258 ripemd160_block(c,p,64);
259 }
260
261#ifndef RMD160_ASM
262
263void ripemd160_block(ctx, X, num)
264RIPEMD160_CTX *ctx;
265register ULONG *X;
266int num;
267 {
268 register ULONG A,B,C,D,E;
269 ULONG a,b,c,d,e;
270 98
271 for (;;) 99 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
272 {
273 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
274 100
275 RIP1(A,B,C,D,E,WL00,SL00); 101 RIP1(A,B,C,D,E,WL00,SL00);
276 RIP1(E,A,B,C,D,WL01,SL01); 102 RIP1(E,A,B,C,D,WL01,SL01);
@@ -453,83 +279,216 @@ int num;
453 ctx->E=ctx->A+b+C; 279 ctx->E=ctx->A+b+C;
454 ctx->A=D; 280 ctx->A=D;
455 281
456 X+=16;
457 num-=64;
458 if (num <= 0) break;
459 } 282 }
460 } 283 }
461#endif 284#endif
462 285
463void RIPEMD160_Final(md, c) 286#ifndef ripemd160_block_data_order
464unsigned char *md; 287#ifdef X
465RIPEMD160_CTX *c; 288#undef X
289#endif
290void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num)
466 { 291 {
467 register int i,j; 292 const unsigned char *data=p;
468 register ULONG l; 293 register unsigned long A,B,C,D,E;
469 register ULONG *p; 294 unsigned long a,b,c,d,e,l;
470 static unsigned char end[4]={0x80,0x00,0x00,0x00}; 295#ifndef MD32_XARRAY
471 unsigned char *cp=end; 296 /* See comment in crypto/sha/sha_locl.h for details. */
472 297 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
473 /* c->num should definitly have room for at least one more byte. */ 298 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
474 p=c->data; 299# define X(i) XX##i
475 j=c->num; 300#else
476 i=j>>2; 301 RIPEMD160_LONG XX[16];
477 302# define X(i) XX[i]
478 /* purify often complains about the following line as an
479 * Uninitialized Memory Read. While this can be true, the
480 * following p_c2l macro will reset l when that case is true.
481 * This is because j&0x03 contains the number of 'valid' bytes
482 * already in p[i]. If and only if j&0x03 == 0, the UMR will
483 * occur but this is also the only time p_c2l will do
484 * l= *(cp++) instead of l|= *(cp++)
485 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
486 * 'potential bug' */
487#ifdef PURIFY
488 if ((j&0x03) == 0) p[i]=0;
489#endif 303#endif
490 l=p[i]; 304
491 p_c2l(cp,l,j&0x03); 305 for (;num--;)
492 p[i]=l;
493 i++;
494 /* i is the next 'undefined word' */
495 if (c->num >= RIPEMD160_LAST_BLOCK)
496 { 306 {
497 for (; i<RIPEMD160_LBLOCK; i++)
498 p[i]=0;
499 ripemd160_block(c,p,64);
500 i=0;
501 }
502 for (; i<(RIPEMD160_LBLOCK-2); i++)
503 p[i]=0;
504 p[RIPEMD160_LBLOCK-2]=c->Nl;
505 p[RIPEMD160_LBLOCK-1]=c->Nh;
506 ripemd160_block(c,p,64);
507 cp=md;
508 l=c->A; l2c(l,cp);
509 l=c->B; l2c(l,cp);
510 l=c->C; l2c(l,cp);
511 l=c->D; l2c(l,cp);
512 l=c->E; l2c(l,cp);
513
514 /* clear stuff, ripemd160_block may be leaving some stuff on the stack
515 * but I'm not worried :-) */
516 c->num=0;
517/* memset((char *)&c,0,sizeof(c));*/
518 }
519 307
520#ifdef undef 308 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
521int printit(l) 309
522unsigned long *l; 310 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
523 { 311 RIP1(A,B,C,D,E,WL00,SL00); HOST_c2l(data,l); X( 2)=l;
524 int i,ii; 312 RIP1(E,A,B,C,D,WL01,SL01); HOST_c2l(data,l); X( 3)=l;
313 RIP1(D,E,A,B,C,WL02,SL02); HOST_c2l(data,l); X( 4)=l;
314 RIP1(C,D,E,A,B,WL03,SL03); HOST_c2l(data,l); X( 5)=l;
315 RIP1(B,C,D,E,A,WL04,SL04); HOST_c2l(data,l); X( 6)=l;
316 RIP1(A,B,C,D,E,WL05,SL05); HOST_c2l(data,l); X( 7)=l;
317 RIP1(E,A,B,C,D,WL06,SL06); HOST_c2l(data,l); X( 8)=l;
318 RIP1(D,E,A,B,C,WL07,SL07); HOST_c2l(data,l); X( 9)=l;
319 RIP1(C,D,E,A,B,WL08,SL08); HOST_c2l(data,l); X(10)=l;
320 RIP1(B,C,D,E,A,WL09,SL09); HOST_c2l(data,l); X(11)=l;
321 RIP1(A,B,C,D,E,WL10,SL10); HOST_c2l(data,l); X(12)=l;
322 RIP1(E,A,B,C,D,WL11,SL11); HOST_c2l(data,l); X(13)=l;
323 RIP1(D,E,A,B,C,WL12,SL12); HOST_c2l(data,l); X(14)=l;
324 RIP1(C,D,E,A,B,WL13,SL13); HOST_c2l(data,l); X(15)=l;
325 RIP1(B,C,D,E,A,WL14,SL14);
326 RIP1(A,B,C,D,E,WL15,SL15);
327
328 RIP2(E,A,B,C,D,WL16,SL16,KL1);
329 RIP2(D,E,A,B,C,WL17,SL17,KL1);
330 RIP2(C,D,E,A,B,WL18,SL18,KL1);
331 RIP2(B,C,D,E,A,WL19,SL19,KL1);
332 RIP2(A,B,C,D,E,WL20,SL20,KL1);
333 RIP2(E,A,B,C,D,WL21,SL21,KL1);
334 RIP2(D,E,A,B,C,WL22,SL22,KL1);
335 RIP2(C,D,E,A,B,WL23,SL23,KL1);
336 RIP2(B,C,D,E,A,WL24,SL24,KL1);
337 RIP2(A,B,C,D,E,WL25,SL25,KL1);
338 RIP2(E,A,B,C,D,WL26,SL26,KL1);
339 RIP2(D,E,A,B,C,WL27,SL27,KL1);
340 RIP2(C,D,E,A,B,WL28,SL28,KL1);
341 RIP2(B,C,D,E,A,WL29,SL29,KL1);
342 RIP2(A,B,C,D,E,WL30,SL30,KL1);
343 RIP2(E,A,B,C,D,WL31,SL31,KL1);
344
345 RIP3(D,E,A,B,C,WL32,SL32,KL2);
346 RIP3(C,D,E,A,B,WL33,SL33,KL2);
347 RIP3(B,C,D,E,A,WL34,SL34,KL2);
348 RIP3(A,B,C,D,E,WL35,SL35,KL2);
349 RIP3(E,A,B,C,D,WL36,SL36,KL2);
350 RIP3(D,E,A,B,C,WL37,SL37,KL2);
351 RIP3(C,D,E,A,B,WL38,SL38,KL2);
352 RIP3(B,C,D,E,A,WL39,SL39,KL2);
353 RIP3(A,B,C,D,E,WL40,SL40,KL2);
354 RIP3(E,A,B,C,D,WL41,SL41,KL2);
355 RIP3(D,E,A,B,C,WL42,SL42,KL2);
356 RIP3(C,D,E,A,B,WL43,SL43,KL2);
357 RIP3(B,C,D,E,A,WL44,SL44,KL2);
358 RIP3(A,B,C,D,E,WL45,SL45,KL2);
359 RIP3(E,A,B,C,D,WL46,SL46,KL2);
360 RIP3(D,E,A,B,C,WL47,SL47,KL2);
361
362 RIP4(C,D,E,A,B,WL48,SL48,KL3);
363 RIP4(B,C,D,E,A,WL49,SL49,KL3);
364 RIP4(A,B,C,D,E,WL50,SL50,KL3);
365 RIP4(E,A,B,C,D,WL51,SL51,KL3);
366 RIP4(D,E,A,B,C,WL52,SL52,KL3);
367 RIP4(C,D,E,A,B,WL53,SL53,KL3);
368 RIP4(B,C,D,E,A,WL54,SL54,KL3);
369 RIP4(A,B,C,D,E,WL55,SL55,KL3);
370 RIP4(E,A,B,C,D,WL56,SL56,KL3);
371 RIP4(D,E,A,B,C,WL57,SL57,KL3);
372 RIP4(C,D,E,A,B,WL58,SL58,KL3);
373 RIP4(B,C,D,E,A,WL59,SL59,KL3);
374 RIP4(A,B,C,D,E,WL60,SL60,KL3);
375 RIP4(E,A,B,C,D,WL61,SL61,KL3);
376 RIP4(D,E,A,B,C,WL62,SL62,KL3);
377 RIP4(C,D,E,A,B,WL63,SL63,KL3);
378
379 RIP5(B,C,D,E,A,WL64,SL64,KL4);
380 RIP5(A,B,C,D,E,WL65,SL65,KL4);
381 RIP5(E,A,B,C,D,WL66,SL66,KL4);
382 RIP5(D,E,A,B,C,WL67,SL67,KL4);
383 RIP5(C,D,E,A,B,WL68,SL68,KL4);
384 RIP5(B,C,D,E,A,WL69,SL69,KL4);
385 RIP5(A,B,C,D,E,WL70,SL70,KL4);
386 RIP5(E,A,B,C,D,WL71,SL71,KL4);
387 RIP5(D,E,A,B,C,WL72,SL72,KL4);
388 RIP5(C,D,E,A,B,WL73,SL73,KL4);
389 RIP5(B,C,D,E,A,WL74,SL74,KL4);
390 RIP5(A,B,C,D,E,WL75,SL75,KL4);
391 RIP5(E,A,B,C,D,WL76,SL76,KL4);
392 RIP5(D,E,A,B,C,WL77,SL77,KL4);
393 RIP5(C,D,E,A,B,WL78,SL78,KL4);
394 RIP5(B,C,D,E,A,WL79,SL79,KL4);
395
396 a=A; b=B; c=C; d=D; e=E;
397 /* Do other half */
398 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
399
400 RIP5(A,B,C,D,E,WR00,SR00,KR0);
401 RIP5(E,A,B,C,D,WR01,SR01,KR0);
402 RIP5(D,E,A,B,C,WR02,SR02,KR0);
403 RIP5(C,D,E,A,B,WR03,SR03,KR0);
404 RIP5(B,C,D,E,A,WR04,SR04,KR0);
405 RIP5(A,B,C,D,E,WR05,SR05,KR0);
406 RIP5(E,A,B,C,D,WR06,SR06,KR0);
407 RIP5(D,E,A,B,C,WR07,SR07,KR0);
408 RIP5(C,D,E,A,B,WR08,SR08,KR0);
409 RIP5(B,C,D,E,A,WR09,SR09,KR0);
410 RIP5(A,B,C,D,E,WR10,SR10,KR0);
411 RIP5(E,A,B,C,D,WR11,SR11,KR0);
412 RIP5(D,E,A,B,C,WR12,SR12,KR0);
413 RIP5(C,D,E,A,B,WR13,SR13,KR0);
414 RIP5(B,C,D,E,A,WR14,SR14,KR0);
415 RIP5(A,B,C,D,E,WR15,SR15,KR0);
416
417 RIP4(E,A,B,C,D,WR16,SR16,KR1);
418 RIP4(D,E,A,B,C,WR17,SR17,KR1);
419 RIP4(C,D,E,A,B,WR18,SR18,KR1);
420 RIP4(B,C,D,E,A,WR19,SR19,KR1);
421 RIP4(A,B,C,D,E,WR20,SR20,KR1);
422 RIP4(E,A,B,C,D,WR21,SR21,KR1);
423 RIP4(D,E,A,B,C,WR22,SR22,KR1);
424 RIP4(C,D,E,A,B,WR23,SR23,KR1);
425 RIP4(B,C,D,E,A,WR24,SR24,KR1);
426 RIP4(A,B,C,D,E,WR25,SR25,KR1);
427 RIP4(E,A,B,C,D,WR26,SR26,KR1);
428 RIP4(D,E,A,B,C,WR27,SR27,KR1);
429 RIP4(C,D,E,A,B,WR28,SR28,KR1);
430 RIP4(B,C,D,E,A,WR29,SR29,KR1);
431 RIP4(A,B,C,D,E,WR30,SR30,KR1);
432 RIP4(E,A,B,C,D,WR31,SR31,KR1);
433
434 RIP3(D,E,A,B,C,WR32,SR32,KR2);
435 RIP3(C,D,E,A,B,WR33,SR33,KR2);
436 RIP3(B,C,D,E,A,WR34,SR34,KR2);
437 RIP3(A,B,C,D,E,WR35,SR35,KR2);
438 RIP3(E,A,B,C,D,WR36,SR36,KR2);
439 RIP3(D,E,A,B,C,WR37,SR37,KR2);
440 RIP3(C,D,E,A,B,WR38,SR38,KR2);
441 RIP3(B,C,D,E,A,WR39,SR39,KR2);
442 RIP3(A,B,C,D,E,WR40,SR40,KR2);
443 RIP3(E,A,B,C,D,WR41,SR41,KR2);
444 RIP3(D,E,A,B,C,WR42,SR42,KR2);
445 RIP3(C,D,E,A,B,WR43,SR43,KR2);
446 RIP3(B,C,D,E,A,WR44,SR44,KR2);
447 RIP3(A,B,C,D,E,WR45,SR45,KR2);
448 RIP3(E,A,B,C,D,WR46,SR46,KR2);
449 RIP3(D,E,A,B,C,WR47,SR47,KR2);
450
451 RIP2(C,D,E,A,B,WR48,SR48,KR3);
452 RIP2(B,C,D,E,A,WR49,SR49,KR3);
453 RIP2(A,B,C,D,E,WR50,SR50,KR3);
454 RIP2(E,A,B,C,D,WR51,SR51,KR3);
455 RIP2(D,E,A,B,C,WR52,SR52,KR3);
456 RIP2(C,D,E,A,B,WR53,SR53,KR3);
457 RIP2(B,C,D,E,A,WR54,SR54,KR3);
458 RIP2(A,B,C,D,E,WR55,SR55,KR3);
459 RIP2(E,A,B,C,D,WR56,SR56,KR3);
460 RIP2(D,E,A,B,C,WR57,SR57,KR3);
461 RIP2(C,D,E,A,B,WR58,SR58,KR3);
462 RIP2(B,C,D,E,A,WR59,SR59,KR3);
463 RIP2(A,B,C,D,E,WR60,SR60,KR3);
464 RIP2(E,A,B,C,D,WR61,SR61,KR3);
465 RIP2(D,E,A,B,C,WR62,SR62,KR3);
466 RIP2(C,D,E,A,B,WR63,SR63,KR3);
467
468 RIP1(B,C,D,E,A,WR64,SR64);
469 RIP1(A,B,C,D,E,WR65,SR65);
470 RIP1(E,A,B,C,D,WR66,SR66);
471 RIP1(D,E,A,B,C,WR67,SR67);
472 RIP1(C,D,E,A,B,WR68,SR68);
473 RIP1(B,C,D,E,A,WR69,SR69);
474 RIP1(A,B,C,D,E,WR70,SR70);
475 RIP1(E,A,B,C,D,WR71,SR71);
476 RIP1(D,E,A,B,C,WR72,SR72);
477 RIP1(C,D,E,A,B,WR73,SR73);
478 RIP1(B,C,D,E,A,WR74,SR74);
479 RIP1(A,B,C,D,E,WR75,SR75);
480 RIP1(E,A,B,C,D,WR76,SR76);
481 RIP1(D,E,A,B,C,WR77,SR77);
482 RIP1(C,D,E,A,B,WR78,SR78);
483 RIP1(B,C,D,E,A,WR79,SR79);
484
485 D =ctx->B+c+D;
486 ctx->B=ctx->C+d+E;
487 ctx->C=ctx->D+e+A;
488 ctx->D=ctx->E+a+B;
489 ctx->E=ctx->A+b+C;
490 ctx->A=D;
525 491
526 for (i=0; i<2; i++)
527 {
528 for (ii=0; ii<8; ii++)
529 {
530 fprintf(stderr,"%08lx ",l[i*8+ii]);
531 }
532 fprintf(stderr,"\n");
533 } 492 }
534 } 493 }
535#endif 494#endif
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
index a1feccf7c1..7b835dfbd4 100644
--- a/src/lib/libcrypto/ripemd/rmd_locl.h
+++ b/src/lib/libcrypto/ripemd/rmd_locl.h
@@ -58,138 +58,72 @@
58 58
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h> 60#include <string.h>
61#include "ripemd.h" 61#include <openssl/opensslconf.h>
62#include <openssl/ripemd.h>
62 63
63#define ULONG unsigned long 64#ifndef RIPEMD160_LONG_LOG2
64#define UCHAR unsigned char 65#define RIPEMD160_LONG_LOG2 2 /* default to 32 bits */
65#define UINT unsigned int 66#endif
66 67
67#ifdef NOCONST 68/*
68#define const 69 * DO EXAMINE COMMENTS IN crypto/md5/md5_locl.h & crypto/md5/md5_dgst.c
70 * FOR EXPLANATIONS ON FOLLOWING "CODE."
71 * <appro@fy.chalmers.se>
72 */
73#ifdef RMD160_ASM
74# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
75# define ripemd160_block_host_order ripemd160_block_asm_host_order
76# endif
69#endif 77#endif
70 78
71#undef c2nl 79void ripemd160_block_host_order (RIPEMD160_CTX *c, const void *p,int num);
72#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ 80void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,int num);
73 l|=(((unsigned long)(*((c)++)))<<16), \ 81
74 l|=(((unsigned long)(*((c)++)))<< 8), \ 82#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
75 l|=(((unsigned long)(*((c)++))) )) 83#define ripemd160_block_data_order ripemd160_block_host_order
76
77#undef p_c2nl
78#define p_c2nl(c,l,n) { \
79 switch (n) { \
80 case 0: l =((unsigned long)(*((c)++)))<<24; \
81 case 1: l|=((unsigned long)(*((c)++)))<<16; \
82 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
83 case 3: l|=((unsigned long)(*((c)++))); \
84 } \
85 }
86
87#undef c2nl_p
88/* NOTE the pointer is not incremented at the end of this */
89#define c2nl_p(c,l,n) { \
90 l=0; \
91 (c)+=n; \
92 switch (n) { \
93 case 3: l =((unsigned long)(*(--(c))))<< 8; \
94 case 2: l|=((unsigned long)(*(--(c))))<<16; \
95 case 1: l|=((unsigned long)(*(--(c))))<<24; \
96 } \
97 }
98
99#undef p_c2nl_p
100#define p_c2nl_p(c,l,sc,len) { \
101 switch (sc) \
102 { \
103 case 0: l =((unsigned long)(*((c)++)))<<24; \
104 if (--len == 0) break; \
105 case 1: l|=((unsigned long)(*((c)++)))<<16; \
106 if (--len == 0) break; \
107 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
108 } \
109 }
110
111#undef nl2c
112#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
113 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
114 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
115 *((c)++)=(unsigned char)(((l) )&0xff))
116
117#undef c2l
118#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
119 l|=(((unsigned long)(*((c)++)))<< 8), \
120 l|=(((unsigned long)(*((c)++)))<<16), \
121 l|=(((unsigned long)(*((c)++)))<<24))
122
123#undef p_c2l
124#define p_c2l(c,l,n) { \
125 switch (n) { \
126 case 0: l =((unsigned long)(*((c)++))); \
127 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
128 case 2: l|=((unsigned long)(*((c)++)))<<16; \
129 case 3: l|=((unsigned long)(*((c)++)))<<24; \
130 } \
131 }
132
133#undef c2l_p
134/* NOTE the pointer is not incremented at the end of this */
135#define c2l_p(c,l,n) { \
136 l=0; \
137 (c)+=n; \
138 switch (n) { \
139 case 3: l =((unsigned long)(*(--(c))))<<16; \
140 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
141 case 1: l|=((unsigned long)(*(--(c)))); \
142 } \
143 }
144
145#undef p_c2l_p
146#define p_c2l_p(c,l,sc,len) { \
147 switch (sc) \
148 { \
149 case 0: l =((unsigned long)(*((c)++))); \
150 if (--len == 0) break; \
151 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
152 if (--len == 0) break; \
153 case 2: l|=((unsigned long)(*((c)++)))<<16; \
154 } \
155 }
156
157#undef l2c
158#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
159 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
160 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
161 *((c)++)=(unsigned char)(((l)>>24)&0xff))
162
163#undef ROTATE
164#if defined(WIN32)
165#define ROTATE(a,n) _lrotl(a,n)
166#else
167#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
168#endif 84#endif
169 85
170/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ 86#define DATA_ORDER_IS_LITTLE_ENDIAN
171#if defined(WIN32) 87
172/* 5 instructions with rotate instruction, else 9 */ 88#define HASH_LONG RIPEMD160_LONG
173#define Endian_Reverse32(a) \ 89#define HASH_LONG_LOG2 RIPEMD160_LONG_LOG2
174 { \ 90#define HASH_CTX RIPEMD160_CTX
175 unsigned long l=(a); \ 91#define HASH_CBLOCK RIPEMD160_CBLOCK
176 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ 92#define HASH_LBLOCK RIPEMD160_LBLOCK
177 } 93#define HASH_UPDATE RIPEMD160_Update
178#else 94#define HASH_TRANSFORM RIPEMD160_Transform
179/* 6 instructions with rotate instruction, else 8 */ 95#define HASH_FINAL RIPEMD160_Final
180#define Endian_Reverse32(a) \ 96#define HASH_BLOCK_HOST_ORDER ripemd160_block_host_order
181 { \ 97#define HASH_MAKE_STRING(c,s) do { \
182 unsigned long l=(a); \ 98 unsigned long ll; \
183 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ 99 ll=(c)->A; HOST_l2c(ll,(s)); \
184 (a)=ROTATE(l,16L); \ 100 ll=(c)->B; HOST_l2c(ll,(s)); \
185 } 101 ll=(c)->C; HOST_l2c(ll,(s)); \
102 ll=(c)->D; HOST_l2c(ll,(s)); \
103 ll=(c)->E; HOST_l2c(ll,(s)); \
104 } while (0)
105#if !defined(L_ENDIAN) || defined(ripemd160_block_data_order)
106#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
186#endif 107#endif
187 108
109#include "md32_common.h"
110
111#if 0
188#define F1(x,y,z) ((x)^(y)^(z)) 112#define F1(x,y,z) ((x)^(y)^(z))
189#define F2(x,y,z) (((x)&(y))|((~x)&z)) 113#define F2(x,y,z) (((x)&(y))|((~x)&z))
190#define F3(x,y,z) (((x)|(~y))^(z)) 114#define F3(x,y,z) (((x)|(~y))^(z))
191#define F4(x,y,z) (((x)&(z))|((y)&(~(z)))) 115#define F4(x,y,z) (((x)&(z))|((y)&(~(z))))
192#define F5(x,y,z) ((x)^((y)|(~(z)))) 116#define F5(x,y,z) ((x)^((y)|(~(z))))
117#else
118/*
119 * Transformed F2 and F4 are courtesy of Wei Dai <weidai@eskimo.com>
120 */
121#define F1(x,y,z) ((x) ^ (y) ^ (z))
122#define F2(x,y,z) ((((y) ^ (z)) & (x)) ^ (z))
123#define F3(x,y,z) (((~(y)) | (x)) ^ (z))
124#define F4(x,y,z) ((((x) ^ (y)) & (z)) ^ (y))
125#define F5(x,y,z) (((~(z)) | (y)) ^ (x))
126#endif
193 127
194#define RIPEMD160_A 0x67452301L 128#define RIPEMD160_A 0x67452301L
195#define RIPEMD160_B 0xEFCDAB89L 129#define RIPEMD160_B 0xEFCDAB89L
@@ -200,27 +134,27 @@
200#include "rmdconst.h" 134#include "rmdconst.h"
201 135
202#define RIP1(a,b,c,d,e,w,s) { \ 136#define RIP1(a,b,c,d,e,w,s) { \
203 a+=F1(b,c,d)+X[w]; \ 137 a+=F1(b,c,d)+X(w); \
204 a=ROTATE(a,s)+e; \ 138 a=ROTATE(a,s)+e; \
205 c=ROTATE(c,10); } 139 c=ROTATE(c,10); }
206 140
207#define RIP2(a,b,c,d,e,w,s,K) { \ 141#define RIP2(a,b,c,d,e,w,s,K) { \
208 a+=F2(b,c,d)+X[w]+K; \ 142 a+=F2(b,c,d)+X(w)+K; \
209 a=ROTATE(a,s)+e; \ 143 a=ROTATE(a,s)+e; \
210 c=ROTATE(c,10); } 144 c=ROTATE(c,10); }
211 145
212#define RIP3(a,b,c,d,e,w,s,K) { \ 146#define RIP3(a,b,c,d,e,w,s,K) { \
213 a+=F3(b,c,d)+X[w]+K; \ 147 a+=F3(b,c,d)+X(w)+K; \
214 a=ROTATE(a,s)+e; \ 148 a=ROTATE(a,s)+e; \
215 c=ROTATE(c,10); } 149 c=ROTATE(c,10); }
216 150
217#define RIP4(a,b,c,d,e,w,s,K) { \ 151#define RIP4(a,b,c,d,e,w,s,K) { \
218 a+=F4(b,c,d)+X[w]+K; \ 152 a+=F4(b,c,d)+X(w)+K; \
219 a=ROTATE(a,s)+e; \ 153 a=ROTATE(a,s)+e; \
220 c=ROTATE(c,10); } 154 c=ROTATE(c,10); }
221 155
222#define RIP5(a,b,c,d,e,w,s,K) { \ 156#define RIP5(a,b,c,d,e,w,s,K) { \
223 a+=F5(b,c,d)+X[w]+K; \ 157 a+=F5(b,c,d)+X(w)+K; \
224 a=ROTATE(a,s)+e; \ 158 a=ROTATE(a,s)+e; \
225 c=ROTATE(c,10); } 159 c=ROTATE(c,10); }
226 160
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
index a7626dbcda..efdf2dd6ef 100644
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ b/src/lib/libcrypto/ripemd/rmd_one.c
@@ -57,12 +57,11 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "rmd_locl.h" 60#include <string.h>
61#include <openssl/ripemd.h>
61 62
62unsigned char *RIPEMD160(d, n, md) 63unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
63unsigned char *d; 64 unsigned char *md)
64unsigned long n;
65unsigned char *md;
66 { 65 {
67 RIPEMD160_CTX c; 66 RIPEMD160_CTX c;
68 static unsigned char m[RIPEMD160_DIGEST_LENGTH]; 67 static unsigned char m[RIPEMD160_DIGEST_LENGTH];