OID functionality moved to a separate module.

A new OID module has been created that contains the main OID searching
functionality based on type-dependent arrays. A base type is used to
contain the basic values (oid_descriptor_t) and that type is extended to
contain type specific information (like a pk_alg_t).

As a result the rsa sign and verify function prototypes have changed. They
now expect a md_type_t identifier instead of the removed RSA_SIG_XXX
defines.

All OID definitions have been moved to oid.h
All OID matching code is in the OID module.

The RSA PKCS#1 functions cleaned up as a result and adapted to use the
MD layer.

The SSL layer cleanup up as a result and adapted to use the MD layer.

The X509 parser cleaned up and matches OIDs in certificates with new
module and adapted to use the MD layer.

The X509 writer cleaned up and adapted to use the MD layer.

Apps and tests modified accordingly
diff --git a/library/x509write.c b/library/x509write.c
index 026afe6..cf68b02 100644
--- a/library/x509write.c
+++ b/library/x509write.c
@@ -30,24 +30,8 @@
 #include "polarssl/asn1write.h"
 #include "polarssl/x509write.h"
 #include "polarssl/x509.h"
-#if defined(POLARSSL_MD2_C)
-#include "polarssl/md2.h"
-#endif
-#if defined(POLARSSL_MD4_C)
-#include "polarssl/md4.h"
-#endif
-#if defined(POLARSSL_MD5_C)
-#include "polarssl/md5.h"
-#endif
-#if defined(POLARSSL_SHA1_C)
-#include "polarssl/sha1.h"
-#endif
-#if defined(POLARSSL_SHA2_C)
-#include "polarssl/sha2.h"
-#endif
-#if defined(POLARSSL_SHA4_C)
-#include "polarssl/sha4.h"
-#endif
+#include "polarssl/md.h"
+#include "polarssl/oid.h"
 
 int x509_write_pubkey_der( unsigned char *buf, size_t size, rsa_context *rsa )
 {
@@ -157,41 +141,7 @@
     return( len );
 }
 
-/*
- * Wrapper for x509 hashes.
- */
-static void x509_hash( const unsigned char *in, size_t len, int alg,
-                       unsigned char *out )
-{
-    switch( alg )
-    {
-#if defined(POLARSSL_MD2_C)
-        case SIG_RSA_MD2    :  md2( in, len, out ); break;
-#endif
-#if defined(POLARSSL_MD4_C)
-        case SIG_RSA_MD4    :  md4( in, len, out ); break;
-#endif
-#if defined(POLARSSL_MD5_C)
-        case SIG_RSA_MD5    :  md5( in, len, out ); break;
-#endif
-#if defined(POLARSSL_SHA1_C)
-        case SIG_RSA_SHA1   : sha1( in, len, out ); break;
-#endif
-#if defined(POLARSSL_SHA2_C)
-        case SIG_RSA_SHA224 : sha2( in, len, out, 1 ); break;
-        case SIG_RSA_SHA256 : sha2( in, len, out, 0 ); break;
-#endif
-#if defined(POLARSSL_SHA4_C)
-        case SIG_RSA_SHA384 : sha4( in, len, out, 1 ); break;
-        case SIG_RSA_SHA512 : sha4( in, len, out, 0 ); break;
-#endif
-        default:
-            memset( out, '\xFF', 64 );
-            break;
-    }
-}
-
-int x509_write_sig( unsigned char **p, unsigned char *start, char *oid,
+int x509_write_sig( unsigned char **p, unsigned char *start, const char *oid,
                     unsigned char *sig, size_t size )
 {
     int ret;
@@ -218,10 +168,10 @@
 }
 
 int x509_write_cert_req( unsigned char *buf, size_t size, rsa_context *rsa,
-                         x509_req_name *req_name, int hash_id )
+                         x509_req_name *req_name, md_type_t md_alg )
 {
     int ret;
-    char sig_oid[10];
+    const char *sig_oid;
     unsigned char *c, *c2;
     unsigned char hash[64];
     unsigned char sig[POLARSSL_MPI_MAX_SIZE];
@@ -272,15 +222,13 @@
     ASN1_CHK_ADD( len, asn1_write_len( &c, tmp_buf, len ) );
     ASN1_CHK_ADD( len, asn1_write_tag( &c, tmp_buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
     
-    x509_hash( c, len, hash_id, hash );
+    md( md_info_from_type( md_alg ), c, len, hash );
 
-    rsa_pkcs1_sign( rsa, NULL, NULL, RSA_PRIVATE, hash_id, 0, hash, sig );
+    rsa_pkcs1_sign( rsa, NULL, NULL, RSA_PRIVATE, md_alg, 0, hash, sig );
 
     // Generate correct OID
     //
-    memcpy( sig_oid, OID_PKCS1, 8 );
-    sig_oid[8] = hash_id;
-    sig_oid[9] = '\0';
+    ret = oid_get_oid_by_sig_alg( POLARSSL_PK_RSA, md_alg, &sig_oid );
 
     c2 = buf + size - 1;
     ASN1_CHK_ADD( sig_len, x509_write_sig( &c2, buf, sig_oid, sig, rsa->len ) );