mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpg: Start using OpenPGP digest algo ids.
* g10/misc.c (print_pubkey_algo_note): Use enum typedef for the arg. (print_cipher_algo_note): Ditto. (print_digest_algo_note): Ditto. (map_md_openpgp_to_gcry): New. (openpgp_md_test_algo): Rewrite. (openpgp_md_algo_name): Rewrite to do without Libgcrypt. * g10/cpr.c (write_status_begin_signing): Remove hardwired list of algo ranges.
This commit is contained in:
parent
16a6311ade
commit
bf50604a0d
17
g10/cpr.c
17
g10/cpr.c
@ -307,24 +307,19 @@ write_status_begin_signing (gcry_md_hd_t md)
|
||||
{
|
||||
char buf[100];
|
||||
size_t buflen;
|
||||
int i;
|
||||
int i, ga;
|
||||
|
||||
/* We use a hard coded list of possible algorithms. Using other
|
||||
algorithms than specified by OpenPGP does not make sense
|
||||
anyway. We do this out of performance reasons: Walking all
|
||||
the 110 allowed Ids is not a good idea given the way the
|
||||
check is implemented in libgcrypt. Recall that the only use
|
||||
of this status code is to create the micalg algorithm for
|
||||
PGP/MIME. */
|
||||
buflen = 0;
|
||||
for (i=1; i <= 11; i++)
|
||||
if (i < 4 || i > 7)
|
||||
if (gcry_md_is_enabled (md, i) && buflen < DIM(buf))
|
||||
for (i=1; i <= 110; i++)
|
||||
{
|
||||
ga = map_md_openpgp_to_gcry (i);
|
||||
if (ga && gcry_md_is_enabled (md, ga) && buflen+10 < DIM(buf))
|
||||
{
|
||||
snprintf (buf+buflen, DIM(buf) - buflen - 1,
|
||||
"%sH%d", buflen? " ":"",i);
|
||||
buflen += strlen (buf+buflen);
|
||||
}
|
||||
}
|
||||
write_status_text (STATUS_BEGIN_SIGNING, buf);
|
||||
}
|
||||
else
|
||||
|
@ -71,9 +71,9 @@ extern int g10_errors_seen;
|
||||
#else
|
||||
void g10_exit(int rc);
|
||||
#endif
|
||||
void print_pubkey_algo_note( int algo );
|
||||
void print_cipher_algo_note( int algo );
|
||||
void print_digest_algo_note( int algo );
|
||||
void print_pubkey_algo_note (pubkey_algo_t algo);
|
||||
void print_cipher_algo_note (cipher_algo_t algo);
|
||||
void print_digest_algo_note (digest_algo_t algo);
|
||||
|
||||
/*-- armor.c --*/
|
||||
char *make_radix64_string( const byte *data, size_t len );
|
||||
@ -108,7 +108,8 @@ int openpgp_pk_test_algo2 (pubkey_algo_t algo, unsigned int use);
|
||||
int openpgp_pk_algo_usage ( int algo );
|
||||
const char *openpgp_pk_algo_name (pubkey_algo_t algo);
|
||||
|
||||
int openpgp_md_test_algo( int algo );
|
||||
enum gcry_md_algos map_md_openpgp_to_gcry (digest_algo_t algo);
|
||||
int openpgp_md_test_algo (digest_algo_t algo);
|
||||
const char *openpgp_md_algo_name (int algo);
|
||||
|
||||
struct expando_args
|
||||
|
67
g10/misc.c
67
g10/misc.c
@ -1,6 +1,7 @@
|
||||
/* misc.c - miscellaneous functions
|
||||
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
|
||||
* 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2014 Werner Koch
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
@ -286,7 +287,7 @@ buffer_to_u32( const byte *buffer )
|
||||
}
|
||||
|
||||
void
|
||||
print_pubkey_algo_note( int algo )
|
||||
print_pubkey_algo_note (pubkey_algo_t algo)
|
||||
{
|
||||
if(algo >= 100 && algo <= 110)
|
||||
{
|
||||
@ -305,7 +306,7 @@ print_pubkey_algo_note( int algo )
|
||||
}
|
||||
|
||||
void
|
||||
print_cipher_algo_note( int algo )
|
||||
print_cipher_algo_note (cipher_algo_t algo)
|
||||
{
|
||||
if(algo >= 100 && algo <= 110)
|
||||
{
|
||||
@ -320,7 +321,7 @@ print_cipher_algo_note( int algo )
|
||||
}
|
||||
|
||||
void
|
||||
print_digest_algo_note( int algo )
|
||||
print_digest_algo_note (digest_algo_t algo)
|
||||
{
|
||||
if(algo >= 100 && algo <= 110)
|
||||
{
|
||||
@ -579,17 +580,43 @@ openpgp_pk_algo_name (pubkey_algo_t algo)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
openpgp_md_test_algo( int algo )
|
||||
/* Explicit mapping of OpenPGP digest algos to Libgcrypt. */
|
||||
/* FIXME: We do not yes use it everywhere. */
|
||||
enum gcry_md_algos
|
||||
map_md_openpgp_to_gcry (digest_algo_t algo)
|
||||
{
|
||||
/* Note: If the list of actual supported OpenPGP algorithms changes,
|
||||
make sure that our hard coded values at
|
||||
print_status_begin_signing() gets updated. */
|
||||
/* 4, 5, 6, 7 are defined by rfc2440 but will be removed from the
|
||||
next revision of the standard. */
|
||||
if (algo < 0 || algo > 110 || (algo >= 4 && algo <= 7))
|
||||
switch (algo)
|
||||
{
|
||||
case DIGEST_ALGO_MD5: return GCRY_MD_MD5;
|
||||
case DIGEST_ALGO_SHA1: return GCRY_MD_SHA1;
|
||||
case DIGEST_ALGO_RMD160: return GCRY_MD_RMD160;
|
||||
case DIGEST_ALGO_SHA224: return GCRY_MD_SHA224;
|
||||
case DIGEST_ALGO_SHA256: return GCRY_MD_SHA256;
|
||||
case DIGEST_ALGO_SHA384: return GCRY_MD_SHA384;
|
||||
case DIGEST_ALGO_SHA512: return GCRY_MD_SHA512;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Return 0 if ALGO is suitable and implemented OpenPGP hash
|
||||
algorithm. Note: To only test for a valid OpenPGP hash algorithm,
|
||||
it is better to use map_md_openpgp_to_gcry. */
|
||||
int
|
||||
openpgp_md_test_algo (digest_algo_t algo)
|
||||
{
|
||||
enum gcry_md_algos ga;
|
||||
|
||||
ga = map_md_openpgp_to_gcry (algo);
|
||||
switch (algo)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!ga)
|
||||
return gpg_error (GPG_ERR_DIGEST_ALGO);
|
||||
return gcry_md_test_algo (algo);
|
||||
|
||||
return gcry_md_test_algo (ga);
|
||||
}
|
||||
|
||||
|
||||
@ -599,9 +626,17 @@ openpgp_md_test_algo( int algo )
|
||||
const char *
|
||||
openpgp_md_algo_name (int algo)
|
||||
{
|
||||
if (algo < 0 || algo > 110)
|
||||
return "?";
|
||||
return gcry_md_algo_name (algo);
|
||||
switch (algo)
|
||||
{
|
||||
case DIGEST_ALGO_MD5: return "MD5";
|
||||
case DIGEST_ALGO_SHA1: return "SHA1";
|
||||
case DIGEST_ALGO_RMD160: return "RIPEMD160";
|
||||
case DIGEST_ALGO_SHA256: return "SHA256";
|
||||
case DIGEST_ALGO_SHA384: return "SHA384";
|
||||
case DIGEST_ALGO_SHA512: return "SHA512";
|
||||
case DIGEST_ALGO_SHA224: return "SHA224";
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
|
||||
@ -920,6 +955,8 @@ string_to_digest_algo (const char *string)
|
||||
{
|
||||
int val;
|
||||
|
||||
/* FIXME: We should make use of our wrapper fucntion and not assume
|
||||
that there is a 1 to 1 mapping between OpenPGP and Libgcrypt. */
|
||||
val = gcry_md_map_name (string);
|
||||
if (!val && string && (string[0]=='H' || string[0]=='h'))
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user