X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=apps%2Fspeed.c;h=8e1fe840c6acb53f0ac28e3d2feabb132c46b04d;hb=b91dd150d2b9b5ddca37722e7f52ea59ba7f80da;hp=7dfdda8bf59156b503821282160f9227b10cd2db;hpb=b196e7d936fb377d9c5b305748ac25ff0e53ef6d;p=openssl.git diff --git a/apps/speed.c b/apps/speed.c index 7dfdda8bf5..8e1fe840c6 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -297,9 +297,9 @@ static double Time_F(int s) schlock = 0; thr = CreateThread(NULL, 4096, sleepy, NULL, 0, NULL); if (thr == NULL) { - DWORD ret = GetLastError(); - BIO_printf(bio_err, "unable to CreateThread (%d)", ret); - ExitProcess(ret); + DWORD err = GetLastError(); + BIO_printf(bio_err, "unable to CreateThread (%lu)", err); + ExitProcess(err); } while (!schlock) Sleep(0); /* scheduler spinlock */ @@ -358,22 +358,21 @@ OPTIONS speed_options[] = { {OPT_HELP_STR, 1, '-', "Usage: %s [options] ciphers...\n"}, {OPT_HELP_STR, 1, '-', "Valid options are:\n"}, {"help", OPT_HELP, '-', "Display this summary"}, -#if defined(TIMES) || defined(USE_TOD) - {"elapsed", OPT_ELAPSED, '-', - "Measure time in real time instead of CPU user time"}, -#endif {"evp", OPT_EVP, 's', "Use specified EVP cipher"}, {"decrypt", OPT_DECRYPT, '-', "Time decryption instead of encryption (only EVP)"}, -#ifndef NO_FORK - {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"}, -#endif {"mr", OPT_MR, '-', "Produce machine readable output"}, {"mb", OPT_MB, '-'}, {"misalign", OPT_MISALIGN, 'n', "Amount to mis-align buffers"}, + {"elapsed", OPT_ELAPSED, '-', + "Measure time in real time instead of CPU user time"}, +#ifndef NO_FORK + {"multi", OPT_MULTI, 'p', "Run benchmarks in parallel"}, +#endif #ifndef OPENSSL_NO_ENGINE {"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"}, #endif + {NULL}, }; #define D_MD2 0 @@ -406,7 +405,7 @@ OPTIONS speed_options[] = { #define D_IGE_192_AES 27 #define D_IGE_256_AES 28 #define D_GHASH 29 -OPT_PAIR doit_choices[] = { +static OPT_PAIR doit_choices[] = { #ifndef OPENSSL_NO_MD2 {"md2", D_MD2}, #endif @@ -428,7 +427,7 @@ OPT_PAIR doit_choices[] = { #ifndef OPENSSL_NO_WHIRLPOOL {"whirlpool", D_WHIRLPOOL}, #endif -#ifndef OPENSSL_NO_RIPEMD +#ifndef OPENSSL_NO_RMD160 {"ripemd", D_RMD160}, {"rmd160", D_RMD160}, {"ripemd160", D_RMD160}, @@ -522,7 +521,7 @@ static OPT_PAIR rsa_choices[] = { #define R_EC_B283 13 #define R_EC_B409 14 #define R_EC_B571 15 -#ifndef OPENSSL_NO_ECA +#ifndef OPENSSL_NO_EC static OPT_PAIR ecdsa_choices[] = { {"ecdsap160", R_EC_P160}, {"ecdsap192", R_EC_P192}, @@ -576,7 +575,6 @@ int speed_main(int argc, char **argv) long c[ALGOR_NUM][SIZE_NUM], count = 0, save_count = 0; unsigned char *buf_malloc = NULL, *buf2_malloc = NULL; unsigned char *buf = NULL, *buf2 = NULL; - unsigned char *save_buf = NULL, *save_buf2 = NULL; unsigned char md[EVP_MAX_MD_SIZE]; #ifndef NO_FORK int multi = 0; @@ -604,7 +602,7 @@ int speed_main(int argc, char **argv) #ifndef OPENSSL_NO_WHIRLPOOL unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH]; #endif -#ifndef OPENSSL_NO_RIPEMD +#ifndef OPENSSL_NO_RMD160 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH]; #endif #ifndef OPENSSL_NO_RC4 @@ -754,9 +752,6 @@ int speed_main(int argc, char **argv) long ecdh_c[EC_NUM][2]; int ecdh_doit[EC_NUM]; #endif -#ifndef TIMES - usertime = -1; -#endif memset(results, 0, sizeof(results)); #ifndef OPENSSL_NO_DSA @@ -791,17 +786,9 @@ int speed_main(int argc, char **argv) ecdh_doit[i] = 0; #endif - if ((buf_malloc = OPENSSL_malloc((int)BUFSIZE + misalign)) == NULL) { - BIO_printf(bio_err, "out of memory\n"); - goto end; - } - if ((buf2_malloc = OPENSSL_malloc((int)BUFSIZE + misalign)) == NULL) { - BIO_printf(bio_err, "out of memory\n"); - goto end; - } + buf = buf_malloc = app_malloc((int)BUFSIZE + misalign, "input buffer"); + buf2 = buf2_malloc = app_malloc((int)BUFSIZE + misalign, "output buffer"); misalign = 0; - buf = buf_malloc; - buf2 = buf2_malloc; prog = opt_init(argc, argv, speed_options); while ((o = opt_next()) != OPT_EOF) { @@ -836,11 +823,11 @@ int speed_main(int argc, char **argv) case OPT_ENGINE: (void)setup_engine(opt_arg(), 0); break; -#ifndef NO_FORK case OPT_MULTI: +#ifndef NO_FORK multi = atoi(opt_arg()); - break; #endif + break; case OPT_MISALIGN: if (!opt_int(opt_arg(), &misalign)) goto end; @@ -882,7 +869,7 @@ int speed_main(int argc, char **argv) #ifndef OPENSSL_NO_RSA # ifndef RSA_NULL if (strcmp(*argv, "openssl") == 0) { - RSA_set_default_method(RSA_PKCS1_SSLeay()); + RSA_set_default_method(RSA_PKCS1_OpenSSL()); continue; } # endif @@ -953,7 +940,7 @@ int speed_main(int argc, char **argv) #endif /* No parameters; turn on everything. */ - if (argc == 0) { + if ((argc == 0) && !doit[D_EVP]) { for (i = 0; i < ALGOR_NUM; i++) if (i != D_EVP) doit[i] = 1; @@ -1311,24 +1298,28 @@ int speed_main(int argc, char **argv) #if !defined(OPENSSL_NO_MD5) if (doit[D_HMAC]) { - HMAC_CTX hctx; + HMAC_CTX *hctx = NULL; - HMAC_CTX_init(&hctx); - HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...", + hctx = HMAC_CTX_new(); + if (hctx == NULL) { + BIO_printf(bio_err, "HMAC malloc failure, exiting..."); + exit(1); + } + HMAC_Init_ex(hctx, (unsigned char *)"This is a key...", 16, EVP_md5(), NULL); for (j = 0; j < SIZE_NUM; j++) { print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]); Time_F(START); for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) { - HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL); - HMAC_Update(&hctx, buf, lengths[j]); - HMAC_Final(&hctx, &(hmac[0]), NULL); + HMAC_Init_ex(hctx, NULL, 0, NULL, NULL); + HMAC_Update(hctx, buf, lengths[j]); + HMAC_Final(hctx, &(hmac[0]), NULL); } d = Time_F(STOP); print_result(D_HMAC, j, count, d); } - HMAC_CTX_cleanup(&hctx); + HMAC_CTX_free(hctx); } #endif if (doit[D_SHA1]) { @@ -1653,7 +1644,7 @@ int speed_main(int argc, char **argv) if (! (EVP_CIPHER_flags(evp_cipher) & EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) { - fprintf(stderr, "%s is not multi-block capable\n", + BIO_printf(bio_err, "%s is not multi-block capable\n", OBJ_nid2ln(evp_cipher->nid)); goto end; } @@ -1700,7 +1691,7 @@ int speed_main(int argc, char **argv) EVP_CIPHER_CTX_cleanup(&ctx); } if (evp_md) { - names[D_EVP] = OBJ_nid2ln(evp_md->type); + names[D_EVP] = OBJ_nid2ln(EVP_MD_type(evp_md)); print_message(names[D_EVP], save_count, lengths[j]); Time_F(START); @@ -2054,8 +2045,8 @@ int speed_main(int argc, char **argv) show_res: #endif if (!mr) { - printf("%s\n", SSLeay_version(SSLEAY_VERSION)); - printf("%s\n", SSLeay_version(SSLEAY_BUILT_ON)); + printf("%s\n", OpenSSL_version(OPENSSL_VERSION)); + printf("%s\n", OpenSSL_version(OPENSSL_BUILT_ON)); printf("options:"); printf("%s ", BN_options()); #ifndef OPENSSL_NO_MD2 @@ -2076,7 +2067,7 @@ int speed_main(int argc, char **argv) #ifndef OPENSSL_NO_BF printf("%s ", BF_options()); #endif - printf("\n%s\n", SSLeay_version(SSLEAY_CFLAGS)); + printf("\n%s\n", OpenSSL_version(OPENSSL_CFLAGS)); } if (pr_header) { @@ -2192,8 +2183,8 @@ int speed_main(int argc, char **argv) end: ERR_print_errors(bio_err); - OPENSSL_free(save_buf); - OPENSSL_free(save_buf2); + OPENSSL_free(buf_malloc); + OPENSSL_free(buf2_malloc); #ifndef OPENSSL_NO_RSA for (i = 0; i < RSA_NUM; i++) RSA_free(rsa_key[i]); @@ -2210,7 +2201,6 @@ int speed_main(int argc, char **argv) EC_KEY_free(ecdh_b[i]); } #endif - return (ret); } @@ -2291,14 +2281,14 @@ static int do_multi(int multi) int *fds; static char sep[] = ":"; - fds = malloc(multi * sizeof *fds); + fds = malloc(sizeof(*fds) * multi); for (n = 0; n < multi; ++n) { if (pipe(fd) == -1) { - fprintf(stderr, "pipe failure\n"); + BIO_printf(bio_err, "pipe failure\n"); exit(1); } fflush(stdout); - fflush(stderr); + (void)BIO_flush(bio_err); if (fork()) { close(fd[1]); fds[n] = fd[0]; @@ -2306,7 +2296,7 @@ static int do_multi(int multi) close(fd[0]); close(1); if (dup(fd[1]) == -1) { - fprintf(stderr, "dup failed\n"); + BIO_printf(bio_err, "dup failed\n"); exit(1); } close(fd[1]); @@ -2330,12 +2320,12 @@ static int do_multi(int multi) if (p) *p = '\0'; if (buf[0] != '+') { - fprintf(stderr, "Don't understand line '%s' from child %d\n", + BIO_printf(bio_err, "Don't understand line '%s' from child %d\n", buf, n); continue; } printf("Got: %s from %d\n", buf, n); - if (!strncmp(buf, "+F:", 3)) { + if (strncmp(buf, "+F:", 3) == 0) { int alg; int j; @@ -2344,7 +2334,7 @@ static int do_multi(int multi) sstrsep(&p, sep); for (j = 0; j < SIZE_NUM; ++j) results[alg][j] += atof(sstrsep(&p, sep)); - } else if (!strncmp(buf, "+F2:", 4)) { + } else if (strncmp(buf, "+F2:", 4) == 0) { int k; double d; @@ -2365,7 +2355,7 @@ static int do_multi(int multi) rsa_results[k][1] = d; } # ifndef OPENSSL_NO_DSA - else if (!strncmp(buf, "+F3:", 4)) { + else if (strncmp(buf, "+F3:", 4) == 0) { int k; double d; @@ -2387,7 +2377,7 @@ static int do_multi(int multi) } # endif # ifndef OPENSSL_NO_EC - else if (!strncmp(buf, "+F4:", 4)) { + else if (strncmp(buf, "+F4:", 4) == 0) { int k; double d; @@ -2412,7 +2402,7 @@ static int do_multi(int multi) # endif # ifndef OPENSSL_NO_EC - else if (!strncmp(buf, "+F5:", 4)) { + else if (strncmp(buf, "+F5:", 4) == 0) { int k; double d; @@ -2429,10 +2419,10 @@ static int do_multi(int multi) } # endif - else if (!strncmp(buf, "+H:", 3)) { + else if (strncmp(buf, "+H:", 3) == 0) { ; } else - fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n); + BIO_printf(bio_err, "Unknown type '%s' from child %d\n", buf, n); } fclose(f); @@ -2446,19 +2436,14 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher) { static int mblengths[] = { 8 * 1024, 2 * 8 * 1024, 4 * 8 * 1024, 8 * 8 * 1024, 8 * 16 * 1024 }; - int j, count, num = sizeof(lengths) / sizeof(lengths[0]); + int j, count, num = OSSL_NELEM(lengths); const char *alg_name; unsigned char *inp, *out, no_key[32], no_iv[16]; EVP_CIPHER_CTX ctx; double d = 0.0; - inp = OPENSSL_malloc(mblengths[num - 1]); - out = OPENSSL_malloc(mblengths[num - 1] + 1024); - if (!inp || !out) { - BIO_printf(bio_err, "Out of memory\n"); - goto end; - } - + inp = app_malloc(mblengths[num - 1], "multiblock input buffer"); + out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer"); EVP_CIPHER_CTX_init(&ctx); EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, no_key, no_iv); EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), @@ -2469,7 +2454,7 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher) print_message(alg_name, 0, mblengths[j]); Time_F(START); for (count = 0, run = 1; run && count < 0x7fffffff; count++) { - unsigned char aad[13]; + unsigned char aad[EVP_AEAD_TLS1_AAD_LEN]; EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param; size_t len = mblengths[j]; int packlen; @@ -2504,7 +2489,8 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher) aad[11] = len >> 8; aad[12] = len; pad = EVP_CIPHER_CTX_ctrl(&ctx, - EVP_CTRL_AEAD_TLS1_AAD, 13, aad); + EVP_CTRL_AEAD_TLS1_AAD, + EVP_AEAD_TLS1_AAD_LEN, aad); EVP_Cipher(&ctx, out, inp, len + pad); } } @@ -2541,9 +2527,6 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher) fprintf(stdout, "\n"); } -end: - if (inp) - OPENSSL_free(inp); - if (out) - OPENSSL_free(out); + OPENSSL_free(inp); + OPENSSL_free(out); }