diff options
author | Werner Koch <wk@gnupg.org> | 2024-04-18 14:37:40 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2024-04-18 14:37:40 +0200 |
commit | ba3c873934c920d18399fd194f07e0159ee31ec3 (patch) | |
tree | c461e13aa42db25c096495bbb950234f6d0a73dd /common | |
parent | gpg: Mark disabled keys and add show-ownertrust list option. (diff) | |
download | gnupg2-ba3c873934c920d18399fd194f07e0159ee31ec3.tar.xz gnupg2-ba3c873934c920d18399fd194f07e0159ee31ec3.zip |
gpg: Prepare Kyber encryption code for more variants.
* common/openpgp-oid.c (oidtable): Add field kem_algo.
(openpgp_oid_to_kem_algo): New.
* g10/pkglue.c (do_encrypt_kem): Add support for Kyber1024.
--
GnuPG-bug-id: 6815
Diffstat (limited to 'common')
-rw-r--r-- | common/openpgp-oid.c | 28 | ||||
-rw-r--r-- | common/util.h | 1 |
2 files changed, 27 insertions, 2 deletions
diff --git a/common/openpgp-oid.c b/common/openpgp-oid.c index 4b59c1aeb..74541a03f 100644 --- a/common/openpgp-oid.c +++ b/common/openpgp-oid.c @@ -45,14 +45,15 @@ static struct { const char *alias; /* NULL or alternative name of the curve. */ const char *abbr; /* NULL or abbreviated name of the curve. */ int pubkey_algo; /* Required OpenPGP algo or 0 for ECDSA/ECDH. */ + enum gcry_kem_algos kem_algo; /* 0 or the KEM algorithm for PQC. */ } oidtable[] = { { "Curve25519", "1.3.6.1.4.1.3029.1.5.1", 255, "cv25519", NULL, - PUBKEY_ALGO_ECDH }, + PUBKEY_ALGO_ECDH, GCRY_KEM_RAW_X25519 /* only during development */}, { "Ed25519", "1.3.6.1.4.1.11591.15.1", 255, "ed25519", NULL, PUBKEY_ALGO_EDDSA }, { "Curve25519", "1.3.101.110", 255, "cv25519", NULL, - PUBKEY_ALGO_ECDH }, + PUBKEY_ALGO_ECDH, GCRY_KEM_RAW_X25519 }, { "Ed25519", "1.3.101.112", 255, "ed25519", NULL, PUBKEY_ALGO_EDDSA }, { "X448", "1.3.101.111", 448, "cv448", NULL, @@ -542,6 +543,29 @@ openpgp_oid_or_name_to_curve (const char *oidname, int canon) } +/* Return the KEM algorithm id for the curve with OIDNAME. */ +enum gcry_kem_algos +openpgp_oid_to_kem_algo (const char *oidname) +{ + int i; + + if (!oidname) + return 0; + + for (i=0; oidtable[i].name; i++) + if (!strcmp (oidtable[i].oidstr, oidname)) + return oidtable[i].kem_algo; + + for (i=0; oidtable[i].name; i++) + if (!ascii_strcasecmp (oidtable[i].name, oidname) + || (oidtable[i].alias + && !ascii_strcasecmp (oidtable[i].alias, oidname))) + return oidtable[i].kem_algo; + + return 0; +} + + /* Return true if the curve with NAME is supported. */ static int curve_supported_p (const char *name) diff --git a/common/util.h b/common/util.h index 5c953a8a1..238b8f1bc 100644 --- a/common/util.h +++ b/common/util.h @@ -227,6 +227,7 @@ int openpgp_oidbuf_is_cv25519 (const void *buf, size_t len); int openpgp_oid_is_cv25519 (gcry_mpi_t a); int openpgp_oid_is_cv448 (gcry_mpi_t a); int openpgp_oid_is_ed448 (gcry_mpi_t a); +enum gcry_kem_algos openpgp_oid_to_kem_algo (const char *oidname); const char *openpgp_curve_to_oid (const char *name, unsigned int *r_nbits, int *r_algo); const char *openpgp_oid_to_curve (const char *oid, int mode); |