<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#! /usr/bin/env perl
# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License").  You may not use
# this file except in compliance with the License.  You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html


# Normal is the
# md5_block_x86(MD5_CTX *c, ULONG *X);
# version, non-normal is the
# md5_block_x86(MD5_CTX *c, ULONG *X,int blocks);

$normal=0;

$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
push(@INC,"${dir}","${dir}../../perlasm");
require "x86asm.pl";

$output=pop;
open STDOUT,"&gt;$output";

&amp;asm_init($ARGV[0]);

$A="eax";
$B="ebx";
$C="ecx";
$D="edx";
$tmp1="edi";
$tmp2="ebp";
$X="esi";

# What we need to load into $tmp for the next round
%Ltmp1=("R0",&amp;Np($C), "R1",&amp;Np($C), "R2",&amp;Np($C), "R3",&amp;Np($D));
@xo=(
 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,	# R0
 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12,	# R1
 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2,	# R2
 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9,	# R3
 );

&amp;md5_block("md5_block_asm_data_order");
&amp;asm_finish();

close STDOUT;

sub Np
	{
	local($p)=@_;
	local(%n)=($A,$D,$B,$A,$C,$B,$D,$C);
	return($n{$p});
	}

sub R0
	{
	local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;

	&amp;mov($tmp1,$C)  if $pos &lt; 0;
	&amp;mov($tmp2,&amp;DWP($xo[$ki]*4,$K,"",0)) if $pos &lt; 0; # very first one

	# body proper

	&amp;comment("R0 $ki");
	&amp;xor($tmp1,$d); # F function - part 2

	&amp;and($tmp1,$b); # F function - part 3
	&amp;lea($a,&amp;DWP($t,$a,$tmp2,1));

	&amp;xor($tmp1,$d); # F function - part 4
	&amp;mov($tmp2,&amp;DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);

	&amp;add($a,$tmp1);

	&amp;rotl($a,$s);

	&amp;mov($tmp1,&amp;Np($c)) if $pos &lt; 1;	# next tmp1 for R0
	&amp;mov($tmp1,&amp;Np($c)) if $pos == 1;	# next tmp1 for R1

	&amp;add($a,$b);
	}

sub R1
	{
	local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;

	&amp;comment("R1 $ki");

	&amp;xor($tmp1,$b); # G function - part 2
	&amp;and($tmp1,$d); # G function - part 3
	&amp;lea($a,&amp;DWP($t,$a,$tmp2,1));

	&amp;xor($tmp1,$c);			# G function - part 4
	&amp;mov($tmp2,&amp;DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);

	&amp;add($a,$tmp1);
	&amp;mov($tmp1,&amp;Np($c)) if $pos &lt; 1;	# G function - part 1
	&amp;mov($tmp1,&amp;Np($c)) if $pos == 1;	# G function - part 1

	&amp;rotl($a,$s);

	&amp;add($a,$b);
	}

sub R2
	{
	local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;
	# This one is different, only 3 logical operations

if (($n &amp; 1) == 0)
	{
	&amp;comment("R2 $ki");
	# make sure to do 'D' first, not 'B', else we clash with
	# the last add from the previous round.

	&amp;xor($tmp1,$d); # H function - part 2

	&amp;xor($tmp1,$b); # H function - part 3
	&amp;lea($a,&amp;DWP($t,$a,$tmp2,1));

	&amp;add($a,$tmp1);
	&amp;mov($tmp2,&amp;DWP($xo[$ki+1]*4,$K,"",0));

	&amp;rotl($a,$s);

	&amp;mov($tmp1,&amp;Np($c));
	}
else
	{
	&amp;comment("R2 $ki");
	# make sure to do 'D' first, not 'B', else we clash with
	# the last add from the previous round.

	&amp;add($b,$c);			# MOVED FORWARD
	&amp;xor($tmp1,$d); # H function - part 2

	&amp;lea($a,&amp;DWP($t,$a,$tmp2,1));

	&amp;xor($tmp1,$b); # H function - part 3
	&amp;mov($tmp2,&amp;DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2);

	&amp;add($a,$tmp1);
	&amp;mov($tmp1,&amp;Np($c)) if $pos &lt; 1;	# H function - part 1
	&amp;mov($tmp1,-1) if $pos == 1;		# I function - part 1

	&amp;rotl($a,$s);

	&amp;add($a,$b);
	}
	}

sub R3
	{
	local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_;

	&amp;comment("R3 $ki");

	# &amp;not($tmp1)
	&amp;xor($tmp1,$d) if $pos &lt; 0; 	# I function - part 2

	&amp;or($tmp1,$b);				# I function - part 3
	&amp;lea($a,&amp;DWP($t,$a,$tmp2,1));

	&amp;xor($tmp1,$c); 			# I function - part 4
	&amp;mov($tmp2,&amp;DWP($xo[$ki+1]*4,$K,"",0))	if $pos != 2; # load X/k value
	&amp;mov($tmp2,&amp;wparam(0)) if $pos == 2;

	&amp;add($a,$tmp1);
	&amp;mov($tmp1,-1) if $pos &lt; 1;	# H function - part 1
	&amp;add($K,64) if $pos &gt;=1 &amp;&amp; !$normal;

	&amp;rotl($a,$s);

	&amp;xor($tmp1,&amp;Np($d)) if $pos &lt;= 0; 	# I function - part = first time
	&amp;mov($tmp1,&amp;DWP( 0,$tmp2,"",0)) if $pos &gt; 0;
	&amp;add($a,$b);
	}


