diff options
author | Werner Koch <wk@gnupg.org> | 2001-11-20 16:07:24 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2001-11-20 16:07:24 +0000 |
commit | a254fd15dc5a93ee35ab10f9dfba6b8481120525 (patch) | |
tree | c3b4c6a4342d4ef9af25bd6f5595a1f104f6a6fa /cipher/md.c | |
parent | 47fd6ef8d201a2a8ea5bfa86baf269f851d804e4 (diff) | |
download | libgcrypt-a254fd15dc5a93ee35ab10f9dfba6b8481120525.tar.gz |
* md.c (gcry_md_map_name): Lookup by OID if the the name begins
with a digit.
(oid_table): New.
Diffstat (limited to 'cipher/md.c')
-rw-r--r-- | cipher/md.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cipher/md.c b/cipher/md.c index e7671366..e29b8991 100644 --- a/cipher/md.c +++ b/cipher/md.c @@ -31,6 +31,24 @@ #include "rmd.h" +static struct { + const char *oidstring; + int algo; +} oid_table[] = { + /* iso.member-body.us.rsadsi.pkcs.pkcs-1.5 (sha1WithRSAEncryption) */ + { "1.2.840.113549.1.1.5", GCRY_MD_SHA1 }, + /* iso.member-body.us.rsadsi.pkcs.pkcs-1.4 (md5WithRSAEncryption) */ + { "1.2.840.113549.1.1.4", GCRY_MD_MD5 }, + /* iso.member-body.us.x9-57.x9cm.3 (dsaWithSha1)*/ + { "1.2.840.10040.4.3", GCRY_MD_SHA1 }, + /* from NIST's OIW (sha1) */ + { "1.3.14.3.2.26", GCRY_MD_SHA1 }, + {NULL} +}; + + + + struct md_digest_list_s; /* this structure is put right after the GCRY_MD_HD buffer, so that @@ -82,7 +100,11 @@ struct md_digest_list_s { static struct md_digest_list_s *digest_list; +#define digitp(p) (*(p) >= 0 && *(p) <= '9') + + + static struct md_digest_list_s * new_list_item( int algo, const char *(*get_info)( int, size_t*,byte**, int*, int*, @@ -179,6 +201,21 @@ int gcry_md_map_name( const char *string ) { struct md_digest_list_s *r; + + if (!string) + return 0; + + /* If the string starts with a digit, we first look into our table + of ASN.1 object identifiers to figure out the algorithm */ + if (digitp (string)) + { + int i; + for (i=0; oid_table[i].oidstring; i++) + { + if (!strcmp (string, oid_table[i].oidstring)) + return oid_table[i].algo; + } + } do { for(r = digest_list; r; r = r->next ) |