X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=apps%2Fspeed.c;h=885784ee1d2318c5d47ce620aef527a82cf829ae;hp=2d34310e61434571f78385b64c33baa6f00177da;hb=b359642ffd0ae9dff8e1eb7d871356c99b093f57;hpb=329c744f519c67aaf8a240e38b5c44a8ce5e0dfd diff --git a/apps/speed.c b/apps/speed.c index 2d34310e61..885784ee1d 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -74,9 +74,10 @@ #ifndef OPENSSL_NO_SPEED #undef SECONDS -#define SECONDS 3 -#define RSA_SECONDS 10 -#define DSA_SECONDS 10 +#define SECONDS 3 +#define PRIME_SECONDS 10 +#define RSA_SECONDS 10 +#define DSA_SECONDS 10 #define ECDSA_SECONDS 10 #define ECDH_SECONDS 10 @@ -108,8 +109,14 @@ #include #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) #include +# if defined(__CYGWIN__) && !defined(_WIN32) + /* should define _WIN32, which normally is mutually + * exclusive with __CYGWIN__, but if it didn't... */ +# define _WIN32 + /* this is done because Cygwin alarm() fails sometimes. */ +# endif #endif #include @@ -185,6 +192,8 @@ #endif #include +#include "../crypto/bn/bn_lcl.h" + #ifndef HAVE_FORK # if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_NETWARE) # define HAVE_FORK 0 @@ -208,15 +217,18 @@ static int usertime=1; static double Time_F(int s); static void print_message(const char *s,long num,int length); +static void prime_print_message(const char *s, long num); static void pkey_print_message(const char *str, const char *str2, long num, int bits, int sec); static void print_result(int alg,int run_no,int count,double time_used); +static void prime_print_result(int alg, int count, double time_used); #ifndef NO_FORK static int do_multi(int multi); #endif #define ALGOR_NUM 30 #define SIZE_NUM 5 +#define PRIME_NUM 2 #define RSA_NUM 4 #define DSA_NUM 3 @@ -233,6 +245,8 @@ static const char *names[ALGOR_NUM]={ "aes-128 ige","aes-192 ige","aes-256 ige","ghash" }; static double results[ALGOR_NUM][SIZE_NUM]; static int lengths[SIZE_NUM]={16,64,256,1024,8*1024}; +static const char *prime_names[PRIME_NUM]={ + "prime trial division", "prime coprime" }; #ifndef OPENSSL_NO_RSA static double rsa_results[RSA_NUM][2]; #endif @@ -274,9 +288,12 @@ static SIGRETTYPE sig_done(int sig) #if defined(_WIN32) -#define SIGALRM +#if !defined(SIGALRM) +# define SIGALRM +#endif static unsigned int lapse,schlock; -static void alarm(unsigned int secs) { lapse = secs*1000; } +static void alarm_win32(unsigned int secs) { lapse = secs*1000; } +#define alarm alarm_win32 static DWORD WINAPI sleepy(VOID *arg) { @@ -480,9 +497,14 @@ int MAIN(int argc, char **argv) #define D_IGE_128_AES 26 #define D_IGE_192_AES 27 #define D_IGE_256_AES 28 -#define D_GHASH 29 +#define D_GHASH 29 double d=0.0; long c[ALGOR_NUM][SIZE_NUM]; + +#define D_PRIME_TRIAL_DIVISION 0 +#define D_PRIME_COPRIME 1 + long prime_c[PRIME_NUM]; + #define R_DSA_512 0 #define R_DSA_1024 1 #define R_DSA_2048 2 @@ -596,6 +618,7 @@ int MAIN(int argc, char **argv) long ecdh_c[EC_NUM][2]; #endif + int prime_doit[PRIME_NUM]; int rsa_doit[RSA_NUM]; int dsa_doit[DSA_NUM]; #ifndef OPENSSL_NO_ECDSA @@ -965,7 +988,7 @@ int MAIN(int argc, char **argv) else #endif #ifndef OPENSSL_NO_ECDH - if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2; + if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2; else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2; else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2; else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2; @@ -988,6 +1011,9 @@ int MAIN(int argc, char **argv) } else #endif + if (strcmp(*argv,"prime-trial-division") == 0) prime_doit[D_PRIME_TRIAL_DIVISION]=1; + else if (strcmp(*argv,"prime-coprime") == 0) prime_doit[D_PRIME_COPRIME]=1; + else { BIO_printf(bio_err,"Error: bad option or value\n"); BIO_printf(bio_err,"\n"); @@ -1114,6 +1140,7 @@ int MAIN(int argc, char **argv) !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA) BIO_printf(bio_err,"\n"); #endif + BIO_printf(bio_err,"prime-trial-division prime-coprime\n"); BIO_printf(bio_err,"\n"); BIO_printf(bio_err,"Available options:\n"); @@ -1282,25 +1309,26 @@ int MAIN(int argc, char **argv) c[D_IGE_256_AES][0]=count; c[D_GHASH][0]=count; - for (i=1; i