[PATCH 3/7] tests/basic: Skip tests if PK algo is unavailable

Clemens Lang cllang at redhat.com
Tue Jun 21 19:00:44 CEST 2022


* tests/basic.c (check_pubkey): Skip tests if the required public key
  algorithm is not available.

--

When libgcrypt is configured with a non-default --enable-pubkey-ciphers
option (e.g., without RSA), some of the tests cannot be run because the
algorithms are not supported. Check for unsupported algorithms using
gcry_pk_test_algo and print a message if they are not available.

Signed-off-by: Clemens Lang <cllang at redhat.com>
---
 tests/basic.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/tests/basic.c b/tests/basic.c
index ab00667e..ecbe58c2 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -206,6 +206,22 @@ show_mac_not_available (int algo)
 }
 
 
+static void
+show_pk_not_available (int algo)
+{
+    static int list[100];
+    static int listlen;
+    int i;
+
+    for (i = 0; i < listlen; i++)
+      if (algo == list[i])
+        return; /* Note already printed. */
+    if (listlen < DIM (list))
+      list[listlen++] = algo;
+    show_note ("PK algorithm %d not available - skipping tests", algo);
+}
+
+
 
 static void
 progress_handler (void *cb_data, const char *what, int printchar,
@@ -9428,6 +9444,8 @@ check_gost28147_cipher_basic (enum gcry_cipher_algos algo)
         gcry_cipher_close (hdd);
     }
 
+#else
+  (void) algo;
 #endif
 }
 
@@ -17079,7 +17097,7 @@ check_pubkey (void)
               }
             else
               {
-                fail ("gcry_pk_test_algo failed: %s\n", gpg_strerror (err));
+                show_pk_not_available (pubkeys[i].id);
                 continue;
               }
           }
@@ -17090,7 +17108,10 @@ check_pubkey (void)
 
   if (verbose)
     fprintf (stderr, "Starting additional public key check.\n");
-  check_one_pubkey_new (i);
+  if (gcry_pk_test_algo (GCRY_PK_RSA) == 0)
+    check_one_pubkey_new (i);
+  else
+    show_pk_not_available (GCRY_PK_RSA);
   if (verbose)
     fprintf (stderr, "Completed additional public key check.\n");
 
-- 
2.35.3




More information about the Gcrypt-devel mailing list