summaryrefslogtreecommitdiff
path: root/src/usr.bin/openssl/speed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr.bin/openssl/speed.c')
-rw-r--r--src/usr.bin/openssl/speed.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/usr.bin/openssl/speed.c b/src/usr.bin/openssl/speed.c
index 3b78c551eb..a1a69c267f 100644
--- a/src/usr.bin/openssl/speed.c
+++ b/src/usr.bin/openssl/speed.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: speed.c,v 1.32 2023/05/20 11:44:15 tb Exp $ */ 1/* $OpenBSD: speed.c,v 1.33 2023/05/20 12:03:02 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -79,6 +79,8 @@
79#define ECDSA_SECONDS 10 79#define ECDSA_SECONDS 10
80#define ECDH_SECONDS 10 80#define ECDH_SECONDS 10
81 81
82#define MAX_UNALIGN 16
83
82#include <math.h> 84#include <math.h>
83#include <signal.h> 85#include <signal.h>
84#include <stdio.h> 86#include <stdio.h>
@@ -227,7 +229,9 @@ KDF1_SHA1(const void *in, size_t inlen, void *out, size_t * outlen)
227int 229int
228speed_main(int argc, char **argv) 230speed_main(int argc, char **argv)
229{ 231{
232 unsigned char *real_buf = NULL, *real_buf2 = NULL;
230 unsigned char *buf = NULL, *buf2 = NULL; 233 unsigned char *buf = NULL, *buf2 = NULL;
234 size_t unaligned = 0;
231 int mret = 1; 235 int mret = 1;
232 long count = 0, save_count = 0; 236 long count = 0, save_count = 0;
233 int i, j, k; 237 int i, j, k;
@@ -450,11 +454,11 @@ speed_main(int argc, char **argv)
450 for (i = 0; i < RSA_NUM; i++) 454 for (i = 0; i < RSA_NUM; i++)
451 rsa_key[i] = NULL; 455 rsa_key[i] = NULL;
452 456
453 if ((buf = malloc(BUFSIZE)) == NULL) { 457 if ((buf = real_buf = malloc(BUFSIZE + MAX_UNALIGN)) == NULL) {
454 BIO_printf(bio_err, "out of memory\n"); 458 BIO_printf(bio_err, "out of memory\n");
455 goto end; 459 goto end;
456 } 460 }
457 if ((buf2 = malloc(BUFSIZE)) == NULL) { 461 if ((buf2 = real_buf2 = malloc(BUFSIZE + MAX_UNALIGN)) == NULL) {
458 BIO_printf(bio_err, "out of memory\n"); 462 BIO_printf(bio_err, "out of memory\n");
459 goto end; 463 goto end;
460 } 464 }
@@ -516,6 +520,23 @@ speed_main(int argc, char **argv)
516 } 520 }
517 j--; /* Otherwise, -multi gets confused with an 521 j--; /* Otherwise, -multi gets confused with an
518 * algorithm. */ 522 * algorithm. */
523 } else if (argc > 0 && strcmp(*argv, "-unaligned") == 0) {
524 argc--;
525 argv++;
526 if (argc == 0) {
527 BIO_printf(bio_err, "no alignment offset given\n");
528 goto end;
529 }
530 unaligned = strtonum(argv[0], 0, MAX_UNALIGN, &errstr);
531 if (errstr) {
532 BIO_printf(bio_err, "bad alignment offset: %s",
533 errstr);
534 goto end;
535 }
536 buf = real_buf + unaligned;
537 buf2 = real_buf2 + unaligned;
538 j--; /* Otherwise, -unaligned gets confused with an
539 * algorithm. */
519 } else if (argc > 0 && strcmp(*argv, "-mr") == 0) { 540 } else if (argc > 0 && strcmp(*argv, "-mr") == 0) {
520 mr = 1; 541 mr = 1;
521 j--; /* Otherwise, -mr gets confused with an 542 j--; /* Otherwise, -mr gets confused with an
@@ -835,6 +856,7 @@ speed_main(int argc, char **argv)
835 BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n"); 856 BIO_printf(bio_err, "-decrypt time decryption instead of encryption (only EVP).\n");
836 BIO_printf(bio_err, "-mr produce machine readable output.\n"); 857 BIO_printf(bio_err, "-mr produce machine readable output.\n");
837 BIO_printf(bio_err, "-multi n run n benchmarks in parallel.\n"); 858 BIO_printf(bio_err, "-multi n run n benchmarks in parallel.\n");
859 BIO_printf(bio_err, "-unaligned n use buffers with offset n from proper alignment.\n");
838 goto end; 860 goto end;
839 } 861 }
840 argc--; 862 argc--;
@@ -1848,8 +1870,8 @@ show_res:
1848 1870
1849 end: 1871 end:
1850 ERR_print_errors(bio_err); 1872 ERR_print_errors(bio_err);
1851 free(buf); 1873 free(real_buf);
1852 free(buf2); 1874 free(real_buf2);
1853 for (i = 0; i < RSA_NUM; i++) 1875 for (i = 0; i < RSA_NUM; i++)
1854 if (rsa_key[i] != NULL) 1876 if (rsa_key[i] != NULL)
1855 RSA_free(rsa_key[i]); 1877 RSA_free(rsa_key[i]);