From 23830280e4713a433c4ad0e2a49bff2027940aa1 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Thu, 19 Jul 2007 12:17:56 +0000 Subject: [PATCH] Add SSE2 support to VC++ build. Update MASM script. --- CHANGES | 5 +++++ crypto/perlasm/x86ms.pl | 18 ++++++++---------- crypto/rc4/rc4_skey.c | 5 +++++ ms/do_masm.bat | 31 ++++++++++++++++++++----------- ms/do_nasm.bat | 31 ++++++++++++++++++++----------- util/mk1mf.pl | 11 ++++++----- util/pl/VC-32.pl | 10 +++++++--- 7 files changed, 71 insertions(+), 40 deletions(-) diff --git a/CHANGES b/CHANGES index 9161182623..59c47af1eb 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,11 @@ Changes between 0.9.8e and 0.9.8f-fips [xx XXX xxxx] + *) Add SSE2 instruction support to WIN32 build. These will be compiled + by default and used it an appopriate CPU is detected. Some older versions + of NASM or MASM which don't support SSE2 will need to be updated. + [Steve Henson] + *) Tolerate DigestInfo structure with absent parameters in FIPS mode (as required by several standards). [Steve Henson] diff --git a/crypto/perlasm/x86ms.pl b/crypto/perlasm/x86ms.pl index 82538a9a9a..4badd1fc1c 100644 --- a/crypto/perlasm/x86ms.pl +++ b/crypto/perlasm/x86ms.pl @@ -204,16 +204,17 @@ sub main'pand { &out2("pand",@_); } sub out2 { local($name,$p1,$p2)=@_; - local($l,$t); + local($l,$t,$line); - push(@out,"\t$name\t"); + $line="\t$name\t"; $t=&conv($p1).","; $l=length($t); - push(@out,$t); + $line.="$t"; $l=4-($l+9)/8; - push(@out,"\t" x $l); - push(@out,&conv($p2)); - push(@out,"\n"); + $line.="\t" x $l; + $line.=&conv($p2); + if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; } + push(@out,$line."\n"); } sub out0 @@ -338,12 +339,9 @@ EOF sub main'file_end { # try to detect if SSE2 or MMX extensions were used... - if (grep {/xmm[0-7]\s*,/i} @out) { + if (grep {/\b[x]?mm[0-7]\b,/i} @out) { grep {s/\.[3-7]86/\.686\n\t\.XMM/} @out; } - elsif (grep {/mm[0-7]\s*,/i} @out) { - grep {s/\.[3-7]86/\.686\n\t\.MMX/} @out; - } push(@out,"_TEXT\$ ENDS\n"); push(@out,"END\n"); } diff --git a/crypto/rc4/rc4_skey.c b/crypto/rc4/rc4_skey.c index 22bf053174..4ab9981b22 100644 --- a/crypto/rc4/rc4_skey.c +++ b/crypto/rc4/rc4_skey.c @@ -128,7 +128,12 @@ FIPS_NON_FIPS_VCIPHER_Init(RC4) * module... * */ +#ifdef OPENSSL_FIPS + unsigned long *ia32cap_ptr = OPENSSL_ia32cap_loc(); + if (ia32cap_ptr && (*ia32cap_ptr & (1<<28))) { +#else if (OPENSSL_ia32cap_P & (1<<28)) { +#endif unsigned char *cp=(unsigned char *)d; for (i=0;i<256;i++) cp[i]=i; diff --git a/ms/do_masm.bat b/ms/do_masm.bat index d522232ce7..6ea1c98716 100755 --- a/ms/do_masm.bat +++ b/ms/do_masm.bat @@ -1,63 +1,72 @@ @echo off + +SET ASMOPTS=-DOPENSSL_IA32_SSE2 echo Generating x86 for MASM assember echo Bignum cd crypto\bn\asm -perl x86.pl win32 > bn_win32.asm +perl bn-586.pl win32 %ASMOPTS% > bn_win32.asm +perl co-586.pl win32 %ASMOPTS% > co_win32.asm cd ..\..\.. echo AES cd crypto\aes\asm -perl aes-586.pl win32 > a_win32.asm +perl aes-586.pl win32 %ASMOPTS% > a_win32.asm cd ..\..\.. echo DES cd crypto\des\asm -perl des-586.pl win32 > d_win32.asm +perl des-586.pl win32 %ASMOPTS% > d_win32.asm cd ..\..\.. echo "crypt(3)" cd crypto\des\asm -perl crypt586.pl win32 > y_win32.asm +perl crypt586.pl win32 %ASMOPTS% > y_win32.asm cd ..\..\.. echo Blowfish cd crypto\bf\asm -perl bf-586.pl win32 > b_win32.asm +perl bf-586.pl win32 %ASMOPTS% > b_win32.asm cd ..\..\.. echo CAST5 cd crypto\cast\asm -perl cast-586.pl win32 > c_win32.asm +perl cast-586.pl win32 %ASMOPTS% > c_win32.asm cd ..\..\.. echo RC4 cd crypto\rc4\asm -perl rc4-586.pl win32 > r4_win32.asm +perl rc4-586.pl win32 %ASMOPTS% > r4_win32.asm cd ..\..\.. echo MD5 cd crypto\md5\asm -perl md5-586.pl win32 > m5_win32.asm +perl md5-586.pl win32 %ASMOPTS% > m5_win32.asm cd ..\..\.. echo SHA1 cd crypto\sha\asm -perl sha1-586.pl win32 > s1_win32.asm +perl sha1-586.pl win32 %ASMOPTS% > s1_win32.asm +perl sha512-sse2.pl win32 %ASMOPTS% > sha512-sse2.asm cd ..\..\.. echo RIPEMD160 cd crypto\ripemd\asm -perl rmd-586.pl win32 > rm_win32.asm +perl rmd-586.pl win32 %ASMOPTS% > rm_win32.asm cd ..\..\.. echo RC5\32 cd crypto\rc5\asm -perl rc5-586.pl win32 > r5_win32.asm +perl rc5-586.pl win32 %ASMOPTS% > r5_win32.asm cd ..\..\.. +echo CPU-ID +cd crypto +perl x86cpuid.pl win32 %ASMOPTS% > cpu_win32.asm +cd .. + echo on perl util\mkfiles.pl >MINFO diff --git a/ms/do_nasm.bat b/ms/do_nasm.bat index 9a27b1af66..7a2fa45663 100755 --- a/ms/do_nasm.bat +++ b/ms/do_nasm.bat @@ -1,64 +1,73 @@ @echo off + +SET ASMOPTS=-DOPENSSL_IA32_SSE2 echo Generating x86 for NASM assember echo Bignum cd crypto\bn\asm -perl x86.pl win32n > bn_win32.asm +perl bn-586.pl win32n %ASMOPTS% > bn_win32.asm +perl co-586.pl win32n %ASMOPTS% > co_win32.asm cd ..\..\.. echo AES cd crypto\aes\asm -perl aes-586.pl win32n > a_win32.asm +perl aes-586.pl win32n %ASMOPTS% > a_win32.asm cd ..\..\.. echo DES cd crypto\des\asm -perl des-586.pl win32n > d_win32.asm +perl des-586.pl win32n %ASMOPTS% > d_win32.asm cd ..\..\.. echo "crypt(3)" cd crypto\des\asm -perl crypt586.pl win32n > y_win32.asm +perl crypt586.pl win32n %ASMOPTS% > y_win32.asm cd ..\..\.. echo Blowfish cd crypto\bf\asm -perl bf-586.pl win32n > b_win32.asm +perl bf-586.pl win32n %ASMOPTS% > b_win32.asm cd ..\..\.. echo CAST5 cd crypto\cast\asm -perl cast-586.pl win32n > c_win32.asm +perl cast-586.pl win32n %ASMOPTS% > c_win32.asm cd ..\..\.. echo RC4 cd crypto\rc4\asm -perl rc4-586.pl win32n > r4_win32.asm +perl rc4-586.pl win32n %ASMOPTS% > r4_win32.asm cd ..\..\.. echo MD5 cd crypto\md5\asm -perl md5-586.pl win32n > m5_win32.asm +perl md5-586.pl win32n %ASMOPTS% > m5_win32.asm cd ..\..\.. echo SHA1 cd crypto\sha\asm -perl sha1-586.pl win32n > s1_win32.asm +perl sha1-586.pl win32n %ASMOPTS% > s1_win32.asm +perl sha512-sse2.pl win32n %ASMOPTS% > sha512-sse2.asm cd ..\..\.. echo RIPEMD160 cd crypto\ripemd\asm -perl rmd-586.pl win32n > rm_win32.asm +perl rmd-586.pl win32n %ASMOPTS% > rm_win32.asm cd ..\..\.. echo RC5\32 cd crypto\rc5\asm -perl rc5-586.pl win32n > r5_win32.asm +perl rc5-586.pl win32n %ASMOPTS% > r5_win32.asm cd ..\..\.. +echo CPU-ID +cd crypto +perl x86cpuid.pl win32n %ASMOPTS% > cpu_win32.asm +cd .. + echo on perl util\mkfiles.pl >MINFO diff --git a/util/mk1mf.pl b/util/mk1mf.pl index b2d7153c24..3b46cb2daf 100755 --- a/util/mk1mf.pl +++ b/util/mk1mf.pl @@ -372,6 +372,7 @@ if ($fips) $fips_exclude_obj{$1} = 1 if (/\/([^\/]*)$/); } + $fips_exclude_obj{"cpu_win32"} = 1; $fips_exclude_obj{"bn_asm"} = 1; $fips_exclude_obj{"des_enc"} = 1; $fips_exclude_obj{"fcrypt_b"} = 1; @@ -787,6 +788,11 @@ foreach (values %lib_nam) if ((!$fips && ($_ eq "CRYPTO")) || ($fips && ($_ eq "FIPS"))) { + if ($cpuid_asm_obj ne "") + { + $lib_obj =~ s/\s(\S*\/cryptlib\S*)/ $1 \$(CPUID_ASM_OBJ)/; + $rules.=&do_asm_rule($cpuid_asm_obj,$cpuid_asm_src); + } if ($aes_asm_obj ne "") { $lib_obj =~ s/\s(\S*\/aes_core\S*)/ \$(AES_ASM_OBJ)/; @@ -845,11 +851,6 @@ foreach (values %lib_nam) $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/; $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src); } - if (($cpuid_asm_obj ne "") && ($_ eq "CRYPTO")) - { - $lib_obj =~ s/\s(\S*\/cversion\S*)/ $1 \$(CPUID_ASM_OBJ)/; - $rules.=&do_asm_rule($cpuid_asm_obj,$cpuid_asm_src); - } $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj); $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)"; $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib); diff --git a/util/pl/VC-32.pl b/util/pl/VC-32.pl index 6f64f3abf4..7682a591ce 100644 --- a/util/pl/VC-32.pl +++ b/util/pl/VC-32.pl @@ -194,6 +194,8 @@ if (!$no_asm) $aes_asm_src='crypto\aes\asm\a_win32.asm'; $bn_asm_obj='crypto\bn\asm\bn_win32.obj'; $bn_asm_src='crypto\bn\asm\bn_win32.asm'; + $bnco_asm_obj='crypto\bn\asm\co_win32.obj'; + $bnco_asm_src='crypto\bn\asm\co_win32.asm'; $des_enc_obj='crypto\des\asm\d_win32.obj crypto\des\asm\y_win32.obj'; $des_enc_src='crypto\des\asm\d_win32.asm crypto\des\asm\y_win32.asm'; $bf_enc_obj='crypto\bf\asm\b_win32.obj'; @@ -206,11 +208,13 @@ if (!$no_asm) $rc5_enc_src='crypto\rc5\asm\r5_win32.asm'; $md5_asm_obj='crypto\md5\asm\m5_win32.obj'; $md5_asm_src='crypto\md5\asm\m5_win32.asm'; - $sha1_asm_obj='crypto\sha\asm\s1_win32.obj'; - $sha1_asm_src='crypto\sha\asm\s1_win32.asm'; + $sha1_asm_obj='crypto\sha\asm\s1_win32.obj crypto\sha\asm\sha512-sse2.obj'; + $sha1_asm_src='crypto\sha\asm\s1_win32.asm crypto\sha\asm\sha512-sse2.asm'; $rmd160_asm_obj='crypto\ripemd\asm\rm_win32.obj'; $rmd160_asm_src='crypto\ripemd\asm\rm_win32.asm'; - $cflags.=" -DAES_ASM -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM"; + $cpuid_asm_obj='crypto\cpu_win32.obj'; + $cpuid_asm_src='crypto\cpu_win32.asm'; + $cflags.=" -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DAES_ASM -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DSHA1_ASM -DRMD160_ASM"; } if ($shlib && $FLAVOR !~ /CE/) -- 2.25.1