summaryrefslogtreecommitdiff
path: root/lib/libcrypto/bn
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2016-11-04 17:30:31 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2016-11-04 17:30:31 +0000
commitc43596c1b44ce26fd68289447ba3e90b3309ad62 (patch)
treedf98ebfc6e7b2cc867619b5b6bf458986975094f /lib/libcrypto/bn
parentba50086d387a9271c3975d49e9700d931d18abb8 (diff)
Replace all uses of magic numbers when operating on OPENSSL_ia32_P[] by
meaningful constants in a private header file, so that reviewers can actually get a chance to figure out what the code is attempting to do without knowing all cpuid bits. While there, turn it from an array of two 32-bit ints into a properly aligned 64-bit int. Use of OPENSSL_ia32_P is now restricted to the assembler parts. C code will now always use OPENSSL_cpu_caps() and check for the proper bits in the whole 64-bit word it returns. i386 tests and ok jsing@
Diffstat (limited to 'lib/libcrypto/bn')
-rw-r--r--lib/libcrypto/bn/asm/bn-586.pl12
-rw-r--r--lib/libcrypto/bn/asm/x86-gf2m.pl6
-rwxr-xr-xlib/libcrypto/bn/asm/x86-mont.pl6
-rw-r--r--lib/libcrypto/bn/asm/x86_64-gf2m.pl5
4 files changed, 16 insertions, 13 deletions
diff --git a/lib/libcrypto/bn/asm/bn-586.pl b/lib/libcrypto/bn/asm/bn-586.pl
index 332ef3e91d6..c4e2baa6c5a 100644
--- a/lib/libcrypto/bn/asm/bn-586.pl
+++ b/lib/libcrypto/bn/asm/bn-586.pl
@@ -25,7 +25,7 @@ sub bn_mul_add_words
{
local($name)=@_;
- &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
+ &function_begin_B($name,"");
$r="eax";
$a="edx";
@@ -33,7 +33,7 @@ sub bn_mul_add_words
if ($sse2) {
&picmeup("eax","OPENSSL_ia32cap_P");
- &bt(&DWP(0,"eax"),26);
+ &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2");
&jnc(&label("maw_non_sse2"));
&mov($r,&wparam(0));
@@ -211,7 +211,7 @@ sub bn_mul_words
{
local($name)=@_;
- &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
+ &function_begin_B($name,"");
$r="eax";
$a="edx";
@@ -219,7 +219,7 @@ sub bn_mul_words
if ($sse2) {
&picmeup("eax","OPENSSL_ia32cap_P");
- &bt(&DWP(0,"eax"),26);
+ &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2");
&jnc(&label("mw_non_sse2"));
&mov($r,&wparam(0));
@@ -322,7 +322,7 @@ sub bn_sqr_words
{
local($name)=@_;
- &function_begin_B($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":"");
+ &function_begin_B($name,"");
$r="eax";
$a="edx";
@@ -330,7 +330,7 @@ sub bn_sqr_words
if ($sse2) {
&picmeup("eax","OPENSSL_ia32cap_P");
- &bt(&DWP(0,"eax"),26);
+ &bt(&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2");
&jnc(&label("sqr_non_sse2"));
&mov($r,&wparam(0));
diff --git a/lib/libcrypto/bn/asm/x86-gf2m.pl b/lib/libcrypto/bn/asm/x86-gf2m.pl
index 808a1e59691..97d91362602 100644
--- a/lib/libcrypto/bn/asm/x86-gf2m.pl
+++ b/lib/libcrypto/bn/asm/x86-gf2m.pl
@@ -203,12 +203,12 @@ if (!$x86only) {
&picmeup("edx","OPENSSL_ia32cap_P");
&mov ("eax",&DWP(0,"edx"));
&mov ("edx",&DWP(4,"edx"));
- &test ("eax",1<<23); # check MMX bit
+ &test ("eax","\$IA32CAP_MASK0_MMX"); # check MMX bit
&jz (&label("ialu"));
if ($sse2) {
- &test ("eax",1<<24); # check FXSR bit
+ &test ("eax","\$IA32CAP_MASK0_FXSR"); # check FXSR bit
&jz (&label("mmx"));
- &test ("edx",1<<1); # check PCLMULQDQ bit
+ &test ("edx","\$IA32CAP_MASK1_PCLMUL"); # check PCLMULQDQ bit
&jz (&label("mmx"));
&movups ("xmm0",&QWP(8,"esp"));
diff --git a/lib/libcrypto/bn/asm/x86-mont.pl b/lib/libcrypto/bn/asm/x86-mont.pl
index 5cd3cd2ed50..a0bdd5787e5 100755
--- a/lib/libcrypto/bn/asm/x86-mont.pl
+++ b/lib/libcrypto/bn/asm/x86-mont.pl
@@ -114,7 +114,7 @@ $temp="mm6";
$mask="mm7";
&picmeup("eax","OPENSSL_ia32cap_P");
- &bt (&DWP(0,"eax"),26);
+ &bt (&DWP(0,"eax"),"\$IA32CAP_BIT0_SSE2");
&jnc (&label("non_sse2"));
&mov ("eax",-1);
@@ -527,8 +527,10 @@ $sbit=$num;
&jle (&label("sqradd"));
&mov ($carry,"edx");
- &lea ("edx",&DWP(0,$sbit,"edx",2));
+ &add ("edx","edx");
&shr ($carry,31);
+ &add ("edx",$sbit);
+ &adc ($carry,0);
&set_label("sqrlast");
&mov ($word,$_n0);
&mov ($inp,$_np);
diff --git a/lib/libcrypto/bn/asm/x86_64-gf2m.pl b/lib/libcrypto/bn/asm/x86_64-gf2m.pl
index 8e45c7479b3..3ecb425dad2 100644
--- a/lib/libcrypto/bn/asm/x86_64-gf2m.pl
+++ b/lib/libcrypto/bn/asm/x86_64-gf2m.pl
@@ -163,12 +163,13 @@ ___
$code.=<<___;
.extern OPENSSL_ia32cap_P
+.hidden OPENSSL_ia32cap_P
.globl bn_GF2m_mul_2x2
.type bn_GF2m_mul_2x2,\@abi-omnipotent
.align 16
bn_GF2m_mul_2x2:
- mov OPENSSL_ia32cap_P(%rip),%rax
- bt \$33,%rax
+ mov OPENSSL_ia32cap_P+4(%rip),%eax
+ bt \$IA32CAP_BIT1_PCLMUL,%eax
jnc .Lvanilla_mul_2x2
movd $a1,%xmm0