tools icon indicating copy to clipboard operation
tools copied to clipboard

Benchmark for decoder performance (privkey) #454

Open Sashan opened this issue 1 year ago • 12 comments

pemread.c/pemread gets renamed to pkeyread.c/pkeyread The tool can newly benchmak RSA, DSA, DH, DHX, EC, XKEY.

To run benchmark for all keys and both formats (PEM, DER) using four threads execute pkeyread command as follows:

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

The output will look like this:

lifty$ ./pkeyread -k all -f all -t 4
[dh pem] 317963.170000
[dh der] 323924.870000
[dhx pem] 76381.500000
[dhx der] 81370.580000
[dsa pem] 84088.790000
[dsa der] 84630.180000
[ec pem] 24644.910000
[ec der] 77426.390000
[rsa pem] 41520.410000
[rsa der] 65746.920000
[xkey pem] 17786.360000
[xkey der] 20157.880000

Change also adds genkey.sh which generates private keys for testing. The script is called by Makefile as regen_key_samples target. Makefile generates the key samples into keys.h. The keys.h file is also committed to minimize a builttime dependency on genkey.sh script.

To add a new key one should update genkey.sh script, run make regen_key_samples and commit new version of keys.h file.

Sashan avatar Apr 13 '24 22:04 Sashan

rebased on current.

Sashan avatar Apr 17 '24 15:04 Sashan

New revision is rebased on current. the list of changes is as follows

  • introduced report_result() function to remove code duplication (pointed out by @mattcaswell)
  • fixed indentation at fprintf() functions (by @mattcaswell )
  • fixed typo in genkeys.sh
  • updated README

opened issues: - Shall I add license header to keys.h which is generated by genkeys.sh - Shall I remove calls to X509_PUBKEY_*() found in do_derread() function

Sashan avatar Apr 18 '24 22:04 Sashan

the new version will arrive shortly, resolved items:

  • add a copyright header to keys.h
  • remove calls to X509_PUBKEY_*() functions

item which needs further clarification:

  • remove duplicate code.

Sashan avatar Apr 23 '24 16:04 Sashan

There seems to be an extra commit in this PR from #182. I suspect #182 was merged to the wrong repo - but your PR picked it up before it later got wiped by the next mirror.

Anyway - no big deal.

mattcaswell avatar Apr 24 '24 09:04 mattcaswell

Conflicts with PR which added rwlock tests got resolved. Please check changes to Makefile and Readme file. thanks.

Sashan avatar Apr 25 '24 08:04 Sashan

Please rebase and drop the merge commits.

t8m avatar Apr 25 '24 08:04 t8m

sorry about poor git driving, the merge commits should be gone now.

Sashan avatar Apr 25 '24 09:04 Sashan

and now with fix for glitch spotted by matt

Sashan avatar Apr 25 '24 09:04 Sashan

the pull request will be updated shortly. The list of changes is as follows:

  • the benchmark for DER uses d2i_PrivateKey_ex() now. it required changes to genkey.sh so it also generates table of EVP_PKEY_* constants with keys supported by test. keys.h got regenrated.
  • I also made two tweaks to report results, the diff chunk for this bellow
@@ -168,13 +157,14 @@ static int format_name_to_id(const char *format_name)
     return i;
 }
 
-double get_avcalltime(void)
+static double get_avcalltime(void)
 {
     int i;
     OSSL_TIME t;
     double avcalltime;
 
-    for (i = 1; i < threadcount; i++)
+    memset(&t, 0, sizeof(t));
+    for (i = 0; i < threadcount; i++)
         t = ossl_time_add(t, times[i]);
     avcalltime = (double)ossl_time2ticks(t) / (double)NUM_CALLS_PER_TEST;
 
@@ -183,7 +173,7 @@ double get_avcalltime(void)
     return avcalltime;
 }
 
-void report_result(int key_id, int format_id, int verbose)
+static void report_result(int key_id, int format_id, int verbose)
 {
     if (err) {
        fprintf(stderr, "Error during test of %s in %s format\n",
@@ -192,10 +182,10 @@ void report_result(int key_id, int format_id, int verbose)
     }
 
     if (verbose)
-       printf("Average time per %s(%s) calls: %lfus\n",
+       printf("Average time per %s(%s) call: %lfus\n",
               format_names[format_id], sample_names[key_id], get_avcalltime());
     else
-       printf("[%s %s] %lf\n", sample_names[key_id],
+       printf("[%s %s] %lfus\n", sample_names[key_id],
               format_names[format_id], get_avcalltime());
 }

Sashan avatar Apr 26 '24 07:04 Sashan

Why it was necessary to change the key data? IMO d2i_PrivateKey_ex() should be able to decode the original data.

t8m avatar Apr 26 '24 07:04 t8m

Why it was necessary to change the key data? IMO d2i_PrivateKey_ex() should be able to decode the original data.

keys.h now contains array with EVP_PKEY_ constant. I use this array later in newly introduced function sample_id_to_evp(). I could add that array to keys.h by hand, but I decided to give the genkeys.h script a try.

Sashan avatar Apr 26 '24 07:04 Sashan

README got updated.

Sashan avatar May 01 '24 18:05 Sashan

rebased to master.

Sashan avatar May 06 '24 14:05 Sashan

approval holds

nhorman avatar May 06 '24 15:05 nhorman

My approval holds too. Merging.

t8m avatar May 06 '24 15:05 t8m

Actually @mattcaswell could you please also reconfirm?

t8m avatar May 06 '24 15:05 t8m

Merged. Thank you.

t8m avatar May 10 '24 13:05 t8m