[Pkg-gnupg-commit] [gnupg2] 42/102: common: New function openpgp_is_curve_supported.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Jun 17 00:14:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gnupg2.

commit 072acb69be55e366e2da921e3953404765fa3928
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jun 2 15:10:52 2016 +0200

    common: New function openpgp_is_curve_supported.
    
    * common/openpgp-oid.c: Include openpgpdefs.h.
    (oidtable): Add field pubkey_algo.
    (openpgp_is_curve_supported): New.
    --
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 common/openpgp-oid.c | 33 ++++++++++++++++++++++++++++++---
 common/util.h        |  2 +-
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/common/openpgp-oid.c b/common/openpgp-oid.c
index 1b6d5f3..7c93547 100644
--- a/common/openpgp-oid.c
+++ b/common/openpgp-oid.c
@@ -35,7 +35,7 @@
 #include <assert.h>
 
 #include "util.h"
-
+#include "openpgpdefs.h"
 
 /* A table with all our supported OpenPGP curves.  */
 static struct {
@@ -43,10 +43,11 @@ static struct {
   const char *oidstr; /* IETF formatted OID.  */
   unsigned int nbits; /* Nominal bit length of the curve.  */
   const char *alias;  /* NULL or alternative name of the curve.  */
+  int pubkey_algo;    /* Required OpenPGP algo or 0 for ECDSA/ECDH.  */
 } oidtable[] = {
 
-  { "Curve25519",      "1.3.6.1.4.1.3029.1.5.1", 255, "cv25519" },
-  { "Ed25519",         "1.3.6.1.4.1.11591.15.1", 255, "ed25519" },
+  { "Curve25519", "1.3.6.1.4.1.3029.1.5.1", 255, "cv25519", PUBKEY_ALGO_ECDH },
+  { "Ed25519",    "1.3.6.1.4.1.11591.15.1", 255, "ed25519", PUBKEY_ALGO_EDDSA },
 
   { "NIST P-256",      "1.2.840.10045.3.1.7",    256, "nistp256" },
   { "NIST P-384",      "1.3.132.0.34",           384, "nistp384" },
@@ -408,3 +409,29 @@ openpgp_enum_curves (int *iterp)
   *iterp = idx;
   return NULL;
 }
+
+
+/* Return the Libgcrypt name for for the gpg curve NAME if supported.
+ * If R_ALGO is not NULL the required OpenPGP public key algo or 0 is
+ * stored at that address.  NULL is returned if the curev is not
+ * supported. */
+const char *
+openpgp_is_curve_supported (const char *name, int *r_algo)
+{
+  int idx;
+
+  if (r_algo)
+    *r_algo = 0;
+  for (idx = 0; idx < DIM (oidtable) && oidtable[idx].name; idx++)
+    {
+      if (!strcmp (name, (oidtable[idx].alias? oidtable[idx].alias
+                          /**/               : oidtable[idx].name))
+          && curve_supported_p (oidtable[idx].name))
+        {
+          if (r_algo)
+            *r_algo = oidtable[idx].pubkey_algo;
+          return oidtable[idx].name;
+        }
+    }
+  return NULL;
+}
diff --git a/common/util.h b/common/util.h
index 84a15ab..7634885 100644
--- a/common/util.h
+++ b/common/util.h
@@ -214,7 +214,7 @@ int openpgp_oid_is_crv25519 (gcry_mpi_t a);
 const char *openpgp_curve_to_oid (const char *name, unsigned int *r_nbits);
 const char *openpgp_oid_to_curve (const char *oid, int canon);
 const char *openpgp_enum_curves (int *idxp);
-
+const char *openpgp_is_curve_supported (const char *name, int *r_algo);
 
 
 /*-- homedir.c --*/

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list