diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/openpgp-misc.c | 37 | ||||
-rw-r--r-- | common/openpgpdefs.h | 6 |
2 files changed, 12 insertions, 31 deletions
diff --git a/common/openpgp-misc.c b/common/openpgp-misc.c index 2caad9093..178a4938e 100644 --- a/common/openpgp-misc.c +++ b/common/openpgp-misc.c @@ -23,45 +23,28 @@ #include "util.h" #include "openpgpdefs.h" +/* + * Parse the key (pubkey or seckey), and return real version of the + * key; That is, for Ed448/X448, return key with prefix removed. + */ gcry_mpi_t -openpgp_ecc_parse_pubkey (pubkey_algo_t pkalgo, const char *curve, - gcry_mpi_t pubkey) -{ - unsigned int nbits = 0; - unsigned char *buf = NULL; - - if ((pkalgo == PUBKEY_ALGO_EDDSA && !strcmp (curve, "Ed448")) - || (pkalgo == PUBKEY_ALGO_ECDH && !strcmp (curve, "X448"))) - buf = gcry_mpi_get_opaque (pubkey, &nbits); - - if (nbits == 0 - || (pkalgo == PUBKEY_ALGO_EDDSA && (nbits+7)/8 == (448 + 8)/8) - || (pkalgo == PUBKEY_ALGO_ECDH && (nbits+7)/8 == 448/8)) - return gcry_mpi_copy (pubkey); - - if (pkalgo == PUBKEY_ALGO_EDDSA) - return gcry_mpi_set_opaque_copy (NULL, buf+1, 8 + 448); - else - return gcry_mpi_set_opaque_copy (NULL, buf+1, 448); -} - - -gcry_mpi_t -openpgp_ecc_parse_seckey (pubkey_algo_t pkalgo, const char *curve, - gcry_mpi_t seckey) +openpgp_ecc_parse_key (pubkey_algo_t pkalgo, const char *curve, + gcry_mpi_t key) { unsigned int nbits = 0; unsigned char *buf = NULL; if ((pkalgo == PUBKEY_ALGO_EDDSA && !strcmp (curve, "Ed448")) || (pkalgo == PUBKEY_ALGO_ECDH && !strcmp (curve, "X448"))) - buf = gcry_mpi_get_opaque (seckey, &nbits); + buf = gcry_mpi_get_opaque (key, &nbits); + /* Either Ed448/X448 non-prefixed or not Ed448/X448. */ if (nbits == 0 || (pkalgo == PUBKEY_ALGO_EDDSA && (nbits+7)/8 == (448 + 8)/8) || (pkalgo == PUBKEY_ALGO_ECDH && (nbits+7)/8 == 448/8)) - return gcry_mpi_copy (seckey); + return gcry_mpi_copy (key); + /* Ed448 or X448 prefixed. */ if (pkalgo == PUBKEY_ALGO_EDDSA) return gcry_mpi_set_opaque_copy (NULL, buf+1, 8 + 448); else diff --git a/common/openpgpdefs.h b/common/openpgpdefs.h index 4e5500d0b..2ed4a6cd0 100644 --- a/common/openpgpdefs.h +++ b/common/openpgpdefs.h @@ -240,9 +240,7 @@ enum gcry_pk_algos map_openpgp_pk_to_gcry (pubkey_algo_t algo); /*-- openpgp-misc.c --*/ -gcry_mpi_t openpgp_ecc_parse_pubkey (pubkey_algo_t pkalgo, const char *curve, - gcry_mpi_t pubkey); -gcry_mpi_t openpgp_ecc_parse_seckey (pubkey_algo_t pkalgo, const char *curve_oid, - gcry_mpi_t seckey); +gcry_mpi_t openpgp_ecc_parse_key (pubkey_algo_t pkalgo, const char *curve, + gcry_mpi_t key); #endif /*GNUPG_COMMON_OPENPGPDEFS_H*/ |