[PATCH 1/2] gpgme: Recognize RFC 9980 SLH-DSA algorithms

Stavros Kousidis stavros.kousidis at th-koeln.de
Wed Oct 21 14:44:47 CEST 2026


* src/conversion.c (_gpgme_map_pk_algo): Map OpenPGP identifiers
32 through 34 to the SLH-DSA family.
* src/gpgme.h.in (gpgme_pubkey_algo_t): Add GPGME_PK_SLHDSA.
* src/gpgme.c (gpgme_pubkey_algo_name, gpgme_pubkey_algo_string):
Describe the family without inferring a parameter set.
* tests/Makefile.am: Add a dedicated algorithm-mapping test.
* tests/t-pubkey-algo.c: Check mapping, names, enum values and strings.
* doc/gpgme.texi: Document the family and representation limits.
* NEWS: Record the new public enum.
--

This adds recognition and representation using the existing mapper.
It does not implement cryptography or change engine selection.

Signed-off-by: Stavros Kousidis <stavros.kousidis at th-koeln.de>
---
 NEWS                  |   1 +
 doc/gpgme.texi        |   9 +++
 src/conversion.c      |   6 ++
 src/gpgme.c           |   4 ++
 src/gpgme.h.in        |   3 +-
 tests/Makefile.am     |   4 +-
 tests/t-pubkey-algo.c | 152 ++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 177 insertions(+), 2 deletions(-)
 create mode 100644 tests/t-pubkey-algo.c

diff --git a/NEWS b/NEWS
index 249eab3e61f35bf965ae59b46e0d6e89c4548c4a..26b77db9c8f0425066370c248696ee00e489194b 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Noteworthy changes in version 2.3.0 (unreleased)   [C__/A_/R0]
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  GPGME_PK_MLKEM                NEW.
  GPGME_PK_MLDSA                NEW.
+ GPGME_PK_SLHDSA               NEW.
 
  Release-info: https://dev.gnupg.org/T8427
 
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index dc4adf2e8a67285655273b4dbf0d44f53a8678f4..e20353d19186fe3f95da3ed108f73d4a54e4da1d 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -1295,6 +1295,15 @@ encryption algorithm as defined by RFC-6637.
 
 This value indicates the EdDSA algorithm.
 
+ at item GPGME_PK_SLHDSA
+ at since{2.3.0}
+
+This value indicates the SLH-DSA signature algorithm family, including
+the SHAKE-128s, SHAKE-128f, and SHAKE-256s variants defined by RFC 9980.
+This family value does not identify the concrete parameter set.
+The algorithm string helper returns the generic descriptor @code{slhdsa}
+without inferring a parameter set from the key length or optional curve text.
+
 @end table
 @end deftp
 
diff --git a/src/conversion.c b/src/conversion.c
index b36457c138380629d3d9d13dc332bfd1d4c77b1a..c6656b70a6c86dcff241e486afc6f593c6b463d3 100644
--- a/src/conversion.c
+++ b/src/conversion.c
@@ -702,6 +702,12 @@ _gpgme_map_pk_algo (int algo, gpgme_protocol_t protocol)
           algo = GPGME_PK_MLDSA;
           break;
 
+        case 32: /* SLH-DSA-SHAKE-128s (RFC9980)    */
+        case 33: /* SLH-DSA-SHAKE-128f (RFC9980)    */
+        case 34: /* SLH-DSA-SHAKE-256s (RFC9980)    */
+          algo = GPGME_PK_SLHDSA;
+          break;
+
         case 35: /* ML-KEM-768+X25519 (RFC9980)      */
         case 36: /* ML-KEM-1024+X448 (RFC9980)       */
         case 37: /* ML-KEM-768+ECDH-NIST-P-384       */
diff --git a/src/gpgme.c b/src/gpgme.c
index ec99a1312d1df9290e3387e46fe5c6120844a163..52ac56874bd27e44859f91b09a764cacc96327d9 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -1330,6 +1330,9 @@ gpgme_pubkey_algo_string (gpgme_subkey_t subkey)
     case GPGME_PK_EDDSA: prefix = "";    break;
     case GPGME_PK_MLDSA: composite = 1; break;
     case GPGME_PK_MLKEM: composite = 1; break;
