diff options
author | Werner Koch <[email protected]> | 2020-02-09 13:00:57 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2020-02-09 13:04:18 +0000 |
commit | 49c891a9bfac24a1d95e76d33d44a49426247777 (patch) | |
tree | 9803fe27ec8e3f8274f16da2db1191522cea6dfa /common/openpgp-oid.c | |
parent | card: Support brainpool curves in the generate command. (diff) | |
download | gnupg-49c891a9bfac24a1d95e76d33d44a49426247777.tar.gz gnupg-49c891a9bfac24a1d95e76d33d44a49426247777.zip |
common: Add OpenPGP<->Gcrypt pubkey id mapping functions.
* g10/misc.c (map_pk_gcry_to_openpgp): Move to ...
* common/openpgp-oid.c (map_gcry_pk_to_openpgp): here and rename.
Change all 4 callers.
(map_openpgp_pk_to_gcry): New.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/openpgp-oid.c')
-rw-r--r-- | common/openpgp-oid.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/common/openpgp-oid.c b/common/openpgp-oid.c index 419471870..802d71162 100644 --- a/common/openpgp-oid.c +++ b/common/openpgp-oid.c @@ -462,3 +462,33 @@ openpgp_is_curve_supported (const char *name, int *r_algo, } return NULL; } + + +/* Map a Gcrypt public key algorithm number to the used by OpenPGP. + * Returns 0 for unknown gcry algorithm. */ +pubkey_algo_t +map_gcry_pk_to_openpgp (enum gcry_pk_algos algo) +{ + switch (algo) + { + case GCRY_PK_EDDSA: return PUBKEY_ALGO_EDDSA; + case GCRY_PK_ECDSA: return PUBKEY_ALGO_ECDSA; + case GCRY_PK_ECDH: return PUBKEY_ALGO_ECDH; + default: return algo < 110 ? (pubkey_algo_t)algo : 0; + } +} + + +/* Map an OpenPGP public key algorithm number to the one used by + * Libgcrypt. Returns 0 for unknown gcry algorithm. */ +enum gcry_pk_algos +map_openpgp_pk_to_gcry (pubkey_algo_t algo) +{ + switch (algo) + { + case PUBKEY_ALGO_EDDSA: return GCRY_PK_EDDSA; + case PUBKEY_ALGO_ECDSA: return GCRY_PK_ECDSA; + case PUBKEY_ALGO_ECDH: return GCRY_PK_ECDH; + default: return algo < 110 ? algo : 0; + } +} |