提交 2b247cf8 编写于 作者: A Andy Polyakov

OPENSSL_ia32cap final touches. Note that OPENSSL_ia32cap is no longer a

symbol, but a macro expanded as (*(OPENSSL_ia32cap_loc())). The latter
is the only one to be exported to application.
上级 746fc252
......@@ -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"));
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
......@@ -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();
......
......@@ -48,6 +48,8 @@
#include <openssl/sha.h>
#include <openssl/opensslv.h>
#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
......
......@@ -9,6 +9,7 @@
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
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
......
......@@ -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();
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册