summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha
diff options
context:
space:
mode:
authormarkus <>2002-09-05 12:51:50 +0000
committermarkus <>2002-09-05 12:51:50 +0000
commit15b5d84f9da2ce4bfae8580e56e34a859f74ad71 (patch)
treebf939e82d7fd73cc8a01cf6959002209972091bc /src/lib/libcrypto/sha
parent027351f729b9e837200dae6e1520cda6577ab930 (diff)
downloadopenbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.gz
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.tar.bz2
openbsd-15b5d84f9da2ce4bfae8580e56e34a859f74ad71.zip
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/sha')
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl115
-rw-r--r--src/lib/libcrypto/sha/sha.h72
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c9
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c407
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h522
5 files changed, 508 insertions, 617 deletions
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl
index d6d998f8ee..fe51fd0794 100644
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-586.pl
@@ -1,15 +1,15 @@
1#!/usr/bin/perl 1#!/usr/local/bin/perl
2 2
3$normal=0; 3$normal=0;
4 4
5push(@INC,"perlasm","../../perlasm"); 5push(@INC,"perlasm","../../perlasm");
6require "x86asm.pl"; 6require "x86asm.pl";
7 7
8&asm_init($ARGV[0],"sha1-586.pl"); 8&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
9 9
10$A="eax"; 10$A="eax";
11$B="ebx"; 11$B="ecx";
12$C="ecx"; 12$C="ebx";
13$D="edx"; 13$D="edx";
14$E="edi"; 14$E="edi";
15$T="esi"; 15$T="esi";
@@ -19,7 +19,7 @@ $off=9*4;
19 19
20@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6); 20@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6);
21 21
22&sha1_block("sha1_block_x86"); 22&sha1_block_data("sha1_block_asm_data_order");
23 23
24&asm_finish(); 24&asm_finish();
25 25
@@ -53,11 +53,14 @@ sub X_expand
53 local($in)=@_; 53 local($in)=@_;
54 54
55 &comment("First, load the words onto the stack in network byte order"); 55 &comment("First, load the words onto the stack in network byte order");
56 for ($i=0; $i<16; $i++) 56 for ($i=0; $i<16; $i+=2)
57 { 57 {
58 &mov("eax",&DWP(($i+0)*4,$in,"",0)) unless $i == 0; 58 &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0;
59 &bswap("eax"); 59 &mov($B,&DWP(($i+1)*4,$in,"",0));
60 &mov(&swtmp($i+0),"eax"); 60 &bswap($A);
61 &bswap($B);
62 &mov(&swtmp($i+0),$A);
63 &mov(&swtmp($i+1),$B);
61 } 64 }
62 65
63 &comment("We now have the X array on the stack"); 66 &comment("We now have the X array on the stack");
@@ -312,9 +315,9 @@ sub BODY_60_79
312 &BODY_20_39(@_); 315 &BODY_20_39(@_);
313 } 316 }
314 317
315sub sha1_block 318sub sha1_block_host
316 { 319 {
317 local($name)=@_; 320 local($name, $sclabel)=@_;
318 321
319 &function_begin_B($name,""); 322 &function_begin_B($name,"");
320 323
@@ -325,35 +328,77 @@ sub sha1_block
325 # D 12 328 # D 12
326 # E 16 329 # E 16
327 330
328 &push("esi"); 331 &mov("ecx", &wparam(2));
329 &push("ebp"); 332 &push("esi");
330 &mov("eax", &wparam(2)); 333 &shl("ecx",6);
331 &mov("esi", &wparam(1)); 334 &mov("esi", &wparam(1));
332 &add("eax", "esi"); # offset to leave on 335 &push("ebp");
336 &add("ecx","esi"); # offset to leave on
337 &push("ebx");
333 &mov("ebp", &wparam(0)); 338 &mov("ebp", &wparam(0));
339 &push("edi");
340 &mov($D, &DWP(12,"ebp","",0));
341 &stack_push(18+9);
342 &mov($E, &DWP(16,"ebp","",0));
343 &mov($C, &DWP( 8,"ebp","",0));
344 &mov(&swtmp(17),"ecx");
345
346 &comment("First we need to setup the X array");
347
348 for ($i=0; $i<16; $i+=2)
349 {
350 &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0;
351 &mov($B,&DWP(($i+1)*4,"esi","",0));
352 &mov(&swtmp($i+0),$A);
353 &mov(&swtmp($i+1),$B);
354 }
355 &jmp($sclabel);
356 &function_end_B($name);
357 }
358
359
360sub sha1_block_data
361 {
362 local($name)=@_;
363
364 &function_begin_B($name,"");
365
366 # parameter 1 is the MD5_CTX structure.
367 # A 0
368 # B 4
369 # C 8
370 # D 12
371 # E 16
372
373 &mov("ecx", &wparam(2));
374 &push("esi");
375 &shl("ecx",6);
376 &mov("esi", &wparam(1));
377 &push("ebp");
378 &add("ecx","esi"); # offset to leave on
334 &push("ebx"); 379 &push("ebx");
335 &sub("eax", 64); 380 &mov("ebp", &wparam(0));
336 &push("edi"); 381 &push("edi");
337 &mov($B, &DWP( 4,"ebp","",0));
338 &stack_push(18);
339 &mov($D, &DWP(12,"ebp","",0)); 382 &mov($D, &DWP(12,"ebp","",0));
340 &mov($E, &DWP(16,"ebp","",0)); 383 &stack_push(18+9);
341 &mov($C, &DWP( 8,"ebp","",0)); 384 &mov($E, &DWP(16,"ebp","",0));
342 &mov(&swtmp(17),"eax"); 385 &mov($C, &DWP( 8,"ebp","",0));
386 &mov(&swtmp(17),"ecx");
343 387
344 &comment("First we need to setup the X array"); 388 &comment("First we need to setup the X array");
345 &mov("eax",&DWP(0,"esi","",0)); # pulled out of X_expand
346 389
347 &set_label("start") unless $normal; 390 &set_label("start") unless $normal;
348 391
349 &X_expand("esi"); 392 &X_expand("esi");
350 &mov(&swtmp(16),"esi"); 393 &mov(&wparam(1),"esi");
351 394
395 &set_label("shortcut", 0, 1);
352 &comment(""); 396 &comment("");
353 &comment("Start processing"); 397 &comment("Start processing");
354 398
355 # odd start 399 # odd start
356 &mov($A, &DWP( 0,"ebp","",0)); 400 &mov($A, &DWP( 0,"ebp","",0));
401 &mov($B, &DWP( 4,"ebp","",0));
357 $X="esp"; 402 $X="esp";
358 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T); 403 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
359 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E); 404 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
@@ -468,24 +513,28 @@ sub sha1_block
468 &add($C,$T); 513 &add($C,$T);
469 514
470 &mov(&DWP( 0,$tmp1,"",0),$A); 515 &mov(&DWP( 0,$tmp1,"",0),$A);
471 &mov("esi",&swtmp(16)); 516 &mov("esi",&wparam(1));
472 &mov(&DWP( 8,$tmp1,"",0),$C); # This is for looping 517 &mov(&DWP( 8,$tmp1,"",0),$C);
473 &add("esi",64); 518 &add("esi",64);
474 &mov("eax",&swtmp(17)); 519 &mov("eax",&swtmp(17));
475 &mov(&DWP(16,$tmp1,"",0),$E); 520 &mov(&DWP(16,$tmp1,"",0),$E);
476 &cmp("eax","esi"); 521 &cmp("esi","eax");
477 &mov(&DWP( 4,$tmp1,"",0),$B); # This is for looping 522 &mov(&DWP( 4,$tmp1,"",0),$B);
478 &jl(&label("end")); 523 &jl(&label("start"));
479 &mov("eax",&DWP(0,"esi","",0)); # Pulled down from 524
480 &jmp(&label("start")); 525 &stack_pop(18+9);
481
482 &set_label("end");
483 &stack_pop(18);
484 &pop("edi"); 526 &pop("edi");
485 &pop("ebx"); 527 &pop("ebx");
486 &pop("ebp"); 528 &pop("ebp");
487 &pop("esi"); 529 &pop("esi");
488 &ret(); 530 &ret();
531
532 # keep a note of shortcut label so it can be used outside
533 # block.
534 my $sclabel = &label("shortcut");
535
489 &function_end_B($name); 536 &function_end_B($name);
537 # Putting this here avoids problems with MASM in debugging mode
538 &sha1_block_host("sha1_block_asm_host_order", $sclabel);
490 } 539 }
491 540
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
index 4cf0ea0225..3fd54a10cc 100644
--- a/src/lib/libcrypto/sha/sha.h
+++ b/src/lib/libcrypto/sha/sha.h
@@ -59,49 +59,61 @@
59#ifndef HEADER_SHA_H 59#ifndef HEADER_SHA_H
60#define HEADER_SHA_H 60#define HEADER_SHA_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
66#define SHA_CBLOCK 64 68#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1))
69#error SHA is disabled.
70#endif
71
72/*
73 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
74 * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then !
75 * ! SHA_LONG_LOG2 has to be defined along. !
76 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
77 */
78
79#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__)
80#define SHA_LONG unsigned long
81#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__)
82#define SHA_LONG unsigned long
83#define SHA_LONG_LOG2 3
84#else
85#define SHA_LONG unsigned int
86#endif
87
67#define SHA_LBLOCK 16 88#define SHA_LBLOCK 16
68#define SHA_BLOCK 16 89#define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a
69#define SHA_LAST_BLOCK 56 90 * contiguous array of 32 bit
70#define SHA_LENGTH_BLOCK 8 91 * wide big-endian values. */
92#define SHA_LAST_BLOCK (SHA_CBLOCK-8)
71#define SHA_DIGEST_LENGTH 20 93#define SHA_DIGEST_LENGTH 20
72 94
73typedef struct SHAstate_st 95typedef struct SHAstate_st
74 { 96 {
75 unsigned long h0,h1,h2,h3,h4; 97 SHA_LONG h0,h1,h2,h3,h4;
76 unsigned long Nl,Nh; 98 SHA_LONG Nl,Nh;
77 unsigned long data[SHA_LBLOCK]; 99 SHA_LONG data[SHA_LBLOCK];
78 int num; 100 int num;
79 } SHA_CTX; 101 } SHA_CTX;
80 102
81#ifndef NOPROTO 103#ifndef OPENSSL_NO_SHA0
82void SHA_Init(SHA_CTX *c); 104int SHA_Init(SHA_CTX *c);
83void SHA_Update(SHA_CTX *c, unsigned char *data, unsigned long len); 105int SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
84void SHA_Final(unsigned char *md, SHA_CTX *c); 106int SHA_Final(unsigned char *md, SHA_CTX *c);
85unsigned char *SHA(unsigned char *d, unsigned long n,unsigned char *md); 107unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
86void SHA_Transform(SHA_CTX *c, unsigned char *data); 108void SHA_Transform(SHA_CTX *c, const unsigned char *data);
87void SHA1_Init(SHA_CTX *c); 109#endif
88void SHA1_Update(SHA_CTX *c, unsigned char *data, unsigned long len); 110#ifndef OPENSSL_NO_SHA1
89void SHA1_Final(unsigned char *md, SHA_CTX *c); 111int SHA1_Init(SHA_CTX *c);
90unsigned char *SHA1(unsigned char *d, unsigned long n,unsigned char *md); 112int SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
91void SHA1_Transform(SHA_CTX *c, unsigned char *data); 113int SHA1_Final(unsigned char *md, SHA_CTX *c);
92#else 114unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
93void SHA_Init(); 115void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
94void SHA_Update();
95void SHA_Final();
96unsigned char *SHA();
97void SHA_Transform();
98void SHA1_Init();
99void SHA1_Update();
100void SHA1_Final();
101unsigned char *SHA1();
102void SHA1_Transform();
103#endif 116#endif
104
105#ifdef __cplusplus 117#ifdef __cplusplus
106} 118}
107#endif 119#endif
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c
index fe5770d601..e6a24888ed 100644
--- a/src/lib/libcrypto/sha/sha1_one.c
+++ b/src/lib/libcrypto/sha/sha1_one.c
@@ -58,12 +58,10 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "sha.h" 61#include <openssl/sha.h>
62 62
63unsigned char *SHA1(d, n, md) 63#ifndef OPENSSL_NO_SHA1
64unsigned char *d; 64unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)
65unsigned long n;
66unsigned char *md;
67 { 65 {
68 SHA_CTX c; 66 SHA_CTX c;
69 static unsigned char m[SHA_DIGEST_LENGTH]; 67 static unsigned char m[SHA_DIGEST_LENGTH];
@@ -75,3 +73,4 @@ unsigned char *md;
75 memset(&c,0,sizeof(c)); 73 memset(&c,0,sizeof(c));
76 return(md); 74 return(md);
77 } 75 }
76#endif
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c
index 2b0ae1f0d4..182f65982a 100644
--- a/src/lib/libcrypto/sha/sha1dgst.c
+++ b/src/lib/libcrypto/sha/sha1dgst.c
@@ -56,413 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h> 59#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA)
60#include <string.h> 60
61#undef SHA_0 61#undef SHA_0
62#define SHA_1 62#define SHA_1
63#include "sha.h"
64#include "sha_locl.h"
65
66char *SHA1_version="SHA1 part of SSLeay 0.9.0b 29-Jun-1998";
67
68/* Implemented from SHA-1 document - The Secure Hash Algorithm
69 */
70
71#define INIT_DATA_h0 (unsigned long)0x67452301L
72#define INIT_DATA_h1 (unsigned long)0xefcdab89L
73#define INIT_DATA_h2 (unsigned long)0x98badcfeL
74#define INIT_DATA_h3 (unsigned long)0x10325476L
75#define INIT_DATA_h4 (unsigned long)0xc3d2e1f0L
76
77#define K_00_19 0x5a827999L
78#define K_20_39 0x6ed9eba1L
79#define K_40_59 0x8f1bbcdcL
80#define K_60_79 0xca62c1d6L
81
82#ifndef NOPROTO
83# ifdef SHA1_ASM
84 void sha1_block_x86(SHA_CTX *c, register unsigned long *p, int num);
85# define sha1_block sha1_block_x86
86# else
87 void sha1_block(SHA_CTX *c, register unsigned long *p, int num);
88# endif
89#else
90# ifdef SHA1_ASM
91 void sha1_block_x86();
92# define sha1_block sha1_block_x86
93# else
94 void sha1_block();
95# endif
96#endif
97
98 63
99#if defined(L_ENDIAN) && defined(SHA1_ASM) 64#include <openssl/opensslv.h>
100# define M_c2nl c2l
101# define M_p_c2nl p_c2l
102# define M_c2nl_p c2l_p
103# define M_p_c2nl_p p_c2l_p
104# define M_nl2c l2c
105#else
106# define M_c2nl c2nl
107# define M_p_c2nl p_c2nl
108# define M_c2nl_p c2nl_p
109# define M_p_c2nl_p p_c2nl_p
110# define M_nl2c nl2c
111#endif
112
113void SHA1_Init(c)
114SHA_CTX *c;
115 {
116 c->h0=INIT_DATA_h0;
117 c->h1=INIT_DATA_h1;
118 c->h2=INIT_DATA_h2;
119 c->h3=INIT_DATA_h3;
120 c->h4=INIT_DATA_h4;
121 c->Nl=0;
122 c->Nh=0;
123 c->num=0;
124 }
125
126void SHA1_Update(c, data, len)
127SHA_CTX *c;
128register unsigned char *data;
129unsigned long len;
130 {
131 register ULONG *p;
132 int ew,ec,sw,sc;
133 ULONG l;
134
135 if (len == 0) return;
136
137 l=(c->Nl+(len<<3))&0xffffffffL;
138 if (l < c->Nl) /* overflow */
139 c->Nh++;
140 c->Nh+=(len>>29);
141 c->Nl=l;
142 65
143 if (c->num != 0) 66const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
144 {
145 p=c->data;
146 sw=c->num>>2;
147 sc=c->num&0x03;
148
149 if ((c->num+len) >= SHA_CBLOCK)
150 {
151 l= p[sw];
152 M_p_c2nl(data,l,sc);
153 p[sw++]=l;
154 for (; sw<SHA_LBLOCK; sw++)
155 {
156 M_c2nl(data,l);
157 p[sw]=l;
158 }
159 len-=(SHA_CBLOCK-c->num);
160
161 sha1_block(c,p,64);
162 c->num=0;
163 /* drop through and do the rest */
164 }
165 else
166 {
167 c->num+=(int)len;
168 if ((sc+len) < 4) /* ugly, add char's to a word */
169 {
170 l= p[sw];
171 M_p_c2nl_p(data,l,sc,len);
172 p[sw]=l;
173 }
174 else
175 {
176 ew=(c->num>>2);
177 ec=(c->num&0x03);
178 l= p[sw];
179 M_p_c2nl(data,l,sc);
180 p[sw++]=l;
181 for (; sw < ew; sw++)
182 { M_c2nl(data,l); p[sw]=l; }
183 if (ec)
184 {
185 M_c2nl_p(data,l,ec);
186 p[sw]=l;
187 }
188 }
189 return;
190 }
191 }
192 /* We can only do the following code for assember, the reason
193 * being that the sha1_block 'C' version changes the values
194 * in the 'data' array. The assember code avoids this and
195 * copies it to a local array. I should be able to do this for
196 * the C version as well....
197 */
198#if 1
199#if defined(B_ENDIAN) || defined(SHA1_ASM)
200 if ((((unsigned int)data)%sizeof(ULONG)) == 0)
201 {
202 sw=len/SHA_CBLOCK;
203 if (sw)
204 {
205 sw*=SHA_CBLOCK;
206 sha1_block(c,(ULONG *)data,sw);
207 data+=sw;
208 len-=sw;
209 }
210 }
211#endif
212#endif
213 /* we now can process the input data in blocks of SHA_CBLOCK
214 * chars and save the leftovers to c->data. */
215 p=c->data;
216 while (len >= SHA_CBLOCK)
217 {
218#if defined(B_ENDIAN) || defined(L_ENDIAN)
219 if (p != (unsigned long *)data)
220 memcpy(p,data,SHA_CBLOCK);
221 data+=SHA_CBLOCK;
222# ifdef L_ENDIAN
223# ifndef SHA1_ASM /* Will not happen */
224 for (sw=(SHA_LBLOCK/4); sw; sw--)
225 {
226 Endian_Reverse32(p[0]);
227 Endian_Reverse32(p[1]);
228 Endian_Reverse32(p[2]);
229 Endian_Reverse32(p[3]);
230 p+=4;
231 }
232 p=c->data;
233# endif
234# endif
235#else
236 for (sw=(SHA_BLOCK/4); sw; sw--)
237 {
238 M_c2nl(data,l); *(p++)=l;
239 M_c2nl(data,l); *(p++)=l;
240 M_c2nl(data,l); *(p++)=l;
241 M_c2nl(data,l); *(p++)=l;
242 }
243 p=c->data;
244#endif
245 sha1_block(c,p,64);
246 len-=SHA_CBLOCK;
247 }
248 ec=(int)len;
249 c->num=ec;
250 ew=(ec>>2);
251 ec&=0x03;
252 67
253 for (sw=0; sw < ew; sw++) 68/* The implementation is in ../md32_common.h */
254 { M_c2nl(data,l); p[sw]=l; }
255 M_c2nl_p(data,l,ec);
256 p[sw]=l;
257 }
258 69
259void SHA1_Transform(c,b) 70#include "sha_locl.h"
260SHA_CTX *c;
261unsigned char *b;
262 {
263 ULONG p[16];
264#ifndef B_ENDIAN
265 ULONG *q;
266 int i;
267#endif
268
269#if defined(B_ENDIAN) || defined(L_ENDIAN)
270 memcpy(p,b,64);
271#ifdef L_ENDIAN
272 q=p;
273 for (i=(SHA_LBLOCK/4); i; i--)
274 {
275 Endian_Reverse32(q[0]);
276 Endian_Reverse32(q[1]);
277 Endian_Reverse32(q[2]);
278 Endian_Reverse32(q[3]);
279 q+=4;
280 }
281#endif
282#else
283 q=p;
284 for (i=(SHA_LBLOCK/4); i; i--)
285 {
286 ULONG l;
287 c2nl(b,l); *(q++)=l;
288 c2nl(b,l); *(q++)=l;
289 c2nl(b,l); *(q++)=l;
290 c2nl(b,l); *(q++)=l;
291 }
292#endif
293 sha1_block(c,p,64);
294 }
295
296#ifndef SHA1_ASM
297
298void sha1_block(c, W, num)
299SHA_CTX *c;
300register unsigned long *W;
301int num;
302 {
303 register ULONG A,B,C,D,E,T;
304 ULONG X[16];
305
306 A=c->h0;
307 B=c->h1;
308 C=c->h2;
309 D=c->h3;
310 E=c->h4;
311
312 for (;;)
313 {
314 BODY_00_15( 0,A,B,C,D,E,T,W);
315 BODY_00_15( 1,T,A,B,C,D,E,W);
316 BODY_00_15( 2,E,T,A,B,C,D,W);
317 BODY_00_15( 3,D,E,T,A,B,C,W);
318 BODY_00_15( 4,C,D,E,T,A,B,W);
319 BODY_00_15( 5,B,C,D,E,T,A,W);
320 BODY_00_15( 6,A,B,C,D,E,T,W);
321 BODY_00_15( 7,T,A,B,C,D,E,W);
322 BODY_00_15( 8,E,T,A,B,C,D,W);
323 BODY_00_15( 9,D,E,T,A,B,C,W);
324 BODY_00_15(10,C,D,E,T,A,B,W);
325 BODY_00_15(11,B,C,D,E,T,A,W);
326 BODY_00_15(12,A,B,C,D,E,T,W);
327 BODY_00_15(13,T,A,B,C,D,E,W);
328 BODY_00_15(14,E,T,A,B,C,D,W);
329 BODY_00_15(15,D,E,T,A,B,C,W);
330 BODY_16_19(16,C,D,E,T,A,B,W,W,W,W);
331 BODY_16_19(17,B,C,D,E,T,A,W,W,W,W);
332 BODY_16_19(18,A,B,C,D,E,T,W,W,W,W);
333 BODY_16_19(19,T,A,B,C,D,E,W,W,W,X);
334
335 BODY_20_31(20,E,T,A,B,C,D,W,W,W,X);
336 BODY_20_31(21,D,E,T,A,B,C,W,W,W,X);
337 BODY_20_31(22,C,D,E,T,A,B,W,W,W,X);
338 BODY_20_31(23,B,C,D,E,T,A,W,W,W,X);
339 BODY_20_31(24,A,B,C,D,E,T,W,W,X,X);
340 BODY_20_31(25,T,A,B,C,D,E,W,W,X,X);
341 BODY_20_31(26,E,T,A,B,C,D,W,W,X,X);
342 BODY_20_31(27,D,E,T,A,B,C,W,W,X,X);
343 BODY_20_31(28,C,D,E,T,A,B,W,W,X,X);
344 BODY_20_31(29,B,C,D,E,T,A,W,W,X,X);
345 BODY_20_31(30,A,B,C,D,E,T,W,X,X,X);
346 BODY_20_31(31,T,A,B,C,D,E,W,X,X,X);
347 BODY_32_39(32,E,T,A,B,C,D,X);
348 BODY_32_39(33,D,E,T,A,B,C,X);
349 BODY_32_39(34,C,D,E,T,A,B,X);
350 BODY_32_39(35,B,C,D,E,T,A,X);
351 BODY_32_39(36,A,B,C,D,E,T,X);
352 BODY_32_39(37,T,A,B,C,D,E,X);
353 BODY_32_39(38,E,T,A,B,C,D,X);
354 BODY_32_39(39,D,E,T,A,B,C,X);
355
356 BODY_40_59(40,C,D,E,T,A,B,X);
357 BODY_40_59(41,B,C,D,E,T,A,X);
358 BODY_40_59(42,A,B,C,D,E,T,X);
359 BODY_40_59(43,T,A,B,C,D,E,X);
360 BODY_40_59(44,E,T,A,B,C,D,X);
361 BODY_40_59(45,D,E,T,A,B,C,X);
362 BODY_40_59(46,C,D,E,T,A,B,X);
363 BODY_40_59(47,B,C,D,E,T,A,X);
364 BODY_40_59(48,A,B,C,D,E,T,X);
365 BODY_40_59(49,T,A,B,C,D,E,X);
366 BODY_40_59(50,E,T,A,B,C,D,X);
367 BODY_40_59(51,D,E,T,A,B,C,X);
368 BODY_40_59(52,C,D,E,T,A,B,X);
369 BODY_40_59(53,B,C,D,E,T,A,X);
370 BODY_40_59(54,A,B,C,D,E,T,X);
371 BODY_40_59(55,T,A,B,C,D,E,X);
372 BODY_40_59(56,E,T,A,B,C,D,X);
373 BODY_40_59(57,D,E,T,A,B,C,X);
374 BODY_40_59(58,C,D,E,T,A,B,X);
375 BODY_40_59(59,B,C,D,E,T,A,X);
376
377 BODY_60_79(60,A,B,C,D,E,T,X);
378 BODY_60_79(61,T,A,B,C,D,E,X);
379 BODY_60_79(62,E,T,A,B,C,D,X);
380 BODY_60_79(63,D,E,T,A,B,C,X);
381 BODY_60_79(64,C,D,E,T,A,B,X);
382 BODY_60_79(65,B,C,D,E,T,A,X);
383 BODY_60_79(66,A,B,C,D,E,T,X);
384 BODY_60_79(67,T,A,B,C,D,E,X);
385 BODY_60_79(68,E,T,A,B,C,D,X);
386 BODY_60_79(69,D,E,T,A,B,C,X);
387 BODY_60_79(70,C,D,E,T,A,B,X);
388 BODY_60_79(71,B,C,D,E,T,A,X);
389 BODY_60_79(72,A,B,C,D,E,T,X);
390 BODY_60_79(73,T,A,B,C,D,E,X);
391 BODY_60_79(74,E,T,A,B,C,D,X);
392 BODY_60_79(75,D,E,T,A,B,C,X);
393 BODY_60_79(76,C,D,E,T,A,B,X);
394 BODY_60_79(77,B,C,D,E,T,A,X);
395 BODY_60_79(78,A,B,C,D,E,T,X);
396 BODY_60_79(79,T,A,B,C,D,E,X);
397
398 c->h0=(c->h0+E)&0xffffffffL;
399 c->h1=(c->h1+T)&0xffffffffL;
400 c->h2=(c->h2+A)&0xffffffffL;
401 c->h3=(c->h3+B)&0xffffffffL;
402 c->h4=(c->h4+C)&0xffffffffL;
403
404 num-=64;
405 if (num <= 0) break;
406
407 A=c->h0;
408 B=c->h1;
409 C=c->h2;
410 D=c->h3;
411 E=c->h4;
412
413 W+=16;
414 }
415 }
416#endif
417
418void SHA1_Final(md, c)
419unsigned char *md;
420SHA_CTX *c;
421 {
422 register int i,j;
423 register ULONG l;
424 register ULONG *p;
425 static unsigned char end[4]={0x80,0x00,0x00,0x00};
426 unsigned char *cp=end;
427 71
428 /* c->num should definitly have room for at least one more byte. */
429 p=c->data;
430 j=c->num;
431 i=j>>2;
432#ifdef PURIFY
433 if ((j&0x03) == 0) p[i]=0;
434#endif 72#endif
435 l=p[i];
436 M_p_c2nl(cp,l,j&0x03);
437 p[i]=l;
438 i++;
439 /* i is the next 'undefined word' */
440 if (c->num >= SHA_LAST_BLOCK)
441 {
442 for (; i<SHA_LBLOCK; i++)
443 p[i]=0;
444 sha1_block(c,p,64);
445 i=0;
446 }
447 for (; i<(SHA_LBLOCK-2); i++)
448 p[i]=0;
449 p[SHA_LBLOCK-2]=c->Nh;
450 p[SHA_LBLOCK-1]=c->Nl;
451#if defined(L_ENDIAN) && defined(SHA1_ASM)
452 Endian_Reverse32(p[SHA_LBLOCK-2]);
453 Endian_Reverse32(p[SHA_LBLOCK-1]);
454#endif
455 sha1_block(c,p,64);
456 cp=md;
457 l=c->h0; nl2c(l,cp);
458 l=c->h1; nl2c(l,cp);
459 l=c->h2; nl2c(l,cp);
460 l=c->h3; nl2c(l,cp);
461 l=c->h4; nl2c(l,cp);
462
463 /* clear stuff, sha1_block may be leaving some stuff on the stack
464 * but I'm not worried :-) */
465 c->num=0;
466/* memset((char *)&c,0,sizeof(c));*/
467 }
468 73
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
index 2814ad15fa..471dfb9f8f 100644
--- a/src/lib/libcrypto/sha/sha_locl.h
+++ b/src/lib/libcrypto/sha/sha_locl.h
@@ -59,137 +59,102 @@
59#include <stdlib.h> 59#include <stdlib.h>
60#include <string.h> 60#include <string.h>
61 61
62#ifdef undef 62#include <openssl/opensslconf.h>
63/* one or the other needs to be defined */ 63#include <openssl/sha.h>
64#ifndef SHA_1 /* FIPE 180-1 */ 64
65#define SHA_0 /* FIPS 180 */ 65#ifndef SHA_LONG_LOG2
66#endif 66#define SHA_LONG_LOG2 2 /* default to 32 bits */
67#endif 67#endif
68 68
69#define ULONG unsigned long 69#define DATA_ORDER_IS_BIG_ENDIAN
70#define UCHAR unsigned char
71#define UINT unsigned int
72 70
73#ifdef NOCONST 71#define HASH_LONG SHA_LONG
74#define const 72#define HASH_LONG_LOG2 SHA_LONG_LOG2
75#endif 73#define HASH_CTX SHA_CTX
74#define HASH_CBLOCK SHA_CBLOCK
75#define HASH_LBLOCK SHA_LBLOCK
76#define HASH_MAKE_STRING(c,s) do { \
77 unsigned long ll; \
78 ll=(c)->h0; HOST_l2c(ll,(s)); \
79 ll=(c)->h1; HOST_l2c(ll,(s)); \
80 ll=(c)->h2; HOST_l2c(ll,(s)); \
81 ll=(c)->h3; HOST_l2c(ll,(s)); \
82 ll=(c)->h4; HOST_l2c(ll,(s)); \
83 } while (0)
84
85#if defined(SHA_0)
86
87# define HASH_UPDATE SHA_Update
88# define HASH_TRANSFORM SHA_Transform
89# define HASH_FINAL SHA_Final
90# define HASH_INIT SHA_Init
91# define HASH_BLOCK_HOST_ORDER sha_block_host_order
92# define HASH_BLOCK_DATA_ORDER sha_block_data_order
93# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id))
94
95 void sha_block_host_order (SHA_CTX *c, const void *p,int num);
96 void sha_block_data_order (SHA_CTX *c, const void *p,int num);
97
98#elif defined(SHA_1)
99
100# define HASH_UPDATE SHA1_Update
101# define HASH_TRANSFORM SHA1_Transform
102# define HASH_FINAL SHA1_Final
103# define HASH_INIT SHA1_Init
104# define HASH_BLOCK_HOST_ORDER sha1_block_host_order
105# define HASH_BLOCK_DATA_ORDER sha1_block_data_order
106# if defined(__MWERKS__) && defined(__MC68K__)
107 /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
108# define Xupdate(a,ix,ia,ib,ic,id) do { (a)=(ia^ib^ic^id); \
109 ix=(a)=ROTATE((a),1); \
110 } while (0)
111# else
112# define Xupdate(a,ix,ia,ib,ic,id) ( (a)=(ia^ib^ic^id), \
113 ix=(a)=ROTATE((a),1) \
114 )
115# endif
116
117# ifdef SHA1_ASM
118# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
119# define sha1_block_host_order sha1_block_asm_host_order
120# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
121# define sha1_block_data_order sha1_block_asm_data_order
122# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
123# define HASH_BLOCK_DATA_ORDER_ALIGNED sha1_block_asm_data_order
124# endif
125# endif
126 void sha1_block_host_order (SHA_CTX *c, const void *p,int num);
127 void sha1_block_data_order (SHA_CTX *c, const void *p,int num);
76 128
77#undef c2nl
78#define c2nl(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
79 l|=(((unsigned long)(*((c)++)))<<16), \
80 l|=(((unsigned long)(*((c)++)))<< 8), \
81 l|=(((unsigned long)(*((c)++))) ))
82
83#undef p_c2nl
84#define p_c2nl(c,l,n) { \
85 switch (n) { \
86 case 0: l =((unsigned long)(*((c)++)))<<24; \
87 case 1: l|=((unsigned long)(*((c)++)))<<16; \
88 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
89 case 3: l|=((unsigned long)(*((c)++))); \
90 } \
91 }
92
93#undef c2nl_p
94/* NOTE the pointer is not incremented at the end of this */
95#define c2nl_p(c,l,n) { \
96 l=0; \
97 (c)+=n; \
98 switch (n) { \
99 case 3: l =((unsigned long)(*(--(c))))<< 8; \
100 case 2: l|=((unsigned long)(*(--(c))))<<16; \
101 case 1: l|=((unsigned long)(*(--(c))))<<24; \
102 } \
103 }
104
105#undef p_c2nl_p
106#define p_c2nl_p(c,l,sc,len) { \
107 switch (sc) \
108 { \
109 case 0: l =((unsigned long)(*((c)++)))<<24; \
110 if (--len == 0) break; \
111 case 1: l|=((unsigned long)(*((c)++)))<<16; \
112 if (--len == 0) break; \
113 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
114 } \
115 }
116
117#undef nl2c
118#define nl2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
119 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
120 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
121 *((c)++)=(unsigned char)(((l) )&0xff))
122
123#undef c2l
124#define c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
125 l|=(((unsigned long)(*((c)++)))<< 8), \
126 l|=(((unsigned long)(*((c)++)))<<16), \
127 l|=(((unsigned long)(*((c)++)))<<24))
128
129#undef p_c2l
130#define p_c2l(c,l,n) { \
131 switch (n) { \
132 case 0: l =((unsigned long)(*((c)++))); \
133 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
134 case 2: l|=((unsigned long)(*((c)++)))<<16; \
135 case 3: l|=((unsigned long)(*((c)++)))<<24; \
136 } \
137 }
138
139#undef c2l_p
140/* NOTE the pointer is not incremented at the end of this */
141#define c2l_p(c,l,n) { \
142 l=0; \
143 (c)+=n; \
144 switch (n) { \
145 case 3: l =((unsigned long)(*(--(c))))<<16; \
146 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
147 case 1: l|=((unsigned long)(*(--(c)))); \
148 } \
149 }
150
151#undef p_c2l_p
152#define p_c2l_p(c,l,sc,len) { \
153 switch (sc) \
154 { \
155 case 0: l =((unsigned long)(*((c)++))); \
156 if (--len == 0) break; \
157 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
158 if (--len == 0) break; \
159 case 2: l|=((unsigned long)(*((c)++)))<<16; \
160 } \
161 }
162
163#undef l2c
164#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
165 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
166 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
167 *((c)++)=(unsigned char)(((l)>>24)&0xff))
168
169#undef ROTATE
170#if defined(WIN32)
171#define ROTATE(a,n) _lrotl(a,n)
172#else 129#else
173#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) 130# error "Either SHA_0 or SHA_1 must be defined."
174#endif 131#endif
175 132
176/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */ 133#include "md32_common.h"
177#if defined(WIN32) 134
178/* 5 instructions with rotate instruction, else 9 */ 135#define INIT_DATA_h0 0x67452301UL
179#define Endian_Reverse32(a) \ 136#define INIT_DATA_h1 0xefcdab89UL
180 { \ 137#define INIT_DATA_h2 0x98badcfeUL
181 unsigned long l=(a); \ 138#define INIT_DATA_h3 0x10325476UL
182 (a)=((ROTATE(l,8)&0x00FF00FF)|(ROTATE(l,24)&0xFF00FF00)); \ 139#define INIT_DATA_h4 0xc3d2e1f0UL
183 } 140
184#else 141int HASH_INIT (SHA_CTX *c)
185/* 6 instructions with rotate instruction, else 8 */ 142 {
186#define Endian_Reverse32(a) \ 143 c->h0=INIT_DATA_h0;
187 { \ 144 c->h1=INIT_DATA_h1;
188 unsigned long l=(a); \ 145 c->h2=INIT_DATA_h2;
189 l=(((l&0xFF00FF00)>>8L)|((l&0x00FF00FF)<<8L)); \ 146 c->h3=INIT_DATA_h3;
190 (a)=ROTATE(l,16L); \ 147 c->h4=INIT_DATA_h4;
148 c->Nl=0;
149 c->Nh=0;
150 c->num=0;
151 return 1;
191 } 152 }
192#endif 153
154#define K_00_19 0x5a827999UL
155#define K_20_39 0x6ed9eba1UL
156#define K_40_59 0x8f1bbcdcUL
157#define K_60_79 0xca62c1d6UL
193 158
194/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be 159/* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be
195 * simplified to the code in F_00_19. Wei attributes these optimisations 160 * simplified to the code in F_00_19. Wei attributes these optimisations
@@ -203,44 +168,305 @@
203#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) 168#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
204#define F_60_79(b,c,d) F_20_39(b,c,d) 169#define F_60_79(b,c,d) F_20_39(b,c,d)
205 170
206#ifdef SHA_0 171#define BODY_00_15(i,a,b,c,d,e,f,xi) \
207#undef Xupdate 172 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
208#define Xupdate(a,i,ia,ib,ic,id) X[(i)&0x0f]=(a)=\
209 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);
210#endif
211#ifdef SHA_1
212#undef Xupdate
213#define Xupdate(a,i,ia,ib,ic,id) (a)=\
214 (ia[(i)&0x0f]^ib[((i)+2)&0x0f]^ic[((i)+8)&0x0f]^id[((i)+13)&0x0f]);\
215 X[(i)&0x0f]=(a)=ROTATE((a),1);
216#endif
217
218#define BODY_00_15(i,a,b,c,d,e,f,xa) \
219 (f)=xa[i]+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
220 (b)=ROTATE((b),30); 173 (b)=ROTATE((b),30);
221 174
222#define BODY_16_19(i,a,b,c,d,e,f,xa,xb,xc,xd) \ 175#define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
223 Xupdate(f,i,xa,xb,xc,xd); \ 176 Xupdate(f,xi,xa,xb,xc,xd); \
224 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ 177 (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
225 (b)=ROTATE((b),30); 178 (b)=ROTATE((b),30);
226 179
227#define BODY_20_31(i,a,b,c,d,e,f,xa,xb,xc,xd) \ 180#define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \
228 Xupdate(f,i,xa,xb,xc,xd); \ 181 Xupdate(f,xi,xa,xb,xc,xd); \
229 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ 182 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
230 (b)=ROTATE((b),30); 183 (b)=ROTATE((b),30);
231 184
232#define BODY_32_39(i,a,b,c,d,e,f,xa) \ 185#define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \
233 Xupdate(f,i,xa,xa,xa,xa); \ 186 Xupdate(f,xa,xa,xb,xc,xd); \
234 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ 187 (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \
235 (b)=ROTATE((b),30); 188 (b)=ROTATE((b),30);
236 189
237#define BODY_40_59(i,a,b,c,d,e,f,xa) \ 190#define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \
238 Xupdate(f,i,xa,xa,xa,xa); \ 191 Xupdate(f,xa,xa,xb,xc,xd); \
239 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ 192 (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \
240 (b)=ROTATE((b),30); 193 (b)=ROTATE((b),30);
241 194
242#define BODY_60_79(i,a,b,c,d,e,f,xa) \ 195#define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \
243 Xupdate(f,i,xa,xa,xa,xa); \ 196 Xupdate(f,xa,xa,xb,xc,xd); \
244 (f)=X[(i)&0x0f]+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ 197 (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \
245 (b)=ROTATE((b),30); 198 (b)=ROTATE((b),30);
246 199
200#ifdef X
201#undef X
202#endif
203#ifndef MD32_XARRAY
204 /*
205 * Originally X was an array. As it's automatic it's natural
206 * to expect RISC compiler to accomodate at least part of it in
207 * the register bank, isn't it? Unfortunately not all compilers
208 * "find" this expectation reasonable:-( On order to make such
209 * compilers generate better code I replace X[] with a bunch of
210 * X0, X1, etc. See the function body below...
211 * <appro@fy.chalmers.se>
212 */
213# define X(i) XX##i
214#else
215 /*
216 * However! Some compilers (most notably HP C) get overwhelmed by
217 * that many local variables so that we have to have the way to
218 * fall down to the original behavior.
219 */
220# define X(i) XX[i]
221#endif
222
223#ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
224void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
225 {
226 const SHA_LONG *W=d;
227 register unsigned long A,B,C,D,E,T;
228#ifndef MD32_XARRAY
229 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
230 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
231#else
232 SHA_LONG XX[16];
233#endif
234
235 A=c->h0;
236 B=c->h1;
237 C=c->h2;
238 D=c->h3;
239 E=c->h4;
240
241 for (;;)
242 {
243 BODY_00_15( 0,A,B,C,D,E,T,W[ 0]);
244 BODY_00_15( 1,T,A,B,C,D,E,W[ 1]);
245 BODY_00_15( 2,E,T,A,B,C,D,W[ 2]);
246 BODY_00_15( 3,D,E,T,A,B,C,W[ 3]);
247 BODY_00_15( 4,C,D,E,T,A,B,W[ 4]);
248 BODY_00_15( 5,B,C,D,E,T,A,W[ 5]);
249 BODY_00_15( 6,A,B,C,D,E,T,W[ 6]);
250 BODY_00_15( 7,T,A,B,C,D,E,W[ 7]);
251 BODY_00_15( 8,E,T,A,B,C,D,W[ 8]);
252 BODY_00_15( 9,D,E,T,A,B,C,W[ 9]);
253 BODY_00_15(10,C,D,E,T,A,B,W[10]);
254 BODY_00_15(11,B,C,D,E,T,A,W[11]);
255 BODY_00_15(12,A,B,C,D,E,T,W[12]);
256 BODY_00_15(13,T,A,B,C,D,E,W[13]);
257 BODY_00_15(14,E,T,A,B,C,D,W[14]);
258 BODY_00_15(15,D,E,T,A,B,C,W[15]);
259
260 BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]);
261 BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]);
262 BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]);
263 BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0));
264
265 BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1));
266 BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2));
267 BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3));
268 BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4));
269 BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5));
270 BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6));
271 BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7));
272 BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8));
273 BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9));
274 BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10));
275 BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11));
276 BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12));
277
278 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
279 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
280 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
281 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
282 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
283 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
284 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
285 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
286
287 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
288 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
289 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
290 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
291 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
292 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
293 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
294 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
295 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
296 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
297 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
298 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
299 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
300 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
301 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
302 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
303 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
304 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
305 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
306 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
307
308 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
309 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
310 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
311 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
312 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
313 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
314 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
315 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
316 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
317 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
318 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
319 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
320 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
321 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
322 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
323 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
324 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
325 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
326 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
327 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
328
329 c->h0=(c->h0+E)&0xffffffffL;
330 c->h1=(c->h1+T)&0xffffffffL;
331 c->h2=(c->h2+A)&0xffffffffL;
332 c->h3=(c->h3+B)&0xffffffffL;
333 c->h4=(c->h4+C)&0xffffffffL;
334
335 if (--num <= 0) break;
336
337 A=c->h0;
338 B=c->h1;
339 C=c->h2;
340 D=c->h3;
341 E=c->h4;
342
343 W+=SHA_LBLOCK;
344 }
345 }
346#endif
347
348#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER
349void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
350 {
351 const unsigned char *data=p;
352 register unsigned long A,B,C,D,E,T,l;
353#ifndef MD32_XARRAY
354 unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
355 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
356#else
357 SHA_LONG XX[16];
358#endif
359
360 A=c->h0;
361 B=c->h1;
362 C=c->h2;
363 D=c->h3;
364 E=c->h4;
365
366 for (;;)
367 {
368
369 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
370 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l;
371 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l;
372 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l;
373 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l;
374 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l;
375 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l;
376 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l;
377 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l;
378 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l;
379 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l;
380 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l;
381 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l;
382 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l;
383 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l;
384 BODY_00_15(14,E,T,A,B,C,D,X(14));
385 BODY_00_15(15,D,E,T,A,B,C,X(15));
386
387 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
388 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
389 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
390 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
391
392 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
393 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
394 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
395 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
396 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
397 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
398 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
399 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
400 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
401 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
402 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
403 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
404
405 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
406 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
407 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
408 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
409 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
410 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
411 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
412 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
413
414 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
415 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
416 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
417 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
418 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
419 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
420 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
421 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
422 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
423 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
424 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
425 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
426 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
427 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
428 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
429 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
430 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
431 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
432 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
433 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
434
435 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
436 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
437 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
438 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
439 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
440 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
441 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
442 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
443 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
444 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
445 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
446 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
447 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
448 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
449 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
450 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
451 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
452 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
453 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
454 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
455
456 c->h0=(c->h0+E)&0xffffffffL;
457 c->h1=(c->h1+T)&0xffffffffL;
458 c->h2=(c->h2+A)&0xffffffffL;
459 c->h3=(c->h3+B)&0xffffffffL;
460 c->h4=(c->h4+C)&0xffffffffL;
461
462 if (--num <= 0) break;
463
464 A=c->h0;
465 B=c->h1;
466 C=c->h2;
467 D=c->h3;
468 E=c->h4;
469
470 }
471 }
472#endif