Support the Kyber algorithm in key listings.

* src/gpgme.h.in (GPGME_PK_KYBER): New.
* src/conversion.c (_gpgme_map_pk_algo): Handle Kyber.
* src/gpgme.c (gpgme_pubkey_algo_string): Support Kyber.
(gpgme_pubkey_algo_name): Add Kyber.
This commit is contained in:
Werner Koch 2024-11-14 12:31:21 +01:00
parent 32b4e4a9b5
commit 62b6c1f16a
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 17 additions and 5 deletions

View File

@ -650,7 +650,7 @@ _gpgme_map_pk_algo (int algo, gpgme_protocol_t protocol)
{ {
switch (algo) switch (algo)
{ {
case 1: case 2: case 3: case 16: case 17: break; case 1: case 2: case 3: case 8: case 16: case 17: break;
case 18: algo = GPGME_PK_ECDH; break; case 18: algo = GPGME_PK_ECDH; break;
case 19: algo = GPGME_PK_ECDSA; break; case 19: algo = GPGME_PK_ECDSA; break;
case 20: break; case 20: break;

View File

@ -1295,6 +1295,7 @@ gpgme_pubkey_algo_string (gpgme_subkey_t subkey)
{ {
const char *prefix = NULL; const char *prefix = NULL;
char *result; char *result;
int composite = 0;
if (!subkey) if (!subkey)
{ {
@ -1306,6 +1307,7 @@ gpgme_pubkey_algo_string (gpgme_subkey_t subkey)
{ {
case GPGME_PK_RSA: case GPGME_PK_RSA:
case GPGME_PK_RSA_E: case GPGME_PK_RSA_E:
case GPGME_PK_KYBER: composite = 1; break;
case GPGME_PK_RSA_S: prefix = "rsa"; break; case GPGME_PK_RSA_S: prefix = "rsa"; break;
case GPGME_PK_ELG_E: prefix = "elg"; break; case GPGME_PK_ELG_E: prefix = "elg"; break;
case GPGME_PK_DSA: prefix = "dsa"; break; case GPGME_PK_DSA: prefix = "dsa"; break;
@ -1316,9 +1318,12 @@ gpgme_pubkey_algo_string (gpgme_subkey_t subkey)
case GPGME_PK_EDDSA: prefix = ""; break; case GPGME_PK_EDDSA: prefix = ""; break;
} }
if (prefix && *prefix) if (composite && subkey->curve)
result = strdup (subkey->curve);
else if (prefix && *prefix)
{ {
char buffer[40]; char buffer[40];
snprintf (buffer, sizeof buffer, "%s%u", prefix, subkey->length); snprintf (buffer, sizeof buffer, "%s%u", prefix, subkey->length);
result = strdup (buffer); result = strdup (buffer);
} }
@ -1341,6 +1346,7 @@ gpgme_pubkey_algo_name (gpgme_pubkey_algo_t algo)
case GPGME_PK_RSA: return "RSA"; case GPGME_PK_RSA: return "RSA";
case GPGME_PK_RSA_E: return "RSA-E"; case GPGME_PK_RSA_E: return "RSA-E";
case GPGME_PK_RSA_S: return "RSA-S"; case GPGME_PK_RSA_S: return "RSA-S";
case GPGME_PK_KYBER: return "KYBER";
case GPGME_PK_ELG_E: return "ELG-E"; case GPGME_PK_ELG_E: return "ELG-E";
case GPGME_PK_DSA: return "DSA"; case GPGME_PK_DSA: return "DSA";
case GPGME_PK_ECC: return "ECC"; case GPGME_PK_ECC: return "ECC";

View File

@ -270,6 +270,7 @@ typedef enum
GPGME_PK_RSA = 1, GPGME_PK_RSA = 1,
GPGME_PK_RSA_E = 2, GPGME_PK_RSA_E = 2,
GPGME_PK_RSA_S = 3, GPGME_PK_RSA_S = 3,
GPGME_PK_KYBER = 8,
GPGME_PK_ELG_E = 16, GPGME_PK_ELG_E = 16,
GPGME_PK_DSA = 17, GPGME_PK_DSA = 17,
GPGME_PK_ECC = 18, GPGME_PK_ECC = 18,
@ -616,7 +617,8 @@ struct _gpgme_subkey
/* The serial number of a smart card holding this key or NULL. */ /* The serial number of a smart card holding this key or NULL. */
char *card_number; char *card_number;
/* The name of the curve for ECC algorithms or NULL. */ /* The name of the curve for ECC algorithms, or the entire algorithm
* string for composite algorithms, or NULL. */
char *curve; char *curve;
/* The keygrip of the subkey in hex digit form or NULL if not available. */ /* The keygrip of the subkey in hex digit form or NULL if not available. */

View File

@ -347,13 +347,17 @@ main (int argc, char **argv)
subkey = key->subkeys; subkey = key->subkeys;
for (nsub=0; subkey; subkey = subkey->next, nsub++) for (nsub=0; subkey; subkey = subkey->next, nsub++)
{ {
char *algostr;
printf ("fpr %2d: %s\n", nsub, nonnull (subkey->fpr)); printf ("fpr %2d: %s\n", nsub, nonnull (subkey->fpr));
if (subkey->v5fpr) if (subkey->v5fpr)
printf ("v5fpr %2d: %s\n", nsub, nonnull (subkey->v5fpr)); printf ("v5fpr %2d: %s\n", nsub, nonnull (subkey->v5fpr));
if (subkey->keygrip) if (subkey->keygrip)
printf ("grip %2d: %s\n", nsub, subkey->keygrip); printf ("grip %2d: %s\n", nsub, subkey->keygrip);
if (subkey->curve) algostr = gpgme_pubkey_algo_string (subkey);
printf ("curve %2d: %s\n", nsub, subkey->curve); printf ("algo %2d: %s (%s)\n", nsub, algostr,
gpgme_pubkey_algo_name (subkey->pubkey_algo));
gpgme_free (algostr);
printf ("caps %2d: %s%s%s%s%s%s\n", printf ("caps %2d: %s%s%s%s%s%s\n",
nsub, nsub,
subkey->can_encrypt? "e":"", subkey->can_encrypt? "e":"",