From 072acb69be55e366e2da921e3953404765fa3928 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 2 Jun 2016 15:10:52 +0200 Subject: [PATCH] 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 --- 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 1b6d5f373..7c9354708 100644 --- a/common/openpgp-oid.c +++ b/common/openpgp-oid.c @@ -35,7 +35,7 @@ #include #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 84a15ab74..7634885e7 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 --*/