From 14af2be022ccaf826db048fc16959d0222ff1134 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 10 Mar 2015 15:26:02 +0100 Subject: gpg: Add --list-gcrypt-config and "curve" item for --list-config. * common/openpgp-oid.c (curve_supported_p): New. (openpgp_enum_curves): New. * common/t-openpgp-oid.c (test_openpgp_enum_curves): New. (main): Add option --verbose. * g10/gpg.c (opts): Add --list-gcrypt-config. (list_config): Add items "curve" and "curveoid". Remove unused code. -- GnuPG-bug-id: 1917 Signed-off-by: Werner Koch --- common/openpgp-oid.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'common/openpgp-oid.c') diff --git a/common/openpgp-oid.c b/common/openpgp-oid.c index a0e5566d8..ccb67bbaa 100644 --- a/common/openpgp-oid.c +++ b/common/openpgp-oid.c @@ -347,3 +347,41 @@ openpgp_oid_to_curve (const char *oidstr) return "?"; } + + +/* Return true if the curve with NAME is supported. */ +static int +curve_supported_p (const char *name) +{ + int result = 0; + gcry_sexp_t keyparms; + + if (!gcry_sexp_build (&keyparms, NULL, "(public-key(ecc(curve %s)))", name)) + { + result = !!gcry_pk_get_curve (keyparms, 0, NULL); + gcry_sexp_release (keyparms); + } + return result; +} + + +/* Enumerate available and supported OpenPGP curves. The caller needs + to set the integer variable at ITERP to zero and keep on calling + this fucntion until NULL is returned. */ +const char * +openpgp_enum_curves (int *iterp) +{ + int idx = *iterp; + + while (idx >= 0 && idx < DIM (oidtable) && oidtable[idx].name) + { + if (curve_supported_p (oidtable[idx].name)) + { + *iterp = idx + 1; + return oidtable[idx].alias? oidtable[idx].alias : oidtable[idx].name; + } + idx++; + } + *iterp = idx; + return NULL; +} -- cgit v1.2.3