diff --git a/crypto/bn/asm/bn-586.pl b/crypto/bn/asm/bn-586.pl index 0415015f65100e2f5079904dad5e597cd7c4f9e7..26c2685a726e97ae6c654c3013a677b94d90d9b7 100644 --- a/crypto/bn/asm/bn-586.pl +++ b/crypto/bn/asm/bn-586.pl @@ -8,6 +8,8 @@ require "x86asm.pl"; $sse2=0; for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); } +&external_label("OPENSSL_ia32cap_P") if ($sse2); + &bn_mul_add_words("bn_mul_add_words"); &bn_mul_words("bn_mul_words"); &bn_sqr_words("bn_sqr_words"); @@ -22,7 +24,7 @@ sub bn_mul_add_words { local($name)=@_; - &function_begin($name,""); + &function_begin($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); &comment(""); $Low="eax"; @@ -46,7 +48,7 @@ sub bn_mul_add_words &jz(&label("maw_finish")); if ($sse2) { - &picmeup("eax","OPENSSL_ia32cap"); + &picmeup("eax","OPENSSL_ia32cap_P"); &bt(&DWP(0,"eax"),26); &jnc(&label("maw_loop")); diff --git a/crypto/cryptlib.c b/crypto/cryptlib.c index 419d37ca5dd660ffa036ed0bd99bbca308f23bdf..517678dbd425684f3cad50a460123515eebc7c69 100644 --- a/crypto/cryptlib.c +++ b/crypto/cryptlib.c @@ -541,23 +541,23 @@ const char *CRYPTO_get_lock_name(int type) #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) -unsigned long OPENSSL_ia32cap=0; -unsigned long *OPENSSL_ia32cap_loc() { return &OPENSSL_ia32cap; } +unsigned long OPENSSL_ia32cap_P=0; +unsigned long *OPENSSL_ia32cap_loc(void) { return &OPENSSL_ia32cap_P; } #if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY) #define OPENSSL_CPUID_SETUP -void OPENSSL_cpuid_setup() +void OPENSSL_cpuid_setup(void) { static int trigger=0; - unsigned long OPENSSL_ia32_cpuid(); + unsigned long OPENSSL_ia32_cpuid(void); char *env; if (trigger) return; trigger=1; if ((env=getenv("OPENSSL_ia32cap"))) - OPENSSL_ia32cap = strtoul(env,NULL,0)|(1<<10); + OPENSSL_ia32cap_P = strtoul(env,NULL,0)|(1<<10); else - OPENSSL_ia32cap = OPENSSL_ia32_cpuid()|(1<<10); + OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid()|(1<<10); /* * |(1<<10) sets a reserved bit to signal that variable * was initialized already... This is to avoid interference @@ -568,7 +568,7 @@ void OPENSSL_cpuid_setup() #endif #if !defined(OPENSSL_CPUID_SETUP) -void OPENSSL_cpuid_setup() {} +void OPENSSL_cpuid_setup(void) {} #endif #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_DLL) diff --git a/crypto/cryptlib.h b/crypto/cryptlib.h index 0d6b9d59f0b1896a31cb1276496db8122aa348af..8b0add7e20d9134d1bea04d310ee176b929d0a47 100644 --- a/crypto/cryptlib.h +++ b/crypto/cryptlib.h @@ -93,6 +93,9 @@ extern "C" { #define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) #define HEX_SIZE(type) (sizeof(type)*2) +void OPENSSL_cpuid_setup(void); +extern unsigned long OPENSSL_ia32cap_P; + #ifdef __cplusplus } #endif diff --git a/crypto/crypto.h b/crypto/crypto.h index 9edb24dc6de8df0d4f374464fbf3b0c5da899e21..a1bd005c3a3a9b05f5b9e40c63635690d2875037 100644 --- a/crypto/crypto.h +++ b/crypto/crypto.h @@ -541,6 +541,9 @@ void ERR_load_CRYPTO_strings(void); /* Reason codes. */ #define CRYPTO_R_NO_DYNLOCK_CREATE_CALLBACK 100 +unsigned long *OPENSSL_ia32cap_loc(void); +#define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc())) + #ifdef __cplusplus } #endif diff --git a/crypto/evp/c_all.c b/crypto/evp/c_all.c index c6a3315e649f54b98043e5f3149fd64ccfd91a2e..a5da52e62d8b03ef8625fe39eb64df4f59faf97e 100644 --- a/crypto/evp/c_all.c +++ b/crypto/evp/c_all.c @@ -79,7 +79,6 @@ void OPENSSL_add_all_algorithms_noconf(void) * only on IA-32, but we reserve the option for all * platforms... */ - void OPENSSL_cpuid_setup(); OPENSSL_cpuid_setup(); OpenSSL_add_all_ciphers(); OpenSSL_add_all_digests(); diff --git a/crypto/sha/sha512.c b/crypto/sha/sha512.c index bd1a125485cf64d3cc3e00145e32e9148d41249f..c84bd5addf4e06b09b0b909eb4190b39e6f906f8 100644 --- a/crypto/sha/sha512.c +++ b/crypto/sha/sha512.c @@ -48,6 +48,8 @@ #include #include +#include "cryptlib.h" + const char *SHA512_version="SHA-512" OPENSSL_VERSION_PTEXT; #if defined(_M_IX86) || defined(_M_AMD64) || defined(__i386) || defined(__x86_64) @@ -347,9 +349,8 @@ static const SHA_LONG64 K512[80] = { #if defined(OPENSSL_IA32_SSE2) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY) #define GO_FOR_SSE2(ctx,in,num) do { \ - extern int OPENSSL_ia32cap; \ - void sha512_block_sse2(void *,const void *,size_t); \ - if (!(OPENSSL_ia32cap & (1<<26))) break; \ + void sha512_block_sse2(void *,const void *,size_t); \ + if (!(OPENSSL_ia32cap_P & (1<<26))) break; \ sha512_block_sse2(ctx->h,in,num); return; \ } while (0) #endif diff --git a/crypto/sha/sha512t.c b/crypto/sha/sha512t.c index 96a71efb8e79bc96a267229fe0a58d296e7093ce..7385469beef60072b7a4194bfa01d5b6c6306ff6 100644 --- a/crypto/sha/sha512t.c +++ b/crypto/sha/sha512t.c @@ -9,6 +9,7 @@ #include #include +#include unsigned char app_c1[SHA512_DIGEST_LENGTH] = { 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba, @@ -70,11 +71,12 @@ int main () EVP_MD_CTX evp; #ifdef OPENSSL_IA32_SSE2 - { extern int OPENSSL_ia32cap; - char *env; + /* Alternative to this is to call OpenSSL_add_all_algorithms... + * The below code is retained exclusively for debugging purposes. */ + { char *env; if ((env=getenv("OPENSSL_ia32cap"))) - OPENSSL_ia32cap = strtol (env,NULL,0); + OPENSSL_ia32cap = strtoul (env,NULL,0); } #endif diff --git a/crypto/x86cpuid.pl b/crypto/x86cpuid.pl index 85fbef7417b5e64b02bb989b697ed821a00e47d5..da3e5bcaca185e112fdf1d869150251c113b9c44 100644 --- a/crypto/x86cpuid.pl +++ b/crypto/x86cpuid.pl @@ -25,12 +25,12 @@ require "x86asm.pl"; &mov ("edx","ecx"); &function_end("OPENSSL_ia32_cpuid"); -&external_label("OPENSSL_ia32cap"); +&external_label("OPENSSL_ia32cap_P"); -&function_begin_B("OPENSSL_rdtsc"); +&function_begin_B("OPENSSL_rdtsc","EXTRN\t_OPENSSL_ia32cap_P:DWORD"); &xor ("eax","eax"); &xor ("edx","edx"); - &picmeup("ecx","OPENSSL_ia32cap"); + &picmeup("ecx","OPENSSL_ia32cap_P"); &bt (&DWP(0,"ecx"),4); &jnc (&label("notsc")); &rdtsc (); @@ -38,6 +38,6 @@ require "x86asm.pl"; &ret (); &function_end_B("OPENSSL_rdtsc"); -&initseg("OPENSSL_cpuid_setup") if ($main'elf); +&initseg("OPENSSL_cpuid_setup"); &asm_finish(); diff --git a/doc/crypto/OPENSSL_ia32cap.pod b/doc/crypto/OPENSSL_ia32cap.pod index 46afd1988083ed20de053fd6a0ede2dd23c3bc10..790e8e9b1ef2d120c6a55a2f5546274547be42f4 100644 --- a/doc/crypto/OPENSSL_ia32cap.pod +++ b/doc/crypto/OPENSSL_ia32cap.pod @@ -6,26 +6,26 @@ OPENSSL_ia32cap =head1 SYNOPSIS - extern unsigned long OPENSSL_ia32cap; - unsigned long *OPENSSL_ia32cap_loc(); + unsigned long *OPENSSL_ia32cap_loc(void); + #define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc())) =head1 DESCRIPTION -OPENSSL_ia32cap is a variable containing IA-32 processor capabilities -bit vector as it appears in EDX register after executing CPUID -instruction with EAX=1 input value (see Intel Application Note -#241618). Naturally it's defined/meaningful on IA-32 platforms only. -The variable is normally set up automatically upon toolkit -initialization and can be manipulated afterwards to modify crypto -library behaviour. For the moment of this writing only two bits are -significant, namely bit #26 denoting SSE2 support, and bit #4 denoting -presence of Time-Stamp Counter. Resetting bit #26 at run-time for -example disables high-performance SSE2 code present in the crypto +Value returned by OPENSSL_ia32cap_loc() is address of a variable +containing IA-32 processor capabilities bit vector as it appears in EDX +register after executing CPUID instruction with EAX=1 input value (see +Intel Application Note #241618). Naturally it's meaningful on IA-32 +platforms only. The variable is normally set up automatically upon +toolkit initialization, but can be manipulated afterwards to modify +crypto library behaviour. For the moment of this writing only two bits +are significant, namely bit #26 denoting SSE2 support, and bit #4 +denoting presence of Time-Stamp Counter. Clearing bit #26 at run-time +for example disables high-performance SSE2 code present in the crypto library. You might have to do this if target OpenSSL application is executed on SSE2 capable CPU, but under control of OS which does not -support SSE2 extentions. Even though you can programmatically -manipulate the value, you most likely will find it more appropriate to -set up an environment variable with the same name prior starting target +support SSE2 extentions. Even though you can manipulate the value +programmatically, you most likely will find it more appropriate to set +up an environment variable with the same name prior starting target application, e.g. 'env OPENSSL_ia32cap=0x10 apps/openssl', to achieve same effect without modifying the application source code. Alternatively you can reconfigure the toolkit with no-sse2 option and