summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/sha/asm/sha1-586.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/sha/asm/sha1-586.pl')
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl107
1 files changed, 77 insertions, 30 deletions
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl
index 04e42ab09f..48d9192a4e 100644
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-586.pl
@@ -8,8 +8,8 @@ require "x86asm.pl";
8&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); 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,7 +315,7 @@ 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)=@_;
318 321
@@ -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(&label("shortcut"));
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", 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,26 @@ 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 # it has to reside within sha1_block_asm_host_order body
533 # because it calls &jmp(&label("shortcut"));
534 &sha1_block_host("sha1_block_asm_host_order");
535
489 &function_end_B($name); 536 &function_end_B($name);
490 } 537 }
491 538