mirror of
git://git.gnupg.org/gnupg.git
synced 2024-11-07 21:08:51 +01:00
experiment: Support keygen for new Ed448/X448 keys.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
d506ec2685
commit
2b08e84849
49
g10/keygen.c
49
g10/keygen.c
@ -1283,6 +1283,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)
|
||||
{
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user