summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2003-03-17 16:23:29 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2003-03-17 16:23:29 +0000
commitf3c51cc7fa0d88f56b29f035da25c05fa9d31d5e (patch)
treee0be257fc65eb851c6a1c9f811520c852953f4de
parent2e6177070cf5f2eca7cfc569bd83050f3fdb85c6 (diff)
downloadgnutls-f3c51cc7fa0d88f56b29f035da25c05fa9d31d5e.tar.gz
some cleanups.
-rw-r--r--lib/gnutls_hash_int.c22
-rw-r--r--lib/x509/common.c22
-rw-r--r--lib/x509/common.h4
-rw-r--r--lib/x509/sign.c19
-rw-r--r--lib/x509/verify.c10
5 files changed, 34 insertions, 43 deletions
diff --git a/lib/gnutls_hash_int.c b/lib/gnutls_hash_int.c
index ebbb06b830..4095adc2c2 100644
--- a/lib/gnutls_hash_int.c
+++ b/lib/gnutls_hash_int.c
@@ -207,27 +207,7 @@ GNUTLS_MAC_HANDLE _gnutls_hmac_init(gnutls_mac_algorithm algorithm,
int _gnutls_hmac_get_algo_len(gnutls_mac_algorithm algorithm)
{
- int ret;
-
- switch (algorithm) {
- case GNUTLS_MAC_NULL:
- ret = 0;
- break;
- case GNUTLS_MAC_SHA:
- ret = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
- break;
- case GNUTLS_MAC_MD5:
- ret = gcry_md_get_algo_dlen(GCRY_MD_MD5);
- break;
- case GNUTLS_MAC_MD2:
- ret = gcry_md_get_algo_dlen(GCRY_MD_MD2);
- break;
- default:
- ret = 0;
- }
-
- return ret;
-
+ return _gnutls_hash_get_algo_len( algorithm);
}
int _gnutls_hmac(GNUTLS_MAC_HANDLE handle, const void *text, size_t textlen)
diff --git a/lib/x509/common.c b/lib/x509/common.c
index a196765810..d6ae77f022 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -236,6 +236,28 @@ gnutls_pk_algorithm _gnutls_x509_oid2pk_algorithm( const char* oid)
return GNUTLS_PK_UNKNOWN;
}
+/* returns -1 on error
+ */
+gnutls_mac_algorithm _gnutls_x509_oid2mac_algorithm( const char* oid)
+{
+ if (strcmp( oid, OID_SHA1) == 0)
+ return GNUTLS_MAC_SHA;
+ else if (strcmp( oid, OID_MD5) == 0)
+ return GNUTLS_MAC_MD5;
+ else if (strcmp( oid, OID_MD2) == 0)
+ return GNUTLS_MAC_MD2;
+
+ return (gnutls_mac_algorithm)-1;
+}
+
+const char* _gnutls_x509_mac2oid( gnutls_mac_algorithm mac)
+{
+ if (mac == GNUTLS_MAC_SHA) return OID_SHA1;
+ else if (mac == GNUTLS_MAC_MD5) return OID_MD5;
+ else if (mac == GNUTLS_MAC_MD2) return OID_MD2;
+ else return NULL;
+}
+
const char* _gnutls_x509_pk2oid( gnutls_pk_algorithm pk)
{
if (pk == GNUTLS_PK_RSA) return PKIX1_RSA_OID;
diff --git a/lib/x509/common.h b/lib/x509/common.h
index c3d07a4d82..14dcdac7ef 100644
--- a/lib/x509/common.h
+++ b/lib/x509/common.h
@@ -18,9 +18,13 @@ const char* _gnutls_x509_oid2ldap_string( const char* OID);
int _gnutls_x509_oid_data_choice( const char* OID);
int _gnutls_x509_oid_data_printable( const char* OID);
+
gnutls_pk_algorithm _gnutls_x509_oid2pk_algorithm( const char* oid);
+gnutls_mac_algorithm _gnutls_x509_oid2mac_algorithm( const char* oid);
+
const char* _gnutls_x509_pk2oid( gnutls_pk_algorithm pk);
const char* _gnutls_x509_sign2oid( gnutls_pk_algorithm pk, gnutls_mac_algorithm mac);
+const char* _gnutls_x509_mac2oid( gnutls_mac_algorithm mac);
time_t _gnutls_x509_get_time(ASN1_TYPE c2, const char *when);
diff --git a/lib/x509/sign.c b/lib/x509/sign.c
index 0a345a20db..c6ff7ee609 100644
--- a/lib/x509/sign.c
+++ b/lib/x509/sign.c
@@ -36,6 +36,7 @@
#include <x509.h>
#include <mpi.h>
#include <sign.h>
+#include <common.h>
#include <verify.h>
/* Writes the digest information and the digest in a DER encoded
@@ -46,20 +47,12 @@ static int encode_ber_digest_info( gnutls_mac_algorithm hash,
{
ASN1_TYPE dinfo = ASN1_TYPE_EMPTY;
int result;
-char* algo;
+const char* algo;
- switch(hash) {
- case GNUTLS_MAC_MD5:
- algo = OID_MD5;
- break;
- case GNUTLS_MAC_MD2:
- algo = OID_MD2;
- break;
- case GNUTLS_MAC_SHA:
- algo = OID_SHA1;
- break;
- default:
- return GNUTLS_E_UNIMPLEMENTED_FEATURE;
+ algo = _gnutls_x509_mac2oid( hash);
+ if (algo == NULL) {
+ gnutls_assert();
+ return GNUTLS_E_UNIMPLEMENTED_FEATURE;
}
if ((result=asn1_create_element( _gnutls_get_gnutls_asn(),
diff --git a/lib/x509/verify.c b/lib/x509/verify.c
index b2f348b668..c8b4c0c0ac 100644
--- a/lib/x509/verify.c
+++ b/lib/x509/verify.c
@@ -391,15 +391,7 @@ int len;
return _gnutls_asn2err(result);
}
- *hash = (gnutls_mac_algorithm)-1;
-
- if ( strcmp(str, OID_MD5)==0) { /* MD5 */
- *hash = GNUTLS_MAC_MD5;
- } else if ( strcmp(str, OID_SHA1)==0) { /* SHA1 ID */
- *hash = GNUTLS_MAC_SHA;
- } else if ( strcmp(str, OID_MD2)==0) { /* MD2 */
- *hash = GNUTLS_MAC_MD2;
- }
+ *hash = _gnutls_x509_oid2mac_algorithm( str);
if (*hash==(gnutls_mac_algorithm)-1) {