diff options
author | Werner Koch <[email protected]> | 2020-02-09 23:31:07 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2020-02-09 23:31:07 +0000 |
commit | 332a72f7340895e7db1e9c5f89046f722bb7465b (patch) | |
tree | 28ae6df05fc5d9fbc3564e86bf0f1803e81251c8 | |
parent | common: Remove duplicated call to a function. (diff) | |
download | gnupg-332a72f7340895e7db1e9c5f89046f722bb7465b.tar.gz gnupg-332a72f7340895e7db1e9c5f89046f722bb7465b.zip |
common: Extend the new get_keyalgo_string function
* common/openpgp-oid.c (openpgp_oid_or_name_to_curve): New.
(get_keyalgo_string): Use it.
--
We do not always have an OID, so except the name or the alias of the
curve as well. This creates a second entry mapping to the same name
but that does not matter.
Signed-off-by: Werner Koch <[email protected]>
-rw-r--r-- | common/openpgp-oid.c | 33 | ||||
-rw-r--r-- | common/util.h | 1 |
2 files changed, 29 insertions, 5 deletions
diff --git a/common/openpgp-oid.c b/common/openpgp-oid.c index 412a03b4d..925384f3e 100644 --- a/common/openpgp-oid.c +++ b/common/openpgp-oid.c @@ -389,9 +389,9 @@ openpgp_curve_to_oid (const char *name, unsigned int *r_nbits) } -/* Map an OpenPGP OID to the Libgcrypt curve NAME. Returns NULL for - unknown curve names. Unless CANON is set we prefer an alias name - here which is more suitable for printing. */ +/* Map an OpenPGP OID to the Libgcrypt curve name. Returns NULL for + * unknown curve names. Unless CANON is set we prefer an alias name + * here which is more suitable for printing. */ const char * openpgp_oid_to_curve (const char *oidstr, int canon) { @@ -408,6 +408,27 @@ openpgp_oid_to_curve (const char *oidstr, int canon) } +/* Map an OpenPGP OID, name or alias to the Libgcrypt curve name. + * Returns NULL for unknown curve names. Unless CANON is set we + * prefer an alias name here which is more suitable for printing. */ +const char * +openpgp_oid_or_name_to_curve (const char *oidname, int canon) +{ + int i; + + if (!oidname) + return NULL; + + for (i=0; oidtable[i].name; i++) + if (!strcmp (oidtable[i].oidstr, oidname) + || !strcmp (oidtable[i].name, oidname) + || (oidtable[i].alias &&!strcmp (oidtable[i].alias, oidname))) + return !canon && oidtable[i].alias? oidtable[i].alias : oidtable[i].name; + + return NULL; +} + + /* Return true if the curve with NAME is supported. */ static int curve_supported_p (const char *name) @@ -528,7 +549,7 @@ const char * get_keyalgo_string (enum gcry_pk_algos algo, unsigned int nbits, const char *curve) { - const char *prefix = NULL; + const char *prefix; int i; char *name, *curvebuf; @@ -537,9 +558,11 @@ get_keyalgo_string (enum gcry_pk_algos algo, case GCRY_PK_RSA: prefix = "rsa"; break; case GCRY_PK_ELG: prefix = "elg"; break; case GCRY_PK_DSA: prefix = "dsa"; break; + case GCRY_PK_ECC: case GCRY_PK_ECDH: case GCRY_PK_ECDSA: case GCRY_PK_EDDSA: prefix = ""; break; + default: prefix = NULL; break; } if (prefix && *prefix && nbits) @@ -569,7 +592,7 @@ get_keyalgo_string (enum gcry_pk_algos algo, } /* Not yet in the table - add it. */ - curvename = openpgp_oid_to_curve (curve, 0); + curvename = openpgp_oid_or_name_to_curve (curve, 0); if (curvename) name = xasprintf ("%s", curvename); else if (curve) diff --git a/common/util.h b/common/util.h index 9d73412c3..8ad805832 100644 --- a/common/util.h +++ b/common/util.h @@ -232,6 +232,7 @@ int openpgp_oidbuf_is_cv25519 (const void *buf, size_t len); int openpgp_oid_is_cv25519 (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_oid_or_name_to_curve (const char *oidname, int canon); const char *openpgp_enum_curves (int *idxp); const char *openpgp_is_curve_supported (const char *name, int *r_algo, unsigned int *r_nbits); |