Skip to content
Open
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,29 @@ lock/unlock pairs are reported as a performance measurement

## pkeyread

The `pkeyread` test repeatedly calls the [PEM_read_bio_PrivateKey()](https://docs.openssl.org/master/man3/PEM_read_bio_PrivateKey/) function on a
memory BIO with a private key of desired type, when it is running in pem mode
(-f pem). If test is running in der mode (-f der) it calls to
[d2i_PrivateKey_ex()](https://docs.openssl.org/master/man3/d2i_PrivateKey/) function to repeatedly read private key of desired type.
It does 10000 repetitions divided evenly among each thread. The number of
threads to use is provided by option `-t`. The test reports average time per
call. Use option `-k` to select key type for benchmark. The list of keys for
testing is as follows: dh, dhx, dsa, ec, rsa, xkey. To run benchmark for all
keys and formats using 4 threads run pkeyread as follows:
The `pkeyread` test benchmarks reading of private keys of the specified type
in the specified format. If PEM format is specified (`-f pem`),
the [`PEM_read_bio_PrivateKey()`](https://docs.openssl.org/master/man3/PEM_read_bio_PrivateKey/)
function is called repeatedly on a memory BIO with a private key
of desired type; in case of DER format specification (`-f der`),
[`d2i_PrivateKey_ex()`](https://docs.openssl.org/master/man3/d2i_PrivateKey/)
is called repeatedly to read private key of the desired type.
The calls are performed repeatedly until the timeout (specified in the `-T`
option, 5 seconds by default) is reached.
The number of threads to use is provided by the only positional option.
By default, the test reports average time per call. If `-t` ("terse output")
option is specified, only the number is printed, without key type and format.
If `-v` ("verbose") option is specified, additional information is printed
for each run: median, minimum, maximum time among threads, as well as standard
deviation.
If `-b` ("bind") option is provided, thread affinity is set to the threads
so the available cores are assigned in a round robin manner.
The mandatory option `-k` selects the key type for benchmark. The list of keys
for testing is as follows: dh, dhx, dsa, ec, rsa, x25519. To run benchmark
for all keys and formats using 4 threads, run `pkeyread` as follows:

```sh
./pkeyread -f all -k all -t 4
./pkeyread -f all -k all 4
```

## evp_setpeer
Expand Down
22 changes: 11 additions & 11 deletions source/evp_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
size_t *counts;
OSSL_TIME max_time;

int err = 0;
int error = 0;
int pq = 0;

static int threadcount;
Expand Down Expand Up @@ -194,7 +194,7 @@ void do_fetch(size_t num)
fetch_alg = exclusive_fetch_alg;
}

if (err == 1)
if (error == 1)
return;

switch (j) {
Expand All @@ -203,7 +203,7 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (md == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_MD_free(md);
Expand All @@ -214,7 +214,7 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (cph == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_CIPHER_free(cph);
Expand All @@ -225,7 +225,7 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (kdf == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_KDF_free(kdf);
Expand All @@ -236,7 +236,7 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (mac == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_MAC_free(mac);
Expand All @@ -247,7 +247,7 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (rnd == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_RAND_free(rnd);
Expand All @@ -258,7 +258,7 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (kem == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_KEM_free(kem);
Expand All @@ -269,14 +269,14 @@ void do_fetch(size_t num)
fetch_entries[j].propq);
if (sig == NULL) {
fprintf(stderr, "Failed to fetch %s\n", fetch_alg);
err = 1;
error = 1;
return;
}
EVP_SIGNATURE_free(sig);
break;
}
default:
err = 1;
error = 1;
return;
}
counts[num]++;
Expand Down Expand Up @@ -372,7 +372,7 @@ int main(int argc, char *argv[])
goto out;
}

if (err) {
if (error) {
printf("Error during test\n");
goto out;
}
Expand Down
12 changes: 6 additions & 6 deletions source/evp_setpeer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#define RUN_TIME 5

int err = 0;
int error = 0;

size_t num_calls;
static int threadcount;
Expand All @@ -42,13 +42,13 @@ void do_setpeer(size_t num)

pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL);
if (pkey_ctx == NULL) {
err = 1;
error = 1;
printf("Failed to create pkey_ctx\n");
return;
}

if (EVP_PKEY_derive_init(pkey_ctx) <= 0) {
err = 1;
error = 1;
printf("Failed to init pkey_ctx\n");
EVP_PKEY_CTX_free(pkey_ctx);
return;
Expand All @@ -58,7 +58,7 @@ void do_setpeer(size_t num)

do {
if (EVP_PKEY_derive_set_peer(pkey_ctx, pkey) <= 0) {
err = 1;
error = 1;
break;
}
counts[num]++;
Expand Down Expand Up @@ -97,7 +97,7 @@ static double get_avcalltime(void)

static void report_result(int key_id, int terse)
{
if (err) {
if (error) {
fprintf(stderr, "Error during test of %s\n",
sample_names[key_id]);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -228,7 +228,7 @@ int main(int argc, char *argv[])
EVP_PKEY_free(pkey);
}

if (err) {
if (error) {
printf("Error during test\n");
goto out;
}
Expand Down
18 changes: 9 additions & 9 deletions source/handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define RUN_TIME 5

int err = 0;
int error = 0;

typedef enum {
INIT_LIB_CTX,
Expand Down Expand Up @@ -102,7 +102,7 @@ static void do_handshake(size_t num)
} while (time.t < max_time.t);

if (!ret)
err = 1;
error = 1;
}

static void do_handshake_ossl_lib_ctx_per_thread(size_t num)
Expand All @@ -117,7 +117,7 @@ static void do_handshake_ossl_lib_ctx_per_thread(size_t num)
libctx = OSSL_LIB_CTX_new();
if (libctx == NULL) {
fprintf(stderr, "%s:%d: Failed to create ossl lib context\n", __FILE__, __LINE__);
err = 1;
error = 1;
return;
}

Expand All @@ -132,7 +132,7 @@ static void do_handshake_ossl_lib_ctx_per_thread(size_t num)
privkey)) {
ERR_print_errors_fp(stderr);
fprintf(stderr, "%s:%d: Failed to create SSL_CTX pair\n", __FILE__, __LINE__);
err = 1;
error = 1;
return;
}
}
Expand All @@ -157,7 +157,7 @@ static void do_handshake_ossl_lib_ctx_per_thread(size_t num)
SSL_CTX_free(lcctx);

if (!ret)
err = 1;
error = 1;

OSSL_LIB_CTX_free(libctx);
}
Expand Down Expand Up @@ -187,7 +187,7 @@ static void do_handshake_ctx_pool(size_t num)
privkey)) {
ERR_print_errors_fp(stderr);
fprintf(stderr, "%s:%d: Failed to create SSL_CTX pair\n", __FILE__, __LINE__);
err = 1;
error = 1;
return;
}
}
Expand All @@ -203,7 +203,7 @@ static void do_handshake_ctx_pool(size_t num)
privkey)) {
ERR_print_errors_fp(stderr);
fprintf(stderr, "%s:%d: Failed to create SSL_CTX pair\n", __FILE__, __LINE__);
err = 1;
error = 1;
return;
}
}
Expand All @@ -230,7 +230,7 @@ static void do_handshake_ctx_pool(size_t num)
}

