mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
common: New function to map hash algo names.
* common/sexputil.c (hash_algo_to_string): New. -- Libgcrypt expects lowercase names and it is cumbersome to downcase those retrieved via gcry_md_algo_name. It is easier and also faster to use a dedicated map function.
This commit is contained in:
parent
bfedc760ef
commit
5d5b70ae0f
@ -640,3 +640,44 @@ pubkey_algo_string (gcry_sexp_t s_pkey, enum gcry_pk_algos *r_algoid)
|
|||||||
xfree (algoname);
|
xfree (algoname);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Map a hash algo id from gcrypt to a string. This is the same as
|
||||||
|
* gcry_md_algo_name but the returned string is lower case, as
|
||||||
|
* expected by libksba and it avoids some overhead. */
|
||||||
|
const char *
|
||||||
|
hash_algo_to_string (int algo)
|
||||||
|
{
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
int algo;
|
||||||
|
} hashnames[] =
|
||||||
|
{
|
||||||
|
{ "sha256", GCRY_MD_SHA256 },
|
||||||
|
{ "sha512", GCRY_MD_SHA512 },
|
||||||
|
{ "sha1", GCRY_MD_SHA1 },
|
||||||
|
{ "sha384", GCRY_MD_SHA384 },
|
||||||
|
{ "sha224", GCRY_MD_SHA224 },
|
||||||
|
{ "sha3-224", GCRY_MD_SHA3_224 },
|
||||||
|
{ "sha3-256", GCRY_MD_SHA3_256 },
|
||||||
|
{ "sha3-384", GCRY_MD_SHA3_384 },
|
||||||
|
{ "sha3-512", GCRY_MD_SHA3_512 },
|
||||||
|
{ "ripemd160", GCRY_MD_RMD160 },
|
||||||
|
{ "rmd160", GCRY_MD_RMD160 },
|
||||||
|
{ "md2", GCRY_MD_MD2 },
|
||||||
|
{ "md4", GCRY_MD_MD4 },
|
||||||
|
{ "tiger", GCRY_MD_TIGER },
|
||||||
|
{ "haval", GCRY_MD_HAVAL },
|
||||||
|
#if GCRYPT_VERSION_NUMBER >= 0x010900
|
||||||
|
{ "sm3", GCRY_MD_SM3 },
|
||||||
|
#endif
|
||||||
|
{ "md5", GCRY_MD_MD5 }
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i < DIM (hashnames); i++)
|
||||||
|
if (algo == hashnames[i].algo)
|
||||||
|
return hashnames[i].name;
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
@ -202,6 +202,7 @@ int get_pk_algo_from_key (gcry_sexp_t key);
|
|||||||
int get_pk_algo_from_canon_sexp (const unsigned char *keydata,
|
int get_pk_algo_from_canon_sexp (const unsigned char *keydata,
|
||||||
size_t keydatalen);
|
size_t keydatalen);
|
||||||
char *pubkey_algo_string (gcry_sexp_t s_pkey, enum gcry_pk_algos *r_algoid);
|
char *pubkey_algo_string (gcry_sexp_t s_pkey, enum gcry_pk_algos *r_algoid);
|
||||||
|
const char *hash_algo_to_string (int algo);
|
||||||
|
|
||||||
/*-- convert.c --*/
|
/*-- convert.c --*/
|
||||||
int hex2bin (const char *string, void *buffer, size_t length);
|
int hex2bin (const char *string, void *buffer, size_t length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user