+    case GPGME_PK_SLHDSA:
+      /* The generic family does not identify a parameter set.  */
+      return strdup ("slhdsa");
     }
 
   if (composite && subkey->curve)
@@ -1370,6 +1373,7 @@ gpgme_pubkey_algo_name (gpgme_pubkey_algo_t algo)
     case GPGME_PK_EDDSA: return "EdDSA";
     case GPGME_PK_MLDSA: return "MLDSA";
     case GPGME_PK_MLKEM: return "MLKEM";
+    case GPGME_PK_SLHDSA: return "SLHDSA";
     default:             return NULL;
     }
 }
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 54c5c900b0cf75731ba19505b8865d69e27bad65..bc735c554483f2c2eec1e3a62d71479d43aad651 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -279,7 +279,8 @@ typedef enum
     GPGME_PK_ECDH  = 302,
     GPGME_PK_EDDSA = 303,
     GPGME_PK_MLKEM = 331,    /* Kyber (ML-KEM).      */
-    GPGME_PK_MLDSA = 332     /* Dilithium (ML-DSA).  */
+    GPGME_PK_MLDSA = 332,    /* Dilithium (ML-DSA).  */
+    GPGME_PK_SLHDSA = 334    /* SLH-DSA.  */
   }
 gpgme_pubkey_algo_t;
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d2e01dc013fd06eba42383adf0f87c762bbd84c4..35b54a59169652ecfb501b4015199bc6ca0794d5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,7 +23,7 @@
 GNUPGHOME=$(abs_builddir)
 TESTS_ENVIRONMENT = GNUPGHOME=$(GNUPGHOME)
 
-TESTS = t-version t-data t-engine-info
+TESTS = t-version t-data t-engine-info t-pubkey-algo
 
 EXTRA_DIST = start-stop-agent t-data-1.txt t-data-2.txt ChangeLog-2011
 
@@ -37,6 +37,8 @@ endif
 
 LDADD = ../src/libgpgme.la @GPG_ERROR_LIBS@ @LDADD_FOR_TESTS_KLUDGE@
 
+t_pubkey_algo_LDADD = ../src/conversion.lo $(LDADD)
+
 noinst_HEADERS = run-support.h
 
 noinst_PROGRAMS = $(TESTS) run-keylist run-export run-import run-sign \