sub md5_block
	{
	local($name)=@_;

	&amp;function_begin_B($name,"",3);

	# parameter 1 is the MD5_CTX structure.
	# A	0
	# B	4
	# C	8
	# D 	12

	&amp;push("esi");
	 &amp;push("edi");
	&amp;mov($tmp1,	&amp;wparam(0)); # edi
	 &amp;mov($X,	&amp;wparam(1)); # esi
	&amp;mov($C,	&amp;wparam(2));
	 &amp;push("ebp");
	&amp;shl($C,	6);
	&amp;push("ebx");
	 &amp;add($C,	$X); # offset we end at
	&amp;sub($C,	64);
	 &amp;mov($A,	&amp;DWP( 0,$tmp1,"",0));
	&amp;push($C);	# Put on the TOS
	 &amp;mov($B,	&amp;DWP( 4,$tmp1,"",0));
	&amp;mov($C,	&amp;DWP( 8,$tmp1,"",0));
	 &amp;mov($D,	&amp;DWP(12,$tmp1,"",0));

	&amp;set_label("start") unless $normal;
	&amp;comment("");
	&amp;comment("R0 section");

	&amp;R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478);
	&amp;R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756);
	&amp;R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db);
	&amp;R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee);
	&amp;R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf);
	&amp;R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a);
	&amp;R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613);
	&amp;R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501);
	&amp;R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8);
	&amp;R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af);
	&amp;R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1);
	&amp;R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be);
	&amp;R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122);
	&amp;R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193);
	&amp;R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e);
	&amp;R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821);

	&amp;comment("");
	&amp;comment("R1 section");
	&amp;R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562);
	&amp;R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340);
	&amp;R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51);
	&amp;R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa);
	&amp;R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d);
	&amp;R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453);
	&amp;R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681);
	&amp;R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8);
	&amp;R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6);
	&amp;R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6);
	&amp;R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87);
	&amp;R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed);
	&amp;R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905);
	&amp;R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8);
	&amp;R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9);
	&amp;R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a);

	&amp;comment("");
	&amp;comment("R2 section");
	&amp;R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942);
	&amp;R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681);
	&amp;R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122);
	&amp;R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c);
	&amp;R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44);
	&amp;R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9);
	&amp;R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60);
	&amp;R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70);
	&amp;R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6);
	&amp;R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa);
	&amp;R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085);
	&amp;R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05);
	&amp;R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039);
	&amp;R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5);
	&amp;R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8);
	&amp;R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665);

	&amp;comment("");
	&amp;comment("R3 section");
	&amp;R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244);
	&amp;R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97);
	&amp;R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7);
	&amp;R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039);
	&amp;R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3);
	&amp;R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92);
	&amp;R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d);
	&amp;R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1);
	&amp;R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f);
	&amp;R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0);
	&amp;R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314);
	&amp;R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1);
	&amp;R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82);
	&amp;R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235);
	&amp;R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb);
	&amp;R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391);

	# &amp;mov($tmp2,&amp;wparam(0));	# done in the last R3
	# &amp;mov($tmp1,	&amp;DWP( 0,$tmp2,"",0)); # done is the last R3

	&amp;add($A,$tmp1);
	 &amp;mov($tmp1,	&amp;DWP( 4,$tmp2,"",0));

	&amp;add($B,$tmp1);
	&amp;mov($tmp1,	&amp;DWP( 8,$tmp2,"",0));

	&amp;add($C,$tmp1);
	&amp;mov($tmp1,	&amp;DWP(12,$tmp2,"",0));

	&amp;add($D,$tmp1);
	&amp;mov(&amp;DWP( 0,$tmp2,"",0),$A);

	&amp;mov(&amp;DWP( 4,$tmp2,"",0),$B);
	&amp;mov($tmp1,&amp;swtmp(0)) unless $normal;

	&amp;mov(&amp;DWP( 8,$tmp2,"",0),$C);
	 &amp;mov(&amp;DWP(12,$tmp2,"",0),$D);

	&amp;cmp($tmp1,$X) unless $normal;			# check count
	 &amp;jae(&amp;label("start")) unless $normal;

	&amp;pop("eax"); # pop the temp variable off the stack
	 &amp;pop("ebx");
	&amp;pop("ebp");
	 &amp;pop("edi");
	&amp;pop("esi");
	 &amp;ret();
	&amp;function_end_B($name);
	}

</pre></body></html>