if (!ret)
err = 1;
error = 1;
}

static void free_ctx_pool()
Expand Down Expand Up @@ -482,7 +482,7 @@ int main(int argc, char * const argv[])
goto err;
};

if (err) {
if (error) {
printf("Error during test\n");
goto err;
}
Expand Down
6 changes: 3 additions & 3 deletions source/newrawkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum {
} algorithm = ALGO_X25519;
const char *alg_name = "X25519";

int err = 0;
int error = 0;

static unsigned char key_x25519[32] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
Expand Down Expand Up @@ -377,7 +377,7 @@ void do_newrawkey(size_t num)
sizeof(key_data));
#endif
if (pkey == NULL)
err = 1;
error = 1;
else
EVP_PKEY_free(pkey);
counts[num]++;
Expand Down Expand Up @@ -451,7 +451,7 @@ int main(int argc, char *argv[])
goto out;
}

if (err) {
if (error) {
printf("Error during test\n");
goto out;
}
Expand Down
56 changes: 54 additions & 2 deletions source/perflib/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,52 @@
* https://www.openssl.org/source/license.html
*/

#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#include <openssl/e_os2.h>

const char *progname;

static ossl_inline void *
get_progname(void)
{
if (progname != NULL)
return progname;

#if defined(__GLIBC__)
if (program_invocation_name && program_invocation_name[0])
return program_invocation_name;
#endif

return NULL;
}

void
vwarnx(const char *fmt, va_list ap)
{
if (progname != NULL)
fprintf(stderr, "%s: ", progname);
if (get_progname() != NULL)
fprintf(stderr, "%s: ", get_progname());
vfprintf(stderr, fmt, ap);
putc('\n', stderr);
}

void
vwarn(const char *fmt, va_list ap)
{
int saved_errno = errno;

if (get_progname() != NULL)
fprintf(stderr, "%s: ", get_progname());
vfprintf(stderr, fmt, ap);
fprintf(stderr, ": ");

errno = saved_errno;
perror(NULL);
}

void
errx(int status, const char *fmt, ...)
{
Expand All @@ -33,6 +64,17 @@ errx(int status, const char *fmt, ...)
exit(status);
}

void
err(int status, const char *fmt, ...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why to duplicate errx function? Same for warn and warnx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err/warn append the output of perror() to the message, while errx/warnx just print the provided string (along with the program name as a prefix).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err/warn append the output of perror() to the message, while errx/warnx just print the provided string (along with the program name as a prefix).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now; sorry for the noise

{
va_list ap;

va_start(ap, fmt);
vwarn(fmt, ap);
va_end(ap);
exit(status);
}

void
warnx(const char *fmt, ...)
{
Expand All @@ -42,3 +84,13 @@ warnx(const char *fmt, ...)
vwarnx(fmt, ap);
va_end(ap);
}

void
warn(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
vwarn(fmt, ap);
va_end(ap);
}
Loading