diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/openpgp-oid.c | 30 | ||||
-rw-r--r-- | common/openpgpdefs.h | 8 |
2 files changed, 37 insertions, 1 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; + } +} diff --git a/common/openpgpdefs.h b/common/openpgpdefs.h index 868e141ce..2962fe2d4 100644 --- a/common/openpgpdefs.h +++ b/common/openpgpdefs.h @@ -209,8 +209,14 @@ compress_algo_t; #define S2K_DECODE_COUNT(_val) ((16ul + ((_val) & 15)) << (((_val) >> 4) + 6)) -/*--openpgp-s2k.c --*/ +/*-- openpgp-s2k.c --*/ unsigned char encode_s2k_iterations (int iterations); +/*-- openpgp-oid.c --*/ +pubkey_algo_t map_gcry_pk_to_openpgp (enum gcry_pk_algos algo); +enum gcry_pk_algos map_openpgp_pk_to_gcry (pubkey_algo_t algo); + + + #endif /*GNUPG_COMMON_OPENPGPDEFS_H*/ |