Skip to content

This change hopes to provide a better alignement of pkeyread with other #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions perf/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch
PKEYREAD_SYMLINKS=pkeyread-dh-pem pkeyread-dhx-pem pkeyread-dsa-pem pkeyread-ec-pem pkeyread-rsa-pem pkeyread-x25519-pem \
pkeyread-dh-der pkeyread-dhx-der pkeyread-dsa-der pkeyread-ec-der pkeyread-rsa-der pkeyread-x25519-der
all: randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch \
$(PKEYREAD_SYMLINKS)

# Build target for OpenSSL 1.1.1 builds
all111: randbytes handshake sslnew newrawkey rsasign x509storeissuer rwlocks pkeyread
all111: randbytes handshake sslnew newrawkey rsasign x509storeissuer rwlocks pkeyread \
$(PKEYREAD_SYMLINKS)

clean:
rm -f libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch
rm -f libperf.a *.o randbytes handshake sslnew newrawkey rsasign x509storeissuer providerdoall rwlocks pkeyread evp_fetch \
$(PKEYREAD_SYMLINKS)

CPPFLAGS += -I$(TARGET_OSSL_INCLUDE_PATH) -I.
# For second include path, i.e. out of tree build of OpenSSL uncomment this:
Expand All @@ -13,6 +19,8 @@ LDFLAGS += -L$(TARGET_OSSL_LIBRARY_PATH) -L.
# For setting RUNPATH on built executables uncomment this:
# LDFLAGS += -Wl,-rpath,$(TARGET_OSSL_LIBRARY_PATH)

LN=/bin/ln -s

libperf.a: perflib/*.c perflib/*.h
$(CC) $(CPPFLAGS) $(CFLAGS) -c perflib/*.c
ar rcs libperf.a *.o
Expand Down Expand Up @@ -49,3 +57,6 @@ regen_key_samples:

pkeyread: pkeyread.c keys.h libperf.a
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o pkeyread pkeyread.c -lperf -lcrypto

$(PKEYREAD_SYMLINKS): pkeyread
$(LN) pkeyread $@
101 changes: 101 additions & 0 deletions perf/pkeyread.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <openssl/pem.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
Expand Down Expand Up @@ -217,6 +218,103 @@ static void usage(char * const argv[])
} while (*format_name != NULL);
}

static void implicit_report_result(char *const argv[], int terse)
{
if (terse)
printf("%lf\n", get_avcalltime());
else
printf("%s average time per call: %lfus\n", basename(argv[0]),
get_avcalltime());
}

static int implicit_main(int argc, char *const argv[])
{
OSSL_TIME duration;
char progname[80];
char *key, *format;
int format_id, ch, terse;
void (*do_f[2])(size_t) = {
do_pemread,
do_derread
};

strncpy(progname, basename(argv[0]), sizeof(progname));
progname[79] = '\0';

/* chop off pkeyread */
key = strchr(progname, '-');
if (key == NULL) {
fprintf(stderr, "Unexpected command %s\n", argv[0]);
return EXIT_FAILURE;
}
key++;

format = strchr(key, '-');
if (format == NULL) {
fprintf(stderr, "Unexpected command %s\n", argv[0]);
return EXIT_FAILURE;
}
*format = '\0';
format++;

format_id = format_name_to_id(format);
if (format_id == FORMAT_INVALID || format_id == FORMAT_ALL) {
fprintf(stderr, "%s - unexpected command .%s\n", argv[0], format);
return EXIT_FAILURE;
}

sample_id = sample_name_to_id(key);
if (sample_id == SAMPLE_INVALID || sample_id == SAMPLE_ALL) {
fprintf(stderr, "%s - unexpected command %s.\n", argv[0], key);
return EXIT_FAILURE;
}

terse = 0;
while ((ch = getopt(argc, argv, "t")) != -1) {
switch (ch) {
case 't':
terse = 1;
break;
default:
fprintf(stderr, "invalid option!\n%s [-t]\n"
"\t-t enables minimal output", basename(argv[0]));
return EXIT_FAILURE;
}
}

if (argv[optind] == NULL) {
fprintf(stderr, "%s Missing threadcount argument\n", argv[0]);
return EXIT_FAILURE;
}

threadcount = atoi(argv[optind]);
if (threadcount < 1) {
fprintf(stderr, "%s threadcount must be > 0\n", argv[0]);
return EXIT_FAILURE;
}

times = OPENSSL_malloc(sizeof(OSSL_TIME) * threadcount);
if (times == NULL) {
printf("%s Failed to create times array\n", argv[0]);
return EXIT_FAILURE;
}

num_calls = NUM_CALLS_PER_TEST;
if (NUM_CALLS_PER_TEST % threadcount > 0) /* round up */
num_calls += threadcount - NUM_CALLS_PER_TEST % threadcount;

if (!perflib_run_multi_thread_test(do_f[format_id], threadcount,
&duration)) {
fprintf(stderr, "%s Failed to run the test %s in %s format]\n",
argv[0], key, format);
return EXIT_FAILURE;
}

implicit_report_result(argv, terse);

return EXIT_SUCCESS;
}

int main(int argc, char * const argv[])
{
OSSL_TIME duration;
Expand All @@ -236,6 +334,9 @@ int main(int argc, char * const argv[])
"X509_PUBKEY_get0_param"
};

if (strcmp(basename(argv[0]), "pkeyread") != 0)
return implicit_main(argc, argv);

key_id = SAMPLE_INVALID;
format_id = FORMAT_INVALID;

Expand Down