summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-05-20 12:03:02 +0000
committertb <>2023-05-20 12:03:02 +0000
commit3d109e0a2941852707bea5f42b0adcee09d77740 (patch)
tree11b37b64c3af5d399f11a74b5a3f525d94ceff15
parent562a71cb7be490943eeaa2bae2bb0c1ab0a458f1 (diff)
downloadopenbsd-3d109e0a2941852707bea5f42b0adcee09d77740.tar.gz
openbsd-3d109e0a2941852707bea5f42b0adcee09d77740.tar.bz2
openbsd-3d109e0a2941852707bea5f42b0adcee09d77740.zip
openssl speed: add an '-unaligned n' option
All hashes and ciphers covered by speed should be able to handle unaligned input and output. The buffers used in openssl speed are well aligned since they are large, so will never exercise the more problematic unaligned case. I wished something like this was available on various occasions. It would have been useful to point more easily at OpenSSL's broken T4 assembly. Yesterday there were two independent reasons for wanting it, so I sat down and did it. It's trivial: make the allocations a bit larger and use buffers starting at an offset inside these allocations. Despite the trivality, I managed to have a stupid bug. Thanks miod. discussed with jsing ok miod
-rw-r--r--src/usr.bin/openssl/openssl.112
-rw-r--r--src/usr.bin/openssl/speed.c32
2 files changed, 37 insertions, 7 deletions
diff --git a/src/usr.bin/openssl/openssl.1 b/src/usr.bin/openssl/openssl.1
index 4c9d15b9d1..f01f71bc0c 100644
--- a/src/usr.bin/openssl/openssl.1
+++ b/src/usr.bin/openssl/openssl.1
@@ -1,4 +1,4 @@
1.\" $OpenBSD: openssl.1,v 1.144 2023/05/05 18:01:27 tb Exp $ 1.\" $OpenBSD: openssl.1,v 1.145 2023/05/20 12:03:02 tb Exp $
2.\" ==================================================================== 2.\" ====================================================================
3.\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3.\" Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4.\" 4.\"
@@ -110,7 +110,7 @@
110.\" copied and put under another distribution licence 110.\" copied and put under another distribution licence
111.\" [including the GNU Public Licence.] 111.\" [including the GNU Public Licence.]
112.\" 112.\"
113.Dd $Mdocdate: May 5 2023 $ 113.Dd $Mdocdate: May 20 2023 $
114.Dt OPENSSL 1 114.Dt OPENSSL 1
115.Os 115.Os
116.Sh NAME 116.Sh NAME
@@ -5392,6 +5392,7 @@ An error occurred writing certificates.
5392.Op Fl evp Ar algorithm 5392.Op Fl evp Ar algorithm
5393.Op Fl mr 5393.Op Fl mr
5394.Op Fl multi Ar number 5394.Op Fl multi Ar number
5395.Op Fl unaligned Ar number
5395.Ek 5396.Ek
5396.El 5397.El
5397.Pp 5398.Pp
@@ -5418,6 +5419,13 @@ Produce machine readable output.
5418Run 5419Run
5419.Ar number 5420.Ar number
5420benchmarks in parallel. 5421benchmarks in parallel.
5422.It Fl unaligned Ar number
5423Use allocated buffers with an offset of
5424.Ar number
5425bytes from the alignment provided by
5426.Xr malloc 3 .
5427.Ar number
5428should be between 0 and 16.
5421.El 5429.El
5422.Tg spkac 5430.Tg spkac
5423.Sh SPKAC 5431.Sh SPKAC
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]);