aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2021-10-21 05:07:30 +0000
committerNIIBE Yutaka <[email protected]>2021-10-21 05:07:30 +0000
commit2b08e8484921dc965e91c1592cabcd03ec99f068 (patch)
treed9e5ddc131e3815beb19e043ec42a9bc8e13b491
parentexperiment: Generate new Ed448 signature. (diff)
downloadgnupg-2b08e8484921dc965e91c1592cabcd03ec99f068.tar.gz
gnupg-2b08e8484921dc965e91c1592cabcd03ec99f068.zip
experiment: Support keygen for new Ed448/X448 keys.
Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r--g10/keygen.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/g10/keygen.c b/g10/keygen.c
index cb6487ea3..c90e95be5 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -1284,6 +1284,47 @@ write_keybinding (ctrl_t ctrl, kbnode_t root,
static gpg_error_t
+sos_fixup_pubkey_448 (int algo, gcry_mpi_t *p_pubkey)
+{
+ gcry_mpi_t pubkey_mpi;
+ gcry_mpi_t a;
+ unsigned char *p;
+ const unsigned char *p_key;
+ unsigned int nbits;
+ unsigned int len;
+
+ pubkey_mpi = *p_pubkey;
+ *p_pubkey = NULL;
+ p_key = gcry_mpi_get_opaque (pubkey_mpi, &nbits);
+ len = (nbits+7)/8;
+ if ((algo == PUBKEY_ALGO_ECDH && len != 56)
+ || (algo == PUBKEY_ALGO_EDDSA && len != 57)
+ || (algo != PUBKEY_ALGO_ECDH && algo != PUBKEY_ALGO_EDDSA))
+ {
+ gcry_mpi_release (pubkey_mpi);
+ return gpg_error (GPG_ERR_BAD_PUBKEY);
+ }
+
+ p = xtrymalloc (1 + len);
+ if (!p)
+ {
+ gcry_mpi_release (pubkey_mpi);
+ return gpg_error_from_syserror ();
+ }
+
+ p[0] = 0x40;
+ memcpy (p+1, p_key, len);
+
+ a = gcry_mpi_set_opaque (NULL, p, 0);
+ gcry_mpi_set_flag (a, GCRYMPI_FLAG_USER2);
+ *p_pubkey = a;
+ gcry_mpi_release (pubkey_mpi);
+
+ return 0;
+}
+
+
+static gpg_error_t
ecckey_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, int algo)
{
gpg_error_t err;
@@ -1335,6 +1376,14 @@ ecckey_from_sexp (gcry_mpi_t *array, gcry_sexp_t sexp, int algo)
if (err)
goto leave;
+ if (openpgp_oid_is_ed448 (array[0])
+ || openpgp_oid_is_cv448 (array[0]))
+ {
+ err = sos_fixup_pubkey_448 (algo, &array[1]);
+ if (err)
+ goto leave;
+ }
+
gcry_sexp_release (list);
if (algo == PUBKEY_ALGO_ECDH)