diff --git a/tests/t-pubkey-algo.c b/tests/t-pubkey-algo.c
new file mode 100644
index 0000000000000000000000000000000000000000..eb78b7439ae037f4d2b7965f27d14f8ca3b69a17
--- /dev/null
+++ b/tests/t-pubkey-algo.c
@@ -0,0 +1,152 @@
+/* t-pubkey-algo.c - Public-key algorithm mapping and description tests.
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GPGME is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <https://gnu.org/licenses/>.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <gpgme.h>
+
+/* The mapper is private.  Link conversion.lo rather than exporting it.  */
+extern int _gpgme_map_pk_algo (int algo, gpgme_protocol_t protocol);
+
+static int
+check_mapping (void)
+{
+  static const struct
+  {
+    int openpgp;
+    gpgme_pubkey_algo_t family;
+    const char *name;
+  } tests[] = {
+    { 1, GPGME_PK_RSA, "RSA" },
+    { 2, GPGME_PK_RSA_E, "RSA-E" },
+    { 3, GPGME_PK_RSA_S, "RSA-S" },
+    { 8, GPGME_PK_KYBER, "KYBER" },
+    { 16, GPGME_PK_ELG_E, "ELG-E" },
+    { 17, GPGME_PK_DSA, "DSA" },
+    { 18, GPGME_PK_ECDH, "ECDH" },
+    { 19, GPGME_PK_ECDSA, "ECDSA" },
+    { 20, GPGME_PK_ELG, "ELG" },
+    { 22, GPGME_PK_EDDSA, "EdDSA" },
+    { 25, GPGME_PK_ECDH, "ECDH" },
+    { 27, GPGME_PK_EDDSA, "EdDSA" },
+    { 30, GPGME_PK_MLDSA, "MLDSA" },
+    { 31, GPGME_PK_MLDSA, "MLDSA" },
+    { 32, GPGME_PK_SLHDSA, "SLHDSA" },
+    { 33, GPGME_PK_SLHDSA, "SLHDSA" },
+    { 34, GPGME_PK_SLHDSA, "SLHDSA" },
+    { 35, GPGME_PK_MLKEM, "MLKEM" },
+    { 36, GPGME_PK_MLKEM, "MLKEM" },
+    { 37, GPGME_PK_MLKEM, "MLKEM" },
+    { 38, GPGME_PK_MLKEM, "MLKEM" },
+    { 39, GPGME_PK_MLKEM, "MLKEM" },
+    { 40, GPGME_PK_MLKEM, "MLKEM" },
+    { 41, 0, NULL },
+    { 42, 0, NULL },
+    { 43, 0, NULL },
+    { 44, 0, NULL },
+    { 0, 0, NULL },
+    { 26, 0, NULL },
+    { 28, 0, NULL },
+    { 29, 0, NULL },
+    { 45, 0, NULL },
+    { 99, 0, NULL },
+    { 128, 0, NULL },
+    { 331, 0, NULL },
+    { 332, 0, NULL },
+    { 333, 0, NULL },
+    { 334, 0, NULL },
+    { -1, 0, NULL },
+    { INT_MIN, 0, NULL },
+    { INT_MAX, 0, NULL }
+  };
+  unsigned int i;
+  const char *name;
+
+  if (GPGME_PK_RSA != 1 || GPGME_PK_RSA_E != 2 || GPGME_PK_RSA_S != 3
+      || GPGME_PK_KYBER != 8 || GPGME_PK_ELG_E != 16 || GPGME_PK_DSA != 17
+      || GPGME_PK_ECC != 18 || GPGME_PK_ELG != 20 || GPGME_PK_ECDSA != 301
+      || GPGME_PK_ECDH != 302 || GPGME_PK_EDDSA != 303
+      || GPGME_PK_MLKEM != 331 || GPGME_PK_MLDSA != 332
+      || GPGME_PK_SLHDSA != 334)
+    return 1;
+
+  for (i = 0; i < sizeof tests / sizeof tests[0]; i++)
+    {
+      errno = EDOM;
+      if (_gpgme_map_pk_algo (tests[i].openpgp, GPGME_PROTOCOL_OPENPGP)
+          != tests[i].family || errno != EDOM
+          || _gpgme_map_pk_algo (tests[i].openpgp, GPGME_PROTOCOL_CMS)
+             != tests[i].openpgp || errno != EDOM)
+        {
+          fprintf (stderr, "Wrong mapping for algorithm %d\n", tests[i].openpgp);
+          return 1;
+        }
+      name = gpgme_pubkey_algo_name (tests[i].family);
+      if (tests[i].name ? (!name || strcmp (name, tests[i].name)) : !!name)
+        {
+          fprintf (stderr, "Wrong family name for algorithm %d\n", tests[i].openpgp);
+          return 1;
+        }
+    }
+  return 0;
+}
+
+static int
+check_description (void)
+{
+  static const unsigned int lengths[] = { 0, 128, 256, 4096 };
+  static const char *const descriptions[] = { NULL, "", "backend-specific-text" };
+  struct _gpgme_subkey subkey;
+  unsigned int i, j;
+  char *description;
+
+  memset (&subkey, 0, sizeof subkey);
+  subkey.pubkey_algo = GPGME_PK_SLHDSA;
+  for (i = 0; i < sizeof lengths / sizeof lengths[0]; i++)
+    for (j = 0; j < sizeof descriptions / sizeof descriptions[0]; j++)
+      {
+        subkey.length = lengths[i];
+        subkey.curve = (char *) descriptions[j];
+        description = gpgme_pubkey_algo_string (&subkey);
+        if (!description || strcmp (description, "slhdsa"))
+          {
+            fprintf (stderr, "Wrong generic SLH-DSA description\n");
+            gpgme_free (description);
+            return 1;
+          }
+        gpgme_free (description);
+      }
+  return 0;
+}
+
+int
+main (void)
+{
+  gpgme_check_version (NULL);
+  if (check_mapping () || check_description ())
+    return 1;
+  return 0;
+}


More information about the Gnupg-devel mailing list